QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
Public Member Functions | List of all members
QgsColorRampTransformer Class Reference

QgsPropertyTransformer subclass for transforming a numeric value into a color from a color ramp. More...

#include <qgspropertytransformer.h>

Inheritance diagram for QgsColorRampTransformer:
Inheritance graph
[legend]

Public Member Functions

 QgsColorRampTransformer (const QgsColorRampTransformer &other)
 Copy constructor. More...
 
 QgsColorRampTransformer (double minValue=0.0, double maxValue=1.0, QgsColorRamp *ramp=nullptr, const QColor &nullColor=QColor(0, 0, 0, 0))
 Constructor for QgsColorRampTransformer. More...
 
QgsColorRampTransformerclone () const override
 Returns a clone of the transformer. More...
 
QColor color (double value) const
 Calculates the color corresponding to a specific value. More...
 
QgsColorRampcolorRamp () const
 Returns the color ramp used for calculating property colors. More...
 
bool loadVariant (const QVariant &definition) override
 Loads this transformer from a QVariantMap, wrapped in a QVariant. More...
 
QColor nullColor () const
 Returns the color corresponding to a null value. More...
 
QgsColorRampTransformeroperator= (const QgsColorRampTransformer &other)
 
QString rampName () const
 Returns the color ramp's name. More...
 
void setColorRamp (QgsColorRamp *ramp)
 Sets the color ramp to use for calculating property colors. More...
 
void setNullColor (const QColor &color)
 Sets the color corresponding to a null value. More...
 
void setRampName (const QString &name)
 Sets the color ramp's name. More...
 
QString toExpression (const QString &baseExpression) const override
 Converts the transformer to a QGIS expression string. More...
 
QVariant toVariant () const override
 Saves this transformer to a QVariantMap, wrapped in a QVariant. More...
 
QVariant transform (const QgsExpressionContext &context, const QVariant &value) const override
 Calculates the transform of a value. More...
 
Type transformerType () const override
 Returns the transformer type. More...
 
- Public Member Functions inherited from QgsPropertyTransformer
 QgsPropertyTransformer (const QgsPropertyTransformer &other)
 Copy constructor. More...
 
 QgsPropertyTransformer (double minValue=0.0, double maxValue=1.0)
 Constructor for QgsPropertyTransformer. More...
 
virtual ~QgsPropertyTransformer ()
 
QgsCurveTransformcurveTransform () const
 Returns the curve transform applied to input values before they are transformed by the individual transform subclasses. More...
 
double maxValue () const
 Returns the maximum value expected by the transformer. More...
 
double minValue () const
 Returns the minimum value expected by the transformer. More...
 
QgsPropertyTransformeroperator= (const QgsPropertyTransformer &other)
 
void setCurveTransform (QgsCurveTransform *transform)
 Sets a curve transform to apply to input values before they are transformed by the individual transform subclasses. More...
 
void setMaxValue (double max)
 Sets the maximum value expected by the transformer. More...
 
void setMinValue (double min)
 Sets the minimum value expected by the transformer. More...
 

Additional Inherited Members

- Public Types inherited from QgsPropertyTransformer
enum  Type { GenericNumericTransformer , SizeScaleTransformer , ColorRampTransformer }
 Transformer types. More...
 
- Static Public Member Functions inherited from QgsPropertyTransformer
static QgsPropertyTransformercreate (Type type)
 Factory method for creating a new property transformer of the specified type. More...
 
static QgsPropertyTransformerfromExpression (const QString &expression, QString &baseExpression, QString &fieldName)
 Attempts to parse an expression into a corresponding property transformer. More...
 
- Protected Member Functions inherited from QgsPropertyTransformer
double transformNumeric (double input) const
 Applies base class numeric transformations. More...
 
- Protected Attributes inherited from QgsPropertyTransformer
std::unique_ptr< QgsCurveTransformmCurveTransform
 Optional curve transform. More...
 
double mMaxValue
 Maximum value expected by the transformer. More...
 
double mMinValue
 Minimum value expected by the transformer. More...
 

Detailed Description

QgsPropertyTransformer subclass for transforming a numeric value into a color from a color ramp.

Since
QGIS 3.0

Definition at line 608 of file qgspropertytransformer.h.

Constructor & Destructor Documentation

◆ QgsColorRampTransformer() [1/2]

QgsColorRampTransformer::QgsColorRampTransformer ( double  minValue = 0.0,
double  maxValue = 1.0,
QgsColorRamp ramp = nullptr,
const QColor &  nullColor = QColor( 0, 0, 0, 0 ) 
)

Constructor for QgsColorRampTransformer.

Parameters
minValueminimum expected value
maxValuemaximum expected value
rampsource color ramp. Ownership is transferred to the transformer.
nullColorcolor to return for null values

Definition at line 525 of file qgspropertytransformer.cpp.

◆ QgsColorRampTransformer() [2/2]

QgsColorRampTransformer::QgsColorRampTransformer ( const QgsColorRampTransformer other)

Copy constructor.

Definition at line 535 of file qgspropertytransformer.cpp.

Member Function Documentation

◆ clone()

QgsColorRampTransformer * QgsColorRampTransformer::clone ( ) const
overridevirtual

Returns a clone of the transformer.

Implements QgsPropertyTransformer.

Definition at line 555 of file qgspropertytransformer.cpp.

◆ color()

QColor QgsColorRampTransformer::color ( double  value) const

Calculates the color corresponding to a specific value.

Parameters
valuevalue to calculate color for
Returns
calculated color using transformer's parameters and type

Definition at line 631 of file qgspropertytransformer.cpp.

◆ colorRamp()

QgsColorRamp * QgsColorRampTransformer::colorRamp ( ) const

Returns the color ramp used for calculating property colors.

Returns
color ramp
See also
setColorRamp()

Definition at line 642 of file qgspropertytransformer.cpp.

◆ loadVariant()

bool QgsColorRampTransformer::loadVariant ( const QVariant &  transformer)
overridevirtual

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

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

See also
toVariant()

Reimplemented from QgsPropertyTransformer.

Definition at line 580 of file qgspropertytransformer.cpp.

◆ nullColor()

QColor QgsColorRampTransformer::nullColor ( ) const
inline

Returns the color corresponding to a null value.

See also
setNullColor()

Definition at line 661 of file qgspropertytransformer.h.

◆ operator=()

QgsColorRampTransformer & QgsColorRampTransformer::operator= ( const QgsColorRampTransformer other)

Definition at line 544 of file qgspropertytransformer.cpp.

◆ rampName()

QString QgsColorRampTransformer::rampName ( ) const
inline

Returns the color ramp's name.

See also
setRampName()

Definition at line 674 of file qgspropertytransformer.h.

◆ setColorRamp()

void QgsColorRampTransformer::setColorRamp ( QgsColorRamp ramp)

Sets the color ramp to use for calculating property colors.

Parameters
rampcolor ramp, ownership of ramp is transferred to the transformer.
See also
colorRamp()

Definition at line 647 of file qgspropertytransformer.cpp.

◆ setNullColor()

void QgsColorRampTransformer::setNullColor ( const QColor &  color)
inline

Sets the color corresponding to a null value.

Parameters
colornull color
See also
nullColor()

Definition at line 668 of file qgspropertytransformer.h.

◆ setRampName()

void QgsColorRampTransformer::setRampName ( const QString &  name)
inline

Sets the color ramp's name.

The ramp name must be set to match a color ramp available in the style database for conversion to expression to work correctly.

See also
rampName()

Definition at line 682 of file qgspropertytransformer.h.

◆ toExpression()

QString QgsColorRampTransformer::toExpression ( const QString &  baseExpression) const
overridevirtual

Converts the transformer to a QGIS expression string.

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

Implements QgsPropertyTransformer.

Definition at line 618 of file qgspropertytransformer.cpp.

◆ toVariant()

QVariant QgsColorRampTransformer::toVariant ( ) const
overridevirtual

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

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

See also
loadVariant()

Reimplemented from QgsPropertyTransformer.

Definition at line 566 of file qgspropertytransformer.cpp.

◆ transform()

QVariant QgsColorRampTransformer::transform ( const QgsExpressionContext context,
const QVariant &  value 
) const
overridevirtual

Calculates the transform of a value.

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

Parameters
contextexpression context
valueinput value to transform

Implements QgsPropertyTransformer.

Definition at line 597 of file qgspropertytransformer.cpp.

◆ transformerType()

Type QgsColorRampTransformer::transformerType ( ) const
inlineoverridevirtual

Returns the transformer type.

Implements QgsPropertyTransformer.

Definition at line 629 of file qgspropertytransformer.h.


The documentation for this class was generated from the following files: