Class: register_function¶
- class qgis.core.register_function(function, args='auto', group='custom', usesgeometry=False, referenced_columns=['#!allattributes!#'], handlesnull=False, params_as_list=None, **kwargs)¶
Register a Python function to be used as a expression function.
The function signature may contain special parameters (in any order at the end of the signature): - feature: the
QgsFeature
related to the current evaluation - parent: theQgsExpressionFunction
parent - context: theQgsExpressionContext
related to the current evaluationIf those parameters are present in the function signature, they will be automatically passed to the function, without the need to specify them in the expression.
Functions should return a value compatible with QVariant Eval errors can be raised using parent.setEvalErrorString(“Error message”)
- Parameters:
function – the Python function to be used as an expression function
args – DEPRECATED since QGIS 3.32. Use
params_as_list
if you want to pass parameters as a list.group – the expression group in which the function should be added
usesgeometry – Defines if this expression requires the geometry. By default False.
referenced_columns – An array of field names on which this expression works. By default
[QgsFeatureRequest.ALL_ATTRIBUTES]
. Can be set to None for slightly faster evaluation.handlesnull – Defines if this expression has custom handling for NULL values. If False, the result will always be NULL as soon as any parameter is NULL. False by default.
params_as_list – If True, the function will receive the expression parameters as a list. If False, the function will receive the parameters as individual arguments. False by default.
- Keyword Arguments:
- register (
bool
) – Set to False to create the
QgsPyExpressionFunction
without registering it. Useful for testing puposes. By default True.
- register (
- name (
str
) – If provided, replace the function name
- name (
- helpText (
str
) – If provided, used in the help tooltip instead of the function docstring
- helpText (
- Returns: