Skip to content
Permalink
Browse files

Hide contextual functions from builder unless provided by context

  • Loading branch information
nyalldawson committed Aug 22, 2015
1 parent 2a951ec commit f74db81b9ac2598493117721e6180c65a6a38ab0
@@ -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();

@@ -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. */
@@ -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();

@@ -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 )
@@ -350,6 +351,7 @@ class CORE_EXPORT QgsExpression
, mReferencedColumns( referencedColumns )
, mLazyEval( lazyEval )
, mHandlesNull( handlesNull )
, mIsContextual( isContextual )
{}

virtual ~Function() {}
@@ -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. */
@@ -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
@@ -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() {}
@@ -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( "$" ) )

0 comments on commit f74db81

Please sign in to comment.
You can’t perform that action at this time.