QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsstoredexpressionmanager.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsstoredexpressionmanager.h
3 -------------------
4 begin : August 2019
5 copyright : (C) 2019 David Signer
6 email : david at opengis dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSSTOREDEXPRESSIONMANAGER_H
19#define QGSSTOREDEXPRESSIONMANAGER_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include <QString>
24#include <QObject>
25#include <QUuid>
26
27
28#ifdef SIP_RUN
29% ModuleHeaderCode
31% End
32#endif
33
34class QDomNode;
35class QDomDocument;
36
42class CORE_EXPORT QgsStoredExpression
43{
44 public:
45
52 {
53 FilterExpression = 1 << 0,
54 DefaultValueExpression = 1 << 1,
55 All = FilterExpression | DefaultValueExpression
56 };
57
58#ifndef SIP_RUN
59
64
72 QgsStoredExpression( QString name, QString expression, Category tag = Category::FilterExpression )
73 : id( QUuid::createUuid().toString() ),
74 name( name ),
75 expression( expression ),
76 tag( tag )
77 {}
78#endif
79
81 QString id;
83 QString name;
85 QString expression;
87 Category tag = Category::FilterExpression;
88};
89
95class CORE_EXPORT QgsStoredExpressionManager : public QObject
96{
97 Q_OBJECT
98
99 public:
100
105
114 QString addStoredExpression( const QString &name, const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::FilterExpression );
115
121 void removeStoredExpression( const QString &id );
122
131 void updateStoredExpression( const QString &id, const QString &name, const QString &expression, const QgsStoredExpression::Category &tag );
132
138 void addStoredExpressions( const QList< QgsStoredExpression > &storedExpressions );
139
145 QList< QgsStoredExpression > storedExpressions( const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::All );
146
147
153 QgsStoredExpression storedExpression( const QString &id ) const;
154
161 QgsStoredExpression findStoredExpressionByExpression( const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::All ) const;
162
164 void clearStoredExpressions();
165
167 bool writeXml( QDomNode &layerNode ) const;
168
170 bool readXml( const QDomNode &layerNode );
171
172 signals:
173
174 public slots:
175
176 private:
177 QList< QgsStoredExpression > mStoredExpressions;
178};
179
180#endif // QGSSTOREDEXPRESSIONMANAGER_H
Manages stored expressions regarding creation, modification and storing in the project.
QgsStoredExpressionManager()=default
Constructor for QgsStoredExpressionManager.
Stored expression containing name, content (expression text) and a category tag.
QgsStoredExpression()=default
Constructor for QgsStoredExpression.
QString expression
expression text
Category
Categories of use cases FilterExpression for stored expressions to filter attribute table DefaultValu...
QgsStoredExpression(QString name, QString expression, Category tag=Category::FilterExpression)
Create a new QgsStoredExpression with a generated uuid as id.
QString id
generated uuid used for identification
QString name
descriptive name of the expression
#define SIP_ENUM_BASETYPE(type)
Definition: qgis_sip.h:278