QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
qgsexpressionnode.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsexpressionnode.cpp
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 #include "qgsexpressionnode.h"
17 #include "qgsexpression.h"
18 
19 
20 QVariant QgsExpressionNode::eval( QgsExpression *parent, const QgsExpressionContext *context )
21 {
22  if ( mHasCachedValue )
23  {
24  return mCachedStaticValue;
25  }
26  else
27  {
28  QVariant res = evalNode( parent, context );
29  return res;
30  }
31 }
32 
34 {
35  if ( isStatic( parent, context ) )
36  {
37  mCachedStaticValue = evalNode( parent, context );
38  if ( !parent->hasEvalError() )
39  mHasCachedValue = true;
40  else
41  mHasCachedValue = false;
42  return true;
43  }
44  else
45  {
46  mHasCachedValue = false;
47  return prepareNode( parent, context );
48  }
49 }
50 
52 {
53  target->mHasCachedValue = mHasCachedValue;
54  target->mCachedStaticValue = mCachedStaticValue;
59 }
60 
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.
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.
int parserFirstLine
First line in the parser this node was found.
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.