Skip to content
Permalink
Browse files

Merge pull request #39695 from alexbruy/enum-as-string

[processing] add parameterAsEnumString() method to retrieve the string value of the enum
  • Loading branch information
alexbruy committed Nov 21, 2020
2 parents ca637cf + d952eb4 commit b010d8869478c70bbc046e5d9a91aa8d1a5e3067
@@ -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;
@@ -60,7 +60,7 @@ void QgsDxfExportAlgorithm::initAlgorithm( const QVariantMap & )
addParameter( new QgsProcessingParameterDxfLayers( QStringLiteral( "LAYERS" ), QObject::tr( "Input layers" ) ) );
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "SYMBOLOGY_MODE" ), QObject::tr( "Symbology mode" ), QStringList() << QObject::tr( "No Symbology" ) << QObject::tr( "Feature Symbology" ) << QObject::tr( "Symbol Layer Symbology" ), false, 0 ) );
addParameter( new QgsProcessingParameterScale( QStringLiteral( "SYMBOLOGY_SCALE" ), QObject::tr( "Symbology scale" ), 1000000 ) );
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "ENCODING" ), QObject::tr( "Encoding" ), QgsDxfExport::encodings() ) );
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "ENCODING" ), QObject::tr( "Encoding" ), QgsDxfExport::encodings(), false, QVariant(), false, true ) );
addParameter( new QgsProcessingParameterCrs( QStringLiteral( "CRS" ), QObject::tr( "CRS" ), QStringLiteral( "EPSG:4326" ) ) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "USE_LAYER_TITLE" ), QObject::tr( "Use layer title as name" ), false ) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "FORCE_2D" ), QObject::tr( "Force 2D output" ), false ) );
@@ -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 b010d88

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