20 : QSyntaxHighlighter( parent )
22 HighlightingRule rule;
24 keywordFormat.setForeground( Qt::darkBlue );
25 keywordFormat.setFontWeight( QFont::Bold );
26 QStringList keywordPatterns;
27 keywordPatterns << QStringLiteral(
"\\bCASE\\b" ) << QStringLiteral(
"\\bWHEN\\b" ) << QStringLiteral(
"\\bTHEN\\b" )
28 << QStringLiteral(
"\\bELSE\\b" ) << QStringLiteral(
"\\bEND\\b" );
30 const auto constKeywordPatterns = keywordPatterns;
31 for (
const QString &pattern : constKeywordPatterns )
33 rule.pattern = QRegularExpression( pattern, QRegularExpression::CaseInsensitiveOption );
34 rule.format = keywordFormat;
35 highlightingRules.append( rule );
38 quotationFormat.setForeground( Qt::darkGreen );
39 rule.pattern = QRegularExpression(
"\'[^\'\r\n]*\'" );
40 rule.format = quotationFormat;
41 highlightingRules.append( rule );
43 columnNameFormat.setForeground( Qt::darkRed );
44 rule.pattern = QRegularExpression(
"\"[^\"\r\n]*\"" );
45 rule.format = columnNameFormat;
46 highlightingRules.append( rule );
51 columnNameFormat.setForeground( Qt::darkRed );
52 HighlightingRule rule;
53 const auto constFieldList = fieldList;
54 for (
const QString &field : constFieldList )
56 if ( field.isEmpty() )
58 rule.pattern = QRegularExpression(
"\\b" + field +
"\\b" );
59 rule.format = columnNameFormat;
60 highlightingRules.append( rule );
66 const auto constHighlightingRules = highlightingRules;
67 for (
const HighlightingRule &rule : constHighlightingRules )
69 const QRegularExpression expression( rule.pattern );
70 QRegularExpressionMatch match = expression.match( text );
71 while ( match.hasMatch() )
73 const int index = match.capturedStart();
74 const int length = match.capturedLength();
77 setFormat( index, length, rule.format );
78 match = expression.match( text, index + length );