QGIS API Documentation 3.43.0-Master (c67cf405802)
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
34class GUI_EXPORT QgsExpressionHighlighter : public QSyntaxHighlighter
35{
36 Q_OBJECT
37
38 public:
39 QgsExpressionHighlighter( QTextDocument *parent = nullptr );
40 void addFields( const QStringList &fieldList );
41
42 protected:
43 void highlightBlock( const QString &text ) override;
44
45 private:
46 struct HighlightingRule
47 {
48 QRegularExpression pattern;
49 QTextCharFormat format;
50 };
51 QVector<HighlightingRule> highlightingRules;
52
53 QTextCharFormat columnNameFormat;
54 QTextCharFormat keywordFormat;
55 QTextCharFormat quotationFormat;
56 QTextCharFormat functionFormat;
57};
58
59#endif // QGSEXPRESSIONHIGHLIGHTER_H
Syntax highlighter for QGIS expressions.