QgsPropertyTransformer class

Abstract base class for objects which transform the calculated value of a property.

Possible uses include transformers which map a value into a scaled size or color from a gradient.

Derived classes

class QgsColorRampTransformer
QgsPropertyTransformer subclass for transforming a numeric value into a color from a color ramp.
class QgsGenericNumericTransformer
QgsPropertyTransformer subclass for scaling an input numeric value into an output numeric value.
class QgsSizeScaleTransformer
QgsPropertyTransformer subclass for scaling a value into a size according to various scaling methods.

Public types

enum Type { GenericNumericTransformer, SizeScaleTransformer, ColorRampTransformer }
Transformer types.

Public static functions

static auto create(Type type) -> QgsPropertyTransformer*
Factory method for creating a new property transformer of the specified type.
static auto fromExpression(const QString& expression, QString& baseExpression, QString& fieldName) -> QgsPropertyTransformer*
Attempts to parse an expression into a corresponding property transformer.

Constructors, destructors, conversion operators

QgsPropertyTransformer(double minValue = 0.0, double maxValue = 1.0)
Constructor for QgsPropertyTransformer.
QgsPropertyTransformer(const QgsPropertyTransformer& other)
Copy constructor.

Public functions

auto clone() const -> QgsPropertyTransformer* pure virtual
Returns a clone of the transformer.
auto curveTransform() const -> QgsCurveTransform*
Returns the curve transform applied to input values before they are transformed by the individual transform subclasses.
auto loadVariant(const QVariant& transformer) -> bool virtual
Loads this transformer from a QVariantMap, wrapped in a QVariant.
auto maxValue() const -> double
Returns the maximum value expected by the transformer.
auto minValue() const -> double
Returns the minimum value expected by the transformer.
void setCurveTransform(QgsCurveTransform* transform)
Sets a curve transform to apply to input values before they are transformed by the individual transform subclasses.
void setMaxValue(double max)
Sets the maximum value expected by the transformer.
void setMinValue(double min)
Sets the minimum value expected by the transformer.
auto toExpression(const QString& baseExpression) const -> QString pure virtual
Converts the transformer to a QGIS expression string.
auto toVariant() const -> QVariant virtual
Saves this transformer to a QVariantMap, wrapped in a QVariant.
auto transform(const QgsExpressionContext& context, const QVariant& value) const -> QVariant pure virtual
Calculates the transform of a value.
auto transformerType() const -> Type pure virtual
Returns the transformer type.

Protected functions

auto transformNumeric(double input) const -> double
Applies base class numeric transformations.

Protected variables

std::unique_ptr<QgsCurveTransform> mCurveTransform
Optional curve transform.
double mMaxValue
Maximum value expected by the transformer.
double mMinValue
Minimum value expected by the transformer.

Enum documentation

enum QgsPropertyTransformer::Type

Transformer types.

Enumerators
GenericNumericTransformer

Generic transformer for numeric values (QgsGenericNumericTransformer)

SizeScaleTransformer

Size scaling transformer (QgsSizeScaleTransformer)

ColorRampTransformer

Color ramp transformer (QgsColorRampTransformer)

Function documentation

static QgsPropertyTransformer* QgsPropertyTransformer::create(Type type)

Factory method for creating a new property transformer of the specified type.

Parameters
type transformer type to create

static QgsPropertyTransformer* QgsPropertyTransformer::fromExpression(const QString& expression, QString& baseExpression, QString& fieldName)

Attempts to parse an expression into a corresponding property transformer.

Parameters
expression expression to parse
baseExpression will be set to the component of the source expression which is used to calculate the input to the property transformer. This will be set to an empty string if a field reference is the transformer input.
fieldName will be set to a field name which is used to calculate the input to the property transformer. This will be set to an empty string if an expression is the transformer input.
Returns corresponding property transformer, or nullptr if expression could not be parsed to a transformer.

QgsPropertyTransformer::QgsPropertyTransformer(double minValue = 0.0, double maxValue = 1.0)

Constructor for QgsPropertyTransformer.

Parameters
minValue minimum expected value from source property
maxValue maximum expected value from source property

QgsCurveTransform* QgsPropertyTransformer::curveTransform() const

Returns the curve transform applied to input values before they are transformed by the individual transform subclasses.

bool QgsPropertyTransformer::loadVariant(const QVariant& transformer) virtual

Loads this transformer from a QVariantMap, wrapped in a QVariant.

You can use QgsXmlUtils::readVariant to read it from an XML document.

double QgsPropertyTransformer::maxValue() const

Returns the maximum value expected by the transformer.

double QgsPropertyTransformer::minValue() const

Returns the minimum value expected by the transformer.

void QgsPropertyTransformer::setCurveTransform(QgsCurveTransform* transform)

Sets a curve transform to apply to input values before they are transformed by the individual transform subclasses.

Ownership of transform is transferred to the property transformer.

void QgsPropertyTransformer::setMaxValue(double max)

Sets the maximum value expected by the transformer.

Parameters
max maximum value

void QgsPropertyTransformer::setMinValue(double min)

Sets the minimum value expected by the transformer.

Parameters
min minimum value

QString QgsPropertyTransformer::toExpression(const QString& baseExpression) const pure virtual

Converts the transformer to a QGIS expression string.

The baseExpression string consists of a sub-expression reflecting the parent property's state.

QVariant QgsPropertyTransformer::toVariant() const virtual

Saves this transformer to a QVariantMap, wrapped in a QVariant.

You can use QgsXmlUtils::writeVariant to save it to an XML document.

QVariant QgsPropertyTransformer::transform(const QgsExpressionContext& context, const QVariant& value) const pure virtual

Calculates the transform of a value.

Parameters
context expression context
value input value to transform

Derived classes must implement this to perform their transformations on input values

double QgsPropertyTransformer::transformNumeric(double input) const protected

Applies base class numeric transformations.

Derived classes should call this to transform an input numeric value before they apply any transform to the result. This applies any curve transforms which may exist on the transformer.