QGIS API Documentation  3.6.0-Noosa (5873452)
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...
 

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 139 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 278 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 189 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 116 of file qgscolorramp.cpp.

◆ color1()

QColor QgsGradientColorRamp::color1 ( ) const
inline

Returns the gradient start color.

See also
setColor1()
color2()

Definition at line 172 of file qgscolorramp.h.

◆ color2()

QColor QgsGradientColorRamp::color2 ( ) const
inline

Returns the gradient end color.

See also
setColor2()
color1()

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

◆ count()

int QgsGradientColorRamp::count ( ) const
inlineoverridevirtual

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

Implements QgsColorRamp.

Definition at line 159 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 241 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 162 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 202 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 197 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 187 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 195 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 211 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 248 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 270 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 235 of file qgscolorramp.h.

◆ type()

QString QgsGradientColorRamp::type ( ) const
inlineoverridevirtual

Returns a string representing the color ramp type.

Implements QgsColorRamp.

Reimplemented in QgsCptCityColorRamp.

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

Member Data Documentation

◆ mColor1

QColor QgsGradientColorRamp::mColor1
protected

Definition at line 260 of file qgscolorramp.h.

◆ mColor2

QColor QgsGradientColorRamp::mColor2
protected

Definition at line 261 of file qgscolorramp.h.

◆ mDiscrete

bool QgsGradientColorRamp::mDiscrete
protected

Definition at line 262 of file qgscolorramp.h.

◆ mInfo

QgsStringMap QgsGradientColorRamp::mInfo
protected

Definition at line 264 of file qgscolorramp.h.

◆ mStops

QgsGradientStopsList QgsGradientColorRamp::mStops
protected

Definition at line 263 of file qgscolorramp.h.


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