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
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ class QgsExpression
bool usesGeometry = false,
QStringList referencedColumns = QStringList(),
bool lazyEval = false,
bool handlesNull = false );
bool handlesNull = false,
bool isContextual = false );

virtual ~Function();

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

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. */
QString group();
/** The help text for the function. */
Expand Down
3 changes: 2 additions & 1 deletion python/core/qgsexpressioncontext.sip
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class QgsScopedExpressionFunction : QgsExpression::Function
bool usesGeometry = false,
QStringList referencedColumns = QStringList(),
bool lazyEval = false,
bool handlesNull = false );
bool handlesNull = false,
bool isContextual = true );

virtual ~QgsScopedExpressionFunction();

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

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

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

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

virtual ~QgsScopedExpressionFunction() {}
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsexpressionbuilderwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ void QgsExpressionBuilderWidget::updateFunctionTree()
QString name = func->name();
if ( name.startsWith( "_" ) ) // do not display private functions
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 )
name += "(";
else if ( !name.startsWith( "$" ) )
Expand Down

0 comments on commit f74db81

Please sign in to comment.