diff --git a/src/Tools/RegExp/RegExp.pro b/src/Tools/RegExp/RegExp.pro index e5d89d09a8..601246c3dc 100644 --- a/src/Tools/RegExp/RegExp.pro +++ b/src/Tools/RegExp/RegExp.pro @@ -3,9 +3,10 @@ ###################################################################### TEMPLATE = app -TARGET = +TARGET = regexp DEPENDPATH += . INCLUDEPATH += . +QT += widgets # Input HEADERS += regexpdialog.h diff --git a/src/Tools/RegExp/regexpdialog.cpp b/src/Tools/RegExp/regexpdialog.cpp index 474bfcb8c0..39d984ea4c 100644 --- a/src/Tools/RegExp/regexpdialog.cpp +++ b/src/Tools/RegExp/regexpdialog.cpp @@ -28,7 +28,6 @@ #include #include #include -#include RegExpDialog::RegExpDialog(QWidget* parent) : QDialog(parent), ui(new Ui_RegExpDialog()) @@ -53,10 +52,15 @@ void RegExpDialog::performRegExp() return; } - QRegExp rx(txt); - rx.setCaseSensitivity(ui->checkBox1->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive); - rx.setPatternSyntax(ui->checkBox2->isChecked() ? QRegExp::Wildcard : QRegExp::RegExp); - rx.setMinimal(ui->checkBox3->isChecked()); + QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption; + if (ui->checkBox1->isChecked()) { + options |= QRegularExpression::CaseInsensitiveOption; + } + if (ui->checkBox3->isChecked()) { + options |= QRegularExpression::InvertedGreedinessOption; + } + + QRegularExpression rx(txt, options); // evaluate regular expression ui->textLabel4->setText(rx.errorString()); @@ -92,7 +96,7 @@ void RegExpSyntaxHighlighter::highlightBlock (const QString & text) regFormat.setFontWeight(QFont::Normal); setFormat(0, text.length(), regFormat); - if (regexp.isEmpty()) + if (regexp.pattern().isEmpty()) return; // empty regular expression int pos = 0; @@ -100,16 +104,17 @@ void RegExpSyntaxHighlighter::highlightBlock (const QString & text) regFormat.setFontWeight(QFont::Bold); regFormat.setForeground(Qt::blue); - while ((pos = regexp.indexIn(text, pos)) != -1) { + QRegularExpressionMatch match; + while ((pos = text.indexOf(regexp, pos, &match)) != -1) { if (last == pos) break; - QString sub = text.mid(pos, regexp.matchedLength()); + QString sub = text.mid(pos, match.capturedLength()); if (!sub.isEmpty()) { setFormat(pos, sub.length(), regFormat); } - pos += regexp.matchedLength(); - last=pos; + pos += match.capturedLength(); + last = pos; } } #if 0 @@ -142,7 +147,7 @@ int RegExpSyntaxHighlighter::highlightParagraph ( const QString & text, int /*en return 0; } #endif -void RegExpSyntaxHighlighter::highlightMatchedText(const QRegExp& rx) +void RegExpSyntaxHighlighter::highlightMatchedText(const QRegularExpression& rx) { regexp = rx; rehighlight(); diff --git a/src/Tools/RegExp/regexpdialog.h b/src/Tools/RegExp/regexpdialog.h index 70280cb467..7a6650a0bf 100644 --- a/src/Tools/RegExp/regexpdialog.h +++ b/src/Tools/RegExp/regexpdialog.h @@ -25,8 +25,9 @@ #define REG_EXP_DIALOG_H #include -#include +#include #include +#include class RegExpSyntaxHighlighter; class Ui_RegExpDialog; @@ -57,11 +58,11 @@ public: void highlightBlock (const QString & text); //int highlightParagraph ( const QString & text, int endStateOfLastPara ); - void highlightMatchedText( const QRegExp& ); + void highlightMatchedText( const QRegularExpression& ); void resethighlight(); private: - QRegExp regexp; + QRegularExpression regexp; }; #endif // REG_EXP_DIALOG_H diff --git a/src/Tools/RegExp/regexpdialog.ui b/src/Tools/RegExp/regexpdialog.ui index 675c9dd167..d2832af82b 100644 --- a/src/Tools/RegExp/regexpdialog.ui +++ b/src/Tools/RegExp/regexpdialog.ui @@ -33,7 +33,7 @@ - + 6 @@ -44,17 +44,7 @@ - Case sensitive - - - true - - - - - - - Wildcard + Case insensitive @@ -63,9 +53,6 @@ Minimal - - true - @@ -146,7 +133,7 @@ - +