QgsProcessingParameterNumber class

A numeric parameter for processing algorithms.

For numeric parameters with a dataType() of Double, the number of decimals places shown in the parameter's widget can be specified by setting the parameter's metadata. For example:

  • param = QgsProcessingParameterNumber( 'VAL', 'Threshold', type=QgsProcessingParameter.Double)
    # only show two decimal places in parameter's widgets, not 6:
    param.setMetadata( {'widget_wrapper':
      { 'decimals': 2 }
    })

Base classes

class QgsProcessingParameterDefinition
Base class for the definition of processing parameters.

Derived classes

class QgsProcessingParameterDistance
A double numeric parameter for distance values.

Public types

enum Type { Integer, Double }
Numeric data type.

Public static functions

static auto fromScriptCode(const QString& name, const QString& description, bool isOptional, const QString& definition) -> QgsProcessingParameterNumber*
Creates a new parameter using the definition from a script code.
static auto typeName() -> QString
Returns the type name for the parameter class.

Constructors, destructors, conversion operators

QgsProcessingParameterNumber(const QString& name, const QString& description = QString(), Type type = Integer, const QVariant& defaultValue = QVariant(), bool optional = false, double minValue = std::numeric_limits<double>::lowest()+1, double maxValue = std::numeric_limits<double>::max()) explicit
Constructor for QgsProcessingParameterNumber.

Public functions

auto checkValueIsAcceptable(const QVariant& input, QgsProcessingContext* context = nullptr) const -> bool override
Checks whether the specified input value is acceptable for the parameter.
auto clone() const -> QgsProcessingParameterDefinition* override
Creates a clone of the parameter definition.
auto dataType() const -> Type
Returns the acceptable data type for the parameter.
auto fromVariantMap(const QVariantMap& map) -> bool override
Restores this parameter to a QVariantMap.
auto maximum() const -> double
Returns the maximum value acceptable by the parameter.
auto minimum() const -> double
Returns the minimum value acceptable by the parameter.
void setDataType(Type type)
Sets the acceptable data type for the parameter.
void setMaximum(double maximum)
Sets the maximum value acceptable by the parameter.
void setMinimum(double minimum)
Sets the minimum value acceptable by the parameter.
auto toolTip() const -> QString override
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).
auto toVariantMap() const -> QVariantMap override
Saves this parameter to a QVariantMap.
auto type() const -> QString override
Unique parameter type name.
auto valueAsPythonString(const QVariant& value, QgsProcessingContext& context) const -> QString 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.

Enum documentation

enum QgsProcessingParameterNumber::Type

Numeric data type.

Enumerators
Integer

Integer values.

Double

Double/float values.

Function documentation

bool QgsProcessingParameterNumber::checkValueIsAcceptable(const QVariant& input, QgsProcessingContext* context = nullptr) const override

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.

Type QgsProcessingParameterNumber::dataType() const

Returns the acceptable data type for the parameter.

bool QgsProcessingParameterNumber::fromVariantMap(const QVariantMap& map) override

Restores this parameter to a QVariantMap.

Subclasses should ensure that they call the base class method.

double QgsProcessingParameterNumber::maximum() const

Returns the maximum value acceptable by the parameter.

double QgsProcessingParameterNumber::minimum() const

Returns the minimum value acceptable by the parameter.

void QgsProcessingParameterNumber::setDataType(Type type)

Sets the acceptable data type for the parameter.

void QgsProcessingParameterNumber::setMaximum(double maximum)

Sets the maximum value acceptable by the parameter.

void QgsProcessingParameterNumber::setMinimum(double minimum)

Sets the minimum value acceptable by the parameter.

QVariantMap QgsProcessingParameterNumber::toVariantMap() const override

Saves this parameter to a QVariantMap.

Subclasses should ensure that they call the base class method and then extend the result with additional properties.

QString QgsProcessingParameterNumber::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.

The returned value must be correctly escaped - e.g. string values must be wrapped in ' 's.