Skip to content

Commit

Permalink
Specify for expression functions if they are static
Browse files Browse the repository at this point in the history
... and prepare them whenever possible
  • Loading branch information
m-kuhn committed May 1, 2017
1 parent e137581 commit d70bb9c
Show file tree
Hide file tree
Showing 3 changed files with 338 additions and 81 deletions.
33 changes: 30 additions & 3 deletions python/core/qgsexpression.sip
Expand Up @@ -570,12 +570,31 @@ Does this function use a geometry object.
%Docstring
True if this function should use lazy evaluation. Lazy evaluation functions take QgsExpression.Node objects
rather than the node results when called. You can use node->eval(parent, feature) to evaluate the node and return the result
Functions are non lazy default and will be given the node return value when called **
Functions are non lazy default and will be given the node return value when called.
:rtype: bool
%End

virtual bool isStatic( const QgsExpression::NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const;
%Docstring
Will be called during prepare to determine if the function is static.
A function is static if it will return the same value for every feature with different
attributes and/or geometry.

By default this will return true, if all arguments that have been passed to the function
are also static.

.. versionadded:: 3.0
:rtype: bool
%End

virtual bool prepare( const QgsExpression::NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const;
%Docstring
This will be called during the prepare step() of an expression if it is not static.

This can be used by functions to do any preparation steps that might help to speedup the upcoming
evaluation.

.. versionadded:: 3.0
:rtype: bool
%End

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

:return: a deep copy of this node.
Expand Down Expand Up @@ -888,6 +905,16 @@ return index of the function in Functions array
:rtype: bool
%End


protected:

void cloneTo( QgsExpression::Node *target ) const;
%Docstring
Needs to be called by all subclasses as part of their clone() implementation.

.. versionadded:: 3.0
%End

private:
virtual bool prepareNode( QgsExpression *parent, const QgsExpressionContext *context ) = 0 ;
%Docstring
Expand Down

0 comments on commit d70bb9c

Please sign in to comment.