Skip to content

Commit d70bb9c

Browse files
committed
Specify for expression functions if they are static
... and prepare them whenever possible
1 parent e137581 commit d70bb9c

File tree

3 files changed

+338
-81
lines changed

3 files changed

+338
-81
lines changed

python/core/qgsexpression.sip

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,31 @@ Does this function use a geometry object.
570570
%Docstring
571571
True if this function should use lazy evaluation. Lazy evaluation functions take QgsExpression.Node objects
572572
rather than the node results when called. You can use node->eval(parent, feature) to evaluate the node and return the result
573-
Functions are non lazy default and will be given the node return value when called **
573+
Functions are non lazy default and will be given the node return value when called.
574574
:rtype: bool
575575
%End
576576

577577
virtual bool isStatic( const QgsExpression::NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const;
578578
%Docstring
579+
Will be called during prepare to determine if the function is static.
580+
A function is static if it will return the same value for every feature with different
581+
attributes and/or geometry.
582+
583+
By default this will return true, if all arguments that have been passed to the function
584+
are also static.
585+
586+
.. versionadded:: 3.0
587+
:rtype: bool
588+
%End
589+
590+
virtual bool prepare( const QgsExpression::NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const;
591+
%Docstring
592+
This will be called during the prepare step() of an expression if it is not static.
593+
594+
This can be used by functions to do any preparation steps that might help to speedup the upcoming
595+
evaluation.
596+
597+
.. versionadded:: 3.0
579598
:rtype: bool
580599
%End
581600

@@ -828,8 +847,6 @@ return index of the function in Functions array
828847
virtual QgsExpression::Node *clone() const = 0;
829848
%Docstring
830849
Generate a clone of this node.
831-
Make sure that the clone does not contain any information which is
832-
generated in prepare and context related.
833850
Ownership is transferred to the caller.
834851

835852
:return: a deep copy of this node.
@@ -888,6 +905,16 @@ return index of the function in Functions array
888905
:rtype: bool
889906
%End
890907

908+
909+
protected:
910+
911+
void cloneTo( QgsExpression::Node *target ) const;
912+
%Docstring
913+
Needs to be called by all subclasses as part of their clone() implementation.
914+
915+
.. versionadded:: 3.0
916+
%End
917+
891918
private:
892919
virtual bool prepareNode( QgsExpression *parent, const QgsExpressionContext *context ) = 0 ;
893920
%Docstring

0 commit comments

Comments
 (0)