Subgroup: Expression
Class: QgsExpressionFunction¶
-
class
qgis.core.
QgsExpressionFunction
(fnname: str, params: int, group: str, helpText: str = '', lazyEval: bool = False, handlesNull: bool = False, isContextual: bool = False)¶ Bases:
sip.wrapper
Constructor for function which uses unnamed parameters
QgsExpressionFunction(fnname: str, params: int, groups: Iterable[str], helpText: str = ‘’, lazyEval: bool = False, handlesNull: bool = False, isContextual: bool = False) Constructor for function which uses unnamed parameters and group list
New in version 3.0.
QgsExpressionFunction(fnname: str, params: object, group: str, helpText: str = ‘’, lazyEval: bool = False, handlesNull: bool = False, isContextual: bool = False) Constructor for function which uses named parameter list.
New in version 2.16.
QgsExpressionFunction(fnname: str, params: object, groups: Iterable[str], helpText: str = ‘’, lazyEval: bool = False, handlesNull: bool = False, isContextual: bool = False) Constructor for function which uses named parameter list and group list.
New in version 3.0.
QgsExpressionFunction(QgsExpressionFunction)
A abstract base class for defining QgsExpression functions.
Methods
aliases
Returns a list of possible aliases for the function. allParamsStatic
This will return true if all the params for the provided function node
are static within the constraints imposed by thecontext
within the givenparent
.func
Returns result of evaluating the function. group
Returns the first group which the function belongs to. groups
Returns a list of the groups the function belongs to. handlesNull
helpText
The help text for the function. isContextual
Returns whether the function is only available if provided by a QgsExpressionContext object. isDeprecated
Returns true if the function is deprecated and should not be presented as a valid option to users in expression builders. isStatic
Will be called during prepare to determine if the function is static. lazyEval
True if this function should use lazy evaluation. minParams
The minimum number of parameters this function takes. name
The name of the function. parameters
Returns the list of named parameters for the function, if set. params
The number of parameters this function takes. prepare
This will be called during the prepare step() of an expression if it is not static. referencedColumns
Returns a set of field names which are required for this function. run
usesGeometry
Does this function use a geometry object. Signals
Attributes
-
class
Parameter
(name: str, optional: bool = False, defaultValue: Any = None)¶ Bases:
sip.wrapper
Constructor for Parameter.
Parameters: - name – parameter name, used when named parameter are specified in an expression
- optional – set to true if parameter should be optional
- defaultValue – default value to use for optional parameters
QgsExpressionFunction.Parameter(QgsExpressionFunction.Parameter)
Represents a single parameter passed to a function.
New in version 2.16.
-
defaultValue
(self) → Any¶ Returns the default value for the parameter.
-
name
(self) → str¶ Returns the name of the parameter.
-
optional
(self) → bool¶ Returns true if the parameter is optional.
-
aliases
(self) → List[str]¶ Returns a list of possible aliases for the function. These include other permissible names for the function, e.g., deprecated names.
Returns: list of known aliases New in version 2.9.
-
allParamsStatic
(node: QgsExpressionNodeFunction, parent: QgsExpression, context: QgsExpressionContext) → bool¶ This will return true if all the params for the provided function
node
are static within the constraints imposed by thecontext
within the givenparent
.This can be used as callback for custom implementations of subclasses. It is the default for implementation for StaticFunction.isStatic.
New in version 3.0.
-
func
(self, values: List[Any], context: QgsExpressionContext, parent: QgsExpression, node: QgsExpressionNodeFunction) → Any¶ Returns result of evaluating the function.
Parameters: - values – list of values passed to the function
- context – context expression is being evaluated against
- parent – parent expression
- node – expression node
Returns: result of function
-
group
(self) → str¶ Returns the first group which the function belongs to.
Note
consider using groups() instead, as some functions naturally belong in multiple groups
-
groups
(self) → List[str]¶ Returns a list of the groups the function belongs to.
New in version 3.0.
See also
-
handlesNull
(self) → bool¶
-
helpText
(self) → str¶ The help text for the function.
-
isContextual
(self) → bool¶ Returns whether the function is only available if provided by a QgsExpressionContext object.
New in version 2.12.
-
isDeprecated
(self) → bool¶ Returns true if the function is deprecated and should not be presented as a valid option to users in expression builders.
New in version 3.0.
-
isStatic
(self, node: QgsExpressionNodeFunction, parent: QgsExpression, context: QgsExpressionContext) → bool¶ 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.
New in version 3.0.
-
lazyEval
(self) → bool¶ 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.
-
minParams
(self) → int¶ The minimum number of parameters this function takes.
-
name
(self) → str¶ The name of the function.
-
parameters
(self) → object¶ Returns the list of named parameters for the function, if set.
New in version 2.16.
-
params
(self) → int¶ The number of parameters this function takes.
-
prepare
(self, node: QgsExpressionNodeFunction, parent: QgsExpression, context: QgsExpressionContext) → bool¶ 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.
New in version 3.0.
-
referencedColumns
(self, node: QgsExpressionNodeFunction) → Set[str]¶ Returns a set of field names which are required for this function. May contain QgsFeatureRequest.AllAttributes to signal that all attributes are required. If in doubt this will return more fields than strictly required.
New in version 3.0.
-
run
(self, args: QgsExpressionNode.NodeList, context: QgsExpressionContext, parent: QgsExpression, node: QgsExpressionNodeFunction) → Any¶
-
usesGeometry
(self, node: QgsExpressionNodeFunction) → bool¶ Does this function use a geometry object.
-
class