QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsexpressionnode.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsexpressionnode.h
3 -------------------
4 begin : May 2017
5 copyright : (C) 2017 Matthias Kuhn
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
26class 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;
63 sipType = sipType_QgsExpressionNodeBetweenOperator;
64 break;
65 default:
66 sipType = 0;
67 break;
68 }
70#endif
71
72 Q_DECLARE_TR_FUNCTIONS( QgsExpressionNode )
73
74 public:
75
89
90
96 struct NamedNode
97 {
98 public:
99
105 NamedNode( const QString &name, QgsExpressionNode *node )
106 : name( name )
107 , node( node )
108 {}
109
111 QString name;
112
114 QgsExpressionNode *node = nullptr;
115 };
116
121 class CORE_EXPORT NodeList
122 {
123 public:
124 virtual ~NodeList();
126 void append( QgsExpressionNode *node SIP_TRANSFER ) { mList.append( node ); mNameList.append( QString() ); }
127
132 void append( QgsExpressionNode::NamedNode *node SIP_TRANSFER );
133
137 int count() const { return mList.count(); }
138
144 void reserve( int size ) { mList.reserve( size ); }
145
150 bool hasNamedNodes() const { return mHasNamedNodes; }
151
155 QList<QgsExpressionNode *> list() { return mList; }
156
162 QgsExpressionNode *at( int i ) { return mList.at( i ); }
163
168 QStringList names() const { return mNameList; }
169
172
176 virtual QString dump() const;
177
178 private:
179 QList<QgsExpressionNode *> mList;
180 QStringList mNameList;
181
182 bool mHasNamedNodes = false;
183
187 static QString cleanNamedNodeName( const QString &name );
188
189 public:
190 };
191
192 virtual ~QgsExpressionNode() = default;
193
199 virtual QgsExpressionNode::NodeType nodeType() const = 0;
200
206 virtual QString dump() const = 0;
207
215 QVariant eval( QgsExpression *parent, const QgsExpressionContext *context );
216
223 virtual QgsExpressionNode *clone() const = 0;
224
243 virtual QSet<QString> referencedColumns() const = 0;
244
251 virtual QSet<QString> referencedVariables() const = 0;
252
259 virtual QSet<QString> referencedFunctions() const = 0;
260
267 virtual QList<const QgsExpressionNode *> nodes( ) const = 0; SIP_SKIP
268
277 virtual bool needsGeometry() const = 0;
278
287 virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const = 0;
288
297 bool prepare( QgsExpression *parent, const QgsExpressionContext *context );
298
304 int parserFirstLine = 0;
305
311 int parserFirstColumn = 0;
312
318 int parserLastLine = 0;
319
325 int parserLastColumn = 0;
326
333 bool hasCachedStaticValue() const { return mHasCachedValue; }
334
341 QVariant cachedStaticValue() const { return mCachedStaticValue; }
342
350 void setCachedStaticValue( const QVariant &value ) const SIP_SKIP;
351
364 const QgsExpressionNode *effectiveNode() const { return mCompiledSimplifiedNode ? mCompiledSimplifiedNode.get() : this; }
365
366 protected:
367
371 QgsExpressionNode() = default;
372
374 QgsExpressionNode( const QgsExpressionNode &other );
376 QgsExpressionNode &operator=( const QgsExpressionNode &other );
377
387 void cloneTo( QgsExpressionNode *target ) const SIP_SKIP;
388
389#ifndef SIP_RUN
390
396 mutable bool mHasCachedValue = false;
397
403 mutable QVariant mCachedStaticValue;
404
415 mutable std::unique_ptr< QgsExpressionNode > mCompiledSimplifiedNode;
416#endif
417
418 private:
419
425 virtual bool prepareNode( QgsExpression *parent, const QgsExpressionContext *context ) = 0;
426
432 virtual QVariant evalNode( QgsExpression *parent, const QgsExpressionContext *context ) = 0;
433
434};
435
437
438#endif // QGSEXPRESSIONNODE_H
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A list of expression nodes.
bool hasNamedNodes() const
Returns true if list contains any named nodes.
QStringList names() const
Returns a list of names for nodes.
void append(QgsExpressionNode *node)
Takes ownership of the provided node.
void reserve(int size)
Reserves size for the node list.
QList< QgsExpressionNode * > list()
Gets a list of all the nodes.
QgsExpressionNode * at(int i)
Gets the node at position i in the list.
int count() const
Returns the number of nodes in the list.
Abstract base class for all nodes that can appear in an expression.
const QgsExpressionNode * effectiveNode() const
Returns a reference to the simplest node which represents this node, after any compilation optimizati...
QVariant cachedStaticValue() const
Returns the node's static cached value.
QVariant mCachedStaticValue
Contains the static, precalculated value for the node if mHasCachedValue is true.
QgsExpressionNode()=default
Constructor.
std::unique_ptr< QgsExpressionNode > mCompiledSimplifiedNode
Contains a compiled node which represents a simplified version of this node as a result of compilatio...
NodeType
Known node types.
@ ntBetweenOperator
Between operator.
@ ntIndexOperator
Index operator.
Class for parsing and evaluation of expressions (formerly called "search strings").
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:186
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_ABSTRACT
Definition qgis_sip.h:208
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:203
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
NamedNode(const QString &name, QgsExpressionNode *node)
Constructor for NamedNode.