Skip to content

Commit

Permalink
Hide contextual functions from builder unless provided by context
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 22, 2015
1 parent 2a951ec commit f74db81
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
8 changes: 7 additions & 1 deletion python/core/qgsexpression.sip
Expand Up @@ -247,7 +247,8 @@ class QgsExpression
bool usesGeometry = false, bool usesGeometry = false,
QStringList referencedColumns = QStringList(), QStringList referencedColumns = QStringList(),
bool lazyEval = false, bool lazyEval = false,
bool handlesNull = false ); bool handlesNull = false,
bool isContextual = false );


virtual ~Function(); virtual ~Function();


Expand All @@ -272,6 +273,11 @@ class QgsExpression


virtual QStringList referencedColumns() const; virtual QStringList referencedColumns() const;


/** Returns whether the function is only available if provided by a QgsExpressionContext object.
* @note added in QGIS 2.12
*/
bool isContextual() const;

/** The group the function belongs to. */ /** The group the function belongs to. */
QString group(); QString group();
/** The help text for the function. */ /** The help text for the function. */
Expand Down
3 changes: 2 additions & 1 deletion python/core/qgsexpressioncontext.sip
Expand Up @@ -19,7 +19,8 @@ class QgsScopedExpressionFunction : QgsExpression::Function
bool usesGeometry = false, bool usesGeometry = false,
QStringList referencedColumns = QStringList(), QStringList referencedColumns = QStringList(),
bool lazyEval = false, bool lazyEval = false,
bool handlesNull = false ); bool handlesNull = false,
bool isContextual = true );


virtual ~QgsScopedExpressionFunction(); virtual ~QgsScopedExpressionFunction();


Expand Down
10 changes: 9 additions & 1 deletion src/core/qgsexpression.h
Expand Up @@ -341,7 +341,8 @@ class CORE_EXPORT QgsExpression
bool usesGeometry = false, bool usesGeometry = false,
QStringList referencedColumns = QStringList(), QStringList referencedColumns = QStringList(),
bool lazyEval = false, bool lazyEval = false,
bool handlesNull = false ) bool handlesNull = false,
bool isContextual = false )
: mName( fnname ) : mName( fnname )
, mParams( params ) , mParams( params )
, mUsesGeometry( usesGeometry ) , mUsesGeometry( usesGeometry )
Expand All @@ -350,6 +351,7 @@ class CORE_EXPORT QgsExpression
, mReferencedColumns( referencedColumns ) , mReferencedColumns( referencedColumns )
, mLazyEval( lazyEval ) , mLazyEval( lazyEval )
, mHandlesNull( handlesNull ) , mHandlesNull( handlesNull )
, mIsContextual( isContextual )
{} {}


virtual ~Function() {} virtual ~Function() {}
Expand All @@ -375,6 +377,11 @@ class CORE_EXPORT QgsExpression


virtual QStringList referencedColumns() const { return mReferencedColumns; } virtual QStringList referencedColumns() const { return mReferencedColumns; }


/** Returns whether the function is only available if provided by a QgsExpressionContext object.
* @note added in QGIS 2.12
*/
bool isContextual() const { return mIsContextual; }

/** The group the function belongs to. */ /** The group the function belongs to. */
QString group() { return mGroup; } QString group() { return mGroup; }
/** The help text for the function. */ /** The help text for the function. */
Expand Down Expand Up @@ -409,6 +416,7 @@ class CORE_EXPORT QgsExpression
QStringList mReferencedColumns; QStringList mReferencedColumns;
bool mLazyEval; bool mLazyEval;
bool mHandlesNull; bool mHandlesNull;
bool mIsContextual; //if true function is only available through an expression context
}; };


class StaticFunction : public Function class StaticFunction : public Function
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsexpressioncontext.h
Expand Up @@ -46,8 +46,9 @@ class CORE_EXPORT QgsScopedExpressionFunction : public QgsExpression::Function
bool usesGeometry = false, bool usesGeometry = false,
QStringList referencedColumns = QStringList(), QStringList referencedColumns = QStringList(),
bool lazyEval = false, bool lazyEval = false,
bool handlesNull = false ) bool handlesNull = false,
: QgsExpression::Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull ) bool isContextual = true )
: QgsExpression::Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull, isContextual )
{} {}


virtual ~QgsScopedExpressionFunction() {} virtual ~QgsScopedExpressionFunction() {}
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsexpressionbuilderwidget.cpp
Expand Up @@ -445,6 +445,12 @@ void QgsExpressionBuilderWidget::updateFunctionTree()
QString name = func->name(); QString name = func->name();
if ( name.startsWith( "_" ) ) // do not display private functions if ( name.startsWith( "_" ) ) // do not display private functions
continue; continue;
if ( func->isContextual() )
{
//don't show contextual functions by default - it's up the the QgsExpressionContext
//object to provide them if supported
continue;
}
if ( func->params() != 0 ) if ( func->params() != 0 )
name += "("; name += "(";
else if ( !name.startsWith( "$" ) ) else if ( !name.startsWith( "$" ) )
Expand Down

0 comments on commit f74db81

Please sign in to comment.