QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsexpressionhighlighter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsexpressionhighlighter.h - A syntax highlighter for a qgsexpression
3  --------------------------------------
4  Date : 28-Dec-2011
5  Copyright : (C) 2011 by Nathan Woodrow
6  Email : woodrow.nathan at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSEXPRESSIONHIGHLIGHTER_H
17 #define QGSEXPRESSIONHIGHLIGHTER_H
18 
19 #include "qgsfield.h"
20 #include <QSyntaxHighlighter>
21 
22 #include <QHash>
23 #include <QTextCharFormat>
24 #include <QStringList>
25 
26 class QTextDocument;
27 
28 class GUI_EXPORT QgsExpressionHighlighter : public QSyntaxHighlighter
29 {
30  Q_OBJECT
31 
32  public:
33  QgsExpressionHighlighter( QTextDocument *parent = 0 );
34  void addFields( QStringList fieldList );
35 
36  protected:
37  void highlightBlock( const QString &text );
38 
39  private:
40  struct HighlightingRule
41  {
42  QRegExp pattern;
43  QTextCharFormat format;
44  };
45  QVector<HighlightingRule> highlightingRules;
46 
47  QTextCharFormat columnNameFormat;
48  QTextCharFormat keywordFormat;
49  QTextCharFormat quotationFormat;
50  QTextCharFormat functionFormat;
51 };
52 
53 #endif // QGSEXPRESSIONHIGHLIGHTER_H