33 if ( qIsNaN( value ) )
return c2;
34 int r = ( int )( c1.
red() + value * ( c2.
red() - c1.
red() ) );
36 int b = ( int )( c1.
blue() + value * ( c2.
blue() - c1.
blue() ) );
46 : mColor1( color1 ), mColor2( color2 ), mDiscrete( discrete ), mStops( stops )
64 foreach (
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 )
144 return upper == lower ? c1 :
_interpolate( c1, c2, ( value - lower ) / ( upper - lower ) );
155 return upper == lower ? c1 :
_interpolate( c1, c2, ( value - lower ) / ( upper - lower ) );
179 map[
"stops"] = lst.
join(
":" );
187 map[
"info_" + it.key()] = it.
value();
205 for ( QgsGradientStopsList::const_iterator it =
mStops.
begin();
209 if ( i == numStops - 1 )
221 for ( QgsGradientStopsList::const_iterator it =
mStops.
begin();
225 if ( i == numStops - 3 )
247 for ( QgsGradientStopsList::const_iterator it =
mStops.
begin();
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 = ( int )( value * ( colorCnt - 1 ) );
302 if ( colorIdx >= 0 && colorIdx < colorCnt )
327 int hueMax,
int hueMin,
int satMax,
int satMin,
int valMax,
int valMin )
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 * ( double )qrand() / RAND_MAX;
343 for (
int i = 0; i <
count; i++ )
348 currentHueAngle += 137.50776;
350 h = qBound( 0, qRound(( fmod( currentHueAngle, 360.0 ) / 360.0 ) * ( safeHueMax - safeHueMin ) + safeHueMin ), 359 );
351 s = qBound( 0, ( qrand() % ( safeSatMax - safeSatMin + 1 ) ) + safeSatMin, 255 );
352 v = qBound( 0, ( qrand() % ( safeValMax - safeValMin + 1 ) ) + safeValMin, 255 );
366 : mTotalColorCount( 0 )
392 int colorIndex = ( !qIsNaN( value ) ? value : 1 ) * (
mTotalColorCount - 1 );
400 int h = ( int )( 360.0 * qrand() / ( RAND_MAX + 1.0 ) );
402 int v = ( qrand() % ( maxVal - minVal + 1 ) ) + minVal;
416 double hueOffset = ( 360.0 * qrand() / ( RAND_MAX + 1.0 ) );
421 double hueStep = 359.0 / colorCount;
422 double currentHue = hueOffset;
425 for (
int idx = 0; idx < colorCount; ++ idx )
427 int h = qRound( currentHue ) % 360;
431 currentHue += hueStep;
440 return "randomcolors";
456 : mSchemeName( schemeName ), mColors( colors )
466 if ( props.
contains(
"schemeName" ) )
467 schemeName = props[
"schemeName"];
469 colors = props[
"colors"].toInt();
498 return QColor( 255, 0, 0 );
526 , mSchemeName( schemeName ), mVariantName( variantName )
527 , mVariantList(
QStringList() ), mFileLoaded( false ), mMultiStops( false )
536 QString variantName,
bool doLoadFile )
538 , mSchemeName( schemeName ), mVariantName( variantName )
539 , mVariantList( variantList ), mFileLoaded( false ), mMultiStops( false )
554 if ( props.
contains(
"schemeName" ) )
555 schemeName = props[
"schemeName"];
556 if ( props.
contains(
"variantName" ) )
557 variantName = props[
"variantName"];
593 info[
"cpt-city-license"] =
"<cpt-city>" + copyingFilename;
672 if ( it.
value().first == prev.
value().second )
701 ( 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.
virtual QgsVectorColorRampV2 * clone() const override
bool contains(const Key &key) const
#define DEFAULT_CPTCITY_VARIANTNAME
QgsVectorGradientColorRampV2(QColor color1=DEFAULT_GRADIENT_COLOR1, QColor color2=DEFAULT_GRADIENT_COLOR2, bool discrete=false, QgsGradientStopsList stops=QgsGradientStopsList())
void copy(const QgsCptCityColorRampV2 *other)
static QList< int > listSchemeVariants(QString schemeName)
int count() const override
Returns number of defined colors, or -1 if undefined.
void setColorAt(qreal position, const QColor &color)
static QString defaultBaseDir()
#define DEFAULT_COLORBREWER_SCHEMENAME
#define DEFAULT_RANDOM_HUE_MIN
const_iterator constBegin() const
const T & at(int i) const
QgsVectorColorRampV2 * clone() const override
void setInfo(const QgsStringMap &info)
static QList< int > listSchemeVariants(QString schemeName)
virtual void setTotalColorCount(const int colorCount)
Sets the desired total number of unique colors for the resultant ramp.
static QColor decodeColor(QString str)
QString join(const QString &separator) const
QString & remove(int position, int n)
#define DEFAULT_CPTCITY_SCHEMENAME
double toDouble(bool *ok) const
QMap< QString, QString > QgsStringMap
#define DEFAULT_RANDOM_SAT_MAX
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
QgsStringMap info() const
static QString encodeColor(QColor color)
QColor fromHsv(int h, int s, int v, int a)
virtual QgsStringMap properties() const override
QString variantName() const
QString number(int n, int base)
int count(const T &value) const
void append(const T &value)
QStringList variantList() const
virtual QgsVectorColorRampV2 * clone() const override
#define DEFAULT_GRADIENT_COLOR2
static QList< QColor > listSchemeColors(QString schemeName, int colors)
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
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.
virtual QgsVectorColorRampV2 * clone() const override
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
QgsCptCityColorRampV2(QString schemeName=DEFAULT_CPTCITY_SCHEMENAME, QString variantName=DEFAULT_CPTCITY_VARIANTNAME, bool doLoadFile=true)
virtual QgsVectorColorRampV2 * clone() const override
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)
note not available in python bindings
QgsVectorColorBrewerColorRampV2(QString schemeName=DEFAULT_COLORBREWER_SCHEMENAME, int colors=DEFAULT_COLORBREWER_COLORS)
#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