QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
16 #ifndef QGSCOLORRAMP_H
17 #define QGSCOLORRAMP_H
19 #include "qgis_core.h"
37 sipType = sipType_QgsGradientColorRamp;
39 sipType = sipType_QgsLimitedRandomColorRamp;
41 sipType = sipType_QgsRandomColorRamp;
43 sipType = sipType_QgsPresetSchemeColorRamp;
45 sipType = sipType_QgsColorBrewerColorRamp;
47 sipType = sipType_QgsCptCityColorRamp;
64 virtual double value(
int index )
const = 0;
71 virtual QColor
color(
double value )
const = 0;
76 virtual QString
type()
const = 0;
103 static QList< QPair< QString, QString > > rampTypes();
140 #define DEFAULT_GRADIENT_COLOR1 QColor(0,0,255)
141 #define DEFAULT_GRADIENT_COLOR2 QColor(0,255,0)
164 bool discrete =
false,
170 int count()
const override {
return mStops.count() + 2; }
171 double value(
int index )
const override;
172 QColor
color(
double value )
const override;
179 static QString
typeString() {
return QStringLiteral(
"gradient" ); }
181 QString
type()
const override;
191 QColor color1()
const {
return mColor1; }
198 QColor
color2()
const {
return mColor2; }
239 void convertToDiscrete(
bool discrete );
276 void addStopsToGradient( QGradient *gradient,
double opacity = 1 );
288 #define DEFAULT_RANDOM_COUNT 10
289 #define DEFAULT_RANDOM_HUE_MIN 0
290 #define DEFAULT_RANDOM_HUE_MAX 359
291 #define DEFAULT_RANDOM_VAL_MIN 200
292 #define DEFAULT_RANDOM_VAL_MAX 240
293 #define DEFAULT_RANDOM_SAT_MIN 100
294 #define DEFAULT_RANDOM_SAT_MAX 240
329 double value(
int index )
const override;
330 QColor
color(
double value )
const override;
337 static QString
typeString() {
return QStringLiteral(
"random" ); }
339 QString
type()
const override;
342 int count()
const override {
return mCount; }
348 static QList<QColor> randomColors(
int count,
463 int count()
const override;
465 double value(
int index )
const override;
467 QColor
color(
double value )
const override;
476 virtual void setTotalColorCount(
int colorCount );
483 static QString
typeString() {
return QStringLiteral(
"randomcolors" ); }
485 QString
type()
const override;
493 int mTotalColorCount = 0;
494 QList<QColor> mPrecalculatedColors;
534 bool setColors(
const QgsNamedColorList &colors,
const QString & = QString(),
const QColor & = QColor() )
override { mColors = colors;
return true; }
540 QList< QColor > colors()
const;
542 double value(
int index )
const override;
543 QColor
color(
double value )
const override;
550 static QString
typeString() {
return QStringLiteral(
"preset" ); }
552 QString
type()
const override;
556 int count() const override;
558 QString schemeName()
const override {
return QStringLiteral(
"preset" ); }
559 QgsNamedColorList fetchColors(
const QString &context = QString(),
const QColor &baseColor = QColor() )
override;
568 #define DEFAULT_COLORBREWER_SCHEMENAME "Spectral"
569 #define DEFAULT_COLORBREWER_COLORS 5
589 bool inverted =
false );
599 double value(
int index )
const override;
600 QColor
color(
double value )
const override;
607 static QString
typeString() {
return QStringLiteral(
"colorbrewer" ); }
613 int count()
const override {
return mColors; }
633 void setSchemeName(
const QString &schemeName ) { mSchemeName = schemeName; loadPalette(); }
641 void setColors(
int colors ) { mColors = colors; loadPalette(); }
647 static QStringList listSchemeNames();
655 static QList<int> listSchemeVariants(
const QString &schemeName );
669 #define DEFAULT_CPTCITY_SCHEMENAME "cb/div/BrBG_" //change this
670 #define DEFAULT_CPTCITY_VARIANTNAME "05"
689 bool inverted =
false,
690 bool doLoadFile =
true );
701 const QString &variantName = QString(),
bool inverted =
false,
702 bool doLoadFile =
true );
711 static QString
typeString() {
return QStringLiteral(
"cpt-city" ); }
713 QString
type()
const override;
723 QString schemeName()
const {
return mSchemeName; }
728 void setSchemeName(
const QString &schemeName ) { mSchemeName = schemeName; mFileLoaded =
false; }
729 void setVariantName(
const QString &variantName ) { mVariantName = variantName; mFileLoaded =
false; }
730 void setVariantList(
const QStringList &variantList ) { mVariantList = variantList; }
731 void setName(
const QString &schemeName,
const QString &variantName = QString(),
const QStringList &variantList = QStringList() )
732 { mSchemeName = schemeName; mVariantName = variantName; mVariantList = variantList; mFileLoaded =
false; }
737 QString fileName()
const;
741 QString copyingFileName()
const;
742 QString descFileName()
const;
749 bool mFileLoaded =
false;
750 bool mMultiStops =
false;
QgsGradientStop(double offset, const QColor &color)
Constructor for QgsGradientStop.
#define DEFAULT_RANDOM_VAL_MAX
#define DEFAULT_RANDOM_HUE_MAX
Abstract base class for color ramps.
QColor color
Gradient color at stop.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
void setSchemeName(const QString &schemeName)
void setName(const QString &schemeName, const QString &variantName=QString(), const QStringList &variantList=QStringList())
int hueMin() const
Returns the minimum hue for generated colors.
#define DEFAULT_CPTCITY_VARIANTNAME
#define DEFAULT_COLORBREWER_COLORS
void setInfo(const QgsStringMap &info)
Sets additional info to attach to the gradient ramp (e.g., authorship notes)
A scheme based color ramp consisting of a list of predefined colors.
void setVariantList(const QStringList &variantList)
void setSatMax(int val)
Sets the maximum saturation for generated colors.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
#define DEFAULT_COLORBREWER_SCHEMENAME
QgsGradientColorRamp * clone() const override
Creates a clone of the color ramp.
void setValMin(int val)
Sets the minimum value for generated colors.
QString variantName() const
QStringList variantList() const
#define DEFAULT_RANDOM_HUE_MIN
virtual QgsStringMap properties() const =0
Returns a string map containing all the color ramp's properties.
void invert() override
Inverts the ordering of the color ramp.
static QString typeString()
Returns the string identifier for QgsColorBrewerColorRamp.
Constrained random color ramp, which returns random colors based on preset parameters.
int satMax() const
Returns the maximum saturation for generated colors.
Color ramp utilising "Color Brewer" preset color schemes.
void setSatMin(int val)
Sets the minimum saturation for generated colors.
bool isEditable() const override
Returns whether the color scheme is editable.
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
void setHueMax(int val)
Sets the maximum hue for generated colors.
Totally random color ramp.
QgsGradientStopsList stops() const
Returns the list of intermediate gradient stops for the ramp.
static QString typeString()
Returns the string identifier for QgsCptCityColorRamp.
static QString typeString()
Returns the string identifier for QgsGradientColorRamp.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
QList< QgsGradientStop > QgsGradientStopsList
List of gradient stops.
static QString typeString()
Returns the string identifier for QgsPresetSchemeColorRamp.
void setColor1(const QColor &color)
Sets the gradient start color.
#define DEFAULT_GRADIENT_COLOR1
int count() const override
Returns number of defined colors, or -1 if undefined.
int valMax() const
Returns the maximum value for generated colors.
QColor color2() const
Returns the gradient end color.
int satMin() const
Returns the minimum saturation for generated colors.
static QString typeString()
Returns the string identifier for QgsRandomColorRamp.
int colors() const
Returns the number of colors in the ramp.
virtual ~QgsColorRamp()=default
void setColor2(const QColor &color)
Sets the gradient end color.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void setSchemeName(const QString &schemeName)
Sets the name of the color brewer color scheme.
#define DEFAULT_RANDOM_VAL_MIN
QString schemeName() const
Returns the name of the color brewer color scheme.
QString type() const override
Returns a string representing the color ramp type.
#define DEFAULT_RANDOM_SAT_MIN
#define DEFAULT_CPTCITY_SCHEMENAME
QString type() const override
Returns a string representing the color ramp type.
void setCount(int val)
Sets the number of colors contained in the ramp.
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
QgsRandomColorRamp()=default
Constructor for QgsRandomColorRamp.
void setVariantName(const QString &variantName)
QMap< QString, QString > QgsStringMap
bool operator==(const QgsGradientStop &other) const
Abstract base class for color schemes.
int hueMax() const
Returns the maximum hue for generated colors.
void setHueMin(int val)
Sets the minimum hue for generated colors.
virtual QString type() const =0
Returns a string representing the color ramp type.
#define DEFAULT_RANDOM_COUNT
virtual int count() const =0
Returns number of defined colors, or -1 if undefined.
virtual QColor color(double value) const =0
Returns the color corresponding to a specified value.
bool hasMultiStops() const
void setColors(int colors)
Sets the number of colors in the ramp.
void setDiscrete(bool discrete)
Sets whether the gradient should use discrete interpolation, rather than smoothly interpolating betwe...
static QgsColorRamp * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsColorRamp from a map of properties.
virtual void invert()
Inverts the ordering of the color ramp.
QgsGradientStopsList mStops
#define DEFAULT_GRADIENT_COLOR2
void setValMax(int val)
Sets the maximum value for generated colors.
bool setColors(const QgsNamedColorList &colors, const QString &=QString(), const QColor &=QColor()) override
Sets the list of colors used by the ramp.
static QString typeString()
Returns the string identifier for QgsLimitedRandomColorRamp.
Represents a color stop within a QgsGradientColorRamp color ramp.
bool isDiscrete() const
Returns true if the gradient is using discrete interpolation, rather than smoothly interpolating betw...
int valMin() const
Returns the minimum value for generated colors.
double offset
Relative positional offset, between 0 and 1.
QgsStringMap info() const
Returns any additional info attached to the gradient ramp (e.g., authorship notes)
virtual double value(int index) const =0
Returns relative value between [0,1] of color at specified index.
#define DEFAULT_RANDOM_SAT_MAX