QGIS API Documentation  2.99.0-Master (c558d51)
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 <QSyntaxHighlighter>
20 
21 #include <QHash>
22 #include <QTextCharFormat>
23 #include <QStringList>
24 
25 class QTextDocument;
26 
30 class GUI_EXPORT QgsExpressionHighlighter : public QSyntaxHighlighter
31 {
32  Q_OBJECT
33 
34  public:
35  QgsExpressionHighlighter( QTextDocument *parent = nullptr );
36  void addFields( const QStringList& fieldList );
37 
38  protected:
39  void highlightBlock( const QString &text ) override;
40 
41  private:
42  struct HighlightingRule
43  {
44  QRegExp pattern;
45  QTextCharFormat format;
46  };
47  QVector<HighlightingRule> highlightingRules;
48 
49  QTextCharFormat columnNameFormat;
50  QTextCharFormat keywordFormat;
51  QTextCharFormat quotationFormat;
52  QTextCharFormat functionFormat;
53 };
54 
55 #endif // QGSEXPRESSIONHIGHLIGHTER_H