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 )
226 int satMin,
int satMax,
int valMin,
int valMax )
227 : mCount( count ), mHueMin( hueMin ), mHueMax( hueMax ),
228 mSatMin( satMin ), mSatMax( satMax ), mValMin( valMin ), mValMax( valMax )
240 if ( props.contains(
"count" ) ) count = props[
"count"].toInt();
241 if ( props.contains(
"hueMin" ) ) hueMin = props[
"hueMin"].toInt();
242 if ( props.contains(
"hueMax" ) ) hueMax = props[
"hueMax"].toInt();
243 if ( props.contains(
"satMin" ) ) satMin = props[
"satMin"].toInt();
244 if ( props.contains(
"satMax" ) ) satMax = props[
"satMax"].toInt();
245 if ( props.contains(
"valMin" ) ) valMin = props[
"valMin"].toInt();
246 if ( props.contains(
"valMax" ) ) valMax = props[
"valMax"].toInt();
253 if (
mColors.size() < 1 )
return 0;
254 return index /
mColors.size() - 1;
259 int colorCnt =
mColors.count();
260 int colorIdx = ( int )( value * colorCnt );
262 if ( colorIdx >= 0 && colorIdx < colorCnt )
276 map[
"count"] = QString::number(
mCount );
277 map[
"hueMin"] = QString::number(
mHueMin );
278 map[
"hueMax"] = QString::number(
mHueMax );
279 map[
"satMin"] = QString::number(
mSatMin );
280 map[
"satMax"] = QString::number(
mSatMax );
281 map[
"valMin"] = QString::number(
mValMin );
282 map[
"valMax"] = QString::number(
mValMax );
292 double currentHueAngle = 360.0 * ( double )rand() / RAND_MAX;
294 for (
int i = 0; i <
mCount; i++ )
299 currentHueAngle += 137.50776;
304 mColors.append( QColor::fromHsv( h, s, v ) );
312 : mSchemeName( schemeName ), mColors( colors )
322 if ( props.contains(
"schemeName" ) )
323 schemeName = props[
"schemeName"];
324 if ( props.contains(
"colors" ) )
325 colors = props[
"colors"].toInt();
347 if (
mPalette.size() < 1 )
return 0;
353 if (
mPalette.isEmpty() || value < 0 || value > 1 )
354 return QColor( 255, 0, 0 );
356 int paletteEntry = ( int )( value *
mPalette.count() );
357 if ( paletteEntry >=
mPalette.count() )
358 paletteEntry =
mPalette.count() - 1;
371 map[
"colors"] = QString::number(
mColors );
382 mSchemeName( schemeName ), mVariantName( variantName ),
383 mVariantList( QStringList() ), mFileLoaded( false ), mMultiStops( false )
387 if ( doLoadFile && ( variantName != QString() ||
mVariantList.isEmpty() ) )
392 QString variantName,
bool doLoadFile )
394 mSchemeName( schemeName ), mVariantName( variantName ),
395 mVariantList( variantList ), mFileLoaded( false ), mMultiStops( false )
401 if ( doLoadFile && ( variantName != QString() ||
mVariantList.isEmpty() ) )
410 if ( props.contains(
"schemeName" ) )
411 schemeName = props[
"schemeName"];
412 if ( props.contains(
"variantName" ) )
413 variantName = props[
"variantName"];
449 info[
"cpt-city-license"] =
"<cpt-city>" + copyingFilename;
501 if ( filename.isNull() )
510 QMap< double, QPair<QColor, QColor> > colorMap =
516 QMap<double, QPair<QColor, QColor> >::const_iterator it, prev;
522 it = prev = colorMap.constBegin();
523 while ( it != colorMap.constEnd() )
526 if ( it != colorMap.constBegin() && ( it.value().first != it.value().second ) )
528 if ( it.value().first == prev.value().second )
544 it = prev = colorMap.constBegin();
545 while ( it != colorMap.constEnd() )
557 ( it.key() != 0.0 && it.key() != 1.0 ) )
567 if ( !
mStops.isEmpty() &&
mStops.first().offset == 0.0 )
569 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
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)
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)
#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)
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)
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
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