QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 <QString>
23 #include <QObject>
24 #include <QUuid>
25 
26 
27 #ifdef SIP_RUN
28 % ModuleHeaderCode
30 % End
31 #endif
32 
33 class QDomNode;
34 class QDomDocument;
35 
41 struct CORE_EXPORT QgsStoredExpression
42 {
43 
49  enum Category
50  {
51  FilterExpression = 1 << 0,
52  DefaultValueExpression = 1 << 1,
53  All = FilterExpression | DefaultValueExpression
54  };
55 
56 #ifndef SIP_RUN
57 
61  QgsStoredExpression() = default;
62 
70  QgsStoredExpression( QString name, QString expression, Category tag = Category::FilterExpression )
71  : id( QUuid::createUuid().toString() ),
72  name( name ),
73  expression( expression ),
74  tag( tag )
75  {}
76 #endif
77 
79  QString id;
81  QString name;
83  QString expression;
86 };
87 
93 class CORE_EXPORT QgsStoredExpressionManager : public QObject
94 {
95  Q_OBJECT
96 
97  public:
98 
103 
112  QString addStoredExpression( const QString &name, const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::FilterExpression );
113 
119  void removeStoredExpression( const QString &id );
120 
129  void updateStoredExpression( const QString &id, const QString &name, const QString &expression, const QgsStoredExpression::Category &tag );
130 
136  void addStoredExpressions( const QList< QgsStoredExpression > &storedExpressions );
137 
143  QList< QgsStoredExpression > storedExpressions( const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::All );
144 
145 
151  QgsStoredExpression storedExpression( const QString &id ) const;
152 
159  QgsStoredExpression findStoredExpressionByExpression( const QString &expression, const QgsStoredExpression::Category &tag = QgsStoredExpression::Category::All ) const;
160 
162  void clearStoredExpressions();
163 
165  bool writeXml( QDomNode &layerNode ) const;
166 
168  bool readXml( const QDomNode &layerNode );
169 
170  signals:
171 
172  public slots:
173 
174  private:
175  QList< QgsStoredExpression > mStoredExpressions;
176 };
177 
178 #endif // QGSSTOREDEXPRESSIONMANAGER_H
QgsStoredExpression::Category
Category
Categories of use cases FilterExpression for stored expressions to filter attribute table DefaultValu...
Definition: qgsstoredexpressionmanager.h:50
QgsStoredExpression::QgsStoredExpression
QgsStoredExpression()=default
Constructor for QgsStoredExpression.
QgsStoredExpressionManager::QgsStoredExpressionManager
QgsStoredExpressionManager()=default
Constructor for QgsStoredExpressionManager.
QgsStoredExpression
Stored expression containing name, content (expression text) and a category tag.
Definition: qgsstoredexpressionmanager.h:42
qgsstoredexpressionmanager.h
QgsStoredExpression::expression
QString expression
expression text
Definition: qgsstoredexpressionmanager.h:83
QgsStoredExpression::tag
Category tag
category of the expression use case
Definition: qgsstoredexpressionmanager.h:85
QgsStoredExpression::QgsStoredExpression
QgsStoredExpression(QString name, QString expression, Category tag=Category::FilterExpression)
Create a new QgsStoredExpression with a generated uuid as id.
Definition: qgsstoredexpressionmanager.h:70
QgsStoredExpression::name
QString name
descriptive name of the expression
Definition: qgsstoredexpressionmanager.h:81
QgsStoredExpression::id
QString id
generated uuid used for identification
Definition: qgsstoredexpressionmanager.h:79
QgsStoredExpressionManager
Manages stored expressions regarding creation, modification and storing in the project.
Definition: qgsstoredexpressionmanager.h:94