QgsExpressionNode class

Abstract base class for all nodes that can appear in an expression.

Derived classes

class QgsExpressionNodeBinaryOperator
A binary expression operator, which operates on two values.
class QgsExpressionNodeColumnRef
An expression node which takes it value from a feature's field.
class QgsExpressionNodeCondition
An expression node for CASE WHEN clauses.
class QgsExpressionNodeFunction
An expression node for expression functions.
class QgsExpressionNodeIndexOperator
A indexing expression operator, which allows use of square brackets [] to reference map and array items.
class QgsExpressionNodeInOperator
An expression node for value IN or NOT IN clauses.
class QgsExpressionNodeLiteral
An expression node for literal values.
class QgsExpressionNodeUnaryOperator
A unary node is either negative as in boolean (not) or as in numbers (minus).

Public types

struct NamedNode
Named node.
class NodeList
A list of expression nodes.
enum NodeType { ntUnaryOperator, ntBinaryOperator, ntInOperator, ntFunction, ntLiteral, ntColumnRef, ntCondition, ntIndexOperator }
Known node types.

Public functions

auto clone() const -> QgsExpressionNode* pure virtual
Generate a clone of this node.
auto dump() const -> QString pure virtual
Dump this node into a serialized (part) of an expression.
auto eval(QgsExpression* parent, const QgsExpressionContext* context) -> QVariant
Evaluate this node with the given context and parent.
auto isStatic(QgsExpression* parent, const QgsExpressionContext* context) const -> bool pure virtual
Returns true if this node can be evaluated for a static value.
auto needsGeometry() const -> bool pure virtual
Abstract virtual method which returns if the geometry is required to evaluate this expression.
auto nodes() const -> QList<const QgsExpressionNode*> pure virtual
Returns a list of all nodes which are used in this expression.
auto nodeType() const -> QgsExpressionNode::NodeType pure virtual
Gets the type of this node.
auto prepare(QgsExpression* parent, const QgsExpressionContext* context) -> bool
Prepare this node for evaluation.
auto referencedColumns() const -> QSet<QString> pure virtual
Abstract virtual method which returns a list of columns required to evaluate this node.
auto referencedFunctions() const -> QSet<QString> pure virtual
Returns a set of all functions which are used in this expression.
auto referencedVariables() const -> QSet<QString> pure virtual
Returns a set of all variables which are used in this expression.

Public variables

int parserFirstColumn
First column in the parser this node was found.
int parserFirstLine
First line in the parser this node was found.
int parserLastColumn
Last column in the parser this node was found.
int parserLastLine
Last line in the parser this node was found.

Protected functions

void cloneTo(QgsExpressionNode* target) const
Copies the members of this node to the node provided in target.

Private functions

auto evalNode(QgsExpression* parent, const QgsExpressionContext* context) -> QVariant pure virtual
Abstract virtual eval method Errors are reported to the parent.
auto prepareNode(QgsExpression* parent, const QgsExpressionContext* context) -> bool pure virtual
Abstract virtual preparation method Errors are reported to the parent.

Enum documentation

enum QgsExpressionNode::NodeType

Known node types.

Enumerators
ntUnaryOperator
ntBinaryOperator
ntInOperator
ntFunction
ntLiteral
ntColumnRef
ntCondition
ntIndexOperator

Index operator.

Function documentation

QgsExpressionNode* QgsExpressionNode::clone() const pure virtual

Generate a clone of this node.

Returns a deep copy of this node.

Ownership is transferred to the caller.

QString QgsExpressionNode::dump() const 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.

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.

bool QgsExpressionNode::isStatic(QgsExpression* parent, const QgsExpressionContext* context) const 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.

bool QgsExpressionNode::needsGeometry() const pure virtual

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

Returns true if a geometry is required to evaluate this expression

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

QList<const QgsExpressionNode*> QgsExpressionNode::nodes() const pure virtual

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

QgsExpressionNode::NodeType QgsExpressionNode::nodeType() const pure virtual

Gets the type of this node.

Returns The type of this node

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.

QSet<QString> QgsExpressionNode::referencedColumns() const pure virtual

Abstract virtual method which returns a list of columns required to evaluate this node.

Returns A list of columns required to evaluate this expression

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.

void QgsExpressionNode::cloneTo(QgsExpressionNode* target) const 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.

QVariant QgsExpressionNode::evalNode(QgsExpression* parent, const QgsExpressionContext* context) pure virtual private

Abstract virtual eval method Errors are reported to the parent.

bool QgsExpressionNode::prepareNode(QgsExpression* parent, const QgsExpressionContext* context) pure virtual private

Abstract virtual preparation method Errors are reported to the parent.

Variable documentation

int QgsExpressionNode::parserFirstColumn

First column in the parser this node was found.

int QgsExpressionNode::parserFirstLine

First line in the parser this node was found.

int QgsExpressionNode::parserLastColumn

Last column in the parser this node was found.

int QgsExpressionNode::parserLastLine

Last line in the parser this node was found.