QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 <qgscolorramp.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)
 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...
 
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...
 
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...
 
QgsStringMap 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 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 ()=default
 

Static Public Member Functions

static QgsColorRampcreate (const QgsStringMap &properties=QgsStringMap())
 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
 
bool mDiscrete
 
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 150 of file qgscolorramp.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 44 of file qgscolorramp.cpp.

Member Function Documentation

◆ addStopsToGradient()

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

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 284 of file qgscolorramp.cpp.

◆ clone()

QgsGradientColorRamp * QgsGradientColorRamp::clone ( ) const
overridevirtual

Creates a clone of the color ramp.

Implements QgsColorRamp.

Reimplemented in QgsCptCityColorRamp.

Definition at line 195 of file qgscolorramp.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 117 of file qgscolorramp.cpp.

◆ color1()

QColor QgsGradientColorRamp::color1 ( ) const
inline

Returns the gradient start color.

See also
setColor1()
color2()

Definition at line 191 of file qgscolorramp.h.

◆ color2()

QColor QgsGradientColorRamp::color2 ( ) const
inline

Returns the gradient end color.

See also
setColor2()
color1()

Definition at line 198 of file qgscolorramp.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 229 of file qgscolorramp.cpp.

◆ count()

int QgsGradientColorRamp::count ( ) const
inlineoverridevirtual

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

Implements QgsColorRamp.

Definition at line 170 of file qgscolorramp.h.

◆ create()

QgsColorRamp * QgsGradientColorRamp::create ( const QgsStringMap properties = QgsStringMap())
static

Creates a new QgsColorRamp from a map of properties.

Definition at line 53 of file qgscolorramp.cpp.

◆ 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 260 of file qgscolorramp.h.

◆ invert()

void QgsGradientColorRamp::invert ( )
overridevirtual

Inverts the ordering of the color ramp.

Reimplemented from QgsColorRamp.

Reimplemented in QgsCptCityColorRamp.

Definition at line 168 of file qgscolorramp.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 221 of file qgscolorramp.h.

◆ properties()

QgsStringMap QgsGradientColorRamp::properties ( ) const
overridevirtual

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

Implements QgsColorRamp.

Reimplemented in QgsCptCityColorRamp.

Definition at line 203 of file qgscolorramp.cpp.

◆ setColor1()

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

Sets the gradient start color.

Parameters
colorstart color
See also
color1()
setColor2()

Definition at line 206 of file qgscolorramp.h.

◆ setColor2()

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

Sets the gradient end color.

Parameters
colorend color
See also
color2()
setColor1()

Definition at line 214 of file qgscolorramp.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 230 of file qgscolorramp.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 267 of file qgscolorramp.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 276 of file qgscolorramp.cpp.

◆ stops()

QgsGradientStopsList QgsGradientColorRamp::stops ( ) const
inline

Returns the list of intermediate gradient stops for the ramp.

See also
setStops()

Definition at line 254 of file qgscolorramp.h.

◆ type()

QString QgsGradientColorRamp::type ( ) const
overridevirtual

Returns a string representing the color ramp type.

Implements QgsColorRamp.

Reimplemented in QgsCptCityColorRamp.

Definition at line 163 of file qgscolorramp.cpp.

◆ typeString()

static QString QgsGradientColorRamp::typeString ( )
inlinestatic

Returns the string identifier for QgsGradientColorRamp.

Since
QGIS 3.16

Definition at line 179 of file qgscolorramp.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 101 of file qgscolorramp.cpp.

Member Data Documentation

◆ mColor1

QColor QgsGradientColorRamp::mColor1
protected

Definition at line 279 of file qgscolorramp.h.

◆ mColor2

QColor QgsGradientColorRamp::mColor2
protected

Definition at line 280 of file qgscolorramp.h.

◆ mDiscrete

bool QgsGradientColorRamp::mDiscrete
protected

Definition at line 281 of file qgscolorramp.h.

◆ mInfo

QgsStringMap QgsGradientColorRamp::mInfo
protected

Definition at line 283 of file qgscolorramp.h.

◆ mStops

QgsGradientStopsList QgsGradientColorRamp::mStops
protected

Definition at line 282 of file qgscolorramp.h.


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