QGIS API Documentation  3.9.0-Master (224899f119)
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 : matthias@opengis.ch
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 
void cloneTo(QgsExpressionNode *target) const
Copies the members of this node to the node provided in target.
Class for parsing and evaluation of expressions (formerly called "search strings").
int parserFirstColumn
First column in the parser this node was found.
bool prepare(QgsExpression *parent, const QgsExpressionContext *context)
Prepare this node for evaluation.
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.
int parserLastLine
Last line in the parser this node was found.
int parserFirstLine
First line in the parser this node was found.
virtual bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const =0
Returns true if this node can be evaluated for a static value.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
int parserLastColumn
Last column in the parser this node was found.