Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Also report ScopedFunctions as static when approporiate
  • Loading branch information
m-kuhn committed May 1, 2017
1 parent d70bb9c commit 7a4527d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
16 changes: 16 additions & 0 deletions python/core/qgsexpression.sip
Expand Up @@ -667,6 +667,22 @@ The help text for the function.
:rtype: bool
%End

protected:

static bool allParamsStatic( const NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context );
%Docstring
This will return true if all the params for the provided function ``node`` are static within the
constraints imposed by the ``context`` within the given ``parent``.

This can be used as callback for custom implementations of subclasses. It is the default for implementation
for StaticFunction.isStatic.

.. note::

Added in QGIS 3.0
:rtype: bool
%End

};


Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsexpression.cpp
Expand Up @@ -6552,7 +6552,7 @@ void QgsExpression::StaticFunction::setPrepareFunction( std::function<bool ( con
mPrepareFunc = prepareFunc;
}

bool QgsExpression::StaticFunction::allParamsStatic( const QgsExpression::NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context )
bool QgsExpression::Function::allParamsStatic( const QgsExpression::NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context )
{
if ( node && node->args() )
{
Expand Down
15 changes: 13 additions & 2 deletions src/core/qgsexpression.h
Expand Up @@ -650,6 +650,19 @@ class CORE_EXPORT QgsExpression

virtual bool handlesNull() const { return mHandlesNull; }

protected:

/**
* This will return true if all the params for the provided function \a node are static within the
* constraints imposed by the \a context within the given \a parent.
*
* This can be used as callback for custom implementations of subclasses. It is the default for implementation
* for StaticFunction::isStatic.
*
* \note Added in QGIS 3.0
*/
static bool allParamsStatic( const NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context );

private:
QString mName;
int mParams;
Expand Down Expand Up @@ -800,8 +813,6 @@ class CORE_EXPORT QgsExpression


private:
static bool allParamsStatic( const NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context );

FcnEval mFnc;
QStringList mAliases;
bool mUsesGeometry;
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsexpressioncontext.cpp
Expand Up @@ -1086,3 +1086,8 @@ QSet<QString> QgsScopedExpressionFunction::referencedColumns( const QgsExpressio
Q_UNUSED( node )
return mReferencedColumns;
}

bool QgsScopedExpressionFunction::isStatic( const QgsExpression::NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const
{
return allParamsStatic( node, parent, context );
}
2 changes: 2 additions & 0 deletions src/core/qgsexpressioncontext.h
Expand Up @@ -93,6 +93,8 @@ class CORE_EXPORT QgsScopedExpressionFunction : public QgsExpression::Function

virtual QSet<QString> referencedColumns( const QgsExpression::NodeFunction *node ) const override;

virtual bool isStatic( const QgsExpression::NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const override;

private:
bool mUsesGeometry;
QSet<QString> mReferencedColumns;
Expand Down

0 comments on commit 7a4527d

Please sign in to comment.