QgsGradientColorRamp class
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra color stops.
Contents
Base classes
- class QgsColorRamp
- Abstract base class for color ramps.
Public static functions
- static auto create(const QgsStringMap& properties = QgsStringMap()) -> QgsColorRamp*
- Creates a new QgsColorRamp from a map of properties.
Constructors, destructors, conversion operators
-
QgsGradientColorRamp(const QColor& color1 = DEFAULT_
GRADIENT_ COLOR1, const QColor& color2 = DEFAULT_ GRADIENT_ COLOR2, bool discrete = false, const QgsGradientStopsList& stops = QgsGradientStopsList()) - Constructor for QgsGradientColorRamp.
Public functions
- void addStopsToGradient(QGradient* gradient, double opacity = 1)
- Copy color ramp stops to a QGradient.
- auto clone() const -> QgsGradientColorRamp* override
- Creates a clone of the color ramp.
- auto color(double value) const -> QColor override
- Returns the color corresponding to a specified value.
- auto color1() const -> QColor
- Returns the gradient start color.
- auto color2() const -> QColor
- Returns the gradient end color.
- void convertToDiscrete(bool discrete)
- Converts a gradient with existing color stops to or from discrete interpolation.
- auto count() const -> int override
- Returns number of defined colors, or -1 if undefined.
- auto info() const -> QgsStringMap
- Returns any additional info attached to the gradient ramp (e.g., authorship notes)
- void invert() override
- Inverts the ordering of the color ramp.
- auto isDiscrete() const -> bool
- Returns true if the gradient is using discrete interpolation, rather than smoothly interpolating between colors.
- auto properties() const -> QgsStringMap override
- Returns a string map containing all the color ramp's properties.
- void setColor1(const QColor& color)
- Sets the gradient start color.
- void setColor2(const QColor& color)
- Sets the gradient end color.
- void setDiscrete(bool discrete)
- Sets whether the gradient should use discrete interpolation, rather than smoothly interpolating between colors.
- void setInfo(const QgsStringMap& info)
- Sets additional info to attach to the gradient ramp (e.g., authorship notes)
- void setStops(const QgsGradientStopsList& stops)
- Sets the list of intermediate gradient stops for the ramp.
- auto stops() const -> QgsGradientStopsList
- Returns the list of intermediate gradient stops for the ramp.
- auto type() const -> QString override
- Returns a string representing the color ramp type.
- auto value(int index) const -> double override
- Returns relative value between [0,1] of color at specified index.
Function documentation
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 | |
|---|---|
| color1 | start color, corresponding to a position of 0.0 |
| color2 | end color, corresponding to a position of 1.0 |
| discrete | set to true for discrete interpolation instead of smoothly interpolating between colors |
| stops | optional list of additional color stops |
void QgsGradientColorRamp:: addStopsToGradient(QGradient* gradient,
double opacity = 1)
Copy color ramp stops to a QGradient.
| Parameters | |
|---|---|
| gradient | gradient to copy stops into |
| opacity | opacity multiplier. Opacity of colors will be multiplied by this factor before adding to the gradient. |
QColor QgsGradientColorRamp:: color(double value) const override
Returns the color corresponding to a specified value.
| Parameters | |
|---|---|
| value | value between [0, 1] inclusive |
| Returns | color for value |
QColor QgsGradientColorRamp:: color1() const
Returns the gradient start color.
QColor QgsGradientColorRamp:: color2() const
Returns the gradient end color.
void QgsGradientColorRamp:: convertToDiscrete(bool discrete)
Converts a gradient with existing color stops to or from discrete interpolation.
| Parameters | |
|---|---|
| discrete | set to true to convert the gradient stops to discrete, or false to convert them to smooth interpolation |
QgsStringMap QgsGradientColorRamp:: info() const
Returns any additional info attached to the gradient ramp (e.g., authorship notes)
bool QgsGradientColorRamp:: isDiscrete() const
Returns true if the gradient is using discrete interpolation, rather than smoothly interpolating between colors.
void QgsGradientColorRamp:: setColor1(const QColor& color)
Sets the gradient start color.
| Parameters | |
|---|---|
| color | start color |
void QgsGradientColorRamp:: setColor2(const QColor& color)
Sets the gradient end color.
| Parameters | |
|---|---|
| color | end color |
void QgsGradientColorRamp:: setDiscrete(bool discrete)
Sets whether the gradient should use discrete interpolation, rather than smoothly interpolating between colors.
| Parameters | |
|---|---|
| discrete | set to true to use discrete interpolation |
void QgsGradientColorRamp:: setInfo(const QgsStringMap& info)
Sets additional info to attach to the gradient ramp (e.g., authorship notes)
| Parameters | |
|---|---|
| info | map of string info to attach |
void QgsGradientColorRamp:: setStops(const QgsGradientStopsList& stops)
Sets the list of intermediate gradient stops for the ramp.
| Parameters | |
|---|---|
| stops | list 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. |
QgsGradientStopsList QgsGradientColorRamp:: stops() const
Returns the list of intermediate gradient stops for the ramp.