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 )