Class: QgsProcessingParameterDefinition

Base class for the definition of processing parameters.

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

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: clone(), type()

Class Hierarchy

Inheritance diagram of qgis.core.QgsProcessingParameterDefinition

Subclasses

QgsProcessingDestinationParameter

Base class for all parameter definitions which represent file or layer destinations, e.g. parameters which are used for the destination for layers output by an algorithm.

QgsProcessingParameterAggregate

A parameter for “aggregate” configurations, which consist of a definition of desired output fields, types, and aggregate used to populate them.

QgsProcessingParameterAlignRasterLayers

A parameter for Processing algorithms specifying how rasters should be aligned.

QgsProcessingParameterAnnotationLayer

An annotation layer parameter for processing algorithms.

QgsProcessingParameterNumber

A numeric parameter for processing algorithms.

QgsProcessingParameterAuthConfig

A string parameter for authentication configuration ID values.

QgsProcessingParameterBand

A raster band parameter for Processing algorithms.

QgsProcessingParameterBoolean

A boolean parameter for processing algorithms.

QgsProcessingParameterColor

A color parameter for processing algorithms.

QgsProcessingParameterCoordinateOperation

A coordinate operation parameter for processing algorithms.

QgsProcessingParameterCrs

A coordinate reference system parameter for processing algorithms.

QgsProcessingParameterDatabaseSchema

A database schema parameter for processing algorithms, allowing users to select from existing schemas on a registered database connection.

QgsProcessingParameterDatabaseTable

A database table name parameter for processing algorithms.

QgsProcessingParameterDateTime

A datetime (or pure date or time) parameter for processing algorithms.

QgsProcessingParameterDxfLayers

A parameter for Processing algorithms that need a list of input vector layers to export as DXF file.

QgsProcessingParameterEnum

An enum based parameter for processing algorithms, allowing for selection from predefined values.

QgsProcessingParameterExpression

An expression parameter for processing algorithms.

QgsProcessingParameterExtent

A rectangular map extent parameter for processing algorithms.

QgsProcessingParameterFeatureSource

An input feature source (such as vector layers) parameter for processing algorithms.

QgsProcessingParameterField

A vector layer or feature source field parameter for processing algorithms.

QgsProcessingParameterFieldMapping

A parameter for “field mapping” configurations, which consist of a definition of desired output fields, types, and expressions used to populate them.

QgsProcessingParameterFile

An input file or folder parameter for processing algorithms.

QgsProcessingParameterGeometry

A geometry parameter for processing algorithms.

QgsProcessingParameterLayout

A print layout parameter, allowing users to select a print layout.

QgsProcessingParameterLayoutItem

A print layout item parameter, allowing users to select a particular item from a print layout.

QgsProcessingParameterMapLayer

A map layer parameter for processing algorithms.

QgsProcessingParameterMapTheme

A map theme parameter for processing algorithms, allowing users to select an existing map theme from a project.

QgsProcessingParameterMatrix

A table (matrix) parameter for processing algorithms.

QgsProcessingParameterMeshDatasetGroups

A parameter for processing algorithms that need a list of mesh dataset groups.

QgsProcessingParameterMeshDatasetTime

A parameter for processing algorithms that need a list of mesh dataset index from time parameter.

QgsProcessingParameterMeshLayer

A mesh layer parameter for processing algorithms.

QgsProcessingParameterMultipleLayers

A parameter for processing algorithms which accepts multiple map layers.

QgsProcessingParameterPoint

A point parameter for processing algorithms.

QgsProcessingParameterPointCloudAttribute

A point cloud layer attribute parameter for Processing algorithms.

QgsProcessingParameterPointCloudLayer

A point cloud layer parameter for processing algorithms.

QgsProcessingParameterProviderConnection

A data provider connection parameter for processing algorithms, allowing users to select from available registered connections for a particular data provider.

QgsProcessingParameterRange

A numeric range parameter for processing algorithms.

QgsProcessingParameterRasterLayer

A raster layer parameter for processing algorithms.

QgsProcessingParameterString

A string parameter for processing algorithms.

QgsProcessingParameterTinInputLayers

A parameter for processing algorithms that need a list of input vector layers to construct a TIN.

QgsProcessingParameterVectorLayer

A vector layer (with or without geometry) parameter for processing algorithms.

QgsProcessingParameterVectorTileWriterLayers

A parameter for Processing algorithms that need a list of input vector layers for writing of vector tiles.

Enums

Flag

alias of ProcessingParameterFlag

Abstract Methods

clone

Creates a clone of the parameter definition.

type

Unique parameter type name.

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.

defaultGuiValueFromSetting

Default gui value for an algorithm parameter from settings

defaultValue

Returns the default value for the parameter.

defaultValueForGui

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

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.

guiDefaultValueOverride

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

help

Returns the help for the parameter.

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.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsProcessingParameterDefinition. See the FAQ for more details.

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.

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).

fromVariantMap

Restores this parameter to a QVariantMap.

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.

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).

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).

class qgis.core.QgsProcessingParameterDefinition[source]

Bases: object

__init__(name: str | None, description: str | None = '', defaultValue: Any = None, optional: bool = False, help: str | None = '')

Constructor for QgsProcessingParameterDefinition.

Parameters:
  • name (Optional[str])

  • description (Optional[str] = '')

  • defaultValue (Any = None)

  • optional (bool = False)

  • help (Optional[str] = '')

__init__(a0: QgsProcessingParameterDefinition)
Parameters:

a0 (QgsProcessingParameterDefinition)

Flag

alias of ProcessingParameterFlag

Flags

alias of ProcessingParameterFlags

additionalExpressionContextVariables(self) List[str][source]

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.

Added in version 3.8.

Return type:

List[str]

algorithm(self) QgsProcessingAlgorithm | None[source]

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

See also

provider()

Return type:

Optional[QgsProcessingAlgorithm]

virtual asPythonString(self, outputType: QgsProcessing.PythonOutputType = QgsProcessing.PythonOutputType.PythonQgsProcessingAlgorithmSubclass) str[source]

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.

Added in version 3.6.

Parameters:

outputType (QgsProcessing.PythonOutputType = QgsProcessing.PythonOutputType.PythonQgsProcessingAlgorithmSubclass)

Return type:

str

virtual asScriptCode(self) str[source]

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

Return type:

str

virtual checkValueIsAcceptable(self, input: Any, context: QgsProcessingContext | None = None) bool[source]

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

abstract clone(self) QgsProcessingParameterDefinition | None[source]

Creates a clone of the parameter definition.

Return type:

Optional[QgsProcessingParameterDefinition]

defaultGuiValueFromSetting(self) Any[source]

Default gui value for an algorithm parameter from settings

Return type:

Any

Returns:

default value from settings or invalid QVariant if there is no default value defined in the settings

Added in version 3.34.

defaultValue(self) Any[source]

Returns the default value for the parameter.

Return type:

Any

defaultValueForGui(self) Any[source]

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.

Added in version 3.18.

Return type:

Any

virtual dependsOnOtherParameters(self) List[str][source]

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[source]

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[source]

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[source]

Returns the property definition for dynamic properties.

See also

isDynamic()

Return type:

QgsPropertyDefinition

flags(self) Qgis.ProcessingParameterFlags[source]

Returns any flags associated with the parameter.

See also

setFlags()

Return type:

Qgis.ProcessingParameterFlags

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

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

See also

toVariantMap()

Parameters:

map (Dict[str, Any])

Return type:

bool

guiDefaultValueOverride(self) Any[source]

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()

Added in version 3.18.

Return type:

Any

help(self) str[source]

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()

Added in version 3.16.

Return type:

str

virtual isDestination(self) bool[source]

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[source]

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[source]

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 | None[source]

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:

Optional[QgsProcessingProvider]

setAdditionalExpressionContextVariables(self, variables: Iterable[str | None])[source]

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.

Added in version 3.8.

Parameters:

variables (Iterable[Optional[str]])

setDefaultValue(self, value: Any)[source]

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 | None)[source]

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

See also

description()

Parameters:

description (Optional[str])

setDynamicLayerParameterName(self, name: str | None)[source]

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 (Optional[str])

setDynamicPropertyDefinition(self, definition: QgsPropertyDefinition)[source]

Sets the property definition for dynamic properties.

See also

isDynamic()

Parameters:

definition (QgsPropertyDefinition)

setFlags(self, flags: Qgis.ProcessingParameterFlags | Qgis.ProcessingParameterFlag)[source]

Sets the flags associated with the parameter.

See also

flags()

Parameters:

flags (Union[Qgis.ProcessingParameterFlags, Qgis.ProcessingParameterFlag])

setGuiDefaultValueOverride(self, value: Any)[source]

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.

Added in version 3.18.

Parameters:

value (Any)

setHelp(self, help: str | None)[source]

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()

Added in version 3.16.

Parameters:

help (Optional[str])

setIsDynamic(self, dynamic: bool)[source]

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])[source]

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, Any])

setName(self, name: str | None)[source]

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

See also

name()

Parameters:

name (Optional[str])

virtual toVariantMap(self) Dict[str, Any][source]

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]

virtual toolTip(self) str[source]

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

abstract type(self) str[source]

Unique parameter type name.

Return type:

str

virtual valueAsJsonObject(self, value: Any, context: QgsProcessingContext) Any[source]

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()

Added in version 3.24.

Parameters:
Return type:

Any

virtual valueAsPythonComment(self, value: Any, context: QgsProcessingContext) str[source]

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

Added in version 3.20.

Parameters:
Return type:

str

virtual valueAsPythonString(self, value: Any, context: QgsProcessingContext) str[source]

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

virtual valueAsString(self, value: Any, context: QgsProcessingContext)[source]

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

Parameters:
Returns:

  • value converted to string

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

Added in version 3.24.

virtual valueAsStringList(self, value: Any, context: QgsProcessingContext)[source]

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

Parameters:
  • value (Any) – value to convert

  • context (QgsProcessingContext) -> (List[str]) – processing context

Returns:

  • value converted to string list

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

See also

valueAsString()

Added in version 3.24.