33 if ( qIsNaN( value ) )
return c2;
34 int r =
static_cast< int >( c1.
red() + value * ( c2.
red() - c1.
red() ) );
35 int g =
static_cast< int >( c1.
green() + value * ( c2.
green() - c1.
green() ) );
36 int b =
static_cast< int >( c1.
blue() + value * ( c2.
blue() - c1.
blue() ) );
37 int a =
static_cast< int >( c1.
alpha() + value * ( c2.
alpha() - c1.
alpha() ) );
46 : mColor1( color1 ), mColor2( color2 ), mDiscrete( discrete ), mStops( stops )
64 Q_FOREACH (
const QString& stop, props[
"stops"].split(
':' ) )
76 bool discrete =
false;
79 if ( props[
"discrete"] ==
"1" )
88 if ( it.key().startsWith(
"info_" ) )
89 info[ it.key().mid( 5 )] = it.
value();
109 return mStops[index-1].offset;
132 double lower = 0, upper = 0;
136 if ( it->offset > value )
179 map[
"stops"] = lst.
join(
":" );
187 map[
"info_" + it.key()] = it.
value();
209 if ( i == numStops - 1 )
225 if ( i == numStops - 3 )
250 QColor rampColor = it->color;
255 gradient->
setColorAt( it->offset, rampColor );
264 int satMin,
int satMax,
int valMin,
int valMax )
266 , mHueMin( hueMin ), mHueMax( hueMax )
267 , mSatMin( satMin ), mSatMax( satMax )
268 , mValMin( valMin ), mValMax( valMax )
280 if ( props.
contains(
"count" ) ) count = props[
"count"].toInt();
281 if ( props.
contains(
"hueMin" ) ) hueMin = props[
"hueMin"].toInt();
282 if ( props.
contains(
"hueMax" ) ) hueMax = props[
"hueMax"].toInt();
283 if ( props.
contains(
"satMin" ) ) satMin = props[
"satMin"].toInt();
284 if ( props.
contains(
"satMax" ) ) satMax = props[
"satMax"].toInt();
285 if ( props.
contains(
"valMin" ) ) valMin = props[
"valMin"].toInt();
286 if ( props.
contains(
"valMax" ) ) valMax = props[
"valMax"].toInt();
300 int colorIdx =
static_cast< int >( value * ( colorCnt - 1 ) );
302 if ( colorIdx >= 0 && colorIdx < colorCnt )
333 int safeHueMax = qMax( hueMin, hueMax );
334 int safeHueMin = qMin( hueMin, hueMax );
335 int safeSatMax = qMax( satMin, satMax );
336 int safeSatMin = qMin( satMin, satMax );
337 int safeValMax = qMax( valMin, valMax );
338 int safeValMin = qMin( valMin, valMax );
341 double currentHueAngle = 360.0 *
static_cast< double >( qrand() ) / RAND_MAX;
344 for (
int i = 0; i <
count; ++i )
349 currentHueAngle += 137.50776;
351 h = qBound( 0, qRound(( fmod( currentHueAngle, 360.0 ) / 360.0 ) * ( safeHueMax - safeHueMin ) + safeHueMin ), 359 );
352 s = qBound( 0, ( qrand() % ( safeSatMax - safeSatMin + 1 ) ) + safeSatMin, 255 );
353 v = qBound( 0, ( qrand() % ( safeValMax - safeValMin + 1 ) ) + safeValMin, 255 );
367 : mTotalColorCount( 0 )
393 int colorIndex = ( !qIsNaN( value ) ? value : 1 ) * (
mTotalColorCount - 1 );
401 int h =
static_cast< int >( 360.0 * qrand() / ( RAND_MAX + 1.0 ) );
403 int v = ( qrand() % ( maxVal - minVal + 1 ) ) + minVal;
417 double hueOffset = ( 360.0 * qrand() / ( RAND_MAX + 1.0 ) );
422 double hueStep = 359.0 / colorCount;
423 double currentHue = hueOffset;
426 for (
int idx = 0; idx < colorCount; ++ idx )
428 int h = qRound( currentHue ) % 360;
432 currentHue += hueStep;
441 return "randomcolors";
457 : mSchemeName( schemeName ), mColors( colors )
467 if ( props.
contains(
"schemeName" ) )
468 schemeName = props[
"schemeName"];
470 colors = props[
"colors"].toInt();
501 int paletteEntry =
static_cast< int >( value *
mPalette.
count() );
527 ,
mSchemeName( schemeName ), mVariantName( variantName )
528 , mVariantList(
QStringList() ), mFileLoaded( false ), mMultiStops( false )
555 if ( props.
contains(
"schemeName" ) )
556 schemeName = props[
"schemeName"];
557 if ( props.
contains(
"variantName" ) )
558 variantName = props[
"variantName"];
594 info[
"cpt-city-license"] =
"<cpt-city>" + copyingFilename;
673 if ( it.
value().first == prev.
value().second )
702 ( it.
key() != 0.0 && it.
key() != 1.0 ) )
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
virtual QColor color(double value) const override
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
int count() const override
Returns number of defined colors, or -1 if undefined.
QgsRandomColorsV2 * clone() const override
bool contains(const Key &key) const
#define DEFAULT_CPTCITY_VARIANTNAME
virtual QgsVectorRandomColorRampV2 * clone() const override
void copy(const QgsCptCityColorRampV2 *other)
int count() const override
Returns number of defined colors, or -1 if undefined.
virtual QgsVectorColorBrewerColorRampV2 * clone() const override
void setColorAt(qreal position, const QColor &color)
static QString defaultBaseDir()
static QString encodeColor(const QColor &color)
#define DEFAULT_COLORBREWER_SCHEMENAME
#define DEFAULT_RANDOM_HUE_MIN
const_iterator constBegin() const
const T & at(int i) const
void setInfo(const QgsStringMap &info)
virtual QgsVectorGradientColorRampV2 * clone() const override
virtual QgsCptCityColorRampV2 * clone() const override
virtual void setTotalColorCount(const int colorCount)
Sets the desired total number of unique colors for the resultant ramp.
QString join(const QString &separator) const
QString & remove(int position, int n)
#define DEFAULT_CPTCITY_SCHEMENAME
double toDouble(bool *ok) const
static QList< QColor > listSchemeColors(const QString &schemeName, int colors)
QMap< QString, QString > QgsStringMap
#define DEFAULT_RANDOM_SAT_MAX
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
QgsStringMap info() const
QgsCptCityColorRampV2(const QString &schemeName=DEFAULT_CPTCITY_SCHEMENAME, const QString &variantName=DEFAULT_CPTCITY_VARIANTNAME, bool doLoadFile=true)
QColor fromHsv(int h, int s, int v, int a)
static QList< int > listSchemeVariants(const QString &schemeName)
virtual QgsStringMap properties() const override
virtual int count() const override
Returns number of defined colors, or -1 if undefined.
QString variantName() const
QString number(int n, int base)
int count(const T &value) const
void append(const T &value)
QStringList variantList() const
#define DEFAULT_GRADIENT_COLOR2
virtual QgsStringMap properties() const override
QgsVectorRandomColorRampV2(int count=DEFAULT_RANDOM_COUNT, int hueMin=DEFAULT_RANDOM_HUE_MIN, int hueMax=DEFAULT_RANDOM_HUE_MAX, int satMin=DEFAULT_RANDOM_SAT_MIN, int satMax=DEFAULT_RANDOM_SAT_MAX, int valMin=DEFAULT_RANDOM_VAL_MIN, int valMax=DEFAULT_RANDOM_VAL_MAX)
virtual QColor color(double value) const override
static QColor _interpolate(const QColor &c1, const QColor &c2, const double value)
#define DEFAULT_GRADIENT_COLOR1
const_iterator constEnd() const
#define DEFAULT_RANDOM_VAL_MAX
QgsStringMap copyingInfo() const
static QStringList listSchemeNames()
virtual QgsStringMap properties() const override
static QMap< QString, QString > copyingInfo(const QString &fileName)
static QList< QColor > randomColors(int count, int hueMax=DEFAULT_RANDOM_HUE_MAX, int hueMin=DEFAULT_RANDOM_HUE_MIN, int satMax=DEFAULT_RANDOM_SAT_MAX, int satMin=DEFAULT_RANDOM_SAT_MIN, int valMax=DEFAULT_RANDOM_VAL_MAX, int valMin=DEFAULT_RANDOM_VAL_MIN)
Get a list of random colors.
QgsVectorGradientColorRampV2(const QColor &color1=DEFAULT_GRADIENT_COLOR1, const QColor &color2=DEFAULT_GRADIENT_COLOR2, bool discrete=false, const QgsGradientStopsList &stops=QgsGradientStopsList())
virtual QgsStringMap properties() const override
QString type() const override
void convertToDiscrete(bool discrete)
QString schemeName() const
#define DEFAULT_RANDOM_SAT_MIN
virtual double value(int index) const override
Returns relative value between [0,1] of color at specified index.
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
QgsStringMap properties() const override
virtual QColor color(double value) const override
const Key key(const T &value) const
QgsVectorGradientColorRampV2 * cloneGradientRamp() const
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
QString mid(int position, int n) const
QString descFileName() const
virtual double value(int index) const override
Returns relative value between [0,1] of color at specified index.
#define DEFAULT_COLORBREWER_COLORS
static QStringList listSchemes()
const QgsGradientStopsList & stops() const
QColor color(double value) const override
double value(int index) const override
Returns relative value between [0,1] of color at specified index.
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
QList< QColor > mPrecalculatedColors
#define DEFAULT_RANDOM_HUE_MAX
QString left(int n) const
QgsVectorColorBrewerColorRampV2(const QString &schemeName=DEFAULT_COLORBREWER_SCHEMENAME, int colors=DEFAULT_COLORBREWER_COLORS)
static QColor decodeColor(const QString &str)
static QList< int > listSchemeVariants(const QString &schemeName)
virtual double value(int index) const override
Returns relative value between [0,1] of color at specified index.
static QMap< double, QPair< QColor, QColor > > gradientColorMap(const QString &fileName)
const_iterator constEnd() const
const_iterator constBegin() const
#define DEFAULT_RANDOM_VAL_MIN
QString schemeName() const
void addStopsToGradient(QGradient *gradient, double alpha=1)
Copy color ramp stops to a QGradient.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QgsGradientStopsList mStops
QString copyingFileName() const
#define DEFAULT_RANDOM_COUNT
static QString findFileName(const QString &target, const QString &startDir, const QString &baseDir)
const T value(const Key &key) const