19 : QSyntaxHighlighter( parent )
21 HighlightingRule rule;
23 keywordFormat.setForeground( Qt::darkBlue );
24 keywordFormat.setFontWeight( QFont::Bold );
25 QStringList keywordPatterns;
26 keywordPatterns <<
"\\bCASE\\b" <<
"\\bWHEN\\b" <<
"\\bTHEN\\b"
27 <<
"\\bELSE\\b" <<
"\\bEND\\b";
29 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 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 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 );