QGIS API Documentation  2.13.0-Master
qgsvectorcolorrampv2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorcolorrampv2.cpp
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsvectorcolorrampv2.h"
17 #include "qgscolorbrewerpalette.h"
18 #include "qgscptcityarchive.h"
19 
20 #include "qgssymbollayerv2utils.h"
21 #include "qgsapplication.h"
22 #include "qgslogger.h"
23 
24 #include <stdlib.h> // for random()
25 #include <algorithm>
26 
27 #include <QTime>
28 
30 
31 static QColor _interpolate( const QColor& c1, const QColor& c2, const double value )
32 {
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() ) );
38 
39  return QColor::fromRgb( r, g, b, a );
40 }
41 
43 
45  bool discrete, const QgsGradientStopsList& stops )
46  : mColor1( color1 ), mColor2( color2 ), mDiscrete( discrete ), mStops( stops )
47 {
48 }
49 
51 {
52  // color1 and color2
55  if ( props.contains( "color1" ) )
56  color1 = QgsSymbolLayerV2Utils::decodeColor( props["color1"] );
57  if ( props.contains( "color2" ) )
58  color2 = QgsSymbolLayerV2Utils::decodeColor( props["color2"] );
59 
60  //stops
62  if ( props.contains( "stops" ) )
63  {
64  Q_FOREACH ( const QString& stop, props["stops"].split( ':' ) )
65  {
66  int i = stop.indexOf( ';' );
67  if ( i == -1 )
68  continue;
69 
70  QColor c = QgsSymbolLayerV2Utils::decodeColor( stop.mid( i + 1 ) );
71  stops.append( QgsGradientStop( stop.left( i ).toDouble(), c ) );
72  }
73  }
74 
75  // discrete vs. continuous
76  bool discrete = false;
77  if ( props.contains( "discrete" ) )
78  {
79  if ( props["discrete"] == "1" )
80  discrete = true;
81  }
82 
83  // search for information keys starting with "info_"
85  for ( QgsStringMap::const_iterator it = props.constBegin();
86  it != props.constEnd(); ++it )
87  {
88  if ( it.key().startsWith( "info_" ) )
89  info[ it.key().mid( 5 )] = it.value();
90  }
91 
92  QgsVectorGradientColorRampV2* r = new QgsVectorGradientColorRampV2( color1, color2, discrete, stops );
93  r->setInfo( info );
94  return r;
95 }
96 
98 {
99  if ( index <= 0 )
100  {
101  return 0;
102  }
103  else if ( index >= mStops.size() + 1 )
104  {
105  return 1;
106  }
107  else
108  {
109  return mStops[index-1].offset;
110  }
111 }
112 
114 {
115  if ( qgsDoubleNear( value, 0.0 ) || value < 0.0 )
116  {
117  return mColor1;
118  }
119  else if ( qgsDoubleNear( value, 1.0 ) || value > 1.0 )
120  {
121  return mColor2;
122  }
123  else if ( mStops.isEmpty() )
124  {
125  if ( mDiscrete )
126  return mColor1;
127 
128  return _interpolate( mColor1, mColor2, value );
129  }
130  else
131  {
132  double lower = 0, upper = 0;
133  QColor c1 = mColor1, c2;
134  for ( QgsGradientStopsList::const_iterator it = mStops.begin(); it != mStops.end(); ++it )
135  {
136  if ( it->offset > value )
137  {
138  if ( mDiscrete )
139  return c1;
140 
141  upper = it->offset;
142  c2 = it->color;
143 
144  return qgsDoubleNear( upper, lower ) ? c1 : _interpolate( c1, c2, ( value - lower ) / ( upper - lower ) );
145  }
146  lower = it->offset;
147  c1 = it->color;
148  }
149 
150  if ( mDiscrete )
151  return c1;
152 
153  upper = 1;
154  c2 = mColor2;
155  return qgsDoubleNear( upper, lower ) ? c1 : _interpolate( c1, c2, ( value - lower ) / ( upper - lower ) );
156  }
157 }
158 
160 {
162  mDiscrete, mStops );
163  r->setInfo( mInfo );
164  return r;
165 }
166 
168 {
169  QgsStringMap map;
170  map["color1"] = QgsSymbolLayerV2Utils::encodeColor( mColor1 );
171  map["color2"] = QgsSymbolLayerV2Utils::encodeColor( mColor2 );
172  if ( !mStops.isEmpty() )
173  {
174  QStringList lst;
175  for ( QgsGradientStopsList::const_iterator it = mStops.begin(); it != mStops.end(); ++it )
176  {
177  lst.append( QString( "%1;%2" ).arg( it->offset ).arg( QgsSymbolLayerV2Utils::encodeColor( it->color ) ) );
178  }
179  map["stops"] = lst.join( ":" );
180  }
181 
182  map["discrete"] = mDiscrete ? "1" : "0";
183 
185  it != mInfo.constEnd(); ++it )
186  {
187  map["info_" + it.key()] = it.value();
188  }
189 
190  return map;
191 }
193 {
194  if ( discrete == mDiscrete )
195  return;
196 
197  // if going to/from Discrete, re-arrange stops
198  // this will only work when stops are equally-spaced
199  QgsGradientStopsList newStops;
200  if ( discrete )
201  {
202  // re-arrange stops offset
203  int numStops = mStops.count() + 2;
204  int i = 1;
205  for ( QgsGradientStopsList::const_iterator it = mStops.constBegin();
206  it != mStops.constEnd(); ++it )
207  {
208  newStops.append( QgsGradientStop( static_cast< double >( i ) / numStops, it->color ) );
209  if ( i == numStops - 1 )
210  break;
211  i++;
212  }
213  // replicate last color
214  newStops.append( QgsGradientStop( static_cast< double >( i ) / numStops, mColor2 ) );
215  }
216  else
217  {
218  // re-arrange stops offset, remove duplicate last color
219  int numStops = mStops.count() + 2;
220  int i = 1;
221  for ( QgsGradientStopsList::const_iterator it = mStops.constBegin();
222  it != mStops.constEnd(); ++it )
223  {
224  newStops.append( QgsGradientStop( static_cast< double >( i ) / ( numStops - 2 ), it->color ) );
225  if ( i == numStops - 3 )
226  break;
227  i++;
228  }
229  }
230  mStops = newStops;
231  mDiscrete = discrete;
232 }
233 
235 {
236  //copy color ramp stops to a QGradient
239  if ( alpha < 1 )
240  {
241  color1.setAlpha( color1.alpha() * alpha );
242  color2.setAlpha( color2.alpha() * alpha );
243  }
244  gradient->setColorAt( 0, color1 );
245  gradient->setColorAt( 1, color2 );
246 
247  for ( QgsGradientStopsList::const_iterator it = mStops.constBegin();
248  it != mStops.constEnd(); ++it )
249  {
250  QColor rampColor = it->color;
251  if ( alpha < 1 )
252  {
253  rampColor.setAlpha( rampColor.alpha() * alpha );
254  }
255  gradient->setColorAt( it->offset, rampColor );
256  }
257 }
258 
259 
261 
262 
264  int satMin, int satMax, int valMin, int valMax )
265  : mCount( count )
266  , mHueMin( hueMin ), mHueMax( hueMax )
267  , mSatMin( satMin ), mSatMax( satMax )
268  , mValMin( valMin ), mValMax( valMax )
269 {
270  updateColors();
271 }
272 
274 {
279 
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();
287 
288  return new QgsVectorRandomColorRampV2( count, hueMin, hueMax, satMin, satMax, valMin, valMax );
289 }
290 
292 {
293  if ( mColors.size() < 1 ) return 0;
294  return static_cast< double >( index ) / ( mColors.size() - 1 );
295 }
296 
298 {
299  int colorCnt = mColors.count();
300  int colorIdx = static_cast< int >( value * ( colorCnt - 1 ) );
301 
302  if ( colorIdx >= 0 && colorIdx < colorCnt )
303  return mColors.at( colorIdx );
304 
305  return QColor();
306 }
307 
309 {
311 }
312 
314 {
315  QgsStringMap map;
316  map["count"] = QString::number( mCount );
317  map["hueMin"] = QString::number( mHueMin );
318  map["hueMax"] = QString::number( mHueMax );
319  map["satMin"] = QString::number( mSatMin );
320  map["satMax"] = QString::number( mSatMax );
321  map["valMin"] = QString::number( mValMin );
322  map["valMax"] = QString::number( mValMax );
323  return map;
324 }
325 
327  int hueMax, int hueMin, int satMax, int satMin, int valMax, int valMin )
328 {
329  int h, s, v;
330  QList<QColor> colors;
331 
332  //normalize values
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 );
339 
340  //start hue at random angle
341  double currentHueAngle = 360.0 * static_cast< double >( qrand() ) / RAND_MAX;
342 
343  colors.reserve( count );
344  for ( int i = 0; i < count; ++i )
345  {
346  //increment hue by golden ratio (approx 137.507 degrees)
347  //as this minimises hue nearness as count increases
348  //see http://basecase.org/env/on-rainbows for more details
349  currentHueAngle += 137.50776;
350  //scale hue to between hueMax and hueMin
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 );
354  colors.append( QColor::fromHsv( h, s, v ) );
355  }
356  return colors;
357 }
358 
360 {
362 }
363 
365 
367  : mTotalColorCount( 0 )
368 {
369 }
370 
372 {
373 
374 }
375 
377 {
378  return -1;
379 }
380 
381 double QgsRandomColorsV2::value( int index ) const
382 {
383  Q_UNUSED( index );
384  return 0.0;
385 }
386 
388 {
389  int minVal = 130;
390  int maxVal = 255;
391 
392  //if value is nan, then use last precalculated color
393  int colorIndex = ( !qIsNaN( value ) ? value : 1 ) * ( mTotalColorCount - 1 );
394  if ( mTotalColorCount >= 1 && mPrecalculatedColors.length() > colorIndex )
395  {
396  //use precalculated hue
397  return mPrecalculatedColors.at( colorIndex );
398  }
399 
400  //can't use precalculated hues, use a totally random hue
401  int h = static_cast< int >( 360.0 * qrand() / ( RAND_MAX + 1.0 ) );
402  int s = ( qrand() % ( DEFAULT_RANDOM_SAT_MAX - DEFAULT_RANDOM_SAT_MIN + 1 ) ) + DEFAULT_RANDOM_SAT_MIN;
403  int v = ( qrand() % ( maxVal - minVal + 1 ) ) + minVal;
404  return QColor::fromHsv( h, s, v );
405 }
406 
407 void QgsRandomColorsV2::setTotalColorCount( const int colorCount )
408 {
409  //calculate colors in advance, so that we can ensure they are more visually distinct than pure random colors
411  mTotalColorCount = colorCount;
412 
413  //This works ok for low color counts, but for > 10 or so colors there's still a good chance of
414  //similar colors being picked. TODO - investigate alternative "n-visually distinct color" routines
415 
416  //random offsets
417  double hueOffset = ( 360.0 * qrand() / ( RAND_MAX + 1.0 ) );
418 
419  //try to maximise difference between hues. this is not an ideal implementation, as constant steps
420  //through the hue wheel are not visually perceived as constant changes in hue
421  //(for instance, we are much more likely to get green hues than yellow hues)
422  double hueStep = 359.0 / colorCount;
423  double currentHue = hueOffset;
424 
425  //build up a list of colors
426  for ( int idx = 0; idx < colorCount; ++ idx )
427  {
428  int h = qRound( currentHue ) % 360;
429  int s = ( qrand() % ( DEFAULT_RANDOM_SAT_MAX - DEFAULT_RANDOM_SAT_MIN + 1 ) ) + DEFAULT_RANDOM_SAT_MIN;
430  int v = ( qrand() % ( DEFAULT_RANDOM_VAL_MAX - DEFAULT_RANDOM_VAL_MIN + 1 ) ) + DEFAULT_RANDOM_VAL_MIN;
432  currentHue += hueStep;
433  }
434 
435  //lastly, shuffle color list
436  std::random_shuffle( mPrecalculatedColors.begin(), mPrecalculatedColors.end() );
437 }
438 
440 {
441  return "randomcolors";
442 }
443 
445 {
446  return new QgsRandomColorsV2();
447 }
448 
450 {
451  return QgsStringMap();
452 }
453 
455 
457  : mSchemeName( schemeName ), mColors( colors )
458 {
459  loadPalette();
460 }
461 
463 {
466 
467  if ( props.contains( "schemeName" ) )
468  schemeName = props["schemeName"];
469  if ( props.contains( "colors" ) )
470  colors = props["colors"].toInt();
471 
472  return new QgsVectorColorBrewerColorRampV2( schemeName, colors );
473 }
474 
476 {
478 }
479 
481 {
483 }
484 
486 {
487  return QgsColorBrewerPalette::listSchemeVariants( schemeName );
488 }
489 
491 {
492  if ( mPalette.size() < 1 ) return 0;
493  return static_cast< double >( index ) / ( mPalette.size() - 1 );
494 }
495 
497 {
498  if ( mPalette.isEmpty() || value < 0 || value > 1 )
499  return QColor();
500 
501  int paletteEntry = static_cast< int >( value * mPalette.count() );
502  if ( paletteEntry >= mPalette.count() )
503  paletteEntry = mPalette.count() - 1;
504  return mPalette.at( paletteEntry );
505 }
506 
508 {
510 }
511 
513 {
514  QgsStringMap map;
515  map["schemeName"] = mSchemeName;
516  map["colors"] = QString::number( mColors );
517  return map;
518 }
519 
520 
522 
523 
525  bool doLoadFile )
527  , mSchemeName( schemeName ), mVariantName( variantName )
528  , mVariantList( QStringList() ), mFileLoaded( false ), mMultiStops( false )
529 {
530  // TODO replace this with hard-coded data in the default case
531  // don't load file if variant is missing
532  if ( doLoadFile && ( variantName != QString() || mVariantList.isEmpty() ) )
533  loadFile();
534 }
535 
537  const QString& variantName, bool doLoadFile )
539  , mSchemeName( schemeName ), mVariantName( variantName )
540  , mVariantList( variantList ), mFileLoaded( false ), mMultiStops( false )
541 {
543 
544  // TODO replace this with hard-coded data in the default case
545  // don't load file if variant is missing
546  if ( doLoadFile && ( variantName != QString() || mVariantList.isEmpty() ) )
547  loadFile();
548 }
549 
551 {
554 
555  if ( props.contains( "schemeName" ) )
556  schemeName = props["schemeName"];
557  if ( props.contains( "variantName" ) )
558  variantName = props["variantName"];
559 
560  return new QgsCptCityColorRampV2( schemeName, variantName );
561 }
562 
564 {
565  QgsCptCityColorRampV2* ramp = new QgsCptCityColorRampV2( "", "", false );
566  ramp->copy( this );
567  return ramp;
568 }
569 
571 {
572  if ( ! other )
573  return;
574  mColor1 = other->color1();
575  mColor2 = other->color2();
576  mDiscrete = other->isDiscrete();
577  mStops = other->stops();
578  mSchemeName = other->mSchemeName;
579  mVariantName = other->mVariantName;
580  mVariantList = other->mVariantList;
581  mFileLoaded = other->mFileLoaded;
582 }
583 
585 {
588  // add author and copyright information
589  // TODO also add COPYING.xml file/link?
591  info["cpt-city-gradient"] = "<cpt-city>/" + mSchemeName + mVariantName + ".svg";
592  QString copyingFilename = copyingFileName();
593  copyingFilename.remove( QgsCptCityArchive::defaultBaseDir() );
594  info["cpt-city-license"] = "<cpt-city>" + copyingFilename;
595  ramp->setInfo( info );
596  return ramp;
597 }
598 
599 
601 {
602  QgsStringMap map;
603  map["schemeName"] = mSchemeName;
604  map["variantName"] = mVariantName;
605  return map;
606 }
607 
608 
610 {
611  if ( mSchemeName == "" )
612  return QString();
613  else
614  {
616  }
617 }
618 
620 {
621  return QgsCptCityArchive::findFileName( "COPYING.xml", QFileInfo( fileName() ).dir().path(),
623 }
624 
626 {
627  return QgsCptCityArchive::findFileName( "DESC.xml", QFileInfo( fileName() ).dir().path(),
629 }
630 
632 {
634 }
635 
637 {
638  if ( mFileLoaded )
639  {
640  QgsDebugMsg( "File already loaded for " + mSchemeName + mVariantName );
641  return true;
642  }
643 
644  // get filename
645  QString filename = fileName();
646  if ( filename.isNull() )
647  {
648  QgsDebugMsg( "Couldn't get fileName() for " + mSchemeName + mVariantName );
649  return false;
650  }
651 
652  QgsDebugMsg( QString( "filename= %1 loaded=%2" ).arg( filename ).arg( mFileLoaded ) );
653 
654  // get color ramp from svg file
657 
658  // add colors to palette
659  mFileLoaded = false;
660  mStops.clear();
661  QMap<double, QPair<QColor, QColor> >::const_iterator it, prev;
662  // first detect if file is gradient is continuous or dicrete
663  // discrete: stop contains 2 colors and first color is identical to previous second
664  // multi: stop contains 2 colors and no relation with previous stop
665  mDiscrete = false;
666  mMultiStops = false;
667  it = prev = colorMap.constBegin();
668  while ( it != colorMap.constEnd() )
669  {
670  // look for stops that contain multiple values
671  if ( it != colorMap.constBegin() && ( it.value().first != it.value().second ) )
672  {
673  if ( it.value().first == prev.value().second )
674  {
675  mDiscrete = true;
676  break;
677  }
678  else
679  {
680  mMultiStops = true;
681  break;
682  }
683  }
684  prev = it;
685  ++it;
686  }
687 
688  // fill all stops
689  it = prev = colorMap.constBegin();
690  while ( it != colorMap.constEnd() )
691  {
692  if ( mDiscrete )
693  {
694  // mPalette << qMakePair( it.key(), it.value().second );
695  mStops.append( QgsGradientStop( it.key(), it.value().second ) );
696  }
697  else
698  {
699  // mPalette << qMakePair( it.key(), it.value().first );
700  mStops.append( QgsGradientStop( it.key(), it.value().first ) );
701  if (( mMultiStops ) &&
702  ( it.key() != 0.0 && it.key() != 1.0 ) )
703  {
704  mStops.append( QgsGradientStop( it.key(), it.value().second ) );
705  }
706  }
707  prev = it;
708  ++it;
709  }
710 
711  // remove first and last items (mColor1 and mColor2)
712  if ( ! mStops.isEmpty() && mStops.at( 0 ).offset == 0.0 )
713  mColor1 = mStops.takeFirst().color;
714  if ( ! mStops.isEmpty() && mStops.last().offset == 1.0 )
715  mColor2 = mStops.takeLast().color;
716 
717  mFileLoaded = true;
718  return true;
719 }
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
virtual QColor color(double value) const override
void clear()
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
static unsigned index
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 length() const
int count() const override
Returns number of defined colors, or -1 if undefined.
virtual QgsVectorColorBrewerColorRampV2 * clone() const override
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
void setColorAt(qreal position, const QColor &color)
void reserve(int alloc)
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
void setAlpha(int alpha)
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)
QChar separator()
QMap< QString, QString > QgsStringMap
Definition: qgis.h:384
#define DEFAULT_RANDOM_SAT_MAX
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Definition: qgis.h:285
int size() const
bool isNull() 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.
QColor fromRgb(QRgb rgb)
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
int red() const
static QColor _interpolate(const QColor &c1, const QColor &c2, const double value)
bool isEmpty() const
#define DEFAULT_GRADIENT_COLOR1
const_iterator constEnd() const
#define DEFAULT_RANDOM_VAL_MAX
QgsStringMap copyingInfo() const
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
int alpha() const
int green() const
iterator end()
#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 blue() const
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
T takeLast()
QString mid(int position, int n) const
virtual double value(int index) const override
Returns relative value between [0,1] of color at specified index.
T takeFirst()
#define DEFAULT_COLORBREWER_COLORS
static QStringList listSchemes()
const QgsGradientStopsList & stops() const
QColor color(double value) const override
T & last()
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
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
iterator begin()
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