Fix Revert deprecated QRegExp

Use QRegularExpression instead.

https://doc.qt.io/qt-5/qregularexpression.html#notes-for-qregexp-users
This function was introduced in Qt 5

see https://qelectrotech.org/forum/viewtopic.php?pid=13406#p13406
This commit is contained in:
Simon De Backer
2020-09-23 19:03:13 +02:00
parent 86f7f98031
commit e0c8dd9585

View File

@@ -241,22 +241,38 @@ void ElementsLocation::setPath(const QString &path)
//The path start with project, we get the project and the path from the string //The path start with project, we get the project and the path from the string
else if (tmp_path.startsWith("project")) else if (tmp_path.startsWith("project"))
{ {
QRegExp rx("^project([0-9]+)\\+(embed:\\/\\/.*)$", Qt::CaseInsensitive); QRegularExpression re
if (rx.exactMatch(tmp_path)) ("^project(?<project_id>[0-9])\\+(?<collection_path>embed://*.*)$");
if (!re.isValid())
{ {
qWarning() <<"this is an error in the code"
<< re.errorString()
<< re.patternErrorOffset();
return;
}
QRegularExpressionMatch match = re.match(tmp_path);
if (!match.hasMatch())
{
qDebug()<<"no Match => return";
return;
}
bool conv_ok; bool conv_ok;
uint project_id = rx.capturedTexts().at(1).toUInt(&conv_ok); uint project_id = match.captured("project_id").toUInt(&conv_ok);
if (conv_ok) if (!conv_ok)
{ {
qWarning()<<"toUint failed"
<<match.captured("project_id")
<<re
<<tmp_path;
return;
}
QETProject *project = QETApp::project(project_id); QETProject *project = QETApp::project(project_id);
if (project) if (project)
{ {
m_collection_path = rx.capturedTexts().at(2); m_collection_path = match.captured("collection_path");
m_project = project; m_project = project;
} }
} }
}
}
// The path is in file system, // The path is in file system,
// the given path is relative to common or custom collection // the given path is relative to common or custom collection