From a7dc5c23e450d30341274ece8f16e8ed508aa83a Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 8 Oct 2022 13:33:10 +0200 Subject: [PATCH] TD: replace QRegExp with QRegularExpression --- src/Mod/TechDraw/App/DrawViewDimension.cpp | 33 ++++++++++++---------- src/Mod/TechDraw/Gui/QGIRichAnno.cpp | 14 +++++---- src/Mod/TechDraw/Gui/mrichtextedit.cpp | 5 ++-- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp index 0914f4d6d0..30f9f1320d 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp @@ -27,7 +27,8 @@ # include # include # include -# include +# include +# include # include # include #include @@ -855,10 +856,11 @@ std::string DrawViewDimension::formatValue(qreal value, // qUserString is the value + unit with default decimals, so extract the unit // we cannot just use unit.getString() because this would convert '°' to 'deg' - QRegExp rxUnits(QString::fromUtf8(" \\D*$")); // space + any non digits at end of string - int pos = rxUnits.indexIn(qUserString, 0); + QRegularExpression rxUnits(QString::fromUtf8(" \\D*$")); // space + any non digits at end of string + QRegularExpressionMatch rxMatch; + int pos = qUserString.indexOf(rxUnits, 0, &rxMatch); if (pos != -1) { - qUserStringUnits = rxUnits.cap(0); // entire capture - non numerics at end of qUserString + qUserStringUnits = rxMatch.captured(0); // entire capture - non numerics at end of qUserString } // get value in the base unit with default decimals @@ -881,15 +883,15 @@ std::string DrawViewDimension::formatValue(qreal value, // the user can overwrite the decimal settings, so we must in every case use the formatSpecifier // the default is: if useDecimals(), then formatSpecifier = global decimals, otherwise it is %.2f // Also, handle the new non-standard format-specifier '%w', which has the following rules: works as %f, but no trailing zeros - if (formatSpecifier.contains(QRegExp(QStringLiteral("%.*[wW]")))) { + if (formatSpecifier.contains(QRegularExpression(QStringLiteral("%.*[wW]")))) { QString fs = formatSpecifier; - fs.replace(QRegExp(QStringLiteral("%(.*)w")), QStringLiteral("%\\1f")); - fs.replace(QRegExp(QStringLiteral("%(.*)W")), QStringLiteral("%\\1F")); + fs.replace(QRegularExpression(QStringLiteral("%(.*)w")), QStringLiteral("%\\1f")); + fs.replace(QRegularExpression(QStringLiteral("%(.*)W")), QStringLiteral("%\\1F")); formattedValue = QString::asprintf(Base::Tools::toStdString(fs).c_str(), userVal); // First, try to cut trailing zeros, if AFTER decimal dot there are nonzero numbers // Second, try to cut also decimal dot and zeros, if there are just zeros after it - formattedValue.replace(QRegExp(QStringLiteral("([0-9][0-9]*\\.[0-9]*[1-9])00*$")), QStringLiteral("\\1")); - formattedValue.replace(QRegExp(QStringLiteral("([0-9][0-9]*)\\.0*$")), QStringLiteral("\\1")); + formattedValue.replace(QRegularExpression(QStringLiteral("([0-9][0-9]*\\.[0-9]*[1-9])00*$")), QStringLiteral("\\1")); + formattedValue.replace(QRegularExpression(QStringLiteral("([0-9][0-9]*)\\.0*$")), QStringLiteral("\\1")); } else { formattedValue = QString::asprintf(Base::Tools::toStdString(formatSpecifier).c_str(), userVal); } @@ -931,7 +933,7 @@ std::string DrawViewDimension::formatValue(qreal value, // other units need 1 space for readability if ( angularMeasure && !qUserStringUnits.contains(QString::fromLatin1("deg")) ) { - QRegExp space(QString::fromUtf8("\\s")); + QRegularExpression space(QString::fromUtf8("\\s")); qUserStringUnits.remove(space); } if (angularMeasure) { @@ -963,7 +965,7 @@ std::string DrawViewDimension::formatValue(qreal value, if (angularMeasure) { // remove leading space from unit if unit is not "deg" if ( !qUserStringUnits.contains(QString::fromLatin1("deg")) ) { - QRegExp space(QString::fromUtf8("\\s")); + QRegularExpression space(QString::fromUtf8("\\s")); qUserStringUnits.remove(space); } return Base::Tools::toStdString(qUserStringUnits); @@ -1084,7 +1086,7 @@ std::string DrawViewDimension::getFormattedDimensionValue(int partial) // tolerance might start with a plus sign that we don't want, so cut it off // note plus sign is not at pos = 0! - QRegExp plus(QString::fromUtf8("^\\s*\\+")); + QRegularExpression plus(QString::fromUtf8("^\\s*\\+")); tolerance.remove(plus); return (labelText + @@ -1108,10 +1110,11 @@ QStringList DrawViewDimension::getPrefixSuffixSpec(QString fSpec) { QStringList result; //find the %x.y tag in FormatSpec - QRegExp rxFormat(QStringLiteral("%[+-]?[0-9]*\\.*[0-9]*[aefgwAEFGW]")); //printf double format spec - int pos = rxFormat.indexIn(fSpec, 0); + QRegularExpression rxFormat(QStringLiteral("%[+-]?[0-9]*\\.*[0-9]*[aefgwAEFGW]")); //printf double format spec + QRegularExpressionMatch rxMatch; + int pos = fSpec.indexOf(rxFormat, 0, &rxMatch); if (pos != -1) { - QString match = rxFormat.cap(0); //entire capture of rx + QString match = rxMatch.captured(0); //entire capture of rx QString formatPrefix = fSpec.left(pos); result.append(formatPrefix); QString formatSuffix = fSpec.right(fSpec.size() - pos - match.size()); diff --git a/src/Mod/TechDraw/Gui/QGIRichAnno.cpp b/src/Mod/TechDraw/Gui/QGIRichAnno.cpp index bbc6c2d58d..917c05824b 100644 --- a/src/Mod/TechDraw/Gui/QGIRichAnno.cpp +++ b/src/Mod/TechDraw/Gui/QGIRichAnno.cpp @@ -37,7 +37,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -188,16 +189,17 @@ void QGIRichAnno::setTextItem() //font sizes differently from QGraphicsTextItem (?) if (!getExporting()) { //convert point font sizes to (Rez, mm) font sizes - QRegExp rxFontSize(QString::fromUtf8("font-size:([0-9]*)pt;")); + QRegularExpression rxFontSize(QString::fromUtf8("font-size:([0-9]*)pt;")); + QRegularExpressionMatch match; double mmPerPoint = 0.353; double sizeConvert = Rez::getRezFactor() * mmPerPoint; int pos = 0; QStringList findList; QStringList replList; - while ((pos = rxFontSize.indexIn(inHtml, pos)) != -1) { - QString found = rxFontSize.cap(0); + while ((pos = inHtml.indexOf(rxFontSize, pos, &match)) != -1) { + QString found = match.captured(0); findList << found; - QString qsOldSize = rxFontSize.cap(1); + QString qsOldSize = match.captured(1); QString repl = found; double newSize = qsOldSize.toDouble(); @@ -205,7 +207,7 @@ void QGIRichAnno::setTextItem() QString qsNewSize = QString::number(newSize, 'f', 2); repl.replace(qsOldSize, qsNewSize); replList << repl; - pos += rxFontSize.matchedLength(); + pos += match.capturedLength(); } QString outHtml = inHtml; int iRepl = 0; diff --git a/src/Mod/TechDraw/Gui/mrichtextedit.cpp b/src/Mod/TechDraw/Gui/mrichtextedit.cpp index ffc4c50e37..d30cf4f4bc 100644 --- a/src/Mod/TechDraw/Gui/mrichtextedit.cpp +++ b/src/Mod/TechDraw/Gui/mrichtextedit.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #endif #include @@ -649,11 +650,11 @@ void MRichTextEdit::slotClipboardDataChanged() { QString MRichTextEdit::toHtml() const { QString s = f_textedit->toHtml(); // convert emails to links - s = s.replace(QRegExp( + s = s.replace(QRegularExpression( QString::fromUtf8("(<[^a][^>]+>(?:]+>)?|\\s)([a-zA-Z\\d]+@[a-zA-Z\\d]+\\.[a-zA-Z]+)")), QString::fromUtf8("\\1\\2")); // convert links - s = s.replace(QRegExp( + s = s.replace(QRegularExpression( QString::fromUtf8("(<[^a][^>]+>(?:]+>)?|\\s)((?:https?|ftp|file)://[^\\s'\"<>]+)")), QString::fromUtf8( "\\1\\2")); // see also: Utils::linkify()