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 = QRegExp( pattern, Qt::CaseInsensitive );
33 rule.format = keywordFormat;
34 highlightingRules.append( rule );
37 quotationFormat.setForeground( Qt::darkGreen );
38 rule.pattern = QRegExp(
"\'[^\'\r\n]*\'" );
39 rule.format = quotationFormat;
40 highlightingRules.append( rule );
42 columnNameFormat.setForeground( Qt::darkRed );
43 rule.pattern = QRegExp(
"\"[^\"\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 = QRegExp(
"\\b" + field +
"\\b" );
58 rule.format = columnNameFormat;
59 highlightingRules.append( rule );
65 const auto constHighlightingRules = highlightingRules;
66 for (
const HighlightingRule &rule : constHighlightingRules )
68 QRegExp expression( rule.pattern );
69 int index = expression.indexIn( text );
72 int length = expression.matchedLength();
75 setFormat( index, length, rule.format );
76 index = expression.indexIn( text, index + length );
void highlightBlock(const QString &text) override
QgsExpressionHighlighter(QTextDocument *parent=nullptr)
void addFields(const QStringList &fieldList)