diff --git a/src/Mod/Part/Gui/DlgExportStep.cpp b/src/Mod/Part/Gui/DlgExportStep.cpp index 90b5f6ec87..295b0a2709 100644 --- a/src/Mod/Part/Gui/DlgExportStep.cpp +++ b/src/Mod/Part/Gui/DlgExportStep.cpp @@ -25,8 +25,8 @@ #ifndef _PreComp_ # include # include -# include -# include +# include +# include # include # include #endif @@ -148,13 +148,13 @@ DlgExportHeaderStep::DlgExportHeaderStep(QWidget* parent) ui->lineEditProduct->setReadOnly(true); - QRegExp rx; + QRegularExpression rx; rx.setPattern(QString::fromLatin1("[\\x00-\\x7F]+")); - QRegExpValidator* companyValidator = new QRegExpValidator(ui->lineEditCompany); - companyValidator->setRegExp(rx); + QRegularExpressionValidator* companyValidator = new QRegularExpressionValidator(ui->lineEditCompany); + companyValidator->setRegularExpression(rx); ui->lineEditCompany->setValidator(companyValidator); - QRegExpValidator* authorValidator = new QRegExpValidator(ui->lineEditAuthor); - authorValidator->setRegExp(rx); + QRegularExpressionValidator* authorValidator = new QRegularExpressionValidator(ui->lineEditAuthor); + authorValidator->setRegularExpression(rx); ui->lineEditAuthor->setValidator(authorValidator); } diff --git a/src/Mod/Part/Gui/DlgSettingsGeneral.cpp b/src/Mod/Part/Gui/DlgSettingsGeneral.cpp index 5866363b88..d90753b05e 100644 --- a/src/Mod/Part/Gui/DlgSettingsGeneral.cpp +++ b/src/Mod/Part/Gui/DlgSettingsGeneral.cpp @@ -23,8 +23,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include -# include -# include +# include +# include # include # include #endif @@ -98,13 +98,13 @@ DlgImportExportIges::DlgImportExportIges(QWidget* parent) bg->addButton(ui->radioButtonBRepOff, 0); bg->addButton(ui->radioButtonBRepOn, 1); - QRegExp rx; + QRegularExpression rx; rx.setPattern(QString::fromLatin1("[\\x00-\\x7F]+")); - QRegExpValidator* companyValidator = new QRegExpValidator(ui->lineEditCompany); - companyValidator->setRegExp(rx); + QRegularExpressionValidator* companyValidator = new QRegularExpressionValidator(ui->lineEditCompany); + companyValidator->setRegularExpression(rx); ui->lineEditCompany->setValidator(companyValidator); - QRegExpValidator* authorValidator = new QRegExpValidator(ui->lineEditAuthor); - authorValidator->setRegExp(rx); + QRegularExpressionValidator* authorValidator = new QRegularExpressionValidator(ui->lineEditAuthor); + authorValidator->setRegularExpression(rx); ui->lineEditAuthor->setValidator(authorValidator); } diff --git a/src/Mod/Part/Gui/Mirroring.cpp b/src/Mod/Part/Gui/Mirroring.cpp index fbf77c417e..2b0e3fe108 100644 --- a/src/Mod/Part/Gui/Mirroring.cpp +++ b/src/Mod/Part/Gui/Mirroring.cpp @@ -31,7 +31,7 @@ # include # include -# include +# include # include #endif @@ -142,7 +142,7 @@ bool Mirroring::accept() activeDoc->openTransaction("Mirroring"); QString shape, label; - QRegExp rx(QString::fromLatin1(" \\(Mirror #\\d+\\)$")); + QRegularExpression rx(QString::fromLatin1(" \\(Mirror #\\d+\\)$")); QList items = ui->shapes->selectedItems(); float normx=0, normy=0, normz=0; int index = ui->comboBox->currentIndex(); diff --git a/src/Mod/Part/Gui/TaskAttacher.cpp b/src/Mod/Part/Gui/TaskAttacher.cpp index e53a416f62..40cab985da 100644 --- a/src/Mod/Part/Gui/TaskAttacher.cpp +++ b/src/Mod/Part/Gui/TaskAttacher.cpp @@ -26,7 +26,8 @@ #ifndef _PreComp_ # include # include -# include +# include +# include # include #endif @@ -616,34 +617,43 @@ void TaskAttacher::onRefName(const QString& text, unsigned idx) } else { // TODO: check validity of the text that was entered: Does subElement actually reference to an element on the obj? - // We must expect that "text" is the translation of "Face", "Edge" or "Vertex" followed by an ID. - QRegExp rx; - std::stringstream ss; + auto getSubshapeName = [](const QString& part) -> std::string { + // We must expect that "text" is the translation of "Face", "Edge" or "Vertex" followed by an ID. + QRegularExpression rx; + QRegularExpressionMatch match; + std::stringstream ss; - rx.setPattern(QString::fromLatin1("^") + tr("Face") + QString::fromLatin1("(\\d+)$")); - if (parts[1].indexOf(rx) >= 0) { - int faceId = rx.cap(1).toInt(); - ss << "Face" << faceId; - } else { - rx.setPattern(QString::fromLatin1("^") + tr("Edge") + QString::fromLatin1("(\\d+)$")); - if (parts[1].indexOf(rx) >= 0) { - int lineId = rx.cap(1).toInt(); - ss << "Edge" << lineId; - } else { - rx.setPattern(QString::fromLatin1("^") + tr("Vertex") + QString::fromLatin1("(\\d+)$")); - if (parts[1].indexOf(rx) >= 0) { - int vertexId = rx.cap(1).toInt(); - ss << "Vertex" << vertexId; - } else { - //none of Edge/Vertex/Face. May be empty string. - //Feed in whatever user supplied, even if invalid. - ss << parts[1].toLatin1().constData(); - } + rx.setPattern(QString::fromLatin1("^") + tr("Face") + QString::fromLatin1("(\\d+)$")); + if (part.indexOf(rx, 0, &match) >= 0) { + int faceId = match.captured(1).toInt(); + ss << "Face" << faceId; + return ss.str(); } - } - line->setProperty("RefName", QByteArray(ss.str().c_str())); - subElement = ss.str(); + rx.setPattern(QString::fromLatin1("^") + tr("Edge") + QString::fromLatin1("(\\d+)$")); + if (part.indexOf(rx, 0, &match) >= 0) { + int lineId = match.captured(1).toInt(); + ss << "Edge" << lineId; + return ss.str(); + } + + rx.setPattern(QString::fromLatin1("^") + tr("Vertex") + QString::fromLatin1("(\\d+)$")); + if (part.indexOf(rx, 0, &match) >= 0) { + int vertexId = match.captured(1).toInt(); + ss << "Vertex" << vertexId; + return ss.str(); + } + + //none of Edge/Vertex/Face. May be empty string. + //Feed in whatever user supplied, even if invalid. + ss << part.toLatin1().constData(); + return ss.str(); + }; + + auto name = getSubshapeName(parts[1]); + + line->setProperty("RefName", QByteArray(name.c_str())); + subElement = name; } Part::AttachExtension* pcAttach = ViewProvider->getObject()->getExtensionByType(); diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp index cd1bc567fb..668fc3663f 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp @@ -25,7 +25,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +# include +# include # include #endif @@ -158,16 +159,17 @@ QVariant TaskSketchBasedParameters::setUpToFace(const QString& text) QString name; QTextStream str(&name); str << "^" << tr("Face") << "(\\d+)$"; - QRegExp rx(name); - if (parts[1].indexOf(rx) < 0) { + QRegularExpression rx(name); + QRegularExpressionMatch match; + if (parts[1].indexOf(rx, 0, &match) < 0) { return QVariant(); } - int faceId = rx.cap(1).toInt(); + int faceId = match.captured(1).toInt(); std::stringstream ss; ss << "Face" << faceId; - std::vector upToFaces(1,ss.str()); + std::vector upToFaces(1, ss.str()); PartDesign::ProfileBased* pcSketchBased = static_cast(vp->getObject()); pcSketchBased->UpToFace.setValue(obj, upToFaces); recomputeFeature(); diff --git a/src/Mod/Path/Gui/TaskDlgPathCompound.cpp b/src/Mod/Path/Gui/TaskDlgPathCompound.cpp index 66d1dc282b..a0b9f7aeaf 100644 --- a/src/Mod/Path/Gui/TaskDlgPathCompound.cpp +++ b/src/Mod/Path/Gui/TaskDlgPathCompound.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include #endif #include "TaskDlgPathCompound.h" @@ -86,7 +87,7 @@ std::vector TaskWidgetPathCompound::getList() const { QListWidgetItem* item = ui->PathsList->item(i); QString name = item->text(); QStringList result; - result = name.split(QRegExp(QString::fromLatin1("\\s+"))); + result = name.split(QRegularExpression(QString::fromLatin1("\\s+"))); std::cout << result[0].toStdString() << std::endl; names.push_back(result[0].toStdString()); } diff --git a/src/Mod/Raytracing/Gui/PovrayHighlighter.cpp b/src/Mod/Raytracing/Gui/PovrayHighlighter.cpp index c0c30b261c..d0eb7ceeca 100644 --- a/src/Mod/Raytracing/Gui/PovrayHighlighter.cpp +++ b/src/Mod/Raytracing/Gui/PovrayHighlighter.cpp @@ -23,7 +23,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +# include +# include #endif #include "PovrayHighlighter.h" @@ -95,12 +96,13 @@ void PovrayHighlighter::highlightBlock(const QString &text) state = InsideCStyleComment; } else if (text.mid(i,1) == QLatin1String("#")) { - QRegExp rx(QLatin1String("#\\s*(\\w*)")); - int pos = text.indexOf(rx, i); - if (pos != -1) { - if (d->keywords.contains(rx.cap(1)) != 0) - setFormat(i, rx.matchedLength(), this->colorByType(SyntaxHighlighter::Keyword)); - i += rx.matchedLength(); + QRegularExpression rx(QLatin1String("#\\s*(\\w*)")); + QRegularExpressionMatch match; + text.indexOf(rx, i, &match); + if (match.hasMatch()) { + if (d->keywords.contains(match.captured(1)) != 0) + setFormat(i, match.capturedLength(), this->colorByType(SyntaxHighlighter::Keyword)); + i += match.capturedLength(); } } else if (text[i] == QLatin1Char('"')) { diff --git a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp index 0a3953d096..4ac6e54432 100644 --- a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp +++ b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp @@ -53,6 +53,8 @@ # include # include +# include + # include #endif // #ifndef _PreComp_ @@ -1669,7 +1671,7 @@ QString EditModeConstraintCoinManager::getPresentationString(const Constraint *c if (QString::compare(baseUnitStr, unitStr)==0) { // Example code from: Mod/TechDraw/App/DrawViewDimension.cpp:372 - QRegExp rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string + QRegularExpression rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string valueStr.remove(rxUnits); //getUserString(defaultDecimals) without units } } diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp index 82e5ef65d4..df2a44c8f8 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp @@ -27,7 +27,8 @@ # include # include # include -# include +# include +# include # include # include # include @@ -976,12 +977,13 @@ void TaskSketcherConstraints::onSelectionChanged(const Gui::SelectionChanges& ms if (strcmp(msg.pDocName,sketchView->getSketchObject()->getDocument()->getName())==0 && strcmp(msg.pObjectName,sketchView->getSketchObject()->getNameInDocument())== 0) { if (msg.pSubName) { - QRegExp rx(QString::fromLatin1("^Constraint(\\d+)$")); + QRegularExpression rx(QString::fromLatin1("^Constraint(\\d+)$")); + QRegularExpressionMatch match; QString expr = QString::fromLatin1(msg.pSubName); - int pos = expr.indexOf(rx); - if (pos > -1) { // is a constraint + expr.indexOf(rx, 0, &match); + if (match.hasMatch()) { // is a constraint bool ok; - int ConstrId = rx.cap(1).toInt(&ok) - 1; + int ConstrId = match.captured(1).toInt(&ok) - 1; if (ok) { int countItems = ui->listWidgetConstraints->count(); for (int i=0; i < countItems; i++) { @@ -1025,25 +1027,26 @@ void TaskSketcherConstraints::onSelectionChanged(const Gui::SelectionChanges& ms void TaskSketcherConstraints::getSelectionGeoId(QString expr, int & geoid, Sketcher::PointPos & pointpos) { - QRegExp rxEdge(QString::fromLatin1("^Edge(\\d+)$")); - int pos = expr.indexOf(rxEdge); + QRegularExpression rxEdge(QString::fromLatin1("^Edge(\\d+)$")); + QRegularExpressionMatch match; + expr.indexOf(rxEdge, 0, &match); geoid = Sketcher::GeoEnum::GeoUndef; pointpos = Sketcher::PointPos::none; - if (pos > -1) { + if (match.hasMatch()) { bool ok; - int edgeId = rxEdge.cap(1).toInt(&ok) - 1; + int edgeId = match.captured(1).toInt(&ok) - 1; if (ok) { geoid = edgeId; } } else { - QRegExp rxVertex(QString::fromLatin1("^Vertex(\\d+)$")); - pos = expr.indexOf(rxVertex); + QRegularExpression rxVertex(QString::fromLatin1("^Vertex(\\d+)$")); + expr.indexOf(rxVertex, 0, &match); - if (pos > -1) { + if (match.hasMatch()) { bool ok; - int vertexId = rxVertex.cap(1).toInt(&ok) - 1; + int vertexId = match.captured(1).toInt(&ok) - 1; if (ok) { const Sketcher::SketchObject * sketch = sketchView->getSketchObject(); sketch->getGeoVertexIndex(vertexId, geoid, pointpos); diff --git a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp index 04cf55605c..b10ed786eb 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp @@ -26,7 +26,8 @@ #ifndef _PreComp_ # include # include -# include +# include +# include # include # include # include @@ -360,11 +361,12 @@ void TaskSketcherElements::onSelectionChanged(const Gui::SelectionChanges& msg) std::string shapetype(msg.pSubName); // if-else edge vertex if (shapetype.size() > 4 && shapetype.substr(0,4) == "Edge") { - QRegExp rx(QString::fromLatin1("^Edge(\\d+)$")); - int pos = expr.indexOf(rx); - if (pos > -1) { + QRegularExpression rx(QString::fromLatin1("^Edge(\\d+)$")); + QRegularExpressionMatch match; + expr.indexOf(rx, 0, &match); + if (match.hasMatch()) { bool ok; - int ElementId = rx.cap(1).toInt(&ok) - 1; + int ElementId = match.captured(1).toInt(&ok) - 1; if (ok) { int countItems = ui->listWidgetElements->count(); for (int i=0; i < countItems; i++) { @@ -379,11 +381,12 @@ void TaskSketcherElements::onSelectionChanged(const Gui::SelectionChanges& msg) } } else if (shapetype.size() > 6 && shapetype.substr(0,6) == "Vertex"){ - QRegExp rx(QString::fromLatin1("^Vertex(\\d+)$")); - int pos = expr.indexOf(rx); - if (pos > -1) { + QRegularExpression rx(QString::fromLatin1("^Vertex(\\d+)$")); + QRegularExpressionMatch match; + expr.indexOf(rx, 0, &match); + if (match.hasMatch()) { bool ok; - int ElementId = rx.cap(1).toInt(&ok) - 1; + int ElementId = match.captured(1).toInt(&ok) - 1; if (ok) { // Get the GeoID&Pos int GeoId; diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index cd1ff4feeb..ea05e0458a 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 8c9e2a8ae6..07f5df34d8 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include diff --git a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp index ec7c7179b9..f75f97a614 100644 --- a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp +++ b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp @@ -31,7 +31,6 @@ # include # include # include -# include # include # include # include diff --git a/src/Mod/Web/Gui/BrowserView.cpp b/src/Mod/Web/Gui/BrowserView.cpp index 40ef609db4..3b41889264 100644 --- a/src/Mod/Web/Gui/BrowserView.cpp +++ b/src/Mod/Web/Gui/BrowserView.cpp @@ -32,7 +32,8 @@ # include # include # include -# include +# include +# include # include # include # include @@ -97,11 +98,12 @@ public: if (info.navigationType() == QWebEngineUrlRequestInfo::NavigationTypeLink) { // wash out windows file:///C:/something ->file://C:/something QUrl url = info.requestUrl(); - QRegExp re(QLatin1String("^/([a-zA-Z]\\:.*)")); // match & catch drive letter forward + QRegularExpression re(QLatin1String("^/([a-zA-Z]\\:.*)")); // match & catch drive letter forward + QRegularExpressionMatch match = re.match(url.path()); - if (url.host().isEmpty() && url.isLocalFile() && re.exactMatch(url.path())) + if (url.host().isEmpty() && url.isLocalFile() && match.hasMatch()) // clip / in file urs ie /C:/something -> C:/something - url.setPath(re.cap(1)); + url.setPath(match.captured(1)); // invoke thread safe. QMetaObject::invokeMethod(m_parent, "urlFilter", Q_ARG(QUrl, url));