diff --git a/src/plugins/qmldesigner/components/componentcore/theme.cpp b/src/plugins/qmldesigner/components/componentcore/theme.cpp index 74c53841bdf..7f11f513b71 100644 --- a/src/plugins/qmldesigner/components/componentcore/theme.cpp +++ b/src/plugins/qmldesigner/components/componentcore/theme.cpp @@ -33,7 +33,7 @@ #include #include -#include +#include #include #include #include @@ -92,13 +92,15 @@ Theme *Theme::instance() QString Theme::replaceCssColors(const QString &input) { - QRegExp rx("creatorTheme\\.(\\w+)"); + const QRegularExpression rx("creatorTheme\\.(\\w+)"); int pos = 0; QString output = input; - while ((pos = rx.indexIn(input, pos)) != -1) { - const QString themeColorName = rx.cap(1); + QRegularExpressionMatchIterator it = rx.globalMatch(input); + while (it.hasNext()) { + const QRegularExpressionMatch match = it.next(); + const QString themeColorName = match.captured(1); if (themeColorName == "smallFontPixelSize") { output.replace("creatorTheme." + themeColorName, QString::number(instance()->smallFontPixelSize()) + "px"); @@ -106,9 +108,9 @@ QString Theme::replaceCssColors(const QString &input) output.replace("creatorTheme." + themeColorName, QString::number(instance()->captionFontPixelSize()) + "px"); } else { const QColor color = instance()->evaluateColorAtThemeInstance(themeColorName); - output.replace("creatorTheme." + rx.cap(1), color.name()); + output.replace("creatorTheme." + themeColorName, color.name()); } - pos += rx.matchedLength(); + pos += match.capturedLength(); } return output; diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientpresetitem.cpp b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetitem.cpp index 518dea7b8b2..fbead98717d 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/gradientpresetitem.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetitem.cpp @@ -28,12 +28,13 @@ #include #include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include GradientPresetItem::GradientPresetItem() : m_gradientVal(QGradient()) @@ -155,7 +156,7 @@ QString GradientPresetItem::getNameByPreset(Preset value) QString enumName = QString::fromUtf8(metaEnum.valueToKey(static_cast(value))); - const QStringList sl = enumName.split(QRegExp("(?=[A-Z])"), QString::SkipEmptyParts); + const QStringList sl = enumName.split(QRegularExpression("(?=[A-Z])"), Qt::SkipEmptyParts); enumName.clear(); std::for_each(sl.begin(), sl.end(), [&enumName](const QString &s) { enumName += (s + " "); }); diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp index b2f44710ade..98470133ac7 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp @@ -35,7 +35,7 @@ #include -#include +#include #include //using namespace QmlDesigner; @@ -246,12 +246,13 @@ bool PropertyEditorValue::isTranslated() const if (modelNode().metaInfo().propertyTypeName(name()) == "QString" || modelNode().metaInfo().propertyTypeName(name()) == "string") { const QmlDesigner::QmlObjectNode objectNode(modelNode()); if (objectNode.isValid() && objectNode.hasBindingProperty(name())) { - QRegExp rx("qsTr(|Id|anslate)\\(\".*\"\\)"); + const QRegularExpression rx(QRegularExpression::anchoredPattern( + "qsTr(|Id|anslate)\\(\".*\"\\)")); //qsTr() if (objectNode.propertyAffectedByCurrentState(name())) { - return rx.exactMatch(expression()); + return expression().contains(rx); } else { - return rx.exactMatch(modelNode().bindingProperty(name()).expression()); + return modelNode().bindingProperty(name()).expression().contains(rx); } } return false; @@ -358,9 +359,11 @@ QString PropertyEditorValue::getTranslationContext() const if (modelNode().metaInfo().propertyTypeName(name()) == "QString" || modelNode().metaInfo().propertyTypeName(name()) == "string") { const QmlDesigner::QmlObjectNode objectNode(modelNode()); if (objectNode.isValid() && objectNode.hasBindingProperty(name())) { - QRegExp rx("qsTranslate\\(\"(.*)\"\\s*,\\s*\".*\"\\s*\\)"); - if (rx.exactMatch(expression())) - return rx.cap(1); + const QRegularExpression rx(QRegularExpression::anchoredPattern( + "qsTranslate\\(\"(.*)\"\\s*,\\s*\".*\"\\s*\\)")); + const QRegularExpressionMatch match = rx.match(expression()); + if (match.hasMatch()) + return match.captured(1); } } } @@ -372,11 +375,12 @@ bool PropertyEditorValue::isIdList() const if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name())) { const QmlDesigner::QmlObjectNode objectNode(modelNode()); if (objectNode.isValid() && objectNode.hasBindingProperty(name())) { - static const QRegExp rx("^[a-z_]\\w*|^[A-Z]\\w*\\.{1}([a-z_]\\w*\\.?)+"); + static const QRegularExpression rx(QRegularExpression::anchoredPattern( + "^[a-z_]\\w*|^[A-Z]\\w*\\.{1}([a-z_]\\w*\\.?)+")); const QString exp = objectNode.propertyAffectedByCurrentState(name()) ? expression() : modelNode().bindingProperty(name()).expression(); for (const auto &str : generateStringList(exp)) { - if (!rx.exactMatch(str)) + if (!str.contains(rx)) return false; } return true; @@ -397,8 +401,9 @@ bool PropertyEditorValue::idListAdd(const QString &value) if (!isIdList() && (objectNode.isValid() && objectNode.hasProperty(name()))) return false; - static const QRegExp rx("^[a-z_]\\w*|^[A-Z]\\w*\\.{1}([a-z_]\\w*\\.?)+"); - if (!rx.exactMatch(value)) + static const QRegularExpression rx(QRegularExpression::anchoredPattern( + "^[a-z_]\\w*|^[A-Z]\\w*\\.{1}([a-z_]\\w*\\.?)+")); + if (!value.contains(rx)) return false; auto stringList = generateStringList(expression()); @@ -426,8 +431,9 @@ bool PropertyEditorValue::idListReplace(int idx, const QString &value) { QTC_ASSERT(isIdList(), return false); - static const QRegExp rx("^[a-z_]\\w*|^[A-Z]\\w*\\.{1}([a-z_]\\w*\\.?)+"); - if (!rx.exactMatch(value)) + static const QRegularExpression rx(QRegularExpression::anchoredPattern( + "^[a-z_]\\w*|^[A-Z]\\w*\\.{1}([a-z_]\\w*\\.?)+")); + if (!value.contains(rx)) return false; auto stringList = generateStringList(expression()); @@ -446,7 +452,7 @@ QStringList PropertyEditorValue::generateStringList(const QString &string) const QString copy = string; copy = copy.remove("[").remove("]"); - QStringList tmp = copy.split(",", QString::SkipEmptyParts); + QStringList tmp = copy.split(',', Qt::SkipEmptyParts); for (QString &str : tmp) str = str.trimmed(); diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp index 8a2ca50c154..55ebe91a761 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include @@ -186,10 +186,10 @@ void StatesEditorView::duplicateCurrentState() QString newName = state.name(); // Strip out numbers at the end of the string - QRegExp regEx(QLatin1String("[0-9]+$")); - int numberIndex = newName.indexOf(regEx); - if ((numberIndex != -1) && (numberIndex+regEx.matchedLength()==newName.length())) - newName = newName.left(numberIndex); + QRegularExpression regEx(QLatin1String("[0-9]+$")); + const QRegularExpressionMatch match = regEx.match(newName); + if (match.hasMatch() && (match.capturedStart() + match.capturedLength() == newName.length())) + newName = newName.left(match.capturedStart()); int i = 1; QStringList stateNames = rootStateGroup().names(); diff --git a/src/plugins/qmldesigner/components/timelineeditor/easingcurve.cpp b/src/plugins/qmldesigner/components/timelineeditor/easingcurve.cpp index 3ef6ed20f7b..b2b9c8dad30 100644 --- a/src/plugins/qmldesigner/components/timelineeditor/easingcurve.cpp +++ b/src/plugins/qmldesigner/components/timelineeditor/easingcurve.cpp @@ -150,7 +150,7 @@ bool EasingCurve::fromString(const QString &code) { if (code.startsWith(QLatin1Char('[')) && code.endsWith(QLatin1Char(']'))) { const QStringRef cleanCode(&code, 1, code.size() - 2); - const auto stringList = cleanCode.split(QLatin1Char(','), QString::SkipEmptyParts); + const auto stringList = cleanCode.split(QLatin1Char(','), Qt::SkipEmptyParts); if (stringList.count() >= 6 && (stringList.count() % 6 == 0)) { bool checkX, checkY; diff --git a/src/plugins/qmldesigner/designercore/model/abstractview.cpp b/src/plugins/qmldesigner/designercore/model/abstractview.cpp index 3be64be127d..66dc5ffce94 100644 --- a/src/plugins/qmldesigner/designercore/model/abstractview.cpp +++ b/src/plugins/qmldesigner/designercore/model/abstractview.cpp @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include @@ -520,12 +520,12 @@ QString AbstractView::generateNewId(const QString &prefixName) const */ QString newId = QString(QStringLiteral("%1")).arg(firstCharToLower(prefixName)); - newId.remove(QRegExp(QStringLiteral("[^a-zA-Z0-9_]"))); + newId.remove(QRegularExpression(QStringLiteral("[^a-zA-Z0-9_]"))); while (!ModelNode::isValidId(newId) || hasId(newId) || rootModelNode().hasProperty(newId.toUtf8()) || newId == "item") { counter += 1; newId = QString(QStringLiteral("%1%2")).arg(firstCharToLower(prefixName)).arg(counter - 1); - newId.remove(QRegExp(QStringLiteral("[^a-zA-Z0-9_]"))); + newId.remove(QRegularExpression(QStringLiteral("[^a-zA-Z0-9_]"))); } return newId; diff --git a/src/plugins/qmldesigner/designercore/model/modelnode.cpp b/src/plugins/qmldesigner/designercore/model/modelnode.cpp index eb2d2859974..f5b4b677808 100644 --- a/src/plugins/qmldesigner/designercore/model/modelnode.cpp +++ b/src/plugins/qmldesigner/designercore/model/modelnode.cpp @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include @@ -224,8 +224,8 @@ static bool isIdToAvoid(const QString& id) static bool idContainsWrongLetter(const QString& id) { - static QRegExp idExpr(QStringLiteral("[a-z_][a-zA-Z0-9_]*")); - return !idExpr.exactMatch(id); + static QRegularExpression idExpr(QStringLiteral("^[a-z_][a-zA-Z0-9_]+$")); + return !id.contains(idExpr); } bool ModelNode::isValidId(const QString &id) diff --git a/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp b/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp index 234872d661f..cebe171295e 100644 --- a/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp @@ -44,7 +44,7 @@ #include #endif -#include +#include namespace QmlDesigner { @@ -246,8 +246,9 @@ bool QmlObjectNode::isTranslatableText(const PropertyName &name) const if (modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name)) if (modelNode().metaInfo().propertyTypeName(name) == "QString" || modelNode().metaInfo().propertyTypeName(name) == "string") { if (modelNode().hasBindingProperty(name)) { - static QRegExp regularExpressionPatter(QLatin1String("qsTr(|Id|anslate)\\(\".*\"\\)")); - return regularExpressionPatter.exactMatch(modelNode().bindingProperty(name).expression()); + static QRegularExpression regularExpressionPattern( + QLatin1String("^qsTr(|Id|anslate)\\(\".*\"\\)$")); + return modelNode().bindingProperty(name).expression().contains(regularExpressionPattern); } return false; @@ -259,9 +260,12 @@ bool QmlObjectNode::isTranslatableText(const PropertyName &name) const QString QmlObjectNode::stripedTranslatableText(const PropertyName &name) const { if (modelNode().hasBindingProperty(name)) { - static QRegExp regularExpressionPatter(QLatin1String("qsTr(|Id|anslate)\\(\"(.*)\"\\)")); - if (regularExpressionPatter.exactMatch(modelNode().bindingProperty(name).expression())) - return regularExpressionPatter.cap(2); + static QRegularExpression regularExpressionPattern( + QLatin1String("^qsTr(|Id|anslate)\\(\"(.*)\"\\)$")); + const QRegularExpressionMatch match = regularExpressionPattern.match( + modelNode().bindingProperty(name).expression()); + if (match.hasMatch()) + return match.captured(2); return instanceValue(name).toString(); } return instanceValue(name).toString(); diff --git a/src/plugins/qmldesigner/designercore/model/rewriterview.cpp b/src/plugins/qmldesigner/designercore/model/rewriterview.cpp index eb9c6507469..a036813cbdf 100644 --- a/src/plugins/qmldesigner/designercore/model/rewriterview.cpp +++ b/src/plugins/qmldesigner/designercore/model/rewriterview.cpp @@ -53,7 +53,7 @@ #include #include -#include +#include #include #include @@ -542,7 +542,7 @@ QString RewriterView::auxiliaryDataAsQML() const int columnCount = 0; - const QRegExp safeName("[a-z][a-zA-Z0-9]*"); + const QRegularExpression safeName("^[a-z][a-zA-Z0-9]+$"); for (const auto &node : allModelNodes()) { QHash data = node.auxiliaryData(); @@ -576,7 +576,7 @@ QString RewriterView::auxiliaryDataAsQML() const if (idIsQmlKeyWord(key)) continue; - if (!safeName.exactMatch(key)) + if (!key.contains(safeName)) continue; const QVariant value = data.value(key.toUtf8()); diff --git a/src/plugins/qmldesigner/designercore/model/stylesheetmerger.cpp b/src/plugins/qmldesigner/designercore/model/stylesheetmerger.cpp index 52cf0f2ba14..2c724313ea8 100644 --- a/src/plugins/qmldesigner/designercore/model/stylesheetmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/stylesheetmerger.cpp @@ -353,7 +353,7 @@ void StylesheetMerger::adjustNodeIndex(ModelNode &node) void StylesheetMerger::applyStyleProperties(ModelNode &templateNode, const ModelNode &styleNode) { - QRegExp regEx("[a-z]", Qt::CaseInsensitive); + const QRegularExpression regEx("[a-z]", QRegularExpression::CaseInsensitiveOption); for (const VariantProperty &variantProperty : styleNode.variantProperties()) { if (templateNode.hasBindingProperty(variantProperty.name())) { // if the binding does not contain any alpha letters (i.e. binds to a term rather than a property,