31 int r = ( int )( c1.red() + value * ( c2.red() - c1.red() ) );
32 int g = ( int )( c1.green() + value * ( c2.green() - c1.green() ) );
33 int b = ( int )( c1.blue() + value * ( c2.blue() - c1.blue() ) );
34 int a = ( int )( c1.alpha() + value * ( c2.alpha() - c1.alpha() ) );
36 return QColor::fromRgb( r, g, b, a );
43 : mColor1( color1 ), mColor2( color2 ), mDiscrete( discrete ), mStops( stops )
52 if ( props.contains(
"color1" ) )
54 if ( props.contains(
"color2" ) )
59 if ( props.contains(
"stops" ) )
61 foreach ( QString stop, props[
"stops"].split(
':' ) )
63 int i = stop.indexOf(
';' );
73 bool discrete =
false;
74 if ( props.contains(
"discrete" ) )
76 if ( props[
"discrete"] ==
"1" )
82 for ( QgsStringMap::const_iterator it = props.constBegin();
83 it != props.constEnd(); ++it )
85 if ( it.key().startsWith(
"info_" ) )
86 info[ it.key().mid( 5 )] = it.value();
100 else if ( index >=
mStops.size() + 1 )
106 return mStops[index-1].offset;
120 double lower = 0, upper = 0;
122 for ( QgsGradientStopsList::const_iterator it =
mStops.begin(); it !=
mStops.end(); ++it )
124 if ( it->offset > value )
132 return upper == lower ? c1 :
_interpolate( c1, c2, ( value - lower ) / ( upper - lower ) );
143 return upper == lower ? c1 :
_interpolate( c1, c2, ( value - lower ) / ( upper - lower ) );
163 for ( QgsGradientStopsList::const_iterator it =
mStops.begin(); it !=
mStops.end(); ++it )
167 map[
"stops"] = lst.join(
":" );
172 for ( QgsStringMap::const_iterator it =
mInfo.constBegin();
173 it !=
mInfo.constEnd(); ++it )
175 map[
"info_" + it.key()] = it.value();
191 int numStops =
mStops.count() + 2;
193 for ( QgsGradientStopsList::const_iterator it =
mStops.begin();
194 it !=
mStops.end(); ++it )
196 newStops.append(
QgsGradientStop((
double ) i / numStops, it->color ) );
197 if ( i == numStops - 1 )
207 int numStops =
mStops.count() + 2;
209 for ( QgsGradientStopsList::const_iterator it =
mStops.begin();
210 it !=
mStops.end(); ++it )
212 newStops.append(
QgsGradientStop((
double ) i / ( numStops - 2 ), it->color ) );
213 if ( i == numStops - 3 )
229 color1.setAlpha( color1.alpha() * alpha );
230 color2.setAlpha( color2.alpha() * alpha );
232 gradient->setColorAt( 0, color1 );
233 gradient->setColorAt( 1, color2 );
235 for ( QgsGradientStopsList::const_iterator it =
mStops.begin();
236 it !=
mStops.end(); ++it )
238 QColor rampColor = it->color;
241 rampColor.setAlpha( rampColor.alpha() * alpha );
243 gradient->setColorAt( it->offset , rampColor );
252 int satMin,
int satMax,
int valMin,
int valMax )
253 : mCount( count ), mHueMin( hueMin ), mHueMax( hueMax ),
254 mSatMin( satMin ), mSatMax( satMax ), mValMin( valMin ), mValMax( valMax )
266 if ( props.contains(
"count" ) ) count = props[
"count"].toInt();
267 if ( props.contains(
"hueMin" ) ) hueMin = props[
"hueMin"].toInt();
268 if ( props.contains(
"hueMax" ) ) hueMax = props[
"hueMax"].toInt();
269 if ( props.contains(
"satMin" ) ) satMin = props[
"satMin"].toInt();
270 if ( props.contains(
"satMax" ) ) satMax = props[
"satMax"].toInt();
271 if ( props.contains(
"valMin" ) ) valMin = props[
"valMin"].toInt();
272 if ( props.contains(
"valMax" ) ) valMax = props[
"valMax"].toInt();
279 if (
mColors.size() < 1 )
return 0;
280 return index /
mColors.size() - 1;
285 int colorCnt =
mColors.count();
286 int colorIdx = ( int )( value * colorCnt );
288 if ( colorIdx >= 0 && colorIdx < colorCnt )
302 map[
"count"] = QString::number(
mCount );
303 map[
"hueMin"] = QString::number(
mHueMin );
304 map[
"hueMax"] = QString::number(
mHueMax );
305 map[
"satMin"] = QString::number(
mSatMin );
306 map[
"satMax"] = QString::number(
mSatMax );
307 map[
"valMin"] = QString::number(
mValMin );
308 map[
"valMax"] = QString::number(
mValMax );
313 int hueMax,
int hueMin,
int satMax,
int satMin,
int valMax,
int valMin )
316 QList<QColor> colors;
319 double currentHueAngle = 360.0 * ( double )rand() / RAND_MAX;
321 for (
int i = 0; i <
count; i++ )
326 currentHueAngle += 137.50776;
328 h = ( fmod( currentHueAngle, 360.0 ) / 360.0 ) * ( hueMax - hueMin ) +
hueMin;
329 s = ( rand() % ( satMax - satMin + 1 ) ) +
satMin;
330 v = ( rand() % ( valMax - valMin + 1 ) ) +
valMin;
331 colors.append( QColor::fromHsv( h, s, v ) );
345 srand( QTime::currentTime().msec() );
369 int h = 1 + ( int )( 360.0 * rand() / ( RAND_MAX + 1.0 ) );
371 int v = ( rand() % ( maxVal - minVal + 1 ) ) + minVal;
372 return QColor::fromHsv( h, s, v );
377 return "randomcolors";
393 : mSchemeName( schemeName ), mColors( colors )
403 if ( props.contains(
"schemeName" ) )
404 schemeName = props[
"schemeName"];
405 if ( props.contains(
"colors" ) )
406 colors = props[
"colors"].toInt();
428 if (
mPalette.size() < 1 )
return 0;
434 if (
mPalette.isEmpty() || value < 0 || value > 1 )
435 return QColor( 255, 0, 0 );
437 int paletteEntry = ( int )( value *
mPalette.count() );
438 if ( paletteEntry >=
mPalette.count() )
439 paletteEntry =
mPalette.count() - 1;
452 map[
"colors"] = QString::number(
mColors );
463 mSchemeName( schemeName ), mVariantName( variantName ),
464 mVariantList( QStringList() ), mFileLoaded( false ), mMultiStops( false )
468 if ( doLoadFile && ( variantName != QString() ||
mVariantList.isEmpty() ) )
473 QString variantName,
bool doLoadFile )
475 mSchemeName( schemeName ), mVariantName( variantName ),
476 mVariantList( variantList ), mFileLoaded( false ), mMultiStops( false )
482 if ( doLoadFile && ( variantName != QString() ||
mVariantList.isEmpty() ) )
491 if ( props.contains(
"schemeName" ) )
492 schemeName = props[
"schemeName"];
493 if ( props.contains(
"variantName" ) )
494 variantName = props[
"variantName"];
530 info[
"cpt-city-license"] =
"<cpt-city>" + copyingFilename;
582 if ( filename.isNull() )
591 QMap< double, QPair<QColor, QColor> > colorMap =
597 QMap<double, QPair<QColor, QColor> >::const_iterator it, prev;
603 it = prev = colorMap.constBegin();
604 while ( it != colorMap.constEnd() )
607 if ( it != colorMap.constBegin() && ( it.value().first != it.value().second ) )
609 if ( it.value().first == prev.value().second )
625 it = prev = colorMap.constBegin();
626 while ( it != colorMap.constEnd() )
638 ( it.key() != 0.0 && it.key() != 1.0 ) )
648 if ( !
mStops.isEmpty() &&
mStops.first().offset == 0.0 )
650 if ( !
mStops.isEmpty() &&
mStops.last().offset == 1.0 )
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
#define DEFAULT_CPTCITY_VARIANTNAME
double value(int index) const
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)
QgsVectorColorRampV2 * clone() const
static QString defaultBaseDir()
#define DEFAULT_COLORBREWER_SCHEMENAME
#define DEFAULT_RANDOM_HUE_MIN
static QColor _interpolate(QColor c1, QColor c2, double value)
void setInfo(const QgsStringMap &info)
static QList< int > listSchemeVariants(QString schemeName)
static QColor decodeColor(QString str)
#define DEFAULT_CPTCITY_SCHEMENAME
QMap< QString, QString > QgsStringMap
#define DEFAULT_RANDOM_SAT_MAX
QgsStringMap info() const
static QString encodeColor(QColor color)
virtual QgsStringMap properties() const
virtual QgsStringMap properties() const
QString variantName() const
virtual QColor color(double value) const
QStringList variantList() const
#define DEFAULT_GRADIENT_COLOR2
static QList< QColor > listSchemeColors(QString schemeName, int colors)
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)
QColor color(double value) const
#define DEFAULT_GRADIENT_COLOR1
#define DEFAULT_RANDOM_VAL_MAX
QgsStringMap copyingInfo() const
static QStringList listSchemeNames()
virtual double value(int index) const
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
virtual double value(int index) const
void convertToDiscrete(bool discrete)
virtual QgsStringMap properties() const
QString schemeName() const
#define DEFAULT_RANDOM_SAT_MIN
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
virtual QColor color(double value) const
virtual QgsVectorColorRampV2 * clone() const
QgsVectorGradientColorRampV2 * cloneGradientRamp() const
int ANALYSIS_EXPORT lower(int n, int i)
lower function
QList< QgsGradientStop > QgsGradientStopsList
virtual double value(int index) const
QString descFileName() const
#define DEFAULT_COLORBREWER_COLORS
static QStringList listSchemes()
const QgsGradientStopsList & stops() const
virtual QgsVectorColorRampV2 * clone() const
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
#define DEFAULT_RANDOM_HUE_MAX
virtual QgsVectorColorRampV2 * clone() const
QgsCptCityColorRampV2(QString schemeName=DEFAULT_CPTCITY_SCHEMENAME, QString variantName=DEFAULT_CPTCITY_VARIANTNAME, bool doLoadFile=true)
QgsStringMap properties() const
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)
virtual QColor color(double value) const
#define DEFAULT_RANDOM_VAL_MIN
QString schemeName() const
void addStopsToGradient(QGradient *gradient, double alpha=1)
copy color ramp stops to a QGradient
QgsGradientStopsList mStops
QString copyingFileName() const
#define DEFAULT_RANDOM_COUNT
static QString findFileName(const QString &target, const QString &startDir, const QString &baseDir)
virtual QgsVectorColorRampV2 * clone() const