Skip to content
Permalink
Browse files

support static (non-translated) strings as enum values in Processing

  • Loading branch information
alexbruy committed Nov 19, 2020
1 parent 83aa68f commit cc98fe30d9169fb63b9759e784132daeb88e379e
@@ -653,6 +653,20 @@ Evaluates the parameter with matching ``name`` to a enum value.
QList<int> parameterAsEnums( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to list of enum values.
%End

QString parameterAsEnumString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a static enum string.

.. versionadded:: 3.18
%End

QStringList parameterAsEnumStrings( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to list of static enum strings.

.. versionadded:: 3.18
%End

bool parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
@@ -852,6 +852,34 @@ Evaluates the parameter with matching ``definition`` to list of enum values.
Evaluates the parameter with matching ``definition`` and ``value`` to list of enum values.

.. versionadded:: 3.4
%End

static QString parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` to a static enum string.

.. versionadded:: 3.18
%End

static QString parameterAsEnumString( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` and ``value`` to a static enum string.

.. versionadded:: 3.18
%End

static QStringList parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` to list of static enum strings.

.. versionadded:: 3.18
%End

static QStringList parameterAsEnumStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` and ``value`` to list of static enum strings.

.. versionadded:: 3.18
%End

static bool parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
@@ -2320,7 +2348,8 @@ An enum based parameter for processing algorithms, allowing for selection from p
QgsProcessingParameterEnum( const QString &name, const QString &description = QString(), const QStringList &options = QStringList(),
bool allowMultiple = false,
const QVariant &defaultValue = QVariant(),
bool optional = false );
bool optional = false,
bool usesStaticStrings = false );
%Docstring
Constructor for QgsProcessingParameterEnum.
%End
@@ -2367,6 +2396,26 @@ Returns ``True`` if the parameter allows multiple selected values.
Sets whether the parameter allows multiple selected values.

.. seealso:: :py:func:`allowMultiple`
%End

bool usesStaticStrings() const;
%Docstring
Returns ``True`` if the parameter uses static (non-translated) string
values for its enumeration choice list.

.. seealso:: :py:func:`setUsesStaticStrings`

.. versionadded:: 3.18
%End

void setUsesStaticStrings( bool usesStaticStrings );
%Docstring
Sets whether the parameter uses static (non-translated) string
values for its enumeration choice list.

.. seealso:: :py:func:`usesStaticStrings`

.. versionadded:: 3.18
%End

virtual QVariantMap toVariantMap() const;
@@ -617,6 +617,16 @@ QList<int> QgsProcessingAlgorithm::parameterAsEnums( const QVariantMap &paramete
return QgsProcessingParameters::parameterAsEnums( parameterDefinition( name ), parameters, context );
}

QString QgsProcessingAlgorithm::parameterAsEnumString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsEnumString( parameterDefinition( name ), parameters, context );
}

QStringList QgsProcessingAlgorithm::parameterAsEnumStrings( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsEnumStrings( parameterDefinition( name ), parameters, context );
}

bool QgsProcessingAlgorithm::parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
@@ -662,6 +662,18 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
QList<int> parameterAsEnums( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;

/**
* Evaluates the parameter with matching \a name to a static enum string.
* \since QGIS 3.18
*/
QString parameterAsEnumString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;

/**
* Evaluates the parameter with matching \a name to list of static enum strings.
* \since QGIS 3.18
*/
QStringList parameterAsEnumStrings( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;

/**
* Evaluates the parameter with matching \a name to a static boolean value.
*/

0 comments on commit cc98fe3

Please sign in to comment.
You can’t perform that action at this time.