Skip to content
Permalink
Browse files

Add QgsProcessingParameters::parameterAsBoolean for consistency

  • Loading branch information
m-kuhn committed Apr 15, 2019
1 parent a6e4fae commit 4771f802fc272d1f56451bbb2891256403d566f1
@@ -636,13 +636,27 @@ Evaluates the parameter with matching ``definition`` and ``value`` to list of en
static bool parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` to a static boolean value.
%End

static bool parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` to a static boolean value.

.. versionadded:: 3.8
%End

static bool parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` and ``value`` to a static boolean value.

.. versionadded:: 3.4
%End

static bool parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` and ``value`` to a static boolean value.

.. versionadded:: 3.8
%End

static QgsFeatureSink *parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters,
@@ -345,6 +345,14 @@ bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefin
return parameterAsBool( definition, parameters.value( definition->name() ), context );
}

bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context )
{
if ( !definition )
return false;

return parameterAsBoolean( definition, parameters.value( definition->name() ), context );
}

bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
{
if ( !definition )
@@ -361,6 +369,22 @@ bool QgsProcessingParameters::parameterAsBool( const QgsProcessingParameterDefin
return def.toBool();
}

bool QgsProcessingParameters::parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context )
{
if ( !definition )
return false;

QVariant def = definition->defaultValue();

QVariant val = value;
if ( val.canConvert<QgsProperty>() )
return val.value< QgsProperty >().valueAsBool( context.expressionContext(), def.toBool() );
else if ( val.isValid() )
return val.toBool();
else
return def.toBool();
}

QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields,
QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs,
QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags )
@@ -703,12 +703,25 @@ class CORE_EXPORT QgsProcessingParameters
*/
static bool parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );

/**
* Evaluates the parameter with matching \a definition to a static boolean value.
*
* \since QGIS 3.8
*/
static bool parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context );

/**
* Evaluates the parameter with matching \a definition and \a value to a static boolean value.
* \since QGIS 3.4
*/
static bool parameterAsBool( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );

/**
* Evaluates the parameter with matching \a definition and \a value to a static boolean value.
* \since QGIS 3.8
*/
static bool parameterAsBoolean( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );

/**
* Evaluates the parameter with matching \a definition to a feature sink.
*

0 comments on commit 4771f80

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