summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/embedded/flightinfo/flightinfo.cpp6
-rw-r--r--examples/opengl/legacy/grabber/mainwindow.cpp9
-rw-r--r--examples/widgets/painting/shared/arthurwidgets.cpp9
-rw-r--r--examples/widgets/tools/codecs/mainwindow.cpp7
-rw-r--r--examples/widgets/tools/settingseditor/variantdelegate.cpp39
-rw-r--r--examples/widgets/tools/settingseditor/variantdelegate.h28
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheeteditor.cpp7
7 files changed, 54 insertions, 51 deletions
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);
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);
}
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 <QFile>
#include <QTextBrowser>
#include <QBoxLayout>
+#include <QRegularExpression>
extern QPixmap cached(const QString &img);
@@ -339,14 +340,12 @@ void ArthurFrame::showSource()
foreach (QString keyword, ppKeywords)
contents.replace(keyword, QLatin1String("<font color=navy>") + keyword + QLatin1String("</font>"));
- contents.replace(QRegExp("(\\d\\d?)"), QLatin1String("<font color=navy>\\1</font>"));
+ contents.replace(QRegularExpression("(\\d\\d?)"), QLatin1String("<font color=navy>\\1</font>"));
- QRegExp commentRe("(//.+)\\n");
- commentRe.setMinimal(true);
+ QRegularExpression commentRe("(//.+?)\\n");
contents.replace(commentRe, QLatin1String("<font color=red>\\1</font>\n"));
- QRegExp stringLiteralRe("(\".+\")");
- stringLiteralRe.setMinimal(true);
+ QRegularExpression stringLiteralRe("(\".+?\")");
contents.replace(stringLiteralRe, QLatin1String("<font color=green>\\1</font>"));
QString html = contents;
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<QString, QTextCodec *> 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;
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 <QItemDelegate>
-#include <QRegExp>
+#include <QRegularExpression>
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
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));