Class: QgsProcessingParameterDefinition

class qgis.core.QgsProcessingParameterDefinition

Bases: sip.wrapper

Base class for the definition of processing parameters.

Parameter definitions encapsulate properties regarding the behavior of parameters, their acceptable ranges, defaults, etc.

New in version 3.0.

QgsProcessingParameterDefinition(name: str, description: str = ‘’, defaultValue: Any = None, optional: bool = False, help: str = ‘’) Constructor for QgsProcessingParameterDefinition.

QgsProcessingParameterDefinition(QgsProcessingParameterDefinition)

Methods

additionalExpressionContextVariables

Returns a list of additional expression context variables which are available for use when evaluating this parameter.

algorithm

Returns a pointer to the algorithm which owns this parameter.

asPythonString

Returns the parameter definition as a Python command which can be used within a Python Processing script.

asScriptCode

Returns the parameter definition encoded in a string which can be used within a Processing script.

checkValueIsAcceptable

Checks whether the specified input value is acceptable for the parameter.

clone

Creates a clone of the parameter definition.

defaultValue

Returns the default value for the parameter.

defaultValueForGui

Returns the default value to use for the parameter in a GUI.

dependsOnOtherParameters

Returns a list of other parameter names on which this parameter is dependent (e.g. field parameters which depend on a parent layer parameter).

description

Returns the description for the parameter.

dynamicLayerParameterName

Returns the name of the parameter for a layer linked to a dynamic parameter, or an empty string if this is not set.

dynamicPropertyDefinition

Returns the property definition for dynamic properties.

flags

Returns any flags associated with the parameter.

fromVariantMap

Restores this parameter to a QVariantMap.

guiDefaultValueOverride

Returns the default value to use in the GUI for the parameter.

help

Returns the help for the parameter.

isDestination

Returns True if this parameter represents a file or layer destination, e.g. parameters which are used for the destination for layers output by an algorithm will return True.

isDynamic

Returns True if the parameter supports is dynamic, and can support data-defined values (i.e. QgsProperty based values).

metadata

Returns the parameter's freeform metadata.

name

Returns the name of the parameter.

provider

Returns a pointer to the provider for the algorithm which owns this parameter.

setAdditionalExpressionContextVariables

Sets a list of additional expression context variables which are available for use when evaluating this parameter.

setDefaultValue

Sets the default value for the parameter.

setDescription

Sets the description for the parameter.

setDynamicLayerParameterName

Sets the name for the parameter for a layer linked to a dynamic parameter, or an empty string if this is not set.

setDynamicPropertyDefinition

Sets the property definition for dynamic properties.

setFlags

Sets the flags associated with the parameter.

setGuiDefaultValueOverride

Sets the default value to use for the parameter in GUI widgets.

setHelp

Sets the help for the parameter.

setIsDynamic

Sets whether the parameter is dynamic, and can support data-defined values (i.e. QgsProperty based values).

setMetadata

Sets the parameter's freeform metadata.

setName

Sets the name of the parameter.

toVariantMap

Saves this parameter to a QVariantMap.

toolTip

Returns a formatted tooltip for use with the parameter, which gives helpful information like parameter description, ID, and extra content like default values (depending on parameter type).

type

Unique parameter type name.

valueAsJsonObject

Returns a version of the parameter input value, which is suitable for use in a JSON object.

valueAsPythonComment

Returns a Python comment explaining a parameter value, or an empty string if no comment is required.

valueAsPythonString

Returns a string version of the parameter input value, which is suitable for use as an input parameter value when running an algorithm directly from a Python command.

valueAsString

Returns a string version of the parameter input value (if possible).

valueAsStringList

Returns a string list version of the parameter input value (if possible).

Attributes

FlagAdvanced

FlagHidden

FlagIsModelOutput

FlagOptional

class Flag

Bases: int

FlagAdvanced = 2
FlagHidden = 4
FlagIsModelOutput = 16
FlagOptional = 8
class Flags
class Flags(Union[QgsProcessingParameterDefinition.Flags, QgsProcessingParameterDefinition.Flag])
class Flags(QgsProcessingParameterDefinition.Flags)

Bases: sip.wrapper

additionalExpressionContextVariables(self) List[str]

Returns a list of additional expression context variables which are available for use when evaluating this parameter.

The additional variables will be added to the variables exposed from the usual expression context available to the parameter. They can be used to expose variables which are ONLY available to this parameter.

The returned list should contain the variable names only, without the usual “@” prefix.

New in version 3.8.

Return type:

List[str]

algorithm(self) QgsProcessingAlgorithm

Returns a pointer to the algorithm which owns this parameter. May be None for non-owned parameters.

See also

provider()

Return type:

QgsProcessingAlgorithm

asPythonString(self, outputType: QgsProcessing.PythonOutputType = QgsProcessing.PythonQgsProcessingAlgorithmSubclass) str

Returns the parameter definition as a Python command which can be used within a Python Processing script.

The outputType argument specifies the desired output format for the Python string, i.e. the intended end use of the generated Python code.

New in version 3.6.

Parameters:

outputType (QgsProcessing.PythonOutputType = QgsProcessing.PythonQgsProcessingAlgorithmSubclass) –

Return type:

str

asScriptCode(self) str

Returns the parameter definition encoded in a string which can be used within a Processing script.

Return type:

str

checkValueIsAcceptable(self, input: Any, context: QgsProcessingContext = None) bool

Checks whether the specified input value is acceptable for the parameter. Returns True if the value can be accepted. The optional context parameter can be specified to allow a more stringent check to be performed, capable of checking for the presence of required layers and other factors within the context.

Parameters:
Return type:

bool

clone(self) QgsProcessingParameterDefinition

Creates a clone of the parameter definition.

Return type:

QgsProcessingParameterDefinition

defaultValue(self) Any

Returns the default value for the parameter.

Return type:

Any

defaultValueForGui(self) Any

Returns the default value to use for the parameter in a GUI.

This will be the parameter’s defaultValue(), unless a guiDefaultValueOverride() is set to override that.

New in version 3.18.

Return type:

Any

dependsOnOtherParameters(self) List[str]

Returns a list of other parameter names on which this parameter is dependent (e.g. field parameters which depend on a parent layer parameter).

Return type:

List[str]

description(self) str

Returns the description for the parameter. This is the user-visible string used to identify this parameter.

See also

setDescription()

Return type:

str

dynamicLayerParameterName(self) str

Returns the name of the parameter for a layer linked to a dynamic parameter, or an empty string if this is not set.

Dynamic parameters (see isDynamic()) can have an optional vector layer parameter linked to them, which indicates which layer the fields and values will be available from when evaluating the dynamic parameter.

See also

isDynamic()

Return type:

str

dynamicPropertyDefinition(self) QgsPropertyDefinition

Returns the property definition for dynamic properties.

See also

isDynamic()

Return type:

QgsPropertyDefinition

flags(self) QgsProcessingParameterDefinition.Flags

Returns any flags associated with the parameter.

See also

setFlags()

Return type:

QgsProcessingParameterDefinition.Flags

fromVariantMap(self, map: Dict[str, Any]) bool

Restores this parameter to a QVariantMap. Subclasses should ensure that they call the base class method.

See also

toVariantMap()

Parameters:

map (Dict[str) –

Return type:

bool

guiDefaultValueOverride(self) Any

Returns the default value to use in the GUI for the parameter.

Usually this will return an invalid variant, which indicates that the standard defaultValue() will be used in the GUI.

See also

defaultValue()

New in version 3.18.

Return type:

Any

help(self) str

Returns the help for the parameter.

This is a descriptive (possibly lengthy), translated string explaining the parameter’s behavior and use in depth.

See also

setHelp()

New in version 3.16.

Return type:

str

isDestination(self) bool

Returns True if this parameter represents a file or layer destination, e.g. parameters which are used for the destination for layers output by an algorithm will return True.

Return type:

bool

isDynamic(self) bool

Returns True if the parameter supports is dynamic, and can support data-defined values (i.e. QgsProperty based values).

See also

setIsDynamic()

Return type:

bool

metadata(self) Dict[str, Any]

Returns the parameter’s freeform metadata. This is mostly used by parameter widget wrappers in order to customize their appearance and behavior.

See also

setMetadata()

Return type:

Dict[str, Any]

name(self) str

Returns the name of the parameter. This is the internal identifier by which algorithms access this parameter.

See also

setName()

Return type:

str

provider(self) QgsProcessingProvider

Returns a pointer to the provider for the algorithm which owns this parameter. May be None for non-owned parameters or algorithms.

See also

algorithm()

Return type:

QgsProcessingProvider

setAdditionalExpressionContextVariables(self, variables: Iterable[str])

Sets a list of additional expression context variables which are available for use when evaluating this parameter.

The additional variables will be added to the variables exposed from the usual expression context available to the parameter. They can be used to expose variables which are ONLY available to this parameter.

The variables list should contain the variable names only, without the usual “@” prefix.

Note

Specifying variables via this method is for metadata purposes only. It is the algorithm’s responsibility to correctly set the value of these additional variables in all expression context used when evaluating the parameter, in whichever way is appropriate for that particular variable.

New in version 3.8.

Parameters:

variables (Iterable[str]) –

setDefaultValue(self, value: Any)

Sets the default value for the parameter. Caller takes responsibility to ensure that value is a valid input for the parameter subclass.

See also

defaultValue()

Parameters:

value (Any) –

setDescription(self, description: str)

Sets the description for the parameter. This is the user-visible string used to identify this parameter.

See also

description()

Parameters:

description (str) –

setDynamicLayerParameterName(self, name: str)

Sets the name for the parameter for a layer linked to a dynamic parameter, or an empty string if this is not set.

Dynamic parameters (see isDynamic()) can have an optional vector layer parameter linked to them, which indicates which layer the fields and values will be available from when evaluating the dynamic parameter.

See also

isDynamic()

Parameters:

name (str) –

setDynamicPropertyDefinition(self, definition: QgsPropertyDefinition)

Sets the property definition for dynamic properties.

See also

isDynamic()

Parameters:

definition (QgsPropertyDefinition) –

setFlags(self, flags: QgsProcessingParameterDefinition.Flags | QgsProcessingParameterDefinition.Flag)

Sets the flags associated with the parameter.

See also

flags()

Parameters:

flags (Union[QgsProcessingParameterDefinition.Flags) –

setGuiDefaultValueOverride(self, value: Any)

Sets the default value to use for the parameter in GUI widgets. Caller takes responsibility to ensure that value is a valid input for the parameter subclass.

Usually the guiDefaultValueOverride() is a invalid variant, which indicates that the standard defaultValue() should be used in the GUI. In cases where it is decided that a previous default value was inappropriate, setting a non-invalid default GUI value can be used to change the default value for the parameter shown to users when running algorithms without changing the actual defaultValue() and potentially breaking third party scripts.

New in version 3.18.

Parameters:

value (Any) –

setHelp(self, help: str)

Sets the help for the parameter.

The help string should be a descriptive, translated string explaining the parameter’s behavior and use in depth.

See also

help()

New in version 3.16.

Parameters:

help (str) –

setIsDynamic(self, dynamic: bool)

Sets whether the parameter is dynamic, and can support data-defined values (i.e. QgsProperty based values).

See also

isDynamic()

Parameters:

dynamic (bool) –

setMetadata(self, metadata: Dict[str, Any])

Sets the parameter’s freeform metadata. This is mostly used by parameter widget wrappers in order to customize their appearance and behavior.

See also

metadata()

Parameters:

metadata (Dict[str) –

setName(self, name: str)

Sets the name of the parameter. This is the internal identifier by which algorithms access this parameter.

See also

name()

Parameters:

name (str) –

toVariantMap(self) Dict[str, Any]

Saves this parameter to a QVariantMap. Subclasses should ensure that they call the base class method and then extend the result with additional properties.

See also

fromVariantMap()

Return type:

Dict[str, Any]

toolTip(self) str

Returns a formatted tooltip for use with the parameter, which gives helpful information like parameter description, ID, and extra content like default values (depending on parameter type).

Return type:

str

type(self) str

Unique parameter type name.

Return type:

str

valueAsJsonObject(self, value: Any, context: QgsProcessingContext) Any

Returns a version of the parameter input value, which is suitable for use in a JSON object.

This method must return only simple values which can be losslessly encapsulated in a serialized JSON map. For instance, any QGIS class values (such as QgsCoordinateReferenceSystem) must be converted to a simple string or numeric value equivalent.

See also

valueAsString()

New in version 3.24.

Parameters:
Return type:

Any

valueAsPythonComment(self, value: Any, context: QgsProcessingContext) str

Returns a Python comment explaining a parameter value, or an empty string if no comment is required.

New in version 3.20.

Parameters:
Return type:

str

valueAsPythonString(self, value: Any, context: QgsProcessingContext) str

Returns a string version of the parameter input value, which is suitable for use as an input parameter value when running an algorithm directly from a Python command.

See also

valueAsString()

Parameters:
Return type:

str

valueAsString(self, value: Any, context: QgsProcessingContext) Tuple[str, bool]

Returns a string version of the parameter input value (if possible).

Parameters:
Return type:

Tuple[str, bool]

Returns:

  • value converted to string

  • ok: will be set to True if value could be represented as a string.

New in version 3.24.

valueAsStringList(self, value: Any, context: QgsProcessingContext) Tuple[List[str], bool]

Returns a string list version of the parameter input value (if possible).

Parameters:
Return type:

Tuple[List[str], bool]

Returns:

  • value converted to string list

  • ok: will be set to True if value could be represented as a string list

See also

valueAsString()

New in version 3.24.