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 QString ElementsLocation::baseName() const
{ {
QRegExp regexp("^.*([^/]+)\\.elmt$"); QRegularExpression regexp("^.*(?<name>[^/]+)\\.elmt$");
if (regexp.exactMatch(m_collection_path)) { if (!regexp.isValid())
return(regexp.capturedTexts().at(1)); {
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");
} }
/** /**
@@ -183,9 +195,9 @@ QString ElementsLocation::projectCollectionPath() const
return QString(); return QString();
else else
return QString("project" return QString("project"
+ QString::number(QETApp::projectId(m_project)) + QString::number(QETApp::projectId(m_project))
+ "+" + "+"
+ collectionPath()); + collectionPath());
} }
/** /**
@@ -254,7 +266,7 @@ void ElementsLocation::setPath(const QString &path)
if (!match.hasMatch()) if (!match.hasMatch())
{ {
qDebug()<<"no Match => return" qDebug()<<"no Match => return"
<<tmp_path; <<tmp_path;
return; return;
} }
bool conv_ok; bool conv_ok;
@@ -344,7 +356,7 @@ bool ElementsLocation::addToPath(const QString &string)
if (m_collection_path.endsWith(".elmt", Qt::CaseInsensitive)) if (m_collection_path.endsWith(".elmt", Qt::CaseInsensitive))
{ {
qDebug() << "ElementsLocation::addToPath :" qDebug() << "ElementsLocation::addToPath :"
" Can't add string to the path of an element"; " Can't add string to the path of an element";
return(false); return(false);
} }
@@ -368,12 +380,22 @@ bool ElementsLocation::addToPath(const QString &string)
ElementsLocation ElementsLocation::parent() const ElementsLocation ElementsLocation::parent() const
{ {
ElementsLocation copy(*this); ElementsLocation copy(*this);
QRegExp re1("^([a-z]+://)(.*)/*$"); QRegularExpression re ("^(?<path_proto>[a-z]+://.*)/.*$");
if (re1.exactMatch(m_collection_path)) { if (!re.isValid())
QString path_proto = re1.capturedTexts().at(1); {
QString path_path = re1.capturedTexts().at(2); qWarning()
QString parent_path = path_path.remove(QRegExp("/*[^/]+$")); <<QObject::tr("this is an error in the code")
copy.setPath(path_proto + parent_path); << 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); return(copy);
} }
@@ -700,7 +722,7 @@ bool ElementsLocation::setXml(const QDomDocument &xml_document) const
if (xml_document.documentElement().tagName() != "definition") if (xml_document.documentElement().tagName() != "definition")
{ {
qDebug() << "ElementsLocation::setXml :" qDebug() << "ElementsLocation::setXml :"
" tag name of document element isn't 'definition'"; " tag name of document element isn't 'definition'";
return false; return false;
} }
@@ -734,6 +756,7 @@ bool ElementsLocation::setXml(const QDomDocument &xml_document) const
//Element doesn't exist, we create the element //Element doesn't exist, we create the element
else else
{ {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
QString path_ = collectionPath(false); QString path_ = collectionPath(false);
QRegExp rx ("^(.*)/(.*\\.elmt)$"); QRegExp rx ("^(.*)/(.*\\.elmt)$");
@@ -748,9 +771,14 @@ bool ElementsLocation::setXml(const QDomDocument &xml_document) const
} }
else { else {
qDebug() << "ElementsLocation::setXml :" qDebug() << "ElementsLocation::setXml :"
" rx don't match"; " 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
} }
} }
@@ -863,7 +891,7 @@ QDebug operator<< (QDebug debug, const ElementsLocation &location)
QString msg; QString msg;
msg += "ElementsLocation("; msg += "ElementsLocation(";
msg += (location.isProject()? location.projectCollectionPath() msg += (location.isProject()? location.projectCollectionPath()
: location.collectionPath(true)); : location.collectionPath(true));
msg += location.exist()? ", true" : ", false"; msg += location.exist()? ", true" : ", false";
msg +=")"; msg +=")";