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 <szehowe.koh@gmail.com>
This commit is contained in:
Samuel Gaist 2017-01-21 21:52:20 +01:00
parent d2e713f3fd
commit beb98bdafc

View File

@ -59,6 +59,7 @@
#include <QFile> #include <QFile>
#include <QTextBrowser> #include <QTextBrowser>
#include <QBoxLayout> #include <QBoxLayout>
#include <QRegularExpression>
extern QPixmap cached(const QString &img); extern QPixmap cached(const QString &img);
@ -339,14 +340,12 @@ void ArthurFrame::showSource()
foreach (QString keyword, ppKeywords) foreach (QString keyword, ppKeywords)
contents.replace(keyword, QLatin1String("<font color=navy>") + keyword + QLatin1String("</font>")); 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"); QRegularExpression commentRe("(//.+?)\\n");
commentRe.setMinimal(true);
contents.replace(commentRe, QLatin1String("<font color=red>\\1</font>\n")); contents.replace(commentRe, QLatin1String("<font color=red>\\1</font>\n"));
QRegExp stringLiteralRe("(\".+\")"); QRegularExpression stringLiteralRe("(\".+?\")");
stringLiteralRe.setMinimal(true);
contents.replace(stringLiteralRe, QLatin1String("<font color=green>\\1</font>")); contents.replace(stringLiteralRe, QLatin1String("<font color=green>\\1</font>"));
QString html = contents; QString html = contents;