19 : QSyntaxHighlighter( parent )
21 HighlightingRule rule;
23 keywordFormat.setForeground( Qt::darkBlue );
24 keywordFormat.setFontWeight( QFont::Bold );
25 QStringList keywordPatterns;
26 keywordPatterns << QStringLiteral(
"\\bCASE\\b" ) << QStringLiteral(
"\\bWHEN\\b" ) << QStringLiteral(
"\\bTHEN\\b" )
27 << QStringLiteral(
"\\bELSE\\b" ) << QStringLiteral(
"\\bEND\\b" );
29 const auto constKeywordPatterns = keywordPatterns;
30 for (
const QString &pattern : constKeywordPatterns )
32 rule.pattern = QRegularExpression( pattern, QRegularExpression::CaseInsensitiveOption );
33 rule.format = keywordFormat;
34 highlightingRules.append( rule );
37 quotationFormat.setForeground( Qt::darkGreen );
38 rule.pattern = QRegularExpression(
"\'[^\'\r\n]*\'" );
39 rule.format = quotationFormat;
40 highlightingRules.append( rule );
42 columnNameFormat.setForeground( Qt::darkRed );
43 rule.pattern = QRegularExpression(
"\"[^\"\r\n]*\"" );
44 rule.format = columnNameFormat;
45 highlightingRules.append( rule );
50 columnNameFormat.setForeground( Qt::darkRed );
51 HighlightingRule rule;
52 const auto constFieldList = fieldList;
53 for (
const QString &
field : constFieldList )
55 if (
field.isEmpty() )
57 rule.pattern = QRegularExpression(
"\\b" +
field +
"\\b" );
58 rule.format = columnNameFormat;
59 highlightingRules.append( rule );
65 const auto constHighlightingRules = highlightingRules;
66 for (
const HighlightingRule &rule : constHighlightingRules )
68 const QRegularExpression expression( rule.pattern );
69 QRegularExpressionMatch match = expression.match( text );
70 while ( match.hasMatch() )
72 const int index = match.capturedStart();
73 const int length = match.capturedLength();
76 setFormat( index, length, rule.format );
77 match = expression.match( text, index + length );
void highlightBlock(const QString &text) override
QgsExpressionHighlighter(QTextDocument *parent=nullptr)
void addFields(const QStringList &fieldList)