16 #ifndef QGSCOLORRAMP_H 17 #define QGSCOLORRAMP_H 19 #include "qgis_core.h" 36 if ( sipCpp->type() ==
"gradient" )
37 sipType = sipType_QgsGradientColorRamp;
38 else if ( sipCpp->type() ==
"random" )
39 sipType = sipType_QgsLimitedRandomColorRamp;
40 else if ( sipCpp->type() ==
"randomcolors" )
41 sipType = sipType_QgsRandomColorRamp;
42 else if ( sipCpp->type() ==
"preset" )
43 sipType = sipType_QgsPresetSchemeColorRamp;
44 else if ( sipCpp->type() ==
"colorbrewer" )
45 sipType = sipType_QgsColorBrewerColorRamp;
46 else if ( sipCpp->type() ==
"cpt-city" )
47 sipType = sipType_QgsCptCityColorRamp;
59 virtual int count()
const = 0;
64 virtual double value(
int index )
const = 0;
71 virtual QColor color(
double value )
const = 0;
76 virtual QString type()
const = 0;
129 #define DEFAULT_GRADIENT_COLOR1 QColor(0,0,255) 130 #define DEFAULT_GRADIENT_COLOR2 QColor(0,255,0) 153 bool discrete =
false,
159 int count()
const override {
return mStops.count() + 2; }
160 double value(
int index )
const override;
161 QColor
color(
double value )
const override;
162 QString
type()
const override {
return QStringLiteral(
"gradient" ); }
172 QColor
color1()
const {
return mColor1; }
179 QColor
color2()
const {
return mColor2; }
220 void convertToDiscrete(
bool discrete );
257 void addStopsToGradient( QGradient *gradient,
double opacity = 1 );
269 #define DEFAULT_RANDOM_COUNT 10 270 #define DEFAULT_RANDOM_HUE_MIN 0 271 #define DEFAULT_RANDOM_HUE_MAX 359 272 #define DEFAULT_RANDOM_VAL_MIN 200 273 #define DEFAULT_RANDOM_VAL_MAX 240 274 #define DEFAULT_RANDOM_SAT_MIN 100 275 #define DEFAULT_RANDOM_SAT_MAX 240 310 double value(
int index )
const override;
311 QColor
color(
double value )
const override;
312 QString
type()
const override {
return QStringLiteral(
"random" ); }
315 int count()
const override {
return mCount; }
321 static QList<QColor> randomColors(
int count,
436 int count()
const override;
438 double value(
int index )
const override;
440 QColor
color(
double value )
const override;
449 virtual void setTotalColorCount(
int colorCount );
451 QString
type()
const override;
459 int mTotalColorCount = 0;
500 bool setColors(
const QgsNamedColorList &colors,
const QString & = QString(),
const QColor & = QColor() )
override { mColors = colors;
return true; }
506 QList< QColor > colors()
const;
508 double value(
int index )
const override;
509 QColor
color(
double value )
const override;
510 QString
type()
const override {
return QStringLiteral(
"preset" ); }
514 int count()
const override;
516 QString
schemeName()
const override {
return QStringLiteral(
"preset" ); }
526 #define DEFAULT_COLORBREWER_SCHEMENAME "Spectral" 527 #define DEFAULT_COLORBREWER_COLORS 5 547 bool inverted =
false );
557 double value(
int index )
const override;
558 QColor
color(
double value )
const override;
559 QString
type()
const override {
return QStringLiteral(
"colorbrewer" ); }
563 int count()
const override {
return mColors; }
583 void setSchemeName(
const QString &schemeName ) { mSchemeName = schemeName; loadPalette(); }
591 void setColors(
int colors ) { mColors = colors; loadPalette(); }
597 static QStringList listSchemeNames();
605 static QList<int> listSchemeVariants(
const QString &schemeName );
619 #define DEFAULT_CPTCITY_SCHEMENAME "cb/div/BrBG_" //change this 620 #define DEFAULT_CPTCITY_VARIANTNAME "05" 639 bool inverted =
false,
640 bool doLoadFile =
true );
651 const QString &variantName = QString(),
bool inverted =
false,
652 bool doLoadFile =
true );
656 QString
type()
const override {
return QStringLiteral(
"cpt-city" ); }
671 void setSchemeName(
const QString &schemeName ) { mSchemeName = schemeName; mFileLoaded =
false; }
672 void setVariantName(
const QString &variantName ) { mVariantName = variantName; mFileLoaded =
false; }
673 void setVariantList(
const QStringList &variantList ) { mVariantList = variantList; }
674 void setName(
const QString &schemeName,
const QString &variantName = QString(),
const QStringList &variantList = QStringList() )
675 { mSchemeName = schemeName; mVariantName = variantName; mVariantList = variantList; mFileLoaded =
false; }
680 QString fileName()
const;
684 QString copyingFileName()
const;
685 QString descFileName()
const;
692 bool mFileLoaded =
false;
693 bool mMultiStops =
false;
int valMin() const
Returns the minimum value for generated colors.
#define DEFAULT_RANDOM_SAT_MAX
void setColor2(const QColor &color)
Sets the gradient end color.
#define DEFAULT_RANDOM_VAL_MAX
#define DEFAULT_RANDOM_HUE_MAX
Represents a color stop within a QgsGradientColorRamp color ramp.
void setCount(int val)
Sets the number of colors contained in the ramp.
bool operator==(const QgsGradientStop &other) const
void invert() override
Inverts the ordering of the color ramp.
QString schemeName() const override
Gets the name for the color scheme.
void setSchemeName(const QString &schemeName)
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
Abstract base class for color schemes.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Abstract base class for color ramps.
int colors() const
Returns the number of colors in the ramp.
void setHueMax(int val)
Sets the maximum hue for generated colors.
#define DEFAULT_RANDOM_HUE_MIN
void setVariantName(const QString &variantName)
QString schemeName() const
#define DEFAULT_COLORBREWER_SCHEMENAME
void setHueMin(int val)
Sets the minimum hue for generated colors.
bool isEditable() const override
Returns whether the color scheme is editable.
virtual void invert()
Inverts the ordering of the color ramp.
virtual QColor color(double value) const =0
Returns the color corresponding to a specified value.
QMap< QString, QString > QgsStringMap
Q_DECLARE_METATYPE(QModelIndex)
QList< QgsGradientStop > QgsGradientStopsList
List of gradient stops.
void setName(const QString &schemeName, const QString &variantName=QString(), const QStringList &variantList=QStringList())
QgsGradientColorRamp * clone() const override
Creates a clone of the color ramp.
QString variantName() const
QgsStringMap info() const
Returns any additional info attached to the gradient ramp (e.g., authorship notes) ...
QString type() const override
Returns a string representing the color ramp type.
Constrained random color ramp, which returns random colors based on preset parameters.
#define DEFAULT_RANDOM_VAL_MIN
double offset
Relative positional offset, between 0 and 1.
QString type() const override
Returns a string representing the color ramp type.
int count() const override
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.
int satMax() const
Returns the maximum saturation for generated colors.
#define DEFAULT_CPTCITY_SCHEMENAME
int hueMin() const
Returns the minimum hue for generated colors.
void setDiscrete(bool discrete)
Sets whether the gradient should use discrete interpolation, rather than smoothly interpolating betwe...
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
void setSchemeName(const QString &schemeName)
Sets the name of the color brewer color scheme.
int count() const override
Returns number of defined colors, or -1 if undefined.
int hueMax() const
Returns the maximum hue for generated colors.
bool isDiscrete() const
Returns true if the gradient is using discrete interpolation, rather than smoothly interpolating betw...
virtual QString type() const =0
Returns a string representing the color ramp type.
virtual int count() const =0
Returns number of defined colors, or -1 if undefined.
#define DEFAULT_GRADIENT_COLOR1
A scheme based color ramp consisting of a list of predefined colors.
void setSatMax(int val)
Sets the maximum saturation for generated colors.
bool setColors(const QgsNamedColorList &colors, const QString &=QString(), const QColor &=QColor()) override
Sets the list of colors used by the ramp.
Totally random color ramp.
void setValMin(int val)
Sets the minimum value for generated colors.
QString type() const override
Returns a string representing the color ramp type.
static QgsColorRamp * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsColorRamp from a map of properties.
#define DEFAULT_RANDOM_COUNT
QString type() const override
Returns a string representing the color ramp type.
#define DEFAULT_RANDOM_SAT_MIN
QString type() const override
Returns a string representing the color ramp type.
void setVariantList(const QStringList &variantList)
void setInfo(const QgsStringMap &info)
Sets additional info to attach to the gradient ramp (e.g., authorship notes)
int satMin() const
Returns the minimum saturation for generated colors.
virtual QgsStringMap properties() const =0
Returns a string map containing all the color ramp's properties.
virtual QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor())=0
Gets a list of colors from the scheme.
QList< QColor > mPrecalculatedColors
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
void setSatMin(int val)
Sets the minimum saturation for generated colors.
Color ramp utilising "Color Brewer" preset color schemes.
#define DEFAULT_GRADIENT_COLOR2
QgsGradientStopsList mStops
int valMax() const
Returns the maximum value for generated colors.
QgsGradientStopsList stops() const
Returns the list of intermediate gradient stops for the ramp.
QColor color2() const
Returns the gradient end color.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
#define DEFAULT_CPTCITY_VARIANTNAME
QColor color1() const
Returns the gradient start color.
QgsStringMap properties() const override
Returns a string map containing all the color ramp's properties.
void setColors(int colors)
Sets the number of colors in the ramp.
QgsGradientStop(double offset, const QColor &color)
Constructor for QgsGradientStop.
QString schemeName() const
Returns the name of the color brewer color scheme.
#define DEFAULT_COLORBREWER_COLORS
QStringList variantList() const
bool hasMultiStops() const
void setValMax(int val)
Sets the maximum value for generated colors.
void setColor1(const QColor &color)
Sets the gradient start color.
QColor color
Gradient color at stop.
int count() const override
Returns number of defined colors, or -1 if undefined.