QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
32 {
33  Q_OBJECT
34 
35  public:
36  QgsExpressionHighlighter( QTextDocument *parent = nullptr );
37  void addFields( const QStringList& fieldList );
38 
39  protected:
40  void highlightBlock( const QString &text ) override;
41 
42  private:
43  struct HighlightingRule
44  {
45  QRegExp pattern;
46  QTextCharFormat format;
47  };
48  QVector<HighlightingRule> highlightingRules;
49 
50  QTextCharFormat columnNameFormat;
51  QTextCharFormat keywordFormat;
52  QTextCharFormat quotationFormat;
53  QTextCharFormat functionFormat;
54 };
55 
56 #endif // QGSEXPRESSIONHIGHLIGHTER_H
virtual void highlightBlock(const QString &text)=0