Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Port QRegExp to QRegularExpression

Freya Lupenb15db5d40901
diff --git a/libs/flake/svg/SvgCssHelper.cpp b/libs/flake/svg/SvgCssHelper.cpp
index 117cda2b58..528bfd4d9f 100644
--- a/libs/flake/svg/SvgCssHelper.cpp
+++ b/libs/flake/svg/SvgCssHelper.cpp
@@ -7,7 +7,7 @@
#include "SvgCssHelper.h"
#include <FlakeDebug.h>
#include <QPair>
-#include <QRegExp>
+#include <QRegularExpression>
/// Token types used for tokenizing complex selectors
enum CssTokenType {
@@ -624,13 +624,8 @@ void SvgCssHelper::parseStylesheet(const QDomElement &e)
return;
// remove comments
- QRegExp commentExp("\\/\\*.*\\*\\/");
- commentExp.setMinimal(true); // do not match greedy
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+ QRegularExpression commentExp("\\/\\*.*?\\*\\/");
data.remove(commentExp);
-#else
- commentExp.removeIn(data);
-#endif
QStringList defs = data.split('}', Qt::SkipEmptyParts);
for (int i = 0; i < defs.count(); ++i) {
diff --git a/libs/flake/svg/SvgUtil.cpp b/libs/flake/svg/SvgUtil.cpp
index e995dbece8..c54b6d6965 100644
--- a/libs/flake/svg/SvgUtil.cpp
+++ b/libs/flake/svg/SvgUtil.cpp
@@ -13,7 +13,7 @@
#include <QString>
#include <QRectF>
#include <QStringList>
-#include <QRegExp>
+#include <QRegularExpression>
#include <math.h>
#include "kis_debug.h"
@@ -458,18 +458,18 @@ QStringList SvgUtil::simplifyList(const QString &str)
SvgUtil::PreserveAspectRatioParser::PreserveAspectRatioParser(const QString &str)
{
- QRegExp rexp("(defer)?\\s*(none|(x(Min|Max|Mid)Y(Min|Max|Mid)))\\s*(meet|slice)?", Qt::CaseInsensitive);
- int index = rexp.indexIn(str.toLower());
+ QRegularExpression rexp("(defer)?\\s*(none|(x(Min|Max|Mid)Y(Min|Max|Mid)))\\s*(meet|slice)?", QRegularExpression::CaseInsensitiveOption);
+ QRegularExpressionMatch match = rexp.match(str.toLower());
- if (index >= 0) {
- if (rexp.cap(1) == "defer") {
+ if (match.hasMatch()) {
+ if (match.captured(1) == "defer") {
defer = true;
}
- if (rexp.cap(2) != "none") {
- xAlignment = alignmentFromString(rexp.cap(4));
- yAlignment = alignmentFromString(rexp.cap(5));
- mode = rexp.cap(6) == "slice" ?
+ if (match.captured(2) != "none") {
+ xAlignment = alignmentFromString(match.captured(4));
+ yAlignment = alignmentFromString(match.captured(5));
+ mode = match.captured(6) == "slice" ?
Qt::KeepAspectRatioByExpanding : Qt::KeepAspectRatio;
}
}
diff --git a/libs/flake/text/KoSvgTextProperties.cpp b/libs/flake/text/KoSvgTextProperties.cpp
index 6774495de0..8ed0aa3bd5 100644
--- a/libs/flake/text/KoSvgTextProperties.cpp
+++ b/libs/flake/text/KoSvgTextProperties.cpp
@@ -9,7 +9,7 @@
#include <QFontMetrics>
#include <QGlobalStatic>
#include <QMap>
-#include <QRegExp>
+#include <QRegularExpression>
#include <fontconfig/fontconfig.h>
@@ -362,14 +362,9 @@ void KoSvgTextProperties::parseSvgTextAttribute(const SvgLoadingContext &context
setProperty(BaselineShiftValueId, QVariant::fromValue(shift));
}
} else if (command == "vertical-align") {
- QRegExp digits = QRegExp("\\d");
+ QRegularExpression digits = QRegularExpression("\\d");
Q_FOREACH (const QString &param, value.split(' ', Qt::SkipEmptyParts)) {
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
bool paramContains = param.contains(digits);
-#else
- bool paramContains = (digits.indexIn(param) > 0);
-#endif
-
if (param == "sub" || param == "super" || param == "top" || param == "bottom" || paramContains) {
parseSvgTextAttribute(context, "baseline-shift", param);
diff --git a/libs/flake/text/KoWritingSystemUtils.cpp b/libs/flake/text/KoWritingSystemUtils.cpp
index 1a85f95233..9355ce53e9 100644
--- a/libs/flake/text/KoWritingSystemUtils.cpp
+++ b/libs/flake/text/KoWritingSystemUtils.cpp
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "KoWritingSystemUtils.h"
-#include <QRegExp>
+#include <QRegularExpression>
static QMap<QFontDatabase::WritingSystem, QString> WRITINGSYSTEM_SCRIPT_MAP {
{{QFontDatabase::Any},{"Zyyy"}},
@@ -449,15 +449,15 @@ KoWritingSystemUtils::Bcp47Locale KoWritingSystemUtils::parseBcp47Locale(const Q
if (tags.isEmpty()) return bcp;
- const QRegExp alphas("[A-Z]+", Qt::CaseInsensitive);
- const QRegExp digits("[\\d]+");
+ const QRegularExpression alphas("^[A-Za-z]+$");
+ const QRegularExpression digits("^\\d+$");
// Language -- single primary language, followed by optional 3 letter extended tags.
if (tags.first().size() == 2 || tags.first().size() == 3) {
bcp.languageTags.append(tags.takeFirst().toLower());
// extensions only happen when first tag is 2 or 3 long.
- while (!tags.isEmpty() && tags.first().size() == 3 && alphas.exactMatch(tags.first())) {
+ while (!tags.isEmpty() && tags.first().size() == 3 && tags.first().contains(alphas)) {
bcp.languageTags.append(tags.takeFirst().toLower());
}
} else if (tags.first().size() >= 4 || tags.first().size() <= 8) {
@@ -473,7 +473,7 @@ KoWritingSystemUtils::Bcp47Locale KoWritingSystemUtils::parseBcp47Locale(const Q
// Script -- This is an 4 letter alpha only.
- if (alphas.exactMatch(tags.first()) && tags.first().size() == 4) {
+ if (tags.first().contains(alphas) && tags.first().size() == 4) {
bcp.scriptTag = tags.takeFirst().toLower();
bcp.scriptTag = bcp.scriptTag.at(0).toUpper()+bcp.scriptTag.mid(1);
}
@@ -482,8 +482,8 @@ KoWritingSystemUtils::Bcp47Locale KoWritingSystemUtils::parseBcp47Locale(const Q
// Region -- 2 letter alpha only.
- if ((alphas.exactMatch(tags.first()) && tags.first().size() == 2)
- || (digits.exactMatch(tags.first()) && tags.first().size() == 3)) {
+ if ((tags.first().contains(alphas) && tags.first().size() == 2)
+ || (tags.first().contains(digits) && tags.first().size() == 3)) {
bcp.regionTag = tags.takeFirst().toUpper();
}
@@ -491,11 +491,11 @@ KoWritingSystemUtils::Bcp47Locale KoWritingSystemUtils::parseBcp47Locale(const Q
// Variants -- [0+] alpha numerics, either between 5-8 char long, or 4 but starting with a digit.
- const QRegExp variantAlphaNumeric("\\d[a-z0-9]{3}", Qt::CaseInsensitive);
+ const QRegularExpression variantAlphaNumeric("^\\d[A-Za-z0-9]{3}$");
while (!tags.isEmpty()
&& ( (tags.first().size() >= 5 && tags.first().size() <= 8)
- || (variantAlphaNumeric.exactMatch(tags.first()) && tags.first().size() == 4) )
+ || (tags.first().contains(variantAlphaNumeric) && tags.first().size() == 4) )
) {
bcp.variantTags.append(tags.takeFirst().toLower());
}
diff --git a/libs/image/tests/kis_asl_layer_style_serializer_test.cpp b/libs/image/tests/kis_asl_layer_style_serializer_test.cpp
index ee5c901bad..347cf0cf5e 100644
--- a/libs/image/tests/kis_asl_layer_style_serializer_test.cpp
+++ b/libs/image/tests/kis_asl_layer_style_serializer_test.cpp
@@ -9,7 +9,7 @@
#include <simpletest.h>
#include <QDomDocument>
-#include <QRegExp>
+#include <QRegularExpression>
#include <KoCompositeOpRegistry.h>
#include <resources/KoAbstractGradient.h>
@@ -390,13 +390,8 @@ void KisAslLayerStyleSerializerTest::testWritingGradients()
{
// the reference document has stripped "Idnt" field which is random
- QRegExp rx("<node key=\"Idnt\" type=\"Text\" value=\".+\"/>");
- rx.setMinimal(true);
-
- int pos = 0;
- while ((pos = rx.indexIn(xmlDoc, pos)) != -1) {
- xmlDoc.remove(pos, rx.matchedLength());
- }
+ QRegularExpression rx("<node key=\"Idnt\" type=\"Text\" value=\".+?\"/>");
+ xmlDoc.remove(rx);
{
//QFile xmlFile("reference_gradients.asl.xml");
diff --git a/libs/metadata/kis_meta_data_parser.cc b/libs/metadata/kis_meta_data_parser.cc
index 3ee7e952d2..87901a7878 100644
--- a/libs/metadata/kis_meta_data_parser.cc
+++ b/libs/metadata/kis_meta_data_parser.cc
@@ -17,7 +17,7 @@ Parser::~Parser()
#include "kis_meta_data_parser_p.h"
#include <QDateTime>
-#include <QRegExp>
+#include <QRegularExpression>
#include <QVariant>
@@ -50,9 +50,10 @@ Value DateParser::parse(const QString& _v) const
Value RationalParser::parse(const QString& _v) const
{
- QRegExp regexp("(\\-?\\d+)/(\\d+)");
- regexp.indexIn(_v);
- if (regexp.capturedTexts().size() > 2)
- return Value(Rational(regexp.capturedTexts()[1].toInt(), regexp.capturedTexts()[2].toInt()));
+ QRegularExpression regexp("(\\-?\\d+)/(\\d+)");
+ QRegularExpressionMatch match = regexp.match(_v);
+
+ if (match.capturedTexts().size() > 2)
+ return Value(Rational(match.captured(1).toInt(), match.captured(2).toInt()));
return Value();
}
diff --git a/libs/metadata/kis_meta_data_value.cc b/libs/metadata/kis_meta_data_value.cc
index 3c8355b64c..bc4e89872f 100644
--- a/libs/metadata/kis_meta_data_value.cc
+++ b/libs/metadata/kis_meta_data_value.cc
@@ -6,7 +6,7 @@
#include "kis_meta_data_value.h"
#include <QPoint>
-#include <QRegExp>
+#include <QRegularExpression>
#include <QTime>
#include <QVariant>
@@ -157,8 +157,7 @@ bool Value::setVariant(const QVariant& variant)
*this = KisMetaData::Value(variant);
return true;
case Rational: {
- QRegExp rx("([^\\/]*)\\/([^\\/]*)");
- rx.indexIn(variant.toString());
+ QRegularExpression rx("([^\\/]*)\\/([^\\/]*)");
// TODO: erm... did someone forgot to write actual code here?
// for now just safe assert and return a failure
diff --git a/libs/pigment/KoColor.cpp b/libs/pigment/KoColor.cpp
index 9b30d5dd8f..3a63a474a4 100644
--- a/libs/pigment/KoColor.cpp
+++ b/libs/pigment/KoColor.cpp
@@ -11,7 +11,7 @@
#include <QColor>
#include <QDomDocument>
-#include <QRegExp>
+#include <QRegularExpression>
#include "DebugPigment.h"
@@ -490,12 +490,8 @@ QString KoColor::toSVG11(QHash<QString, const KoColorProfile *> *profileList) co
QString csName = colorSpace()->profile()->name();
// remove forbidden characters
// https://www.w3.org/TR/SVG11/types.html#DataTypeName
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
- csName.remove(QRegExp("[\\(\\),\\s]"));
-#else
- QRegExp reg("[\\(\\),\\s]");
- reg.removeIn(csName);
-#endif
+ csName.remove(QRegularExpression("[\\(\\),\\s]"));
+
//reuse existing name if possible. We're looking for the color profile, because svg doesn't care about depth.
csName = profileList->key(colorSpace()->profile(), csName);
@@ -544,15 +540,14 @@ KoColor KoColor::fromSVG11(const QString value, QHash<QString, const KoColorProf
profileList.insert("sRGB", KoColorSpaceRegistry::instance()->p709SRGBProfile());
// first, try to split at \w\d\) space.
// we want to split up a string like... colorcolor none rgb(0.8, 0.1, 200%) #ff0000 icc-color(blah, 0.0, 1.0, 1.0, 0.0);
- QRegExp splitDefinitions("(#?\\w+|[\\w\\-]*\\(.+\\))\\s");
+ QRegularExpression splitDefinitions("(#?\\w+|[\\w\\-]*\\(.+\\))\\s");
int pos = 0;
- int pos2 = 0;
QStringList colorDefinitions;
QString valueAdjust = value.split(";").first();
valueAdjust.append(" ");
- while ((pos2 = splitDefinitions.indexIn(valueAdjust, pos)) != -1) {
- colorDefinitions.append(splitDefinitions.cap(1).trimmed());
- pos = pos2 + splitDefinitions.matchedLength();
+ for (const QRegularExpressionMatch &match : splitDefinitions.globalMatch(valueAdjust)) {
+ colorDefinitions.append(match.captured(1).trimmed());
+ pos = match.capturedEnd(0);
}
if (pos < value.length()) {
QString remainder = value.right(value.length()-pos);
diff --git a/libs/resources/KisResourceSearchBoxFilter.cpp b/libs/resources/KisResourceSearchBoxFilter.cpp
index 918abe8bcb..259daf32bf 100644
--- a/libs/resources/KisResourceSearchBoxFilter.cpp
+++ b/libs/resources/KisResourceSearchBoxFilter.cpp
@@ -7,7 +7,6 @@
#include "KisResourceSearchBoxFilter.h"
-#include <QRegExp>
#include <QRegularExpression>
#include <QList>
#include <QSet>
diff --git a/libs/ui/KisViewManager.cpp b/libs/ui/KisViewManager.cpp
index c3b4b4fa6f..9d7541d221 100644
--- a/libs/ui/KisViewManager.cpp
+++ b/libs/ui/KisViewManager.cpp
@@ -41,7 +41,7 @@
#include <QUrl>
#include <QWidget>
#include <QActionGroup>
-#include <QRegExp>
+#include <QRegularExpression>
#include <kactioncollection.h>
#include <klocalizedstring.h>
@@ -1012,49 +1012,23 @@ void KisViewManager::slotSaveIncremental()
// Find current version filenames
// v v Regexp to find incremental versions in the filename, taking our backup scheme into account as well
// Considering our incremental version and backup scheme, format is filename_001~001.ext
- QRegExp regex("_\\d{1,4}[.]|_\\d{1,4}[a-z][.]|_\\d{1,4}[~]|_\\d{1,4}[a-z][~]");
- regex.indexIn(fileName); // Perform the search
- QStringList matches = regex.capturedTexts();
- foundVersion = matches.at(0).isEmpty() ? false : true;
-
- // Ensure compatibility with Save Incremental Backup
- // If this regex is not kept separate, the entire algorithm needs modification;
- // It's simpler to just add this.
- QRegExp regexAux("_\\d{1,4}[~]|_\\d{1,4}[a-z][~]");
- regexAux.indexIn(fileName); // Perform the search
- QStringList matchesAux = regexAux.capturedTexts();
- isBackup = matchesAux.at(0).isEmpty() ? false : true;
+ QRegularExpression regex("_(\\d{1,4})([a-z])?([\\.|~])");
+ QRegularExpressionMatch match;
+ foundVersion = fileName.contains(regex, &match);
+ isBackup = foundVersion ? match.captured(3) == "~" : false;
// If the filename has a version, prepare it for incrementation
if (foundVersion) {
- version = matches.at(matches.count() - 1); // Look at the last index, we don't care about other matches
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
- if (version.contains(QRegExp("[a-z]"))) {
-#else
- if (QRegExp("[a-z]").containedIn(version)) {
-#endif
-
- version.chop(1); // Trim "."
- letter = version.right(1); // Save letter
- version.chop(1); // Trim letter
- } else {
- version.chop(1); // Trim "."
- }
- version.remove(0, 1); // Trim "_"
+ version = match.captured(1);
+ letter = match.captured(2);
} else {
- // TODO: this will not work with files extensions like jp2
// ...else, simply add a version to it so the next loop works
- QRegExp regex2("[.][a-z]{2,4}$"); // Heuristic to find file extension
- regex2.indexIn(fileName);
- QStringList matches2 = regex2.capturedTexts();
- QString extensionPlusVersion = matches2.at(0);
+ QRegularExpression regex2("\\.\\w{2,4}$"); // Heuristic to find file extension
+ QRegularExpressionMatch match = regex2.match(fileName);
+ QString extensionPlusVersion = match.captured(0);
extensionPlusVersion.prepend(version);
extensionPlusVersion.prepend("_");
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
fileName.replace(regex2, extensionPlusVersion);
-#else
- fileName = regex2.replaceIn(fileName, extensionPlusVersion);
-#endif
}
// Prepare the base for new version filename
@@ -1075,11 +1049,7 @@ void KisViewManager::slotSaveIncremental()
} else {
newVersion.append(".");
}
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
fileName.replace(regex, newVersion);
-#else
- fileName = regex.replaceIn(fileName, newVersion);
-#endif
fileAlreadyExists = QFileInfo(path + '/' + fileName).exists();
if (fileAlreadyExists) {
if (!letter.isNull()) {
@@ -1123,26 +1093,14 @@ void KisViewManager::slotSaveIncrementalBackup()
QString fileName = QFileInfo(document()->localFilePath()).fileName();
// First, discover if working on a backup file, or a normal file
- QRegExp regex("~\\d{1,4}[.]|~\\d{1,4}[a-z][.]");
- regex.indexIn(fileName); // Perform the search
- QStringList matches = regex.capturedTexts();
- workingOnBackup = matches.at(0).isEmpty() ? false : true;
+ QRegularExpression regex("~(\\d{1,4})([a-z])?\\.");
+ QRegularExpressionMatch match;
+ workingOnBackup = fileName.contains(regex, &match);
if (workingOnBackup) {
// Try to save incremental version (of backup), use letter for alt versions
- version = matches.at(matches.count() - 1); // Look at the last index, we don't care about other matches
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
- if (version.contains(QRegExp("[a-z]"))) {
-#else
- if (QRegExp("[a-z]").containedIn(version)) {
-#endif
- version.chop(1); // Trim "."
- letter = version.right(1); // Save letter
- version.chop(1); // Trim letter
- } else {
- version.chop(1); // Trim "."
- }
- version.remove(0, 1); // Trim "~"
+ version = match.captured(1);
+ letter = match.captured(2);
// Prepare the base for new version filename
int intVersion = version.toInt(0);
@@ -1159,11 +1117,7 @@ void KisViewManager::slotSaveIncrementalBackup()
newVersion.prepend("~");
if (!letter.isNull()) newVersion.append(letter);
newVersion.append(".");
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
backupFileName.replace(regex, newVersion);
-#else
- backupFileName = regex.replaceIn(backupFileName, newVersion);
-#endif
fileAlreadyExists = QFile(path + '/' + backupFileName).exists();
if (fileAlreadyExists) {
if (!letter.isNull()) {
@@ -1188,28 +1142,19 @@ void KisViewManager::slotSaveIncrementalBackup()
const quint8 HARDCODED_DIGIT_COUNT = 3;
QString baseNewVersion = "000";
QString backupFileName = QFileInfo(document()->localFilePath()).fileName();
- QRegExp regex2("[.][a-z]{2,4}$"); // Heuristic to find file extension
- regex2.indexIn(backupFileName);
- QStringList matches2 = regex2.capturedTexts();
- QString extensionPlusVersion = matches2.at(0);
+ QRegularExpression regex2("\\.\\w{2,4}$"); // Heuristic to find file extension
+ QRegularExpressionMatch match = regex2.match(fileName);
+ QString extensionPlusVersion = match.captured(0);
extensionPlusVersion.prepend(baseNewVersion);
extensionPlusVersion.prepend("~");
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
backupFileName.replace(regex2, extensionPlusVersion);
-#else
- backupFileName = regex2.replaceIn(backupFileName, extensionPlusVersion);
-#endif
// Save version with 1 number higher than the highest version found ignoring letters
do {
newVersion = baseNewVersion;
newVersion.prepend("~");
newVersion.append(".");
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
backupFileName.replace(regex, newVersion);
-#else
- backupFileName = regex.replaceIn(backupFileName, newVersion);
-#endif
fileAlreadyExists = QFile(path + '/' + backupFileName).exists();
if (fileAlreadyExists) {
// Prepare the base for new version filename, increment by 1
diff --git a/libs/ui/animation/KisDlgImportVideoAnimation.cpp b/libs/ui/animation/KisDlgImportVideoAnimation.cpp
index 4ad6b9c7de..0a0b543417 100644
--- a/libs/ui/animation/KisDlgImportVideoAnimation.cpp
+++ b/libs/ui/animation/KisDlgImportVideoAnimation.cpp
@@ -10,7 +10,6 @@
#include "KisDlgImportVideoAnimation.h"
#include <QStandardPaths>
-#include <QRegExp>
#include <QtMath>
#include <QJsonObject>
#include <QJsonArray>
diff --git a/libs/ui/dialogs/kis_dlg_import_image_sequence.cpp b/libs/ui/dialogs/kis_dlg_import_image_sequence.cpp
index fe3a98502f..92998282b6 100644
--- a/libs/ui/dialogs/kis_dlg_import_image_sequence.cpp
+++ b/libs/ui/dialogs/kis_dlg_import_image_sequence.cpp
@@ -13,7 +13,7 @@
#include "KisImportExportManager.h"
#include "KoFileDialog.h"
#include <QStandardPaths>
-#include <QRegExp>
+#include <QRegularExpression>
#include <QListWidgetItem>
class KisDlgImportImageSequence::ListItem : QListWidgetItem {
@@ -27,14 +27,9 @@ public:
bool operator <(const QListWidgetItem &other) const override
{
if (collator->numericMode()) {
- const QRegExp rx(QLatin1String("[^0-9]+"));
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+ const QRegularExpression rx(QLatin1String("[^0-9]+"));
QStringList ours = text().split(rx, Qt::SkipEmptyParts);
QStringList theirs = other.text().split(rx, Qt::SkipEmptyParts);
-#else
- QStringList ours = rx.splitString(this->text(), Qt::SkipEmptyParts);
- QStringList theirs = rx.splitString(other.text(), Qt::SkipEmptyParts);
-#endif
// Let's compare the last numbers -- they are most likely to be the serial numbers
if (ours.size() > 0 && theirs.size() > 0) {
diff --git a/libs/ui/input/kis_input_profile_manager.cpp b/libs/ui/input/kis_input_profile_manager.cpp
index 63ceab3951..a7edcbe6d9 100644
--- a/libs/ui/input/kis_input_profile_manager.cpp
+++ b/libs/ui/input/kis_input_profile_manager.cpp
@@ -12,7 +12,7 @@
#include <QStringList>
#include <QDir>
#include <QGlobalStatic>
-#include <QRegExp>
+#include <QRegularExpression>
#include <KoResourcePaths.h>
#include <kconfig.h>
@@ -453,13 +453,6 @@ void KisInputProfileManager::Private::createActions()
QString KisInputProfileManager::Private::profileFileName(const QString &profileName)
{
- QRegExp reg("[^a-z0-9]");
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
- return profileName.toLower().remove(QRegExp("[^a-z0-9]")).append(".profile");
-#else
- QString pf = profileName.toLower();
- reg.removeIn(pf);
- return pf.append(".profile");
-#endif
-
+ QRegularExpression reg("[^a-z0-9]");
+ return profileName.toLower().remove(reg).append(".profile");
}
diff --git a/libs/ui/kis_animation_importer.cpp b/libs/ui/kis_animation_importer.cpp
index 11c9fe3ca7..6203a7bd9a 100644
--- a/libs/ui/kis_animation_importer.cpp
+++ b/libs/ui/kis_animation_importer.cpp
@@ -21,7 +21,7 @@
#include "kis_raster_keyframe_channel.h"
#include "kis_assign_profile_processing_visitor.h"
#include "commands/kis_image_layer_add_command.h"
-#include <QRegExp>
+#include <QRegularExpression>
struct KisAnimationImporter::Private
{
@@ -85,14 +85,11 @@ KisImportExportErrorCode KisAnimationImporter::import(QStringList files, int fir
QPair<KisPaintLayerSP, KisRasterKeyframeChannel*> layerRasterChannelPair;
- const QRegExp rx(QLatin1String("(\\d+)")); //regex for extracting numbers
+ const QRegularExpression rx(QLatin1String("(\\d+)")); //regex for extracting numbers
QStringList fileNumberRxList;
-
- int pos = 0;
-
- while ((pos = rx.indexIn(files.at(0), pos)) != -1) {
- fileNumberRxList << rx.cap(1);
- pos += rx.matchedLength();
+
+ for (const QRegularExpressionMatch &match : rx.globalMatch(files.at(0))) {
+ fileNumberRxList << match.captured(1);
}
int firstFrameNumber = 0;
@@ -149,11 +146,8 @@ KisImportExportErrorCode KisAnimationImporter::import(QStringList files, int fir
if (!autoAddHoldframes) {
layerRasterChannelPair.second->importFrame(frame, importDoc->image()->projection(), NULL); // as first frame added will go to second slot i.e #1 instead of #0
} else {
- pos = 0;
-
- while ((pos = rx.indexIn(file, pos)) != -1) {
- fileNumberRxList << rx.cap(1);
- pos += rx.matchedLength();
+ for (const QRegularExpressionMatch &match : rx.globalMatch(file)) {
+ fileNumberRxList << match.captured(1);
}
int filenum = fileNumberRxList.last().toInt(&ok);
diff --git a/libs/ui/kis_multinode_property.h b/libs/ui/kis_multinode_property.h
index 743e4e1096..da4befd939 100644
--- a/libs/ui/kis_multinode_property.h
+++ b/libs/ui/kis_multinode_property.h
@@ -10,7 +10,7 @@
#include <QObject>
#include <QCheckBox>
#include <QPointer>
-#include <QRegExp>
+#include <QRegularExpression>
#include <QBitArray>
#include <kundo2command.h>
@@ -77,10 +77,10 @@ struct NameAdapter : public BaseAdapter {
private:
static QString stripName(QString name) {
- QRegExp rexp("^(.+) (\\d{1,3})$");
- int pos = rexp.indexIn(name);
- if (pos > -1) {
- name = rexp.cap(1);
+ QRegularExpression rexp("^(.+) \\d{1,3}$");
+ QRegularExpressionMatch match;
+ if (name.contains(rexp, &match)) {
+ name = match.captured(1);
}
return name;
diff --git a/libs/ui/widgets/kis_floating_message.cpp b/libs/ui/widgets/kis_floating_message.cpp
index 04e51ee64a..24e8e2599f 100644
--- a/libs/ui/widgets/kis_floating_message.cpp
+++ b/libs/ui/widgets/kis_floating_message.cpp
@@ -16,7 +16,7 @@
#include <QScreen>
#include <QMouseEvent>
#include <QPainter>
-#include <QRegExp>
+#include <QRegularExpression>
#include <QScreen>
#include <QLabel>
#include <QGraphicsDropShadowEffect>
@@ -166,20 +166,10 @@ QRect KisFloatingMessage::determineMetrics( const int M )
else {
max = QSize(1024, 768);
}
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
// If we don't do that, the boundingRect() might not be suitable for drawText() (Qt issue N67674)
- m_message.replace(QRegExp( " +\n"), "\n");
+ m_message.replace(QRegularExpression( " +\n"), "\n");
// remove consecutive line breaks
- m_message.replace(QRegExp( "\n+"), "\n");
-#else
- // If we don't do that, the boundingRect() might not be suitable for drawText() (Qt issue N67674)
- QRegExp r(" +\n");
- m_message = r.replaceIn(m_message, "\n");
-
- // remove consecutive line breaks
- QRegExp r2(( "\n+"));
- m_message = r2.replaceIn(m_message, "\n");
-#endif
+ m_message.replace(QRegularExpression( "\n+"), "\n");
// The osd cannot be larger than the screen
QRect rect = fontMetrics().boundingRect(0, 0, max.width() - image.width(), max.height(),
diff --git a/libs/widgets/KoUnitDoubleSpinBox.cpp b/libs/widgets/KoUnitDoubleSpinBox.cpp
index bb981ba78b..3671835986 100644
--- a/libs/widgets/KoUnitDoubleSpinBox.cpp
+++ b/libs/widgets/KoUnitDoubleSpinBox.cpp
@@ -10,7 +10,7 @@
#include <KoUnit.h>
-#include <QRegExp>
+#include <QRegularExpression>
#include <WidgetsDebug.h>
@@ -62,8 +62,9 @@ QValidator::State KoUnitDoubleSpinBox::validate(QString &input, int &pos) const
Q_UNUSED(pos);
#endif
- QRegExp regexp ("([ a-zA-Z]+)$"); // Letters or spaces at end
- const int res = regexp.indexIn(input);
+ QRegularExpression regexp ("([ a-zA-Z]+)$"); // Letters or spaces at end
+ QRegularExpressionMatch match;
+ const int res = input.indexOf(regexp, 0, &match);
if ( res == -1 )
{
@@ -76,7 +77,7 @@ QValidator::State KoUnitDoubleSpinBox::validate(QString &input, int &pos) const
// ### TODO: are all the QString::trimmed really necessary?
const QString number ( input.left( res ).trimmed() );
- const QString unitName ( regexp.cap( 1 ).trimmed().toLower() );
+ const QString unitName ( match.captured( 1 ).trimmed().toLower() );
#ifdef DEBUG_VALIDATOR
debugWidgets <<"Split:" << number <<":" << unitName <<":";
diff --git a/libs/widgetutils/kis_num_parser.cpp b/libs/widgetutils/kis_num_parser.cpp
index a3ce6f6c38..e9aec35584 100644
--- a/libs/widgetutils/kis_num_parser.cpp
+++ b/libs/widgetutils/kis_num_parser.cpp
@@ -9,7 +9,7 @@
#include <qnumeric.h> // for qIsNaN
#include <qmath.h>
#include <QVector>
-#include <QRegExp>
+#include <QRegularExpression>
#include <QStringList>
#include <QVariant>
#include <QLocale>
@@ -23,11 +23,11 @@ const QVector<char> opLevel2 = {'*', '/'};
const QStringList supportedFuncs = {"", "cos", "sin", "tan", "acos", "asin", "atan", "exp", "ln", "log10", "abs"};
-const QRegExp funcExpr("(-)?([a-zA-Z]*[0-9]*)?\\((.+)\\)");
-const QRegExp numberExpr("(-)?([0-9]+\\.?[0-9]*(e[0-9]*)?)");
+const QRegularExpression funcExpr("^(-)?([a-zA-Z]*[0-9]*)?\\((.+)\\)$");
+const QRegularExpression numberExpr("^(-)?([0-9]+\\.?[0-9]*(e[0-9]*)?)$");
-const QRegExp funcExprInteger("(-)?\\((.+)\\)");
-const QRegExp integerExpr("(-)?([0-9]+)");
+const QRegularExpression funcExprInteger("^(-)?\\((.+)\\)$");
+const QRegularExpression integerExpr("^(-)?([0-9]+)$");
//double functions
double treatFuncs(QString const& expr, bool & noProblem);
@@ -364,14 +364,15 @@ double treatFuncs(QString const& expr, bool & noProblem)
noProblem = true;
- QRegExp funcExp = funcExpr; //copy the expression in the current execution stack, to avoid errors for example when multiple thread call this function.
- QRegExp numExp = numberExpr;
+ QRegularExpression funcExp = funcExpr; //copy the expression in the current execution stack, to avoid errors for example when multiple thread call this function.
+ QRegularExpression numExp = numberExpr;
+ QRegularExpressionMatch match;
- if (funcExp.exactMatch(expr.trimmed())) {
+ if (expr.trimmed().contains(funcExp, &match)) {
- int sign = funcExp.capturedTexts()[1].isEmpty() ? 1 : -1;
- QString func = funcExp.capturedTexts()[2].toLower();
- QString subExpr = funcExp.capturedTexts()[3];
+ int sign = match.captured(1).isEmpty() ? 1 : -1;
+ QString func = match.captured(2).toLower();
+ QString subExpr = match.captured(3);
double val = treatLevel1(subExpr, noProblem);
@@ -412,7 +413,7 @@ double treatFuncs(QString const& expr, bool & noProblem)
}
return sign*val;
- } else if(numExp.exactMatch(expr.trimmed())) {
+ } else if(expr.trimmed().contains(numExp)) {
return expr.toDouble(&noProblem);
}
@@ -534,14 +535,14 @@ double treatFuncsInt(QString const& expr, bool & noProblem)
noProblem = true;
- QRegExp funcExpInteger = funcExprInteger;
- QRegExp integerExp = integerExpr;
- QRegExp numberExp = numberExpr;
+ QRegularExpression funcExpInteger = funcExprInteger;
+ QRegularExpression numberExp = numberExpr;
+ QRegularExpressionMatch match;
- if (funcExpInteger.exactMatch(expr.trimmed())) {
+ if (expr.trimmed().contains(funcExpInteger, &match)) {
- int sign = funcExpInteger.capturedTexts()[1].isEmpty() ? 1 : -1;
- QString subExpr = funcExpInteger.capturedTexts()[2];
+ int sign = match.captured(1).isEmpty() ? 1 : -1;
+ QString subExpr = match.captured(2);
double val = treatLevel1Int(subExpr, noProblem);
@@ -551,7 +552,7 @@ double treatFuncsInt(QString const& expr, bool & noProblem)
return sign*val;
- } else if(numberExp.exactMatch(expr.trimmed())) {
+ } else if(expr.trimmed().contains(numberExp)) {
double value = QVariant(expr).toDouble(&noProblem);
return value;
}
diff --git a/libs/widgetutils/xmlgui/kxmlguiclient.cpp b/libs/widgetutils/xmlgui/kxmlguiclient.cpp
index 57aaa2c64e..cb9d87d3bc 100644
--- a/libs/widgetutils/xmlgui/kxmlguiclient.cpp
+++ b/libs/widgetutils/xmlgui/kxmlguiclient.cpp
@@ -16,7 +16,6 @@
#include <QDir>
#include <QFile>
#include <QDomDocument>
-#include <QRegExp>
#include <QPointer>
#include <QCoreApplication>
#include <QStandardPaths>
diff --git a/plugins/extensions/qmic/kis_qmic_import_tools.cpp b/plugins/extensions/qmic/kis_qmic_import_tools.cpp
index 8e089d91fa..804167cce4 100644
--- a/plugins/extensions/qmic/kis_qmic_import_tools.cpp
+++ b/plugins/extensions/qmic/kis_qmic_import_tools.cpp
@@ -7,7 +7,6 @@
*/
#include <QRegularExpression>
-#include <QRegExp>
#include <KoCompositeOpRegistry.h>
#include <commands/KisNodeRenameCommand.h>
@@ -41,9 +40,10 @@ applyLayerNameChanges(const KisQMicImage &srcGmicImage,
dbgPlugins << "Layer name: " << srcGmicImage.m_layerName;
{
- const QRegExp modeRe(R"(mode\(\s*([^)]*)\s*\))");
- if (modeRe.indexIn(srcGmicImage.m_layerName) != -1) {
- QString modeStr = modeRe.cap(1).trimmed();
+ const QRegularExpression modeRe(R"(mode\(\s*([^)]*)\s*\))");
+ QRegularExpressionMatch match;
+ if (srcGmicImage.m_layerName.contains(modeRe, &match)) {
+ QString modeStr = match.captured(1).trimmed();
auto translatedMode =
KisQmicSimpleConvertor::stringToBlendingMode(modeStr);
dbgPlugins << "Detected mode: " << modeStr << " => "
@@ -56,10 +56,10 @@ applyLayerNameChanges(const KisQMicImage &srcGmicImage,
}
{
- const QRegExp opacityRe(R"(opacity\(\s*([^)]*)\s*\))");
-
- if (opacityRe.indexIn(srcGmicImage.m_layerName) != -1) {
- const auto opacity = opacityRe.cap(1).toFloat();
+ const QRegularExpression opacityRe(R"(opacity\(\s*([^)]*)\s*\))");
+ QRegularExpressionMatch match;
+ if (srcGmicImage.m_layerName.contains(opacityRe, &match)) {
+ const float opacity = match.captured(1).toFloat();
dbgPlugins << "Detected opacity: " << opacity
<< std::lround(opacity / 100.f * 255.f);
cmd->addCommand(
@@ -70,10 +70,11 @@ applyLayerNameChanges(const KisQMicImage &srcGmicImage,
}
{
- const QRegExp nameRe(R"(name\(\s*([^)]*)\s*\))");
+ const QRegularExpression nameRe(R"(name\(\s*([^)]*)\s*\))");
- if (nameRe.indexIn(srcGmicImage.m_layerName) != -1) {
- const auto name = nameRe.cap(1);
+ QRegularExpressionMatch match;
+ if (srcGmicImage.m_layerName.contains(nameRe, &match)) {
+ const auto name = match.captured(1);
dbgPlugins << "Detected layer name: " << name;
cmd->addCommand(new KisNodeRenameCommand(node, node->name(), name));
// apply command
diff --git a/plugins/filters/colorsfilters/kis_cross_channel_filter.cpp b/plugins/filters/colorsfilters/kis_cross_channel_filter.cpp
index 6b1b76e714..504df9af47 100644
--- a/plugins/filters/colorsfilters/kis_cross_channel_filter.cpp
+++ b/plugins/filters/colorsfilters/kis_cross_channel_filter.cpp
@@ -14,7 +14,7 @@
#include <QPainter>
#include <QDomDocument>
#include <QHBoxLayout>
-#include <QRegExp>
+#include <QRegularExpression>
#include "KoChannelInfo.h"
#include "KoBasicHistogramProducers.h"
@@ -108,12 +108,13 @@ void KisCrossChannelFilterConfiguration::fromXML(const QDomElement& root)
QVector<int> driverChannels;
driverChannels.resize(m_curves.size());
- QRegExp rx("driver(\\d+)");
+ QRegularExpression rx("^driver(\\d+)$");
+ QRegularExpressionMatch match;
for (QDomElement e = root.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
const QString attributeName = e.attribute("name");
- if (rx.exactMatch(attributeName)) {
- int channel = rx.cap(1).toUShort();
+ if (attributeName.contains(rx, &match)) {
+ int channel = match.captured(1).toUShort();
int driver = KisDomUtils::toInt(e.text());
if (0 <= channel && channel < driverChannels.size()) {
@@ -217,12 +218,13 @@ void KisCrossChannelFilterConfiguration::setProperty(const QString& name, const
bool KisCrossChannelFilterConfiguration::channelIndexFromDriverPropertyName(const QString& name, int& driverIndex) const
{
- QRegExp rx("driver(\\d+)");
- if (rx.indexIn(name, 0) == -1) {
+ QRegularExpression rx("driver(\\d+)");
+ QRegularExpressionMatch match;
+ if (!name.contains(rx, &match)) {
return false;
}
- driverIndex = rx.cap(1).toUShort();
+ driverIndex = match.captured(1).toUShort();
return true;
}
diff --git a/plugins/filters/colorsfilters/kis_multichannel_filter_base.cpp b/plugins/filters/colorsfilters/kis_multichannel_filter_base.cpp
index bdba32b818..29020ef204 100644
--- a/plugins/filters/colorsfilters/kis_multichannel_filter_base.cpp
+++ b/plugins/filters/colorsfilters/kis_multichannel_filter_base.cpp
@@ -15,7 +15,7 @@
#include <QDomDocument>
#include <QHBoxLayout>
#include <QMessageBox>
-#include <QRegExp>
+#include <QRegularExpression>
#include "KoChannelInfo.h"
#include "KoBasicHistogramProducers.h"
@@ -183,7 +183,8 @@ void KisMultiChannelFilterConfiguration::fromXML(const QDomElement& root)
QString attributeName;
KisCubicCurve curve;
quint16 index;
- QRegExp curveRegexp("curve(\\d+)");
+ QRegularExpression curveRegexp("curve(\\d+)");
+ QRegularExpressionMatch match;
while (!e.isNull()) {
if ((attributeName = e.attribute("name")) == "activeCurve") {
@@ -193,9 +194,9 @@ void KisMultiChannelFilterConfiguration::fromXML(const QDomElement& root)
} else if ((attributeName = e.attribute("name")) == "nTransfersWithAlpha") {
numTransfersWithAlpha = e.text().toUShort();
} else {
- if (curveRegexp.indexIn(attributeName, 0) != -1) {
+ if (attributeName.contains(curveRegexp, &match)) {
- index = curveRegexp.cap(1).toUShort();
+ index = match.captured(1).toUShort();
index = qMin(index, quint16(curves.count()));
if (!e.text().isEmpty()) {
@@ -375,12 +376,13 @@ void KisMultiChannelFilterConfiguration::setProperty(const QString& name, const
bool KisMultiChannelFilterConfiguration::curveIndexFromCurvePropertyName(const QString& name, int& curveIndex) const
{
- QRegExp rx("curve(\\d+)");
- if (rx.indexIn(name, 0) == -1) {
+ QRegularExpression rx("curve(\\d+)");
+ QRegularExpressionMatch match;
+ if (!name.contains(rx, &match)) {
return false;
}
- curveIndex = rx.cap(1).toUShort();
+ curveIndex = match.captured(1).toUShort();
return true;
}
diff --git a/plugins/metadata/iptc/kis_iptc_io.cpp b/plugins/metadata/iptc/kis_iptc_io.cpp
index 5a0a705a6f..c65da7dba4 100644
--- a/plugins/metadata/iptc/kis_iptc_io.cpp
+++ b/plugins/metadata/iptc/kis_iptc_io.cpp
@@ -9,7 +9,6 @@
#include <exiv2/iptc.hpp>
#include <QIODevice>
-#include <QRegExp>
#include <kis_debug.h>
#include <kis_exiv2_common.h>
diff --git a/plugins/metadata/xmp/kis_xmp_io.cpp b/plugins/metadata/xmp/kis_xmp_io.cpp
index 81e21872bf..e7abb6a6d1 100644
--- a/plugins/metadata/xmp/kis_xmp_io.cpp
+++ b/plugins/metadata/xmp/kis_xmp_io.cpp
@@ -9,7 +9,7 @@
#include <string>
#include <QIODevice>
-#include <QRegExp>
+#include <QRegularExpression>
#include <kis_exiv2_common.h>
#include <kis_meta_data_entry.h>
@@ -180,10 +180,11 @@ bool parseTagName(const QString &tagString,
}
if (numSubNames == 2) {
- QRegExp regexp("([A-Za-z]\\w+)/([A-Za-z]\\w+):([A-Za-z]\\w+)");
- if (regexp.indexIn(tagString) != -1) {
- structName = regexp.capturedTexts()[1];
- tagName = regexp.capturedTexts()[3];
+ QRegularExpression regexp("([A-Za-z]\\w+)/([A-Za-z]\\w+):([A-Za-z]\\w+)");
+ QRegularExpressionMatch match;
+ if (tagString.contains(regexp, &match)) {
+ structName = match.captured(1);
+ tagName = match.captured(3);
*typeInfo = schema->propertyType(structName);
if (*typeInfo && (*typeInfo)->propertyType() == KisMetaData::TypeInfo::StructureType) {
@@ -193,11 +194,12 @@ bool parseTagName(const QString &tagString,
return true;
}
- QRegExp regexp2("([A-Za-z]\\w+)\\[(\\d+)\\]/([A-Za-z]\\w+):([A-Za-z]\\w+)");
- if (regexp2.indexIn(tagString) != -1) {
- structName = regexp2.capturedTexts()[1];
- arrayIndex = regexp2.capturedTexts()[2].toInt() - 1;
- tagName = regexp2.capturedTexts()[4];
+ QRegularExpression regexp2("([A-Za-z]\\w+)\\[(\\d+)\\]/([A-Za-z]\\w+):([A-Za-z]\\w+)");
+ QRegularExpressionMatch match2;
+ if (tagString.contains(regexp2, &match2)) {
+ structName = match2.captured(1);
+ arrayIndex = match2.captured(2).toInt() - 1;
+ tagName = match2.captured(4);
if (schema->propertyType(structName)) {
*typeInfo = schema->propertyType(structName)->embeddedPropertyType();
diff --git a/plugins/tools/svgtexttool/BasicXMLSyntaxHighlighter.cpp b/plugins/tools/svgtexttool/BasicXMLSyntaxHighlighter.cpp
index f8e17e40d5..055bbc9e6c 100644
--- a/plugins/tools/svgtexttool/BasicXMLSyntaxHighlighter.cpp
+++ b/plugins/tools/svgtexttool/BasicXMLSyntaxHighlighter.cpp
@@ -35,21 +35,15 @@ BasicXMLSyntaxHighlighter::BasicXMLSyntaxHighlighter(QTextEdit * parent) :
void BasicXMLSyntaxHighlighter::highlightBlock(const QString & text)
{
// Special treatment for xml element regex as we use captured text to emulate lookbehind
- int xmlElementIndex = m_xmlElementRegex.indexIn(text);
- while(xmlElementIndex >= 0)
- {
- int matchedPos = m_xmlElementRegex.pos(1);
- int matchedLength = m_xmlElementRegex.cap(1).length();
- setFormat(matchedPos, matchedLength, m_xmlElementFormat);
-
- xmlElementIndex = m_xmlElementRegex.indexIn(text, matchedPos + matchedLength);
- }
+ for (const QRegularExpressionMatch &match : m_xmlElementRegex.globalMatch(text)) {
+ setFormat(match.capturedStart(0), match.capturedLength(0), m_xmlElementFormat);
+ }
// Highlight xml keywords *after* xml elements to fix any occasional / captured into the enclosing element
- typedef QList<QRegExp>::const_iterator Iter;
+ typedef QList<QRegularExpression>::const_iterator Iter;
Iter xmlKeywordRegexesEnd = m_xmlKeywordRegexes.constEnd();
for(Iter it = m_xmlKeywordRegexes.constBegin(); it != xmlKeywordRegexesEnd; ++it) {
- const QRegExp & regex = *it;
+ const QRegularExpression & regex = *it;
highlightByRegex(m_xmlKeywordFormat, regex, text);
}
@@ -59,17 +53,11 @@ void BasicXMLSyntaxHighlighter::highlightBlock(const QString & text)
}
void BasicXMLSyntaxHighlighter::highlightByRegex(const QTextCharFormat & format,
- const QRegExp & regex, const QString & text)
+ const QRegularExpression & regex, const QString & text)
{
- int index = regex.indexIn(text);
-
- while(index >= 0)
- {
- int matchedLength = regex.matchedLength();
- setFormat(index, matchedLength, format);
-
- index = regex.indexIn(text, index + matchedLength);
- }
+ for (const QRegularExpressionMatch &match : regex.globalMatch(text)) {
+ setFormat(match.capturedStart(0), match.capturedLength(0), format);
+ }
}
void BasicXMLSyntaxHighlighter::setRegexes()
@@ -79,9 +67,10 @@ void BasicXMLSyntaxHighlighter::setRegexes()
m_xmlValueRegex.setPattern("\"[^\\n\"]+\"(?=[\\s/>])");
m_xmlCommentRegex.setPattern("<!--[^\\n]*-->");
- m_xmlKeywordRegexes = QList<QRegExp>() << QRegExp("<\\?") << QRegExp("/>")
- << QRegExp(">") << QRegExp("<") << QRegExp("</")
- << QRegExp("\\?>");
+ m_xmlKeywordRegexes = QList<QRegularExpression>()
+ << QRegularExpression("<\\?") << QRegularExpression("/>")
+ << QRegularExpression(">") << QRegularExpression("<") << QRegularExpression("</")
+ << QRegularExpression("\\?>");
}
void BasicXMLSyntaxHighlighter::setFormats()
diff --git a/plugins/tools/svgtexttool/BasicXMLSyntaxHighlighter.h b/plugins/tools/svgtexttool/BasicXMLSyntaxHighlighter.h
index 13aaad84e5..c23f989a19 100644
--- a/plugins/tools/svgtexttool/BasicXMLSyntaxHighlighter.h
+++ b/plugins/tools/svgtexttool/BasicXMLSyntaxHighlighter.h
@@ -8,7 +8,7 @@
#include <QSyntaxHighlighter>
#include <QTextEdit>
-#include <QRegExp>
+#include <QRegularExpression>
/**
* A Basic XML syntax highlighter in C++/Qt (subclass of QSyntaxHighlighter). Uses simple
@@ -36,7 +36,7 @@ protected:
private:
void highlightByRegex(const QTextCharFormat & format,
- const QRegExp & regex, const QString & text);
+ const QRegularExpression & regex, const QString & text);
void setRegexes();
@@ -48,11 +48,11 @@ private:
QTextCharFormat m_xmlValueFormat;
QTextCharFormat m_xmlCommentFormat;
- QList<QRegExp> m_xmlKeywordRegexes;
- QRegExp m_xmlElementRegex;
- QRegExp m_xmlAttributeRegex;
- QRegExp m_xmlValueRegex;
- QRegExp m_xmlCommentRegex;
+ QList<QRegularExpression> m_xmlKeywordRegexes;
+ QRegularExpression m_xmlElementRegex;
+ QRegularExpression m_xmlAttributeRegex;
+ QRegularExpression m_xmlValueRegex;
+ QRegularExpression m_xmlCommentRegex;
};
#endif // BASIC_XML_SYNTAX_HIGHLIGHTER_H
diff --git a/plugins/tools/svgtexttool/SvgTextInsertCommand.cpp b/plugins/tools/svgtexttool/SvgTextInsertCommand.cpp
index a34ae64341..4e48dd6dfe 100644
--- a/plugins/tools/svgtexttool/SvgTextInsertCommand.cpp
+++ b/plugins/tools/svgtexttool/SvgTextInsertCommand.cpp
@@ -8,7 +8,7 @@
#include "KoSvgTextShapeMarkupConverter.h"
#include <KoShapeBulkActionLock.h>
-#include <QRegExp>
+#include <QRegularExpression>
#include "kis_command_ids.h"
SvgTextInsertCommand::SvgTextInsertCommand(KoSvgTextShape *shape, int pos, int anchor, QString text, KUndo2Command *parent)
@@ -20,7 +20,7 @@ SvgTextInsertCommand::SvgTextInsertCommand(KoSvgTextShape *shape, int pos, int a
{
setText(kundo2_i18n("Insert Text"));
- QRegExp exp;
+ QRegularExpression exp;
// This replaces...
// - carriage return
// - linefeed-carriage return
@@ -31,11 +31,7 @@ SvgTextInsertCommand::SvgTextInsertCommand(KoSvgTextShape *shape, int pos, int a
// with a single linefeed to avoid them from being added to the textShape.
exp.setPattern("[\\r|\\r\\n|\\x2029|\\x2028\\x000b]");
-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
text.replace(exp, "\n");
-#else
- text = exp.replaceIn(text, "\n");
-#endif
m_text = text;
}