Skip to content

Commit

Permalink
Add highlighting for CASE condition; make regex for quote matching le…
Browse files Browse the repository at this point in the history
…ss greedy
  • Loading branch information
NathanW2 committed Jan 7, 2012
1 parent c8bb12f commit cb1eb2a
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/gui/qgsexpressionhighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit cb1eb2a

Please sign in to comment.