diff --git a/python/user.py b/python/user.py index e6298af1585..0755df27b24 100644 --- a/python/user.py +++ b/python/user.py @@ -66,16 +66,48 @@ if not os.path.exists(initfile): open(initfile, "w").close() template = """\"\"\" -Define new functions using @qgsfunction. feature and parent must always be the -last args. Use args=-1 to pass a list of values as arguments +Define a new function using the @qgsfunction decorator. + +The function accept the following parameters + +:param [any]: Define any parameters you want to pass to your function before + the following arguments. +:param feature: The current feature +:param parent: The QgsExpression object +:param context: If there is an argument called ``context`` found at the last + position, this variable will contain a ``QgsExpressionContext`` + object, that gives access to various additional information like + expression variables. E.g. ``context.variable('layer_id')`` +:returns: The result of the expression. + + +The @qgsfunction decorator accepts the following arguments: + +:param args: Defines the number of arguments. With ``args='auto'`` the number + arguments will automatically be extracted from the signature. +:param group: The name of the group under which this expression function will + be listed. +:param usesgeometry: Set this to False if your function does not access + feature.geometry(). Defaults to True. +:param referenced_columns: An array of attribute names that are required to run + this function. Defaults to + [QgsFeatureRequest.ALL_ATTRIBUTES]. \"\"\" from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') -def func(value1, feature, parent): - return value1 +def my_sum(value1, value2, feature, parent): + \"\"\" + Calculates the sum of the two parameters value1 and value2. +

Example usage:

+ + \"\"\" + return value1 + value2 """