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 Q_FOREACH (
const QString &pattern, keywordPatterns )
31 rule.pattern = QRegExp( pattern, Qt::CaseInsensitive );
32 rule.format = keywordFormat;
33 highlightingRules.append( rule );
36 quotationFormat.setForeground( Qt::darkGreen );
37 rule.pattern = QRegExp(
"\'[^\'\r\n]*\'" );
38 rule.format = quotationFormat;
39 highlightingRules.append( rule );
41 columnNameFormat.setForeground( Qt::darkRed );
42 rule.pattern = QRegExp(
"\"[^\"\r\n]*\"" );
43 rule.format = columnNameFormat;
44 highlightingRules.append( rule );
49 columnNameFormat.setForeground( Qt::darkRed );
50 HighlightingRule rule;
51 Q_FOREACH (
const QString &field, fieldList )
53 if ( field.isEmpty() )
55 rule.pattern = QRegExp(
"\\b" + field +
"\\b" );
56 rule.format = columnNameFormat;
57 highlightingRules.append( rule );
63 Q_FOREACH (
const HighlightingRule &rule, highlightingRules )
65 QRegExp expression( rule.pattern );
66 int index = expression.indexIn( text );
69 int length = expression.matchedLength();
72 setFormat( index, length, rule.format );
73 index = expression.indexIn( text, index + length );
void highlightBlock(const QString &text) override
QgsExpressionHighlighter(QTextDocument *parent=nullptr)
void addFields(const QStringList &fieldList)