QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
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 : 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
18
#include "
qgsexpression.h
"
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
return
evalNode( parent, context );
33
}
34
}
35
36
bool
QgsExpressionNode::prepare
(
QgsExpression
*parent,
const
QgsExpressionContext
*context )
37
{
38
mHasCachedValue
=
false
;
39
mCompiledSimplifiedNode
.reset();
40
if
(
isStatic
( parent, context ) )
41
{
42
// some calls to isStatic already evaluate the node to a cached value, so if that's
43
// happened then don't re-evaluate again
44
if
( !
mHasCachedValue
)
45
{
46
mCachedStaticValue
= evalNode( parent, context );
47
if
( !parent->
hasEvalError
() )
48
mHasCachedValue
=
true
;
49
}
50
return
true
;
51
}
52
else
53
{
54
return
prepareNode( parent, context );
55
}
56
}
57
58
void
QgsExpressionNode::setCachedStaticValue
(
const
QVariant &value )
const
59
{
60
mHasCachedValue
=
true
;
61
mCachedStaticValue
= value;
62
}
63
64
QgsExpressionNode
*
QgsExpressionNode::simplifiedNode
()
const
65
{
66
return
clone
();
67
}
68
69
QgsExpressionNode::QgsExpressionNode
(
const
QgsExpressionNode
&other )
70
:
parserFirstLine
( other.
parserFirstLine
)
71
,
parserFirstColumn
( other.
parserFirstColumn
)
72
,
parserLastLine
( other.
parserLastLine
)
73
,
parserLastColumn
( other.
parserLastColumn
)
74
,
mHasCachedValue
( other.
mHasCachedValue
)
75
,
mCachedStaticValue
( other.
mCachedStaticValue
)
76
,
mCompiledSimplifiedNode
( other.
mCompiledSimplifiedNode
? other.
mCompiledSimplifiedNode
->
clone
() : nullptr )
77
{}
78
79
QgsExpressionNode
&
QgsExpressionNode::operator=
(
const
QgsExpressionNode
&other )
80
{
81
if
( &other ==
this
)
82
return
*
this
;
83
84
parserFirstLine
= other.
parserFirstLine
;
85
parserFirstColumn
= other.
parserFirstColumn
;
86
parserLastLine
= other.
parserLastLine
;
87
parserLastColumn
= other.
parserLastColumn
;
88
mHasCachedValue
= other.
mHasCachedValue
;
89
mCachedStaticValue
= other.
mCachedStaticValue
;
90
mCompiledSimplifiedNode
.reset( other.
mCompiledSimplifiedNode
? other.
mCompiledSimplifiedNode
->clone() :
nullptr
);
91
return
*
this
;
92
}
93
94
void
QgsExpressionNode::cloneTo
(
QgsExpressionNode
*target )
const
95
{
96
target->
mHasCachedValue
=
mHasCachedValue
;
97
target->
mCachedStaticValue
=
mCachedStaticValue
;
98
if
(
mCompiledSimplifiedNode
)
99
target->
mCompiledSimplifiedNode
.reset(
mCompiledSimplifiedNode
->clone() );
100
target->
parserLastColumn
=
parserLastColumn
;
101
target->
parserLastLine
=
parserLastLine
;
102
target->
parserFirstColumn
=
parserFirstColumn
;
103
target->
parserFirstLine
=
parserFirstLine
;
104
}
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition
qgsexpressioncontext.h:491
QgsExpressionNode::simplifiedNode
virtual QgsExpressionNode * simplifiedNode() const
Returns a new node, which is the simplest node which represents this node before any compilation opti...
Definition
qgsexpressionnode.cpp:64
QgsExpressionNode::setCachedStaticValue
void setCachedStaticValue(const QVariant &value) const
Sets the cached static value for the node.
Definition
qgsexpressionnode.cpp:58
QgsExpressionNode::eval
QVariant eval(QgsExpression *parent, const QgsExpressionContext *context)
Evaluate this node with the given context and parent.
Definition
qgsexpressionnode.cpp:20
QgsExpressionNode::clone
virtual QgsExpressionNode * clone() const =0
Generate a clone of this node.
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::prepare
bool prepare(QgsExpression *parent, const QgsExpressionContext *context)
Prepare this node for evaluation.
Definition
qgsexpressionnode.cpp:36
QgsExpressionNode::mHasCachedValue
bool mHasCachedValue
true if the node has a static, precalculated value.
Definition
qgsexpressionnode.h:397
QgsExpressionNode::mCachedStaticValue
QVariant mCachedStaticValue
Contains the static, precalculated value for the node if mHasCachedValue is true.
Definition
qgsexpressionnode.h:404
QgsExpressionNode::QgsExpressionNode
QgsExpressionNode()=default
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:416
QgsExpressionNode::parserFirstLine
int parserFirstLine
First line in the parser this node was found.
Definition
qgsexpressionnode.h:299
QgsExpressionNode::operator=
QgsExpressionNode & operator=(const QgsExpressionNode &other)
Definition
qgsexpressionnode.cpp:79
QgsExpressionNode::parserLastLine
int parserLastLine
Last line in the parser this node was found.
Definition
qgsexpressionnode.h:313
QgsExpressionNode::cloneTo
void cloneTo(QgsExpressionNode *target) const
Copies the members of this node to the node provided in target.
Definition
qgsexpressionnode.cpp:94
QgsExpressionNode::parserLastColumn
int parserLastColumn
Last column in the parser this node was found.
Definition
qgsexpressionnode.h:320
QgsExpressionNode::parserFirstColumn
int parserFirstColumn
First column in the parser this node was found.
Definition
qgsexpressionnode.h:306
QgsExpression
Handles parsing and evaluation of expressions (formerly called "search strings").
Definition
qgsexpression.h:197
QgsExpression::hasEvalError
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
Definition
qgsexpression.cpp:424
qgsexpression.h
qgsexpressionnode.h
Generated on
for QGIS API Documentation by
1.17.0