QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  {
84  };
85 
86 
92  struct NamedNode
93  {
94  public:
95 
101  NamedNode( const QString &name, QgsExpressionNode *node )
102  : name( name )
103  , node( node )
104  {}
105 
107  QString name;
108 
110  QgsExpressionNode *node = nullptr;
111  };
112 
117  class CORE_EXPORT NodeList
118  {
119  public:
120  virtual ~NodeList();
122  void append( QgsExpressionNode *node SIP_TRANSFER ) { mList.append( node ); mNameList.append( QString() ); }
123 
128  void append( QgsExpressionNode::NamedNode *node SIP_TRANSFER );
129 
133  int count() const { return mList.count(); }
134 
139  bool hasNamedNodes() const { return mHasNamedNodes; }
140 
144  QList<QgsExpressionNode *> list() { return mList; }
145 
151  QgsExpressionNode *at( int i ) { return mList.at( i ); }
152 
157  QStringList names() const { return mNameList; }
158 
161 
165  virtual QString dump() const;
166 
167  private:
168  QList<QgsExpressionNode *> mList;
169  QStringList mNameList;
170 
171  bool mHasNamedNodes = false;
172 
176  static QString cleanNamedNodeName( const QString &name );
177 
178  public:
179  };
180 
181  virtual ~QgsExpressionNode() = default;
182 
188  virtual QgsExpressionNode::NodeType nodeType() const = 0;
189 
195  virtual QString dump() const = 0;
196 
204  QVariant eval( QgsExpression *parent, const QgsExpressionContext *context );
205 
212  virtual QgsExpressionNode *clone() const = 0;
213 
224  virtual QSet<QString> referencedColumns() const = 0;
225 
229  virtual QSet<QString> referencedVariables() const = 0;
230 
234  virtual QSet<QString> referencedFunctions() const = 0;
235 
242  virtual QList<const QgsExpressionNode *> nodes( ) const = 0; SIP_SKIP
243 
252  virtual bool needsGeometry() const = 0;
253 
262  virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const = 0;
263 
272  bool prepare( QgsExpression *parent, const QgsExpressionContext *context );
273 
279  int parserFirstLine = 0;
280 
286  int parserFirstColumn = 0;
287 
293  int parserLastLine = 0;
294 
300  int parserLastColumn = 0;
301 
302  protected:
303 
313  void cloneTo( QgsExpressionNode *target ) const SIP_SKIP;
314 
315  private:
316 
322  virtual bool prepareNode( QgsExpression *parent, const QgsExpressionContext *context ) = 0;
323 
329  virtual QVariant evalNode( QgsExpression *parent, const QgsExpressionContext *context ) = 0;
330 
331  bool mHasCachedValue = false;
332  QVariant mCachedStaticValue;
333 };
334 
336 
337 #endif // QGSEXPRESSIONNODE_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsExpressionNode::NamedNode::name
QString name
Node name.
Definition: qgsexpressionnode.h:107
QgsExpressionNode::ntCondition
@ ntCondition
Definition: qgsexpressionnode.h:82
QgsExpressionNode::NodeType
NodeType
Known node types.
Definition: qgsexpressionnode.h:75
QgsExpressionNode::NodeList::hasNamedNodes
bool hasNamedNodes() const
Returns true if list contains any named nodes.
Definition: qgsexpressionnode.h:139
QgsExpressionNode::ntColumnRef
@ ntColumnRef
Definition: qgsexpressionnode.h:81
qgis.h
QgsExpressionNode::NamedNode::NamedNode
NamedNode(const QString &name, QgsExpressionNode *node)
Constructor for NamedNode.
Definition: qgsexpressionnode.h:101
QgsExpressionNode::NodeList::at
QgsExpressionNode * at(int i)
Gets the node at position i in the list.
Definition: qgsexpressionnode.h:151
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsExpressionNode::ntFunction
@ ntFunction
Definition: qgsexpressionnode.h:79
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsExpressionNode::ntBinaryOperator
@ ntBinaryOperator
Definition: qgsexpressionnode.h:77
QgsExpressionNode::ntLiteral
@ ntLiteral
Definition: qgsexpressionnode.h:80
QgsExpressionNode::NodeList::list
QList< QgsExpressionNode * > list()
Gets a list of all the nodes.
Definition: qgsexpressionnode.h:144
QgsExpressionNode
Abstract base class for all nodes that can appear in an expression.
Definition: qgsexpressionnode.h:35
QgsExpressionNode::ntUnaryOperator
@ ntUnaryOperator
Definition: qgsexpressionnode.h:76
QgsExpressionNode::NodeList::append
void append(QgsExpressionNode *node)
Takes ownership of the provided node.
Definition: qgsexpressionnode.h:122
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:105
QgsExpressionNode::NamedNode
Named node.
Definition: qgsexpressionnode.h:93
SIP_END
#define SIP_END
Definition: qgis_sip.h:194
QgsExpressionNode::NodeList::count
int count() const
Returns the number of nodes in the list.
Definition: qgsexpressionnode.h:133
QgsExpressionNode::ntIndexOperator
@ ntIndexOperator
Index operator.
Definition: qgsexpressionnode.h:83
QgsExpressionNode::NodeList::names
QStringList names() const
Returns a list of names for nodes.
Definition: qgsexpressionnode.h:157
QgsExpressionNode::NodeList
A list of expression nodes.
Definition: qgsexpressionnode.h:118
SIP_ABSTRACT
#define SIP_ABSTRACT
Definition: qgis_sip.h:199
QgsExpressionNode::ntInOperator
@ ntInOperator
Definition: qgsexpressionnode.h:78