summaryrefslogtreecommitdiffstats
path: root/examples/widgets/tools
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/tools')
-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
3 files changed, 38 insertions, 36 deletions
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