QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
src
core
expression
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
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
37
bool
QgsExpressionNode::prepare
(
QgsExpression
*parent,
const
QgsExpressionContext
*context )
38
{
39
mHasCachedValue
=
false
;
40
mCompiledSimplifiedNode
.reset();
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
59
QgsExpressionNode::QgsExpressionNode
(
const
QgsExpressionNode
&other )
60
: parserFirstLine( other.parserFirstLine )
61
, parserFirstColumn( other.parserFirstColumn )
62
, parserLastLine( other.parserLastLine )
63
, parserLastColumn( other.parserLastColumn )
64
, mHasCachedValue( other.mHasCachedValue )
65
, mCachedStaticValue( other.mCachedStaticValue )
66
, mCompiledSimplifiedNode( other.mCompiledSimplifiedNode ? other.mCompiledSimplifiedNode->clone() : nullptr )
67
{
68
69
}
70
71
QgsExpressionNode
&
QgsExpressionNode::operator=
(
const
QgsExpressionNode
&other )
72
{
73
parserFirstLine
= other.
parserFirstLine
;
74
parserFirstColumn
= other.
parserFirstColumn
;
75
parserLastLine
= other.
parserLastLine
;
76
parserLastColumn
= other.
parserLastColumn
;
77
mHasCachedValue
= other.
mHasCachedValue
;
78
mCachedStaticValue
= other.
mCachedStaticValue
;
79
mCompiledSimplifiedNode
.reset( other.
mCompiledSimplifiedNode
? other.
mCompiledSimplifiedNode
->clone() :
nullptr
);
80
return
*
this
;
81
}
82
83
void
QgsExpressionNode::cloneTo
(
QgsExpressionNode
*target )
const
84
{
85
target->
mHasCachedValue
=
mHasCachedValue
;
86
target->
mCachedStaticValue
=
mCachedStaticValue
;
87
if
(
mCompiledSimplifiedNode
)
88
target->
mCompiledSimplifiedNode
.reset(
mCompiledSimplifiedNode
->clone() );
89
target->
parserLastColumn
=
parserLastColumn
;
90
target->
parserLastLine
=
parserLastLine
;
91
target->
parserFirstColumn
=
parserFirstColumn
;
92
target->
parserFirstLine
=
parserFirstLine
;
93
}
94
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition:
qgsexpressioncontext.h:406
QgsExpressionNode::cloneTo
void cloneTo(QgsExpressionNode *target) const
Copies the members of this node to the node provided in target.
Definition:
qgsexpressionnode.cpp:83
qgsexpression.h
QgsExpressionNode::mCachedStaticValue
QVariant mCachedStaticValue
Contains the static, precalculated value for the node if mHasCachedValue is true.
Definition:
qgsexpressionnode.h:387
QgsExpressionNode::mCompiledSimplifiedNode
std::unique_ptr< QgsExpressionNode > mCompiledSimplifiedNode
Contains a compiled node which represents a simplified version of this node as a result of compilatio...
Definition:
qgsexpressionnode.h:399
QgsExpression::hasEvalError
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
Definition:
qgsexpression.cpp:378
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:311
qgsexpressionnode.h
QgsExpressionNode::mHasCachedValue
bool mHasCachedValue
true if the node has a static, precalculated value.
Definition:
qgsexpressionnode.h:380
QgsExpressionNode
Abstract base class for all nodes that can appear in an expression.
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:297
QgsExpressionNode::parserLastColumn
int parserLastColumn
Last column in the parser this node was found.
Definition:
qgsexpressionnode.h:318
QgsExpressionNode::QgsExpressionNode
QgsExpressionNode()=default
Constructor.
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings")....
Definition:
qgsexpression.h:102
QgsExpressionNode::prepare
bool prepare(QgsExpression *parent, const QgsExpressionContext *context)
Prepare this node for evaluation.
Definition:
qgsexpressionnode.cpp:37
QgsExpressionNode::operator=
QgsExpressionNode & operator=(const QgsExpressionNode &other)
Assignment operator.
Definition:
qgsexpressionnode.cpp:71
QgsExpressionNode::parserFirstColumn
int parserFirstColumn
First column in the parser this node was found.
Definition:
qgsexpressionnode.h:304
Generated on Sun Sep 11 2022 00:03:17 for QGIS API Documentation by
1.8.17