QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsexpressionnode.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsexpressionnode.cpp
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#include "qgsexpressionnode.h"
17#include "qgsexpression.h"
18
19
21{
22 if ( mHasCachedValue )
23 {
24 return mCachedStaticValue;
25 }
26 else if ( mCompiledSimplifiedNode )
27 {
28 return mCompiledSimplifiedNode->eval( parent, context );
29 }
30 else
31 {
32 QVariant res = evalNode( parent, context );
33 return res;
34 }
35}
36
38{
39 mHasCachedValue = false;
41 if ( isStatic( parent, context ) )
42 {
43 // some calls to isStatic already evaluate the node to a cached value, so if that's
44 // happened then don't re-evaluate again
45 if ( !mHasCachedValue )
46 {
47 mCachedStaticValue = evalNode( parent, context );
48 if ( !parent->hasEvalError() )
49 mHasCachedValue = true;
50 }
51 return true;
52 }
53 else
54 {
55 return prepareNode( parent, context );
56 }
57}
58
59void QgsExpressionNode::setCachedStaticValue( const QVariant &value ) const
60{
61 mHasCachedValue = true;
62 mCachedStaticValue = value;
63}
64
66 : parserFirstLine( other.parserFirstLine )
67 , parserFirstColumn( other.parserFirstColumn )
68 , parserLastLine( other.parserLastLine )
69 , parserLastColumn( other.parserLastColumn )
70 , mHasCachedValue( other.mHasCachedValue )
71 , mCachedStaticValue( other.mCachedStaticValue )
72 , mCompiledSimplifiedNode( other.mCompiledSimplifiedNode ? other.mCompiledSimplifiedNode->clone() : nullptr )
73{
74
75}
76
88
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Abstract base class for all nodes that can appear in an expression.
void setCachedStaticValue(const QVariant &value) const
Sets the cached static value for the node.
QVariant eval(QgsExpression *parent, const QgsExpressionContext *context)
Evaluate this node with the given context and parent.
virtual bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const =0
Returns true if this node can be evaluated for a static value.
bool prepare(QgsExpression *parent, const QgsExpressionContext *context)
Prepare this node for evaluation.
bool mHasCachedValue
true if the node has a static, precalculated value.
QVariant mCachedStaticValue
Contains the static, precalculated value for the node if mHasCachedValue is true.
QgsExpressionNode()=default
std::unique_ptr< QgsExpressionNode > mCompiledSimplifiedNode
Contains a compiled node which represents a simplified version of this node as a result of compilatio...
int parserFirstLine
First line in the parser this node was found.
QgsExpressionNode & operator=(const QgsExpressionNode &other)
int parserLastLine
Last line in the parser this node was found.
void cloneTo(QgsExpressionNode *target) const
Copies the members of this node to the node provided in target.
int parserLastColumn
Last column in the parser this node was found.
int parserFirstColumn
First column in the parser this node was found.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.