From 824b330e2eaab100f0e2a8bb7d60642674b297d9 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sun, 17 Jun 2018 23:53:43 +0200 Subject: Migrate ChartAxisElement to QRegularExpression This patch updates the ChartAxisElement to use QRegularExpression in place of QRegExp which is to be considered deprecated. Change-Id: I9f028e69c8337e5aad59351c9cccf222169df849 Reviewed-by: Miikka Heikkinen --- src/charts/axis/chartaxiselement.cpp | 49 ++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/charts/axis/chartaxiselement.cpp b/src/charts/axis/chartaxiselement.cpp index 5282ee36..a090582f 100644 --- a/src/charts/axis/chartaxiselement.cpp +++ b/src/charts/axis/chartaxiselement.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -41,8 +42,8 @@ QT_CHARTS_BEGIN_NAMESPACE static const char *labelFormatMatchString = "%[\\-\\+#\\s\\d\\.\\'lhjztL]*([dicuoxfegXFEG])"; static const char *labelFormatMatchLocalizedString = "^([^%]*)%\\.(\\d+)([defgiEG])(.*)$"; -static QRegExp *labelFormatMatcher = 0; -static QRegExp *labelFormatMatcherLocalized = 0; +static QRegularExpression *labelFormatMatcher = 0; +static QRegularExpression *labelFormatMatcherLocalized = 0; class StaticLabelFormatMatcherDeleter { public: @@ -358,19 +359,21 @@ QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, if (presenter()->localizeNumbers()) { if (!labelFormatMatcherLocalized) labelFormatMatcherLocalized - = new QRegExp(QString::fromLatin1(labelFormatMatchLocalizedString)); - if (labelFormatMatcherLocalized->indexIn(format, 0) != -1) { - preStr = labelFormatMatcherLocalized->cap(1); - if (!labelFormatMatcherLocalized->cap(2).isEmpty()) - precision = labelFormatMatcherLocalized->cap(2).toInt(); - formatSpec = labelFormatMatcherLocalized->cap(3); - postStr = labelFormatMatcherLocalized->cap(4); + = new QRegularExpression(QString::fromLatin1(labelFormatMatchLocalizedString)); + QRegularExpressionMatch rmatch; + if (format.indexOf(*labelFormatMatcherLocalized, 0, &rmatch) != -1) { + preStr = rmatch.captured(1); + if (!rmatch.captured(2).isEmpty()) + precision = rmatch.captured(2).toInt(); + formatSpec = rmatch.captured(3); + postStr = rmatch.captured(4); } } else { if (!labelFormatMatcher) - labelFormatMatcher = new QRegExp(QString::fromLatin1(labelFormatMatchString)); - if (labelFormatMatcher->indexIn(format, 0) != -1) - formatSpec = labelFormatMatcher->cap(1); + labelFormatMatcher = new QRegularExpression(QString::fromLatin1(labelFormatMatchString)); + QRegularExpressionMatch rmatch; + if (format.indexOf(*labelFormatMatcher, 0, &rmatch) != -1) + formatSpec = rmatch.captured(1); } for (int i = 0; i < ticks; i++) { qreal value = min + (i * (max - min) / (ticks - 1)); @@ -413,19 +416,21 @@ QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal b if (presenter()->localizeNumbers()) { if (!labelFormatMatcherLocalized) labelFormatMatcherLocalized = - new QRegExp(QString::fromLatin1(labelFormatMatchLocalizedString)); - if (labelFormatMatcherLocalized->indexIn(format, 0) != -1) { - preStr = labelFormatMatcherLocalized->cap(1); - if (!labelFormatMatcherLocalized->cap(2).isEmpty()) - precision = labelFormatMatcherLocalized->cap(2).toInt(); - formatSpec = labelFormatMatcherLocalized->cap(3); - postStr = labelFormatMatcherLocalized->cap(4); + new QRegularExpression(QString::fromLatin1(labelFormatMatchLocalizedString)); + QRegularExpressionMatch rmatch; + if (format.indexOf(*labelFormatMatcherLocalized, 0, &rmatch) != -1) { + preStr = rmatch.captured(1); + if (!rmatch.captured(2).isEmpty()) + precision = rmatch.captured(2).toInt(); + formatSpec = rmatch.captured(3); + postStr = rmatch.captured(4); } } else { if (!labelFormatMatcher) - labelFormatMatcher = new QRegExp(QString::fromLatin1(labelFormatMatchString)); - if (labelFormatMatcher->indexIn(format, 0) != -1) - formatSpec = labelFormatMatcher->cap(1); + labelFormatMatcher = new QRegularExpression(QString::fromLatin1(labelFormatMatchString)); + QRegularExpressionMatch rmatch; + if (format.indexOf(*labelFormatMatcher, 0, &rmatch) != -1) + formatSpec = rmatch.captured(1); } for (int i = firstTick; i < ticks + firstTick; i++) { qreal value = qPow(base, i); -- cgit v1.2.3