Skip to content
Permalink
Browse files
Add highlighting for CASE condition; make regex for quote matching le…
…ss greedy
  • Loading branch information
NathanW2 committed Jan 7, 2012
1 parent c8bb12f commit cb1eb2a239244e6c9e3c4549ede275b6521546a8
Showing with 25 additions and 12 deletions.
  1. +25 −12 src/gui/qgsexpressionhighlighter.cpp
@@ -15,32 +15,45 @@

#include "qgsexpressionhighlighter.h"

QgsExpressionHighlighter::QgsExpressionHighlighter( QTextDocument *parent)
QgsExpressionHighlighter::QgsExpressionHighlighter( QTextDocument *parent )
: QSyntaxHighlighter( parent )
{
HighlightingRule rule;

keywordFormat.setForeground( Qt::darkBlue );
keywordFormat.setFontWeight( QFont::Bold );
QStringList keywordPatterns;
keywordPatterns << "\\bCASE\\b" << "\\bWHEN\\b" << "\\bTHEN\\b"
<< "\\bELSE\\b" << "\\bEND\\b";

foreach( const QString &pattern, keywordPatterns )
{
rule.pattern = QRegExp( pattern, Qt::CaseInsensitive );
rule.format = keywordFormat;
highlightingRules.append( rule );
}

quotationFormat.setForeground( Qt::darkGreen );
rule.pattern = QRegExp( "\'.*\'" );
rule.pattern = QRegExp( "\'[^\'\r\n]*\'" );
rule.format = quotationFormat;
highlightingRules.append( rule );

columnNameFormat.setForeground( Qt::darkRed );
rule.pattern = QRegExp( "\".*\"" );
rule.pattern = QRegExp( "\"[^\"\r\n]*\"" );
rule.format = columnNameFormat;
highlightingRules.append( rule );
}

void QgsExpressionHighlighter::addFields(QStringList fieldList)
void QgsExpressionHighlighter::addFields( QStringList fieldList )
{
columnNameFormat.setForeground( Qt::darkRed );
HighlightingRule rule;
foreach (const QString field, fieldList)
{
rule.pattern = QRegExp("\\b" + field + "\\b");
rule.format = columnNameFormat;
highlightingRules.append( rule );
}
columnNameFormat.setForeground( Qt::darkRed );
HighlightingRule rule;
foreach( const QString field, fieldList )
{
rule.pattern = QRegExp( "\\b" + field + "\\b" );
rule.format = columnNameFormat;
highlightingRules.append( rule );
}
}

void QgsExpressionHighlighter::highlightBlock( const QString &text )

0 comments on commit cb1eb2a

Please sign in to comment.