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();
142 #define DEFAULT_GRADIENT_COLOR1 QColor(69, 116, 40)
143 #define DEFAULT_GRADIENT_COLOR2 QColor(188, 220, 60)
166 bool discrete =
false,
172 int count()
const override {
return mStops.count() + 2; }
173 double value(
int index )
const override;
174 QColor color(
double value )
const override;
181 static QString
typeString() {
return QStringLiteral(
"gradient" ); }
183 QString type()
const override;
184 void invert()
override;
186 QVariantMap properties() const override;
193 QColor color1()
const {
return mColor1; }
200 QColor
color2()
const {
return mColor2; }
208 void setColor1(
const QColor &color ) { mColor1 = color; }
216 void setColor2(
const QColor &color ) { mColor2 = color; }
241 void convertToDiscrete(
bool discrete );
278 void addStopsToGradient( QGradient *gradient,
double opacity = 1 );
290 #define DEFAULT_RANDOM_COUNT 10
291 #define DEFAULT_RANDOM_HUE_MIN 0
292 #define DEFAULT_RANDOM_HUE_MAX 359
293 #define DEFAULT_RANDOM_VAL_MIN 200
294 #define DEFAULT_RANDOM_VAL_MAX 240
295 #define DEFAULT_RANDOM_SAT_MIN 100
296 #define DEFAULT_RANDOM_SAT_MAX 240
331 double value(
int index )
const override;
332 QColor color(
double value )
const override;
339 static QString
typeString() {
return QStringLiteral(
"random" ); }
341 QString type()
const override;
343 QVariantMap properties() const override;
344 int count()
const override {
return mCount; }
350 static QList<QColor> randomColors(
int count,
465 int count()
const override;
467 double value(
int index )
const override;
469 QColor color(
double value )
const override;
478 virtual void setTotalColorCount(
int colorCount );
485 static QString
typeString() {
return QStringLiteral(
"randomcolors" ); }
487 QString type()
const override;
491 QVariantMap properties() const override;
495 int mTotalColorCount = 0;
496 QList<QColor> mPrecalculatedColors;
536 bool setColors(
const QgsNamedColorList &colors,
const QString & = QString(),
const QColor & = QColor() )
override { mColors = colors;
return true; }
542 QList< QColor > colors()
const;
544 double value(
int index )
const override;
545 QColor color(
double value )
const override;
552 static QString
typeString() {
return QStringLiteral(
"preset" ); }
554 QString type()
const override;
555 void invert()
override;
557 QVariantMap properties() const override;
558 int count() const override;
560 QString schemeName()
const override {
return QStringLiteral(
"preset" ); }
561 QgsNamedColorList fetchColors(
const QString &context = QString(),
const QColor &baseColor = QColor() )
override;
570 #define DEFAULT_COLORBREWER_SCHEMENAME "Spectral"
571 #define DEFAULT_COLORBREWER_COLORS 5
591 bool inverted =
false );
601 double value(
int index )
const override;
602 QColor color(
double value )
const override;
609 static QString
typeString() {
return QStringLiteral(
"colorbrewer" ); }
612 void invert()
override;
614 QVariantMap properties() const override;
615 int count()
const override {
return mColors; }
635 void setSchemeName(
const QString &schemeName ) { mSchemeName = schemeName; loadPalette(); }
643 void setColors(
int colors ) { mColors = colors; loadPalette(); }
649 static QStringList listSchemeNames();
657 static QList<int> listSchemeVariants(
const QString &schemeName );
671 #define DEFAULT_CPTCITY_SCHEMENAME "cb/div/BrBG_"
672 #define DEFAULT_CPTCITY_VARIANTNAME "05"
691 bool inverted =
false,
692 bool doLoadFile =
true );
703 const QString &variantName = QString(),
bool inverted =
false,
704 bool doLoadFile =
true );
714 static QString
typeString() {
return QStringLiteral(
"cpt-city" ); }
716 QString type()
const override;
718 void invert()
override;
724 QVariantMap properties() const override;
726 QString schemeName()
const {
return mSchemeName; }
731 void setSchemeName(
const QString &schemeName ) { mSchemeName = schemeName; mFileLoaded =
false; }
732 void setVariantName(
const QString &variantName ) { mVariantName = variantName; mFileLoaded =
false; }
733 void setVariantList(
const QStringList &variantList ) { mVariantList = variantList; }
734 void setName(
const QString &schemeName,
const QString &variantName = QString(),
const QStringList &variantList = QStringList() )
735 { mSchemeName = schemeName; mVariantName = variantName; mVariantList = variantList; mFileLoaded =
false; }
740 QString fileName()
const;
744 QString copyingFileName()
const;
745 QString descFileName()
const;
752 bool mFileLoaded =
false;
753 bool mMultiStops =
false;
Color ramp utilising "Color Brewer" preset color schemes.
static QString typeString()
Returns the string identifier for QgsColorBrewerColorRamp.
QString type() const override
Returns a string representing the color ramp type.
QString schemeName() const
Returns the name of the color brewer color scheme.
int colors() const
Returns the number of colors in the ramp.
void setSchemeName(const QString &schemeName)
Sets the name of the color brewer color scheme.
void setColors(int colors)
Sets the number of colors in the ramp.
Abstract base class for color ramps.
virtual QColor color(double value) const =0
Returns the color corresponding to a specified value.
virtual ~QgsColorRamp()=default
virtual int count() const =0
Returns number of defined colors, or -1 if undefined.
virtual double value(int index) const =0
Returns relative value between [0,1] of color at specified index.
virtual QVariantMap properties() const =0
Returns a string map containing all the color ramp's properties.
virtual QString type() const =0
Returns a string representing the color ramp type.
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
virtual void invert()
Inverts the ordering of the color ramp.
Abstract base class for color schemes.
void setName(const QString &schemeName, const QString &variantName=QString(), const QStringList &variantList=QStringList())
void setSchemeName(const QString &schemeName)
void setVariantList(const QStringList &variantList)
QStringList variantList() const
void setVariantName(const QString &variantName)
static QString typeString()
Returns the string identifier for QgsCptCityColorRamp.
bool hasMultiStops() const
QString variantName() const
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
QgsGradientStopsList mStops
void setColor1(const QColor &color)
Sets the gradient start color.
void setColor2(const QColor &color)
Sets the gradient end color.
void setInfo(const QgsStringMap &info)
Sets additional info to attach to the gradient ramp (e.g., authorship notes)
bool isDiscrete() const
Returns true if the gradient is using discrete interpolation, rather than smoothly interpolating betw...
int count() const override
Returns number of defined colors, or -1 if undefined.
QgsStringMap info() const
Returns any additional info attached to the gradient ramp (e.g., authorship notes)
static QString typeString()
Returns the string identifier for QgsGradientColorRamp.
QgsGradientStopsList stops() const
Returns the list of intermediate gradient stops for the ramp.
void setDiscrete(bool discrete)
Sets whether the gradient should use discrete interpolation, rather than smoothly interpolating betwe...
QColor color2() const
Returns the gradient end color.
Represents a color stop within a QgsGradientColorRamp color ramp.
bool operator==(const QgsGradientStop &other) const
double offset
Relative positional offset, between 0 and 1.
QColor color
Gradient color at stop.
QgsGradientStop(double offset, const QColor &color)
Constructor for QgsGradientStop.
Constrained random color ramp, which returns random colors based on preset parameters.
static QString typeString()
Returns the string identifier for QgsLimitedRandomColorRamp.
void setSatMin(int val)
Sets the minimum saturation for generated colors.
void setHueMin(int val)
Sets the minimum hue for generated colors.
void setSatMax(int val)
Sets the maximum saturation for generated colors.
int valMax() const
Returns the maximum value for generated colors.
int satMax() const
Returns the maximum saturation for generated colors.
void setHueMax(int val)
Sets the maximum hue for generated colors.
void setCount(int val)
Sets the number of colors contained in the ramp.
int hueMax() const
Returns the maximum hue for generated colors.
int hueMin() const
Returns the minimum hue for generated colors.
void setValMax(int val)
Sets the maximum value for generated colors.
int valMin() const
Returns the minimum value for generated colors.
void setValMin(int val)
Sets the minimum value for generated colors.
int satMin() const
Returns the minimum saturation for generated colors.
A scheme based color ramp consisting of a list of predefined 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 QgsPresetSchemeColorRamp.
bool isEditable() const override
Returns whether the color scheme is editable.
Totally random color ramp.
QgsRandomColorRamp()=default
Constructor for QgsRandomColorRamp.
static QString typeString()
Returns the string identifier for QgsRandomColorRamp.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QMap< QString, QString > QgsStringMap
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
#define DEFAULT_COLORBREWER_COLORS
#define DEFAULT_COLORBREWER_SCHEMENAME
#define DEFAULT_RANDOM_HUE_MAX
#define DEFAULT_CPTCITY_SCHEMENAME
#define DEFAULT_RANDOM_HUE_MIN
#define DEFAULT_RANDOM_COUNT
#define DEFAULT_RANDOM_SAT_MAX
#define DEFAULT_RANDOM_SAT_MIN
#define DEFAULT_CPTCITY_VARIANTNAME
#define DEFAULT_GRADIENT_COLOR1
#define DEFAULT_RANDOM_VAL_MIN
QList< QgsGradientStop > QgsGradientStopsList
List of gradient stops.
#define DEFAULT_GRADIENT_COLOR2
#define DEFAULT_RANDOM_VAL_MAX
Q_DECLARE_METATYPE(QgsMeshTimeSettings)