From a1cf6e52818d10ac5d4e6339d5bc4cf9b01bf44e Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sat, 21 Jan 2017 23:33:14 +0100 Subject: Example: migrate stylesheet example to use QRegularExpression Update the stylesheet example to use the new QRegularExpression class in place of the deprecated QRegExp. Change-Id: I7061b8fd462ff012cb67bfdade656b3bfe442dd8 Reviewed-by: Sze Howe Koh --- examples/widgets/widgets/stylesheet/stylesheeteditor.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp b/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp index 7a75233628..3247fa774d 100644 --- a/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp +++ b/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp @@ -57,11 +57,12 @@ StyleSheetEditor::StyleSheetEditor(QWidget *parent) { ui.setupUi(this); - QRegExp regExp(".(.*)\\+?Style"); + QRegularExpression regExp("^.(.*)\\+?Style$"); QString defaultStyle = QApplication::style()->metaObject()->className(); + QRegularExpressionMatch match = regExp.match(defaultStyle); - if (regExp.exactMatch(defaultStyle)) - defaultStyle = regExp.cap(1); + if (match.hasMatch()) + defaultStyle = match.captured(1); ui.styleCombo->addItems(QStyleFactory::keys()); ui.styleCombo->setCurrentIndex(ui.styleCombo->findText(defaultStyle, Qt::MatchContains)); -- cgit v1.2.3 From 57a710467b123e11b651eec951eb87558ea40c25 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sat, 21 Jan 2017 22:57:20 +0100 Subject: Example: migrate settingseditor example to use QRegularExpression Update the settingseditor example to use the new QRegularExpression class in place of the deprecated QRegExp. Change-Id: I07e34bf916bdde161c4253fca70b853061cd589b Reviewed-by: Sze Howe Koh --- .../tools/settingseditor/variantdelegate.cpp | 39 +++++++++++----------- .../widgets/tools/settingseditor/variantdelegate.h | 28 ++++++++-------- 2 files changed, 34 insertions(+), 33 deletions(-) (limited to 'examples') diff --git a/examples/widgets/tools/settingseditor/variantdelegate.cpp b/examples/widgets/tools/settingseditor/variantdelegate.cpp index e8552b66f2..266754ca4d 100644 --- a/examples/widgets/tools/settingseditor/variantdelegate.cpp +++ b/examples/widgets/tools/settingseditor/variantdelegate.cpp @@ -56,14 +56,14 @@ VariantDelegate::VariantDelegate(QObject *parent) : QItemDelegate(parent) { boolExp.setPattern("true|false"); - boolExp.setCaseSensitivity(Qt::CaseInsensitive); + boolExp.setPatternOptions(QRegularExpression::CaseInsensitiveOption); byteArrayExp.setPattern("[\\x00-\\xff]*"); charExp.setPattern("."); - colorExp.setPattern("\\(([0-9]*),([0-9]*),([0-9]*),([0-9]*)\\)"); + colorExp.setPattern("^\\(([0-9]*),([0-9]*),([0-9]*),([0-9]*)\\)$"); doubleExp.setPattern(""); - pointExp.setPattern("\\((-?[0-9]*),(-?[0-9]*)\\)"); - rectExp.setPattern("\\((-?[0-9]*),(-?[0-9]*),(-?[0-9]*),(-?[0-9]*)\\)"); + pointExp.setPattern("^\\((-?[0-9]*),(-?[0-9]*)\\)$"); + rectExp.setPattern("^\\((-?[0-9]*),(-?[0-9]*),(-?[0-9]*),(-?[0-9]*)\\)$"); signedIntegerExp.setPattern("-?[0-9]*"); sizeExp = pointExp; unsignedIntegerExp.setPattern("[0-9]*"); @@ -104,7 +104,7 @@ QWidget *VariantDelegate::createEditor(QWidget *parent, QLineEdit *lineEdit = new QLineEdit(parent); lineEdit->setFrame(false); - QRegExp regExp; + QRegularExpression regExp; switch (originalValue.type()) { case QVariant::Bool: @@ -152,8 +152,8 @@ QWidget *VariantDelegate::createEditor(QWidget *parent, ; } - if (!regExp.isEmpty()) { - QValidator *validator = new QRegExpValidator(regExp, lineEdit); + if (regExp.isValid()) { + QValidator *validator = new QRegularExpressionValidator(regExp, lineEdit); lineEdit->setValidator(validator); } @@ -185,17 +185,18 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, QVariant originalValue = index.model()->data(index, Qt::UserRole); QVariant value; + QRegularExpressionMatch match; switch (originalValue.type()) { case QVariant::Char: value = text.at(0); break; case QVariant::Color: - colorExp.exactMatch(text); - value = QColor(qMin(colorExp.cap(1).toInt(), 255), - qMin(colorExp.cap(2).toInt(), 255), - qMin(colorExp.cap(3).toInt(), 255), - qMin(colorExp.cap(4).toInt(), 255)); + match = colorExp.match(text); + value = QColor(qMin(match.captured(1).toInt(), 255), + qMin(match.captured(2).toInt(), 255), + qMin(match.captured(3).toInt(), 255), + qMin(match.captured(4).toInt(), 255)); break; case QVariant::Date: { @@ -214,17 +215,17 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, } break; case QVariant::Point: - pointExp.exactMatch(text); - value = QPoint(pointExp.cap(1).toInt(), pointExp.cap(2).toInt()); + match = pointExp.match(text); + value = QPoint(match.captured(1).toInt(), match.captured(2).toInt()); break; case QVariant::Rect: - rectExp.exactMatch(text); - value = QRect(rectExp.cap(1).toInt(), rectExp.cap(2).toInt(), - rectExp.cap(3).toInt(), rectExp.cap(4).toInt()); + match = rectExp.match(text); + value = QRect(match.captured(1).toInt(), match.captured(2).toInt(), + match.captured(3).toInt(), match.captured(4).toInt()); break; case QVariant::Size: - sizeExp.exactMatch(text); - value = QSize(sizeExp.cap(1).toInt(), sizeExp.cap(2).toInt()); + match = sizeExp.match(text); + value = QSize(match.captured(1).toInt(), match.captured(2).toInt()); break; case QVariant::StringList: value = text.split(','); diff --git a/examples/widgets/tools/settingseditor/variantdelegate.h b/examples/widgets/tools/settingseditor/variantdelegate.h index a15228fdf9..7cd9fa9ee8 100644 --- a/examples/widgets/tools/settingseditor/variantdelegate.h +++ b/examples/widgets/tools/settingseditor/variantdelegate.h @@ -52,7 +52,7 @@ #define VARIANTDELEGATE_H #include -#include +#include class VariantDelegate : public QItemDelegate { @@ -73,19 +73,19 @@ public: static QString displayText(const QVariant &value); private: - mutable QRegExp boolExp; - mutable QRegExp byteArrayExp; - mutable QRegExp charExp; - mutable QRegExp colorExp; - mutable QRegExp dateExp; - mutable QRegExp dateTimeExp; - mutable QRegExp doubleExp; - mutable QRegExp pointExp; - mutable QRegExp rectExp; - mutable QRegExp signedIntegerExp; - mutable QRegExp sizeExp; - mutable QRegExp timeExp; - mutable QRegExp unsignedIntegerExp; + mutable QRegularExpression boolExp; + mutable QRegularExpression byteArrayExp; + mutable QRegularExpression charExp; + mutable QRegularExpression colorExp; + mutable QRegularExpression dateExp; + mutable QRegularExpression dateTimeExp; + mutable QRegularExpression doubleExp; + mutable QRegularExpression pointExp; + mutable QRegularExpression rectExp; + mutable QRegularExpression signedIntegerExp; + mutable QRegularExpression sizeExp; + mutable QRegularExpression timeExp; + mutable QRegularExpression unsignedIntegerExp; }; #endif -- cgit v1.2.3 From d2e713f3fd591ca9879318f5691709a2cd362d1c Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sat, 21 Jan 2017 22:42:14 +0100 Subject: Example: migrate the codecs example to use QRegularExpression Update the codecs example to use the new QRegularExpression class in place of the deprecated QRegExp. Change-Id: Ibd60b7256071f8166c4bf38e6a40935494c3cf3f Reviewed-by: Sze Howe Koh --- examples/widgets/tools/codecs/mainwindow.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/widgets/tools/codecs/mainwindow.cpp b/examples/widgets/tools/codecs/mainwindow.cpp index 5e4810dd4d..28f904d1a7 100644 --- a/examples/widgets/tools/codecs/mainwindow.cpp +++ b/examples/widgets/tools/codecs/mainwindow.cpp @@ -138,7 +138,8 @@ void MainWindow::aboutToShowSaveAsMenu() void MainWindow::findCodecs() { QMap codecMap; - QRegExp iso8859RegExp("ISO[- ]8859-([0-9]+).*"); + QRegularExpression iso8859RegExp("^ISO[- ]8859-([0-9]+).*$"); + QRegularExpressionMatch match; foreach (int mib, QTextCodec::availableMibs()) { QTextCodec *codec = QTextCodec::codecForMib(mib); @@ -150,8 +151,8 @@ void MainWindow::findCodecs() rank = 1; } else if (sortKey.startsWith(QLatin1String("UTF-16"))) { rank = 2; - } else if (iso8859RegExp.exactMatch(sortKey)) { - if (iso8859RegExp.cap(1).size() == 1) + } else if ((match = iso8859RegExp.match(sortKey)).hasMatch()) { + if (match.captured(1).size() == 1) rank = 3; else rank = 4; -- cgit v1.2.3 From beb98bdafc7d935268d4e98888ba0ba3c85cf92d Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sat, 21 Jan 2017 21:52:20 +0100 Subject: Example: migrate the arthur code sample to use QRegularExpression Update the arthur code sample to use the new QRegularExpression class in place of the deprecated QRegExp. Change-Id: Ic7efd4466b4c0fa50170b80ebb22fcb3624399ce Reviewed-by: Sze Howe Koh --- examples/widgets/painting/shared/arthurwidgets.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/widgets/painting/shared/arthurwidgets.cpp b/examples/widgets/painting/shared/arthurwidgets.cpp index ffed01a3f3..965660a3a3 100644 --- a/examples/widgets/painting/shared/arthurwidgets.cpp +++ b/examples/widgets/painting/shared/arthurwidgets.cpp @@ -59,6 +59,7 @@ #include #include #include +#include extern QPixmap cached(const QString &img); @@ -339,14 +340,12 @@ void ArthurFrame::showSource() foreach (QString keyword, ppKeywords) contents.replace(keyword, QLatin1String("") + keyword + QLatin1String("")); - contents.replace(QRegExp("(\\d\\d?)"), QLatin1String("\\1")); + contents.replace(QRegularExpression("(\\d\\d?)"), QLatin1String("\\1")); - QRegExp commentRe("(//.+)\\n"); - commentRe.setMinimal(true); + QRegularExpression commentRe("(//.+?)\\n"); contents.replace(commentRe, QLatin1String("\\1\n")); - QRegExp stringLiteralRe("(\".+\")"); - stringLiteralRe.setMinimal(true); + QRegularExpression stringLiteralRe("(\".+?\")"); contents.replace(stringLiteralRe, QLatin1String("\\1")); QString html = contents; -- cgit v1.2.3 From 6864374f05c7493be2c18079e3777483d480ac6e Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sat, 21 Jan 2017 01:00:40 +0100 Subject: Example: migrate grabber to use QRegularExpression Update the legacy grabber example to use the new QRegularExpression class in place of the deprecated QRegExp. Change-Id: I1d1871b7e82cdb214fdd8ad55a606d5e7682fab1 Reviewed-by: Sze Howe Koh --- examples/opengl/legacy/grabber/mainwindow.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/opengl/legacy/grabber/mainwindow.cpp b/examples/opengl/legacy/grabber/mainwindow.cpp index da022adcdf..6ea6a28051 100644 --- a/examples/opengl/legacy/grabber/mainwindow.cpp +++ b/examples/opengl/legacy/grabber/mainwindow.cpp @@ -203,10 +203,11 @@ QSize MainWindow::getSize() if (!ok) return QSize(); - QRegExp regExp(tr("([0-9]+) *x *([0-9]+)")); - if (regExp.exactMatch(text)) { - int width = regExp.cap(1).toInt(); - int height = regExp.cap(2).toInt(); + QRegularExpression regExp(tr("^([0-9]+) *x *([0-9]+)$")); + QRegularExpressionMatch match = regExp.match(text); + if (match.hasMatch()) { + int width = match.captured(1).toInt(); + int height = match.captured(2).toInt(); if (width > 0 && width < 2048 && height > 0 && height < 2048) return QSize(width, height); } -- cgit v1.2.3 From 7dff4b921b0111c9ebe392ab1c168aaeff3d2605 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sat, 21 Jan 2017 00:41:45 +0100 Subject: Example: migrate flightinfo to QRegularExpression Update the flightinfo example to use the new QRegularExpression class in place of the deprecated QRegExp. Change-Id: I2395b37170565e922500e675210c400e90ae0f73 Reviewed-by: Sze Howe Koh --- examples/embedded/flightinfo/flightinfo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/embedded/flightinfo/flightinfo.cpp b/examples/embedded/flightinfo/flightinfo.cpp index 8ad1e5c0c0..e91277db58 100644 --- a/examples/embedded/flightinfo/flightinfo.cpp +++ b/examples/embedded/flightinfo/flightinfo.cpp @@ -239,9 +239,9 @@ private: int i = data.indexOf("a href=\"?view=detail"); if (i > 0) { QString href = data.mid(i, data.indexOf('\"', i + 8) - i + 1); - QRegExp regex("dpap=([A-Za-z0-9]+)"); - regex.indexIn(href); - QString airport = regex.cap(1); + QRegularExpression regex("dpap=([A-Za-z0-9]+)"); + QRegularExpressionMatch match = regex.match(href); + QString airport = match.captured(1); QUrlQuery query(m_url); query.addQueryItem("dpap", airport); m_url.setQuery(query); -- cgit v1.2.3