QT6: Fix deprecated QRegExp

This commit is contained in:
Simon De Backer
2020-10-03 15:40:32 +02:00
parent 0b5091b606
commit 9034d8d791

View File

@@ -144,11 +144,23 @@ bool ElementsLocation::operator!=(const ElementsLocation &other) const
*/
QString ElementsLocation::baseName() const
{
QRegExp regexp("^.*([^/]+)\\.elmt$");
if (regexp.exactMatch(m_collection_path)) {
return(regexp.capturedTexts().at(1));
QRegularExpression regexp("^.*(?<name>[^/]+)\\.elmt$");
if (!regexp.isValid())
{
qWarning() <<"this is an error in the code"
<< regexp.errorString()
<< regexp.patternErrorOffset();
return QString();
}
return(QString());
QRegularExpressionMatch match = regexp.match(m_collection_path);
if (!match.hasMatch())
{
qDebug()<<"no Match => return"
<<m_collection_path;
return QString();
}
return match.captured("name");
}
/**
@@ -368,12 +380,22 @@ bool ElementsLocation::addToPath(const QString &string)
ElementsLocation ElementsLocation::parent() const
{
ElementsLocation copy(*this);
QRegExp re1("^([a-z]+://)(.*)/*$");
if (re1.exactMatch(m_collection_path)) {
QString path_proto = re1.capturedTexts().at(1);
QString path_path = re1.capturedTexts().at(2);
QString parent_path = path_path.remove(QRegExp("/*[^/]+$"));
copy.setPath(path_proto + parent_path);
QRegularExpression re ("^(?<path_proto>[a-z]+://.*)/.*$");
if (!re.isValid())
{
qWarning()
<<QObject::tr("this is an error in the code")
<< re.errorString()
<< re.patternErrorOffset();
}
QRegularExpressionMatch match = re.match(m_collection_path);
if (!match.hasMatch())
{
qDebug()
<<"no Match => return"
<<m_collection_path;
}else {
copy.setPath(match.captured("path_proto"));
}
return(copy);
}
@@ -734,6 +756,7 @@ bool ElementsLocation::setXml(const QDomDocument &xml_document) const
//Element doesn't exist, we create the element
else
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
QString path_ = collectionPath(false);
QRegExp rx ("^(.*)/(.*\\.elmt)$");
@@ -750,7 +773,12 @@ bool ElementsLocation::setXml(const QDomDocument &xml_document) const
qDebug() << "ElementsLocation::setXml :"
" rx don't match";
}
#else
#if TODO_LIST
#pragma message("@TODO remove code for QT 6 or later")
#endif
qDebug()<<"Help code for QT 6 or later";
#endif
}
}