QGIS API Documentation
3.22.4-Białowieża (ce8e65e95e)
|
Abstract base class for all nodes that can appear in an expression. More...
#include <qgsexpressionnode.h>
Classes | |
struct | NamedNode |
Named node. More... | |
class | NodeList |
A list of expression nodes. More... | |
Public Types | |
enum | NodeType { ntUnaryOperator , ntBinaryOperator , ntInOperator , ntFunction , ntLiteral , ntColumnRef , ntCondition , ntIndexOperator } |
Known node types. More... | |
Public Member Functions | |
virtual | ~QgsExpressionNode ()=default |
QVariant | cachedStaticValue () const |
Returns the node's static cached value. More... | |
virtual QgsExpressionNode * | clone () const =0 |
Generate a clone of this node. More... | |
virtual QString | dump () const =0 |
Dump this node into a serialized (part) of an expression. More... | |
const QgsExpressionNode * | effectiveNode () const |
Returns a reference to the simplest node which represents this node, after any compilation optimizations have been applied. More... | |
QVariant | eval (QgsExpression *parent, const QgsExpressionContext *context) |
Evaluate this node with the given context and parent. More... | |
bool | hasCachedStaticValue () const |
Returns true if the node can be replaced by a static cached value. More... | |
virtual bool | isStatic (QgsExpression *parent, const QgsExpressionContext *context) const =0 |
Returns true if this node can be evaluated for a static value. More... | |
virtual bool | needsGeometry () const =0 |
Abstract virtual method which returns if the geometry is required to evaluate this expression. More... | |
virtual QList< const QgsExpressionNode * > | nodes () const =0 |
Returns a list of all nodes which are used in this expression. More... | |
virtual QgsExpressionNode::NodeType | nodeType () const =0 |
Gets the type of this node. More... | |
bool | prepare (QgsExpression *parent, const QgsExpressionContext *context) |
Prepare this node for evaluation. More... | |
virtual QSet< QString > | referencedColumns () const =0 |
Abstract virtual method which returns a list of columns required to evaluate this node. More... | |
virtual QSet< QString > | referencedFunctions () const =0 |
Returns a set of all functions which are used in this expression. More... | |
virtual QSet< QString > | referencedVariables () const =0 |
Returns a set of all variables which are used in this expression. More... | |
Public Attributes | |
int | parserFirstColumn = 0 |
First column in the parser this node was found. More... | |
int | parserFirstLine = 0 |
First line in the parser this node was found. More... | |
int | parserLastColumn = 0 |
Last column in the parser this node was found. More... | |
int | parserLastLine = 0 |
Last line in the parser this node was found. More... | |
Protected Member Functions | |
QgsExpressionNode ()=default | |
Constructor. More... | |
QgsExpressionNode (const QgsExpressionNode &other) | |
Copy constructor. More... | |
void | cloneTo (QgsExpressionNode *target) const |
Copies the members of this node to the node provided in target. More... | |
QgsExpressionNode & | operator= (const QgsExpressionNode &other) |
Assignment operator. More... | |
Protected Attributes | |
QVariant | mCachedStaticValue |
Contains the static, precalculated value for the node if mHasCachedValue is true . More... | |
std::unique_ptr< QgsExpressionNode > | mCompiledSimplifiedNode |
Contains a compiled node which represents a simplified version of this node as a result of compilation optimizations. More... | |
bool | mHasCachedValue = false |
true if the node has a static, precalculated value. More... | |
Abstract base class for all nodes that can appear in an expression.
Definition at line 34 of file qgsexpressionnode.h.
Known node types.
Definition at line 74 of file qgsexpressionnode.h.
|
virtualdefault |
|
protecteddefault |
Constructor.
|
protected |
Copy constructor.
Definition at line 59 of file qgsexpressionnode.cpp.
|
inline |
Returns the node's static cached value.
Only valid if hasCachedStaticValue() is true
.
Definition at line 330 of file qgsexpressionnode.h.
|
pure virtual |
Generate a clone of this node.
Ownership is transferred to the caller.
Implemented in QgsExpressionNodeCondition, QgsExpressionNodeColumnRef, QgsExpressionNodeLiteral, QgsExpressionNodeFunction, QgsExpressionNodeInOperator, QgsExpressionNodeIndexOperator, QgsExpressionNodeBinaryOperator, and QgsExpressionNodeUnaryOperator.
|
protected |
Copies the members of this node to the node provided in target.
Needs to be called by all subclasses as part of their clone() implementation.
Definition at line 83 of file qgsexpressionnode.cpp.
|
pure virtual |
Dump this node into a serialized (part) of an expression.
The returned expression does not necessarily literally match the original expression, it's just guaranteed to behave the same way.
Implemented in QgsExpressionNodeCondition, QgsExpressionNodeColumnRef, QgsExpressionNodeLiteral, QgsExpressionNodeFunction, QgsExpressionNodeInOperator, QgsExpressionNodeIndexOperator, QgsExpressionNodeBinaryOperator, and QgsExpressionNodeUnaryOperator.
|
inline |
Returns a reference to the simplest node which represents this node, after any compilation optimizations have been applied.
Eg. a node like "CASE WHEN true THEN "some_field" WHEN other condition THEN ... END" can effectively be replaced entirely by a QgsExpressionNodeColumnRef referencing the "some_field" field, as the CASE WHEN ... will ALWAYS evaluate to "some_field".
Returns a reference to the current object if no optimizations were applied.
Definition at line 344 of file qgsexpressionnode.h.
QVariant QgsExpressionNode::eval | ( | QgsExpression * | parent, |
const QgsExpressionContext * | context | ||
) |
Evaluate this node with the given context and parent.
This will return a cached value if it has been determined to be static during the prepare() execution.
Definition at line 20 of file qgsexpressionnode.cpp.
|
inline |
Returns true
if the node can be replaced by a static cached value.
Definition at line 322 of file qgsexpressionnode.h.
|
pure virtual |
Returns true
if this node can be evaluated for a static value.
This is used during the prepare() step and in case it returns true
, the value of this node will already be evaluated and the result cached (and therefore not re-evaluated in subsequent calls to eval()). In case this returns true
, prepareNode() will never be called.
Implemented in QgsExpressionNodeCondition, QgsExpressionNodeColumnRef, QgsExpressionNodeLiteral, QgsExpressionNodeFunction, QgsExpressionNodeInOperator, QgsExpressionNodeIndexOperator, QgsExpressionNodeBinaryOperator, and QgsExpressionNodeUnaryOperator.
|
pure virtual |
Abstract virtual method which returns if the geometry is required to evaluate this expression.
This needs to call needsGeometry()
recursively on any child nodes.
true
if a geometry is required to evaluate this expression Implemented in QgsExpressionNodeCondition, QgsExpressionNodeColumnRef, QgsExpressionNodeLiteral, QgsExpressionNodeFunction, QgsExpressionNodeInOperator, QgsExpressionNodeIndexOperator, QgsExpressionNodeBinaryOperator, and QgsExpressionNodeUnaryOperator.
|
pure virtual |
Returns a list of all nodes which are used in this expression.
Implemented in QgsExpressionNodeCondition, QgsExpressionNodeColumnRef, QgsExpressionNodeLiteral, QgsExpressionNodeFunction, QgsExpressionNodeInOperator, QgsExpressionNodeIndexOperator, QgsExpressionNodeBinaryOperator, and QgsExpressionNodeUnaryOperator.
|
pure virtual |
Gets the type of this node.
Implemented in QgsExpressionNodeCondition, QgsExpressionNodeColumnRef, QgsExpressionNodeLiteral, QgsExpressionNodeFunction, QgsExpressionNodeInOperator, QgsExpressionNodeIndexOperator, QgsExpressionNodeBinaryOperator, and QgsExpressionNodeUnaryOperator.
|
protected |
Assignment operator.
Definition at line 71 of file qgsexpressionnode.cpp.
bool QgsExpressionNode::prepare | ( | QgsExpression * | parent, |
const QgsExpressionContext * | context | ||
) |
Prepare this node for evaluation.
This will check if the node content is static and in this case cache the value. If it's not static it will call prepareNode() to allow the node to do initialization work like for example resolving a column name to an attribute index.
Definition at line 37 of file qgsexpressionnode.cpp.
|
pure virtual |
Abstract virtual method which returns a list of columns required to evaluate this node.
When reimplementing this, you need to return any column that is required to evaluate this node and in addition recursively collect all the columns required to evaluate child nodes.
Implemented in QgsExpressionNodeCondition, QgsExpressionNodeColumnRef, QgsExpressionNodeLiteral, QgsExpressionNodeFunction, QgsExpressionNodeInOperator, QgsExpressionNodeIndexOperator, QgsExpressionNodeBinaryOperator, and QgsExpressionNodeUnaryOperator.
|
pure virtual |
Returns a set of all functions which are used in this expression.
Implemented in QgsExpressionNodeCondition, QgsExpressionNodeColumnRef, QgsExpressionNodeLiteral, QgsExpressionNodeFunction, QgsExpressionNodeInOperator, QgsExpressionNodeIndexOperator, QgsExpressionNodeBinaryOperator, and QgsExpressionNodeUnaryOperator.
|
pure virtual |
Returns a set of all variables which are used in this expression.
Implemented in QgsExpressionNodeCondition, QgsExpressionNodeColumnRef, QgsExpressionNodeLiteral, QgsExpressionNodeFunction, QgsExpressionNodeInOperator, QgsExpressionNodeIndexOperator, QgsExpressionNodeBinaryOperator, and QgsExpressionNodeUnaryOperator.
|
mutableprotected |
Contains the static, precalculated value for the node if mHasCachedValue is true
.
Definition at line 383 of file qgsexpressionnode.h.
|
mutableprotected |
Contains a compiled node which represents a simplified version of this node as a result of compilation optimizations.
Eg. a node like "CASE WHEN true THEN "some_field" WHEN other condition THEN ... END" can effectively be replaced entirely by a QgsExpressionNodeColumnRef referencing the "some_field" field, as the CASE WHEN ... will ALWAYS evaluate to "some_field".
Definition at line 395 of file qgsexpressionnode.h.
|
mutableprotected |
true
if the node has a static, precalculated value.
Definition at line 376 of file qgsexpressionnode.h.
int QgsExpressionNode::parserFirstColumn = 0 |
First column in the parser this node was found.
Definition at line 300 of file qgsexpressionnode.h.
int QgsExpressionNode::parserFirstLine = 0 |
First line in the parser this node was found.
Definition at line 293 of file qgsexpressionnode.h.
int QgsExpressionNode::parserLastColumn = 0 |
Last column in the parser this node was found.
Definition at line 314 of file qgsexpressionnode.h.
int QgsExpressionNode::parserLastLine = 0 |
Last line in the parser this node was found.
Definition at line 307 of file qgsexpressionnode.h.