QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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#include <QRegularExpression>
25#include "qgis_gui.h"
26
27class QTextDocument;
28
33class GUI_EXPORT QgsExpressionHighlighter : public QSyntaxHighlighter
34{
35 Q_OBJECT
36
37 public:
38 QgsExpressionHighlighter( QTextDocument *parent = nullptr );
39 void addFields( const QStringList &fieldList );
40
41 protected:
42 void highlightBlock( const QString &text ) override;
43
44 private:
45 struct HighlightingRule
46 {
47 QRegularExpression pattern;
48 QTextCharFormat format;
49 };
50 QVector<HighlightingRule> highlightingRules;
51
52 QTextCharFormat columnNameFormat;
53 QTextCharFormat keywordFormat;
54 QTextCharFormat quotationFormat;
55 QTextCharFormat functionFormat;
56};
57
58#endif // QGSEXPRESSIONHIGHLIGHTER_H