QGIS API Documentation  3.24.2-Tisler (13c1a02865)
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
QgsGradientColorRamp Class Reference

Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra color stops. More...

#include <qgscolorrampimpl.h>

Inheritance diagram for QgsGradientColorRamp:
Inheritance graph
[legend]

Public Member Functions

 QgsGradientColorRamp (const QColor &color1=DEFAULT_GRADIENT_COLOR1, const QColor &color2=DEFAULT_GRADIENT_COLOR2, bool discrete=false, const QgsGradientStopsList &stops=QgsGradientStopsList())
 Constructor for QgsGradientColorRamp. More...
 
void addStopsToGradient (QGradient *gradient, double opacity=1) const
 Copy color ramp stops to a QGradient. More...
 
QgsGradientColorRampclone () const override
 Creates a clone of the color ramp. More...
 
QColor color (double value) const override
 Returns the color corresponding to a specified value. More...
 
QColor color1 () const
 Returns the gradient start color. More...
 
QColor color2 () const
 Returns the gradient end color. More...
 
QColor::Spec colorSpec () const
 Returns the color specification in which the color component interpolation will occur. More...
 
void convertToDiscrete (bool discrete)
 Converts a gradient with existing color stops to or from discrete interpolation. More...
 
int count () const override
 Returns number of defined colors, or -1 if undefined. More...
 
Qgis::AngularDirection direction () const
 Returns the direction to traverse the color wheel using when interpolating hue-based color specifications. More...
 
QgsStringMap info () const
 Returns any additional info attached to the gradient ramp (e.g., authorship notes) More...
 
void invert () override
 Inverts the ordering of the color ramp. More...
 
bool isDiscrete () const
 Returns true if the gradient is using discrete interpolation, rather than smoothly interpolating between colors. More...
 
QVariantMap properties () const override
 Returns a string map containing all the color ramp's properties. More...
 
void setColor1 (const QColor &color)
 Sets the gradient start color. More...
 
void setColor2 (const QColor &color)
 Sets the gradient end color. More...
 
void setColorSpec (QColor::Spec spec)
 Sets the color specification in which the color component interpolation will occur. More...
 
void setDirection (Qgis::AngularDirection direction)
 Sets the direction to traverse the color wheel using when interpolating hue-based color specifications. More...
 
void setDiscrete (bool discrete)
 Sets whether the gradient should use discrete interpolation, rather than smoothly interpolating between colors. More...
 
void setInfo (const QgsStringMap &info)
 Sets additional info to attach to the gradient ramp (e.g., authorship notes) More...
 
void setStops (const QgsGradientStopsList &stops)
 Sets the list of intermediate gradient stops for the ramp. More...
 
QgsGradientStopsList stops () const
 Returns the list of intermediate gradient stops for the ramp. More...
 
QString type () const override
 Returns a string representing the color ramp type. More...
 
double value (int index) const override
 Returns relative value between [0,1] of color at specified index. More...
 
- Public Member Functions inherited from QgsColorRamp
virtual ~QgsColorRamp ()
 

Static Public Member Functions

static QgsColorRampcreate (const QVariantMap &properties=QVariantMap())
 Creates a new QgsColorRamp from a map of properties. More...
 
static QString typeString ()
 Returns the string identifier for QgsGradientColorRamp. More...
 
- Static Public Member Functions inherited from QgsColorRamp
static QList< QPair< QString, QString > > rampTypes ()
 Returns a list of available ramp types, where the first value in each item is the QgsColorRamp::type() string and the second is a user friendly, translated name for the color ramp type. More...
 

Protected Attributes

QColor mColor1
 
QColor mColor2
 
QColor::Spec mColorSpec = QColor::Spec::Rgb
 
Qgis::AngularDirection mDirection = Qgis::AngularDirection::CounterClockwise
 
bool mDiscrete
 
InterpolateColorFunc mFunc = nullptr
 
QgsStringMap mInfo
 
QgsGradientStopsList mStops
 

Detailed Description

Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra color stops.

Since
QGIS 3.0

Definition at line 136 of file qgscolorrampimpl.h.

Constructor & Destructor Documentation

◆ QgsGradientColorRamp()

QgsGradientColorRamp::QgsGradientColorRamp ( const QColor &  color1 = DEFAULT_GRADIENT_COLOR1,
const QColor &  color2 = DEFAULT_GRADIENT_COLOR2,
bool  discrete = false,
const QgsGradientStopsList stops = QgsGradientStopsList() 
)

Constructor for QgsGradientColorRamp.

Parameters
color1start color, corresponding to a position of 0.0
color2end color, corresponding to a position of 1.0
discreteset to true for discrete interpolation instead of smoothly interpolating between colors
stopsoptional list of additional color stops

Definition at line 206 of file qgscolorrampimpl.cpp.

Member Function Documentation

◆ addStopsToGradient()

void QgsGradientColorRamp::addStopsToGradient ( QGradient *  gradient,
double  opacity = 1 
) const

Copy color ramp stops to a QGradient.

Parameters
gradientgradient to copy stops into
opacityopacity multiplier. Opacity of colors will be multiplied by this factor before adding to the gradient.
Since
QGIS 2.1

Definition at line 540 of file qgscolorrampimpl.cpp.

◆ clone()

QgsGradientColorRamp * QgsGradientColorRamp::clone ( ) const
overridevirtual

Creates a clone of the color ramp.

Implements QgsColorRamp.

Reimplemented in QgsCptCityColorRamp.

Definition at line 415 of file qgscolorrampimpl.cpp.

◆ color()

QColor QgsGradientColorRamp::color ( double  value) const
overridevirtual

Returns the color corresponding to a specified value.

Parameters
valuevalue between [0, 1] inclusive
Returns
color for value

Implements QgsColorRamp.

Definition at line 316 of file qgscolorrampimpl.cpp.

◆ color1()

QColor QgsGradientColorRamp::color1 ( ) const
inline

Returns the gradient start color.

See also
setColor1()
color2()

Definition at line 177 of file qgscolorrampimpl.h.

◆ color2()

QColor QgsGradientColorRamp::color2 ( ) const
inline

Returns the gradient end color.

See also
setColor2()
color1()

Definition at line 184 of file qgscolorrampimpl.h.

◆ colorSpec()

QColor::Spec QgsGradientColorRamp::colorSpec ( ) const
inline

Returns the color specification in which the color component interpolation will occur.

For multi-stop gradients this color spec will be used for the portion of the color ramp leading into the final stop (i.e. color2()).

See also
setColorSpec()
Since
QGIS 3.24

Definition at line 273 of file qgscolorrampimpl.h.

◆ convertToDiscrete()

void QgsGradientColorRamp::convertToDiscrete ( bool  discrete)

Converts a gradient with existing color stops to or from discrete interpolation.

Parameters
discreteset to true to convert the gradient stops to discrete, or false to convert them to smooth interpolation
See also
isDiscrete()

Definition at line 485 of file qgscolorrampimpl.cpp.

◆ count()

int QgsGradientColorRamp::count ( ) const
inlineoverridevirtual

Returns number of defined colors, or -1 if undefined.

Implements QgsColorRamp.

Definition at line 156 of file qgscolorrampimpl.h.

◆ create()

QgsColorRamp * QgsGradientColorRamp::create ( const QVariantMap &  properties = QVariantMap())
static

Creates a new QgsColorRamp from a map of properties.

Definition at line 216 of file qgscolorrampimpl.cpp.

◆ direction()

Qgis::AngularDirection QgsGradientColorRamp::direction ( ) const
inline

Returns the direction to traverse the color wheel using when interpolating hue-based color specifications.

For multi-stop gradients this direction will be used for the portion of the color ramp leading into the final stop (i.e. color2()).

See also
setDirection()
Since
QGIS 3.24

Definition at line 298 of file qgscolorrampimpl.h.

◆ info()

QgsStringMap QgsGradientColorRamp::info ( ) const
inline

Returns any additional info attached to the gradient ramp (e.g., authorship notes)

See also
setInfo()

Definition at line 246 of file qgscolorrampimpl.h.

◆ invert()

void QgsGradientColorRamp::invert ( )
overridevirtual

Inverts the ordering of the color ramp.

Reimplemented from QgsColorRamp.

Reimplemented in QgsCptCityColorRamp.

Definition at line 367 of file qgscolorrampimpl.cpp.

◆ isDiscrete()

bool QgsGradientColorRamp::isDiscrete ( ) const
inline

Returns true if the gradient is using discrete interpolation, rather than smoothly interpolating between colors.

See also
setDiscrete()

Definition at line 207 of file qgscolorrampimpl.h.

◆ properties()

QVariantMap QgsGradientColorRamp::properties ( ) const
overridevirtual

Returns a string map containing all the color ramp's properties.

Implements QgsColorRamp.

Reimplemented in QgsCptCityColorRamp.

Definition at line 425 of file qgscolorrampimpl.cpp.

◆ setColor1()

void QgsGradientColorRamp::setColor1 ( const QColor &  color)
inline

Sets the gradient start color.

Parameters
colorstart color
See also
color1()
setColor2()

Definition at line 192 of file qgscolorrampimpl.h.

◆ setColor2()

void QgsGradientColorRamp::setColor2 ( const QColor &  color)
inline

Sets the gradient end color.

Parameters
colorend color
See also
color2()
setColor1()

Definition at line 200 of file qgscolorrampimpl.h.

◆ setColorSpec()

void QgsGradientColorRamp::setColorSpec ( QColor::Spec  spec)

Sets the color specification in which the color component interpolation will occur.

Only QColor::Spec::Rgb, QColor::Spec::Hsv and QColor::Spec::Hsl are currently supported.

For multi-stop gradients this color spec will be used for the portion of the color ramp leading into the final stop (i.e. color2()).

See also
colorSpec()
Since
QGIS 3.24

Definition at line 595 of file qgscolorrampimpl.cpp.

◆ setDirection()

void QgsGradientColorRamp::setDirection ( Qgis::AngularDirection  direction)
inline

Sets the direction to traverse the color wheel using when interpolating hue-based color specifications.

For multi-stop gradients this direction will be used for the portion of the color ramp leading into the final stop (i.e. color2()).

See also
direction()
Since
QGIS 3.24

Definition at line 310 of file qgscolorrampimpl.h.

◆ setDiscrete()

void QgsGradientColorRamp::setDiscrete ( bool  discrete)
inline

Sets whether the gradient should use discrete interpolation, rather than smoothly interpolating between colors.

Parameters
discreteset to true to use discrete interpolation
See also
convertToDiscrete()
isDiscrete()

Definition at line 216 of file qgscolorrampimpl.h.

◆ setInfo()

void QgsGradientColorRamp::setInfo ( const QgsStringMap info)
inline

Sets additional info to attach to the gradient ramp (e.g., authorship notes)

Parameters
infomap of string info to attach
See also
info()

Definition at line 253 of file qgscolorrampimpl.h.

◆ setStops()

void QgsGradientColorRamp::setStops ( const QgsGradientStopsList stops)

Sets the list of intermediate gradient stops for the ramp.

Parameters
stopslist of stops. Any existing color stops will be replaced. The stop list will be automatically reordered so that stops are listed in ascending offset order.
See also
stops()

Definition at line 532 of file qgscolorrampimpl.cpp.

◆ stops()

QgsGradientStopsList QgsGradientColorRamp::stops ( ) const
inline

Returns the list of intermediate gradient stops for the ramp.

See also
setStops()

Definition at line 240 of file qgscolorrampimpl.h.

◆ type()

QString QgsGradientColorRamp::type ( ) const
overridevirtual

Returns a string representing the color ramp type.

Implements QgsColorRamp.

Reimplemented in QgsCptCityColorRamp.

Definition at line 362 of file qgscolorrampimpl.cpp.

◆ typeString()

static QString QgsGradientColorRamp::typeString ( )
inlinestatic

Returns the string identifier for QgsGradientColorRamp.

Since
QGIS 3.16

Definition at line 165 of file qgscolorrampimpl.h.

◆ value()

double QgsGradientColorRamp::value ( int  index) const
overridevirtual

Returns relative value between [0,1] of color at specified index.

Implements QgsColorRamp.

Definition at line 300 of file qgscolorrampimpl.cpp.

Member Data Documentation

◆ mColor1

QColor QgsGradientColorRamp::mColor1
protected

Definition at line 313 of file qgscolorrampimpl.h.

◆ mColor2

QColor QgsGradientColorRamp::mColor2
protected

Definition at line 314 of file qgscolorrampimpl.h.

◆ mColorSpec

QColor::Spec QgsGradientColorRamp::mColorSpec = QColor::Spec::Rgb
protected

Definition at line 318 of file qgscolorrampimpl.h.

◆ mDirection

Qgis::AngularDirection QgsGradientColorRamp::mDirection = Qgis::AngularDirection::CounterClockwise
protected

Definition at line 319 of file qgscolorrampimpl.h.

◆ mDiscrete

bool QgsGradientColorRamp::mDiscrete
protected

Definition at line 315 of file qgscolorrampimpl.h.

◆ mFunc

InterpolateColorFunc QgsGradientColorRamp::mFunc = nullptr
protected

Definition at line 321 of file qgscolorrampimpl.h.

◆ mInfo

QgsStringMap QgsGradientColorRamp::mInfo
protected

Definition at line 317 of file qgscolorrampimpl.h.

◆ mStops

QgsGradientStopsList QgsGradientColorRamp::mStops
protected

Definition at line 316 of file qgscolorrampimpl.h.


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