QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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
61
69 QgsStoredExpression( QString name, QString expression, Category tag = Category::FilterExpression )
70 : id( QUuid::createUuid().toString() ),
71 name( name ),
72 expression( expression ),
73 tag( tag )
74 {}
75#endif
76
78 QString id;
80 QString name;
82 QString expression;
84 Category tag = Category::FilterExpression;
85};
86
92class CORE_EXPORT QgsStoredExpressionManager : public QObject
93{
94 Q_OBJECT
95
96 public:
97
99
108 QString addStoredExpression( const QString &name, const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::FilterExpression );
109
115 void removeStoredExpression( const QString &id );
116
125 void updateStoredExpression( const QString &id, const QString &name, const QString &expression, const QgsStoredExpression::Category &tag );
126
132 void addStoredExpressions( const QList< QgsStoredExpression > &storedExpressions );
133
139 QList< QgsStoredExpression > storedExpressions( const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::All );
140
141
147 QgsStoredExpression storedExpression( const QString &id ) const;
148
155 QgsStoredExpression findStoredExpressionByExpression( const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::All ) const;
156
158 void clearStoredExpressions();
159
161 bool writeXml( QDomNode &layerNode ) const;
162
164 bool readXml( const QDomNode &layerNode );
165
166 signals:
167
168 public slots:
169
170 private:
171 QList< QgsStoredExpression > mStoredExpressions;
172};
173
174#endif // QGSSTOREDEXPRESSIONMANAGER_H
Manages stored expressions regarding creation, modification and storing in the project.
QgsStoredExpressionManager()=default
Stored expression containing name, content (expression text) and a category tag.
QgsStoredExpression()=default
QString expression
expression text
Category
Categories of use cases FilterExpression for stored expressions to filter attribute table DefaultValu...
@ FilterExpression
Expressions to filter features.
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