QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
Public Member Functions | List of all members
QgsExpressionNodeLiteral Class Reference

An expression node for literal values. More...

#include <qgsexpressionnodeimpl.h>

Inheritance diagram for QgsExpressionNodeLiteral:
Inheritance graph
[legend]

Public Member Functions

 QgsExpressionNodeLiteral (const QVariant &value)
 Constructor for QgsExpressionNodeLiteral, with the specified literal value. More...
 
QgsExpressionNodeclone () const override
 Generate a clone of this node. More...
 
QString dump () const override
 Dump this node into a serialized (part) of an expression. More...
 
QVariant evalNode (QgsExpression *parent, const QgsExpressionContext *context) override
 Abstract virtual eval method Errors are reported to the parent. More...
 
bool isStatic (QgsExpression *parent, const QgsExpressionContext *context) const override
 Returns true if this node can be evaluated for a static value. More...
 
bool needsGeometry () const override
 Abstract virtual method which returns if the geometry is required to evaluate this expression. More...
 
QList< const QgsExpressionNode * > nodes () const override
 Returns a list of all nodes which are used in this expression. More...
 
QgsExpressionNode::NodeType nodeType () const override
 Gets the type of this node. More...
 
bool prepareNode (QgsExpression *parent, const QgsExpressionContext *context) override
 Abstract virtual preparation method Errors are reported to the parent. More...
 
QSet< QString > referencedColumns () const override
 Abstract virtual method which returns a list of columns required to evaluate this node. More...
 
QSet< QString > referencedFunctions () const override
 Returns a set of all functions which are used in this expression. More...
 
QSet< QString > referencedVariables () const override
 Returns a set of all variables which are used in this expression. More...
 
QVariant value () const
 The value of the literal. More...
 
QString valueAsString () const
 Returns a string representation of the node's literal value. More...
 
- Public Member Functions inherited from QgsExpressionNode
virtual ~QgsExpressionNode ()=default
 
QVariant cachedStaticValue () const
 Returns the node's static cached value. More...
 
virtual QgsExpressionNodeclone () 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 QgsExpressionNodeeffectiveNode () 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...
 
void setCachedStaticValue (const QVariant &value) const
 Sets the cached static value for the node. More...
 

Additional Inherited Members

- Public Types inherited from QgsExpressionNode
enum  NodeType {
  ntUnaryOperator , ntBinaryOperator , ntInOperator , ntFunction ,
  ntLiteral , ntColumnRef , ntCondition , ntIndexOperator ,
  ntBetweenOperator
}
 Known node types. More...
 
- Public Attributes inherited from QgsExpressionNode
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 inherited from QgsExpressionNode
 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...
 
QgsExpressionNodeoperator= (const QgsExpressionNode &other)
 Assignment operator. More...
 
- Protected Attributes inherited from QgsExpressionNode
QVariant mCachedStaticValue
 Contains the static, precalculated value for the node if mHasCachedValue is true. More...
 
std::unique_ptr< QgsExpressionNodemCompiledSimplifiedNode
 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...
 

Detailed Description

An expression node for literal values.

Definition at line 461 of file qgsexpressionnodeimpl.h.

Constructor & Destructor Documentation

◆ QgsExpressionNodeLiteral()

QgsExpressionNodeLiteral::QgsExpressionNodeLiteral ( const QVariant &  value)
inline

Constructor for QgsExpressionNodeLiteral, with the specified literal value.

Definition at line 468 of file qgsexpressionnodeimpl.h.

Member Function Documentation

◆ clone()

QgsExpressionNode * QgsExpressionNodeLiteral::clone ( ) const
overridevirtual

Generate a clone of this node.

Ownership is transferred to the caller.

Returns
a deep copy of this node.

Implements QgsExpressionNode.

Definition at line 1419 of file qgsexpressionnodeimpl.cpp.

◆ dump()

QString QgsExpressionNodeLiteral::dump ( ) const
overridevirtual

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.

Implements QgsExpressionNode.

Definition at line 1387 of file qgsexpressionnodeimpl.cpp.

◆ evalNode()

QVariant QgsExpressionNodeLiteral::evalNode ( QgsExpression parent,
const QgsExpressionContext context 
)
overridevirtual

Abstract virtual eval method Errors are reported to the parent.

Since
QGIS 3.0

Implements QgsExpressionNode.

Definition at line 1345 of file qgsexpressionnodeimpl.cpp.

◆ isStatic()

bool QgsExpressionNodeLiteral::isStatic ( QgsExpression parent,
const QgsExpressionContext context 
) const
overridevirtual

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.

Since
QGIS 3.0

Implements QgsExpressionNode.

Definition at line 1426 of file qgsexpressionnodeimpl.cpp.

◆ needsGeometry()

bool QgsExpressionNodeLiteral::needsGeometry ( ) const
overridevirtual

Abstract virtual method which returns if the geometry is required to evaluate this expression.

This needs to call needsGeometry() recursively on any child nodes.

Returns
true if a geometry is required to evaluate this expression

Implements QgsExpressionNode.

Definition at line 1414 of file qgsexpressionnodeimpl.cpp.

◆ nodes()

QList< const QgsExpressionNode * > QgsExpressionNodeLiteral::nodes ( ) const
overridevirtual

Returns a list of all nodes which are used in this expression.

Note
not available in Python bindings
Since
QGIS 3.2

Implements QgsExpressionNode.

Definition at line 1407 of file qgsexpressionnodeimpl.cpp.

◆ nodeType()

QgsExpressionNode::NodeType QgsExpressionNodeLiteral::nodeType ( ) const
overridevirtual

Gets the type of this node.

Returns
The type of this node

Implements QgsExpressionNode.

Definition at line 1352 of file qgsexpressionnodeimpl.cpp.

◆ prepareNode()

bool QgsExpressionNodeLiteral::prepareNode ( QgsExpression parent,
const QgsExpressionContext context 
)
overridevirtual

Abstract virtual preparation method Errors are reported to the parent.

Since
QGIS 3.0

Implements QgsExpressionNode.

Definition at line 1357 of file qgsexpressionnodeimpl.cpp.

◆ referencedColumns()

QSet< QString > QgsExpressionNodeLiteral::referencedColumns ( ) const
overridevirtual

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.

Warning
If the expression has been prepared via a call to QgsExpression::prepare(), or a call to QgsExpressionNode::prepare() for a node has been made, then some nodes in the expression may have been determined to evaluate to a static pre-calculatable value. In this case the results will omit attribute indices which are used by these pre-calculated nodes, regardless of their actual referenced columns. If you are seeking to use these functions to introspect an expression you must take care to do this with an unprepared expression node.
Returns
A list of columns required to evaluate this expression

Implements QgsExpressionNode.

Definition at line 1392 of file qgsexpressionnodeimpl.cpp.

◆ referencedFunctions()

QSet< QString > QgsExpressionNodeLiteral::referencedFunctions ( ) const
overridevirtual

Returns a set of all functions which are used in this expression.

Note
In contrast to the referencedColumns() function this method is not affected by any previous calls to QgsExpressionNode::prepare().

Implements QgsExpressionNode.

Definition at line 1402 of file qgsexpressionnodeimpl.cpp.

◆ referencedVariables()

QSet< QString > QgsExpressionNodeLiteral::referencedVariables ( ) const
overridevirtual

Returns a set of all variables which are used in this expression.

Note
In contrast to the referencedColumns() function this method is not affected by any previous calls to QgsExpressionNode::prepare().

Implements QgsExpressionNode.

Definition at line 1397 of file qgsexpressionnodeimpl.cpp.

◆ value()

QVariant QgsExpressionNodeLiteral::value ( ) const
inline

The value of the literal.

Definition at line 481 of file qgsexpressionnodeimpl.h.

◆ valueAsString()

QString QgsExpressionNodeLiteral::valueAsString ( ) const

Returns a string representation of the node's literal value.

Since
QGIS 3.20

Definition at line 1365 of file qgsexpressionnodeimpl.cpp.


The documentation for this class was generated from the following files: