QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
16 #ifndef QGSCOLORRAMPIMPL_H
17 #define QGSCOLORRAMPIMPL_H
19 #include "qgis_core.h"
27 typedef QColor( *InterpolateColorFunc )(
const QColor &c1,
const QColor &c2,
const double value,
Qgis::AngularDirection direction );
56 return other.
color == color &&
qgsDoubleNear( other.
offset, offset ) && other.mColorSpec == mColorSpec && other.mDirection == mDirection;
61 return !( *
this == other );
73 QColor::Spec
colorSpec()
const {
return mColorSpec; }
86 void setColorSpec( QColor::Spec spec );
114 QColor::Spec mColorSpec = QColor::Spec::Rgb;
116 InterpolateColorFunc mFunc =
nullptr;
126 #define DEFAULT_GRADIENT_COLOR1 QColor(69, 116, 40)
127 #define DEFAULT_GRADIENT_COLOR2 QColor(188, 220, 60)
150 bool discrete =
false,
156 int count()
const override {
return mStops.count() + 2; }
157 double value(
int index )
const override;
158 QColor
color(
double value )
const override;
165 static QString
typeString() {
return QStringLiteral(
"gradient" ); }
167 QString
type()
const override;
170 QVariantMap properties() const override;
177 QColor color1()
const {
return mColor1; }
184 QColor
color2()
const {
return mColor2; }
225 void convertToDiscrete(
bool discrete );
262 void addStopsToGradient( QGradient *gradient,
double opacity = 1 )
const;
286 void setColorSpec( QColor::Spec spec );
318 QColor::Spec mColorSpec = QColor::Spec::Rgb;
321 InterpolateColorFunc mFunc =
nullptr;
326 #define DEFAULT_RANDOM_COUNT 10
327 #define DEFAULT_RANDOM_HUE_MIN 0
328 #define DEFAULT_RANDOM_HUE_MAX 359
329 #define DEFAULT_RANDOM_VAL_MIN 200
330 #define DEFAULT_RANDOM_VAL_MAX 240
331 #define DEFAULT_RANDOM_SAT_MIN 100
332 #define DEFAULT_RANDOM_SAT_MAX 240
367 double value(
int index )
const override;
368 QColor
color(
double value )
const override;
375 static QString
typeString() {
return QStringLiteral(
"random" ); }
377 QString
type()
const override;
379 QVariantMap properties() const override;
380 int count()
const override {
return mCount; }
386 static QList<QColor> randomColors(
int count,
501 int count()
const override;
503 double value(
int index )
const override;
505 QColor
color(
double value )
const override;
514 virtual void setTotalColorCount(
int colorCount );
521 static QString
typeString() {
return QStringLiteral(
"randomcolors" ); }
523 QString
type()
const override;
527 QVariantMap properties() const override;
531 int mTotalColorCount = 0;
532 QList<QColor> mPrecalculatedColors;
572 bool setColors(
const QgsNamedColorList &colors,
const QString & = QString(),
const QColor & = QColor() )
override { mColors = colors;
return true; }
578 QList< QColor > colors()
const;
580 double value(
int index )
const override;
581 QColor
color(
double value )
const override;
588 static QString
typeString() {
return QStringLiteral(
"preset" ); }
590 QString
type()
const override;
593 QVariantMap properties() const override;
594 int count() const override;
596 QString schemeName()
const override {
return QStringLiteral(
"preset" ); }
597 QgsNamedColorList fetchColors(
const QString &context = QString(),
const QColor &baseColor = QColor() )
override;
606 #define DEFAULT_COLORBREWER_SCHEMENAME "Spectral"
607 #define DEFAULT_COLORBREWER_COLORS 5
627 bool inverted =
false );
637 double value(
int index )
const override;
638 QColor
color(
double value )
const override;
645 static QString
typeString() {
return QStringLiteral(
"colorbrewer" ); }
650 QVariantMap properties() const override;
651 int count()
const override {
return mColors; }
671 void setSchemeName(
const QString &schemeName ) { mSchemeName = schemeName; loadPalette(); }
679 void setColors(
int colors ) { mColors = colors; loadPalette(); }
685 static QStringList listSchemeNames();
693 static QList<int> listSchemeVariants(
const QString &schemeName );
707 #define DEFAULT_CPTCITY_SCHEMENAME "cb/div/BrBG_" //change this
708 #define DEFAULT_CPTCITY_VARIANTNAME "05"
727 bool inverted =
false,
728 bool doLoadFile =
true );
739 const QString &variantName = QString(),
bool inverted =
false,
740 bool doLoadFile =
true );
750 static QString
typeString() {
return QStringLiteral(
"cpt-city" ); }
752 QString
type()
const override;
760 QVariantMap properties() const override;
762 QString schemeName()
const {
return mSchemeName; }
767 void setSchemeName(
const QString &schemeName ) { mSchemeName = schemeName; mFileLoaded =
false; }
768 void setVariantName(
const QString &variantName ) { mVariantName = variantName; mFileLoaded =
false; }
769 void setVariantList(
const QStringList &variantList ) { mVariantList = variantList; }
770 void setName(
const QString &schemeName,
const QString &variantName = QString(),
const QStringList &variantList = QStringList() )
771 { mSchemeName = schemeName; mVariantName = variantName; mVariantList = variantList; mFileLoaded =
false; }
782 static QString fileNameForVariant(
const QString &schema,
const QString &variant )
SIP_SKIP;
784 QString fileName()
const;
788 QString copyingFileName()
const;
789 QString descFileName()
const;
796 bool mFileLoaded =
false;
797 bool mMultiStops =
false;
#define DEFAULT_COLORBREWER_SCHEMENAME
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_GRADIENT_COLOR2
void setInfo(const QgsStringMap &info)
Sets additional info to attach to the gradient ramp (e.g., authorship notes)
#define DEFAULT_RANDOM_VAL_MAX
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.
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
void invert() override
Inverts the ordering of the color ramp.
#define DEFAULT_COLORBREWER_COLORS
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.
#define DEFAULT_GRADIENT_COLOR1
void setSatMin(int val)
Sets the minimum saturation for generated colors.
bool isEditable() const override
Returns whether the color scheme is editable.
#define DEFAULT_RANDOM_SAT_MIN
void setHueMax(int val)
Sets the maximum hue for generated colors.
Totally random color ramp. Returns colors generated at random, but constrained to some hardcoded satu...
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.
void setDirection(Qgis::AngularDirection direction)
Sets the direction to traverse the color wheel using when interpolating hue-based color specification...
static QString typeString()
Returns the string identifier for QgsPresetSchemeColorRamp.
void setColor1(const QColor &color)
Sets the gradient start color.
int count() const override
Returns number of defined colors, or -1 if undefined.
#define DEFAULT_CPTCITY_SCHEMENAME
int valMax() const
Returns the maximum value for generated colors.
static QgsColorRamp * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsColorRamp from a map of properties.
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.
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.
QString schemeName() const
Returns the name of the color brewer color scheme.
Qgis::AngularDirection direction() const
Returns the direction to traverse the color wheel using when interpolating hue-based color specificat...
QString type() const override
Returns a string representing the color ramp type.
@ CounterClockwise
Counter-clockwise direction.
QString type() const override
Returns a string representing the color ramp type.
bool operator!=(const QgsGradientStop &other) const
void setCount(int val)
Sets the number of colors contained in the ramp.
#define DEFAULT_CPTCITY_VARIANTNAME
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
void setDirection(Qgis::AngularDirection direction)
Sets the direction to traverse the color wheel using when interpolating hue-based color specification...
#define DEFAULT_RANDOM_SAT_MAX
QList< QgsGradientStop > QgsGradientStopsList
List of gradient stops.
Qgis::AngularDirection direction() const
Returns the direction to traverse the color wheel using when interpolating hue-based color specificat...
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.
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.
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
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...
#define DEFAULT_RANDOM_HUE_MAX
virtual void invert()
Inverts the ordering of the color ramp.
QColor::Spec colorSpec() const
Returns the color specification in which the color component interpolation will occur.
#define DEFAULT_RANDOM_VAL_MIN
#define DEFAULT_RANDOM_COUNT
QgsGradientStopsList mStops
#define DEFAULT_RANDOM_HUE_MIN
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.
AngularDirection
Angular directions.
QColor::Spec colorSpec() const
Returns the color specification in which the color component interpolation will occur.