QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsExpressionNode::cloneTo
void cloneTo(QgsExpressionNode *target) const
Copies the members of this node to the node provided in target.
Definition: qgsexpressionnode.cpp:51
qgsexpression.h
QgsExpression::hasEvalError
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
Definition: qgsexpression.cpp:374
QgsExpressionNode::eval
QVariant eval(QgsExpression *parent, const QgsExpressionContext *context)
Evaluate this node with the given context and parent.
Definition: qgsexpressionnode.cpp:20
QgsExpressionNode::parserLastLine
int parserLastLine
Last line in the parser this node was found.
Definition: qgsexpressionnode.h:288
qgsexpressionnode.h
QgsExpressionNode
Definition: qgsexpressionnode.h:34
QgsExpressionNode::isStatic
virtual bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const =0
Returns true if this node can be evaluated for a static value.
QgsExpressionNode::parserFirstLine
int parserFirstLine
First line in the parser this node was found.
Definition: qgsexpressionnode.h:274
QgsExpressionNode::parserLastColumn
int parserLastColumn
Last column in the parser this node was found.
Definition: qgsexpressionnode.h:295
QgsExpression
Definition: qgsexpression.h:113
QgsExpressionNode::prepare
bool prepare(QgsExpression *parent, const QgsExpressionContext *context)
Prepare this node for evaluation.
Definition: qgsexpressionnode.cpp:33
QgsExpressionNode::parserFirstColumn
int parserFirstColumn
First column in the parser this node was found.
Definition: qgsexpressionnode.h:281