QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsexpressionnode.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsexpressionnode.h
3  -------------------
4  begin : May 2017
5  copyright : (C) 2017 Matthias Kuhn
6  email : [email protected]
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 
17 #ifndef QGSEXPRESSIONNODE_H
18 #define QGSEXPRESSIONNODE_H
19 
20 #include <QSet>
21 #include <QVariant>
22 #include <QCoreApplication>
23 
24 #include "qgis.h"
25 
26 class QgsExpression;
28 
35 {
36 
37 #ifdef SIP_RUN
39  switch ( sipCpp->nodeType() )
40  {
42  sipType = sipType_QgsExpressionNodeUnaryOperator;
43  break;
45  sipType = sipType_QgsExpressionNodeBinaryOperator;
46  break;
48  sipType = sipType_QgsExpressionNodeInOperator;
49  break;
51  sipType = sipType_QgsExpressionNodeFunction;
52  break;
54  sipType = sipType_QgsExpressionNodeLiteral;
55  break;
57  sipType = sipType_QgsExpressionNodeColumnRef;
58  break;
60  sipType = sipType_QgsExpressionNodeCondition;
61  break;
62  default:
63  sipType = 0;
64  break;
65  }
66  SIP_END
67 #endif
68 
69  Q_DECLARE_TR_FUNCTIONS( QgsExpressionNode );
70 
71  public:
72 
74  enum NodeType
75  {
82  ntCondition
83  };
84 
85 
91  struct NamedNode
92  {
93  public:
94 
100  NamedNode( const QString &name, QgsExpressionNode *node )
101  : name( name )
102  , node( node )
103  {}
104 
106  QString name;
107 
109  QgsExpressionNode *node = nullptr;
110  };
111 
116  class CORE_EXPORT NodeList
117  {
118  public:
119  virtual ~NodeList();
121  void append( QgsExpressionNode *node SIP_TRANSFER ) { mList.append( node ); mNameList.append( QString() ); }
122 
127  void append( QgsExpressionNode::NamedNode *node SIP_TRANSFER );
128 
132  int count() const { return mList.count(); }
133 
138  bool hasNamedNodes() const { return mHasNamedNodes; }
139 
143  QList<QgsExpressionNode *> list() { return mList; }
144 
150  QgsExpressionNode *at( int i ) { return mList.at( i ); }
151 
156  QStringList names() const { return mNameList; }
157 
160 
164  virtual QString dump() const;
165 
166  private:
167  QList<QgsExpressionNode *> mList;
168  QStringList mNameList;
169 
170  bool mHasNamedNodes = false;
171 
172  public:
173  };
174 
175  virtual ~QgsExpressionNode() = default;
176 
182  virtual QgsExpressionNode::NodeType nodeType() const = 0;
183 
189  virtual QString dump() const = 0;
190 
198  QVariant eval( QgsExpression *parent, const QgsExpressionContext *context );
199 
206  virtual QgsExpressionNode *clone() const = 0;
207 
218  virtual QSet<QString> referencedColumns() const = 0;
219 
223  virtual QSet<QString> referencedVariables() const = 0;
224 
228  virtual QSet<QString> referencedFunctions() const = 0;
229 
236  virtual QList<const QgsExpressionNode *> nodes( ) const = 0; SIP_SKIP
237 
246  virtual bool needsGeometry() const = 0;
247 
256  virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const = 0;
257 
266  bool prepare( QgsExpression *parent, const QgsExpressionContext *context );
267 
273  int parserFirstLine = 0;
274 
280  int parserFirstColumn = 0;
281 
287  int parserLastLine = 0;
288 
294  int parserLastColumn = 0;
295 
296  protected:
297 
307  void cloneTo( QgsExpressionNode *target ) const SIP_SKIP;
308 
309  private:
310 
316  virtual bool prepareNode( QgsExpression *parent, const QgsExpressionContext *context ) = 0;
317 
323  virtual QVariant evalNode( QgsExpression *parent, const QgsExpressionContext *context ) = 0;
324 
325  bool mHasCachedValue = false;
326  QVariant mCachedStaticValue;
327 };
328 
330 
331 #endif // QGSEXPRESSIONNODE_H
Class for parsing and evaluation of expressions (formerly called "search strings").
QStringList names() const
Returns a list of names for nodes.
QgsExpressionNode * at(int i)
Gets the node at position i in the list.
NodeType
Known node types.
Q_DECLARE_METATYPE(QModelIndex)
#define SIP_ABSTRACT
Definition: qgis_sip.h:187
#define SIP_SKIP
Definition: qgis_sip.h:119
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:182
NamedNode(const QString &name, QgsExpressionNode *node)
Constructor for NamedNode.
Abstract base class for all nodes that can appear in an expression.
#define SIP_FACTORY
Definition: qgis_sip.h:69
A list of expression nodes.
QList< QgsExpressionNode * > list()
Gets a list of all the nodes.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
int count() const
Returns the number of nodes in the list.
void append(QgsExpressionNode *node)
Takes ownership of the provided node.
bool hasNamedNodes() const
Returns true if list contains any named nodes.