QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
Public Member Functions | Static Public Member Functions | List of all members
QgsProcessingParameterEnum Class Reference

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

#include <qgsprocessingparameters.h>

Inheritance diagram for QgsProcessingParameterEnum:
Inheritance graph
[legend]

Public Member Functions

 QgsProcessingParameterEnum (const QString &name, const QString &description=QString(), const QStringList &options=QStringList(), bool allowMultiple=false, const QVariant &defaultValue=QVariant(), bool optional=false, bool usesStaticStrings=false)
 Constructor for QgsProcessingParameterEnum. More...
 
bool allowMultiple () const
 Returns true if the parameter allows multiple selected values. More...
 
QString asPythonString (QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
 Returns the parameter definition as a Python command which can be used within a Python Processing script. More...
 
QString asScriptCode () const override
 Returns the parameter definition encoded in a string which can be used within a Processing script. More...
 
bool checkValueIsAcceptable (const QVariant &input, QgsProcessingContext *context=nullptr) const override
 Checks whether the specified input value is acceptable for the parameter. More...
 
QgsProcessingParameterDefinitionclone () const override
 Creates a clone of the parameter definition. More...
 
bool fromVariantMap (const QVariantMap &map) override
 Restores this parameter to a QVariantMap. More...
 
QStringList options () const
 Returns the list of acceptable options for the parameter. More...
 
void setAllowMultiple (bool allowMultiple)
 Sets whether the parameter allows multiple selected values. More...
 
void setOptions (const QStringList &options)
 Sets the list of acceptable options for the parameter. More...
 
void setUsesStaticStrings (bool usesStaticStrings)
 Sets whether the parameter uses static (non-translated) string values for its enumeration choice list. More...
 
QVariantMap toVariantMap () const override
 Saves this parameter to a QVariantMap. More...
 
QString type () const override
 Unique parameter type name. More...
 
bool usesStaticStrings () const
 Returns true if the parameter uses static (non-translated) string values for its enumeration choice list. More...
 
QString valueAsPythonComment (const QVariant &value, QgsProcessingContext &context) const override
 Returns a Python comment explaining a parameter value, or an empty string if no comment is required. More...
 
QString valueAsPythonString (const QVariant &value, QgsProcessingContext &context) const override
 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. More...
 
- Public Member Functions inherited from QgsProcessingParameterDefinition
 QgsProcessingParameterDefinition (const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QString &help=QString())
 Constructor for QgsProcessingParameterDefinition. More...
 
virtual ~QgsProcessingParameterDefinition ()=default
 
QStringList additionalExpressionContextVariables () const
 Returns a list of additional expression context variables which are available for use when evaluating this parameter. More...
 
QgsProcessingAlgorithmalgorithm () const
 Returns a pointer to the algorithm which owns this parameter. More...
 
virtual QString asPythonString (QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const
 Returns the parameter definition as a Python command which can be used within a Python Processing script. More...
 
virtual QString asScriptCode () const
 Returns the parameter definition encoded in a string which can be used within a Processing script. More...
 
virtual bool checkValueIsAcceptable (const QVariant &input, QgsProcessingContext *context=nullptr) const
 Checks whether the specified input value is acceptable for the parameter. More...
 
virtual QgsProcessingParameterDefinitionclone () const =0
 Creates a clone of the parameter definition. More...
 
QVariant defaultValue () const
 Returns the default value for the parameter. More...
 
QVariant defaultValueForGui () const
 Returns the default value to use for the parameter in a GUI. More...
 
virtual QStringList dependsOnOtherParameters () const
 Returns a list of other parameter names on which this parameter is dependent (e.g. More...
 
QString description () const
 Returns the description for the parameter. More...
 
QString dynamicLayerParameterName () const
 Returns the name of the parameter for a layer linked to a dynamic parameter, or an empty string if this is not set. More...
 
QgsPropertyDefinition dynamicPropertyDefinition () const
 Returns the property definition for dynamic properties. More...
 
Flags flags () const
 Returns any flags associated with the parameter. More...
 
virtual bool fromVariantMap (const QVariantMap &map)
 Restores this parameter to a QVariantMap. More...
 
QVariant guiDefaultValueOverride () const
 Returns the default value to use in the GUI for the parameter. More...
 
QString help () const
 Returns the help for the parameter. More...
 
virtual bool isDestination () const
 Returns true if this parameter represents a file or layer destination, e.g. More...
 
bool isDynamic () const
 Returns true if the parameter supports is dynamic, and can support data-defined values (i.e. More...
 
QVariantMap & metadata ()
 Returns the parameter's freeform metadata. More...
 
QVariantMap metadata () const
 Returns the parameter's freeform metadata. More...
 
QString name () const
 Returns the name of the parameter. More...
 
QgsProcessingProviderprovider () const
 Returns a pointer to the provider for the algorithm which owns this parameter. More...
 
void setAdditionalExpressionContextVariables (const QStringList &variables)
 Sets a list of additional expression context variables which are available for use when evaluating this parameter. More...
 
void setDefaultValue (const QVariant &value)
 Sets the default value for the parameter. More...
 
void setDescription (const QString &description)
 Sets the description for the parameter. More...
 
void setDynamicLayerParameterName (const QString &name)
 Sets the name for the parameter for a layer linked to a dynamic parameter, or an empty string if this is not set. More...
 
void setDynamicPropertyDefinition (const QgsPropertyDefinition &definition)
 Sets the property definition for dynamic properties. More...
 
void setFlags (Flags flags)
 Sets the flags associated with the parameter. More...
 
void setGuiDefaultValueOverride (const QVariant &value)
 Sets the default value to use for the parameter in GUI widgets. More...
 
void setHelp (const QString &help)
 Sets the help for the parameter. More...
 
void setIsDynamic (bool dynamic)
 Sets whether the parameter is dynamic, and can support data-defined values (i.e. More...
 
void setMetadata (const QVariantMap &metadata)
 Sets the parameter's freeform metadata. More...
 
void setName (const QString &name)
 Sets the name of the parameter. More...
 
virtual QString toolTip () const
 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). More...
 
virtual QVariantMap toVariantMap () const
 Saves this parameter to a QVariantMap. More...
 
virtual QString type () const =0
 Unique parameter type name. More...
 
virtual QVariant valueAsJsonObject (const QVariant &value, QgsProcessingContext &context) const
 Returns a version of the parameter input value, which is suitable for use in a JSON object. More...
 
virtual QString valueAsPythonComment (const QVariant &value, QgsProcessingContext &context) const
 Returns a Python comment explaining a parameter value, or an empty string if no comment is required. More...
 
virtual QString valueAsPythonString (const QVariant &value, QgsProcessingContext &context) const
 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. More...
 
virtual QString valueAsString (const QVariant &value, QgsProcessingContext &context, bool &ok) const
 Returns a string version of the parameter input value (if possible). More...
 
virtual QStringList valueAsStringList (const QVariant &value, QgsProcessingContext &context, bool &ok) const
 Returns a string list version of the parameter input value (if possible). More...
 

Static Public Member Functions

static QgsProcessingParameterEnumfromScriptCode (const QString &name, const QString &description, bool isOptional, const QString &definition)
 Creates a new parameter using the definition from a script code. More...
 
static QString typeName ()
 Returns the type name for the parameter class. More...
 

Additional Inherited Members

- Public Types inherited from QgsProcessingParameterDefinition
enum  Flag { FlagAdvanced = 1 << 1 , FlagHidden = 1 << 2 , FlagOptional = 1 << 3 , FlagIsModelOutput = 1 << 4 }
 Parameter flags. More...
 
enum class  ValueAsStringFlag : int { AllowMapLayerValues = 1 << 0 }
 Flags for passing to the valueAsStringPrivate() method. More...
 
- Protected Member Functions inherited from QgsProcessingParameterDefinition
QVariant valueAsJsonObjectPrivate (const QVariant &value, QgsProcessingContext &context, ValueAsStringFlags flags) const
 Internal method for evaluating values as JSON objects. More...
 
QString valueAsStringPrivate (const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags) const
 Internal method for evaluating values as string. More...
 
- Protected Attributes inherited from QgsProcessingParameterDefinition
QStringList mAdditionalExpressionVariables
 Additional expression context variables exposed for use by this parameter. More...
 
QgsProcessingAlgorithmmAlgorithm = nullptr
 Pointer to algorithm which owns this parameter. More...
 
QVariant mDefault
 Default value for parameter. More...
 
QString mDescription
 Parameter description. More...
 
QString mDynamicLayerParameterName
 Linked vector layer parameter name for dynamic properties. More...
 
Flags mFlags
 Parameter flags. More...
 
QVariant mGuiDefault
 Default value for parameter in GUI. More...
 
QString mHelp
 Parameter help. More...
 
bool mIsDynamic = false
 True for dynamic parameters, which can have data-defined (QgsProperty) based values. More...
 
QVariantMap mMetadata
 Freeform metadata for parameter. Mostly used by widget wrappers to customize their appearance and behavior. More...
 
QString mName
 Parameter name. More...
 
QgsPropertyDefinition mPropertyDefinition
 Data defined property definition. More...
 

Detailed Description

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

Since QGIS 3.24 a list of icons corresponding to the enum values can be specified by setting the widget wrapper metadata "icons" option, as demonstrated below. The "icons" value should be set to a list of QIcon values.

param = QgsProcessingParameterEnum( 'FIELD_TYPE', 'Field type', ['Integer', 'String'])
param.setMetadata( {'widget_wrapper':
{ 'icons': [QIcon('integer.svg'), QIcon('string.svg')] }
})
An enum based parameter for processing algorithms, allowing for selection from predefined values.
Since
QGIS 3.0

Definition at line 2586 of file qgsprocessingparameters.h.

Constructor & Destructor Documentation

◆ QgsProcessingParameterEnum()

QgsProcessingParameterEnum::QgsProcessingParameterEnum ( const QString &  name,
const QString &  description = QString(),
const QStringList &  options = QStringList(),
bool  allowMultiple = false,
const QVariant &  defaultValue = QVariant(),
bool  optional = false,
bool  usesStaticStrings = false 
)

Constructor for QgsProcessingParameterEnum.

Definition at line 4772 of file qgsprocessingparameters.cpp.

Member Function Documentation

◆ allowMultiple()

bool QgsProcessingParameterEnum::allowMultiple ( ) const

Returns true if the parameter allows multiple selected values.

See also
setAllowMultiple()

Definition at line 5077 of file qgsprocessingparameters.cpp.

◆ asPythonString()

QString QgsProcessingParameterEnum::asPythonString ( QgsProcessing::PythonOutputType  outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const
overridevirtual

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.

Since
QGIS 3.6

Reimplemented from QgsProcessingParameterDefinition.

Definition at line 5037 of file qgsprocessingparameters.cpp.

◆ asScriptCode()

QString QgsProcessingParameterEnum::asScriptCode ( ) const
overridevirtual

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

Reimplemented from QgsProcessingParameterDefinition.

Definition at line 5018 of file qgsprocessingparameters.cpp.

◆ checkValueIsAcceptable()

bool QgsProcessingParameterEnum::checkValueIsAcceptable ( const QVariant &  input,
QgsProcessingContext context = nullptr 
) const
overridevirtual

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.

Reimplemented from QgsProcessingParameterDefinition.

Definition at line 4786 of file qgsprocessingparameters.cpp.

◆ clone()

QgsProcessingParameterDefinition * QgsProcessingParameterEnum::clone ( ) const
overridevirtual

Creates a clone of the parameter definition.

Implements QgsProcessingParameterDefinition.

Definition at line 4781 of file qgsprocessingparameters.cpp.

◆ fromScriptCode()

QgsProcessingParameterEnum * QgsProcessingParameterEnum::fromScriptCode ( const QString &  name,
const QString &  description,
bool  isOptional,
const QString &  definition 
)
static

Creates a new parameter using the definition from a script code.

Definition at line 5115 of file qgsprocessingparameters.cpp.

◆ fromVariantMap()

bool QgsProcessingParameterEnum::fromVariantMap ( const QVariantMap &  map)
overridevirtual

Restores this parameter to a QVariantMap.

Subclasses should ensure that they call the base class method.

See also
toVariantMap()

Reimplemented from QgsProcessingParameterDefinition.

Definition at line 5106 of file qgsprocessingparameters.cpp.

◆ options()

QStringList QgsProcessingParameterEnum::options ( ) const

Returns the list of acceptable options for the parameter.

See also
setOptions()

Definition at line 5067 of file qgsprocessingparameters.cpp.

◆ setAllowMultiple()

void QgsProcessingParameterEnum::setAllowMultiple ( bool  allowMultiple)

Sets whether the parameter allows multiple selected values.

See also
allowMultiple()

Definition at line 5082 of file qgsprocessingparameters.cpp.

◆ setOptions()

void QgsProcessingParameterEnum::setOptions ( const QStringList &  options)

Sets the list of acceptable options for the parameter.

See also
options()

Definition at line 5072 of file qgsprocessingparameters.cpp.

◆ setUsesStaticStrings()

void QgsProcessingParameterEnum::setUsesStaticStrings ( bool  usesStaticStrings)

Sets whether the parameter uses static (non-translated) string values for its enumeration choice list.

See also
usesStaticStrings()
Since
QGIS 3.18

Definition at line 5092 of file qgsprocessingparameters.cpp.

◆ toVariantMap()

QVariantMap QgsProcessingParameterEnum::toVariantMap ( ) const
overridevirtual

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

Reimplemented from QgsProcessingParameterDefinition.

Definition at line 5097 of file qgsprocessingparameters.cpp.

◆ type()

QString QgsProcessingParameterEnum::type ( ) const
inlineoverridevirtual

Unique parameter type name.

Implements QgsProcessingParameterDefinition.

Definition at line 2604 of file qgsprocessingparameters.h.

◆ typeName()

static QString QgsProcessingParameterEnum::typeName ( )
inlinestatic

Returns the type name for the parameter class.

Definition at line 2602 of file qgsprocessingparameters.h.

◆ usesStaticStrings()

bool QgsProcessingParameterEnum::usesStaticStrings ( ) const

Returns true if the parameter uses static (non-translated) string values for its enumeration choice list.

See also
setUsesStaticStrings()
Since
QGIS 3.18

Definition at line 5087 of file qgsprocessingparameters.cpp.

◆ valueAsPythonComment()

QString QgsProcessingParameterEnum::valueAsPythonComment ( const QVariant &  value,
QgsProcessingContext context 
) const
overridevirtual

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

Since
QGIS 3.20

Reimplemented from QgsProcessingParameterDefinition.

Definition at line 4972 of file qgsprocessingparameters.cpp.

◆ valueAsPythonString()

QString QgsProcessingParameterEnum::valueAsPythonString ( const QVariant &  value,
QgsProcessingContext context 
) const
overridevirtual

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

Reimplemented from QgsProcessingParameterDefinition.

Definition at line 4911 of file qgsprocessingparameters.cpp.


The documentation for this class was generated from the following files: