31 static QColor
_interpolate(
const QColor& c1,
const QColor& c2,
const double value )
33 if ( qIsNaN( value ) )
return c2;
34 int r = ( int )( c1.red() + value * ( c2.red() - c1.red() ) );
35 int g = ( int )( c1.green() + value * ( c2.green() - c1.green() ) );
36 int b = ( int )( c1.blue() + value * ( c2.blue() - c1.blue() ) );
37 int a = ( int )( c1.alpha() + value * ( c2.alpha() - c1.alpha() ) );
39 return QColor::fromRgb( r, g, b, a );
46 : mColor1( color1 ), mColor2( color2 ), mDiscrete( discrete ), mStops( stops )
55 if ( props.contains(
"color1" ) )
57 if ( props.contains(
"color2" ) )
62 if ( props.contains(
"stops" ) )
64 foreach ( QString stop, props[
"stops"].split(
':' ) )
66 int i = stop.indexOf(
';' );
76 bool discrete =
false;
77 if ( props.contains(
"discrete" ) )
79 if ( props[
"discrete"] ==
"1" )
85 for ( QgsStringMap::const_iterator it = props.constBegin();
86 it != props.constEnd(); ++it )
88 if ( it.key().startsWith(
"info_" ) )
89 info[ it.key().mid( 5 )] = it.value();
103 else if ( index >=
mStops.size() + 1 )
109 return mStops[index-1].offset;
123 else if (
mStops.isEmpty() )
132 double lower = 0, upper = 0;
134 for ( QgsGradientStopsList::const_iterator it =
mStops.begin(); it !=
mStops.end(); ++it )
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 ) );
175 for ( QgsGradientStopsList::const_iterator it =
mStops.begin(); it !=
mStops.end(); ++it )
179 map[
"stops"] = lst.join(
":" );
184 for ( QgsStringMap::const_iterator it =
mInfo.constBegin();
185 it !=
mInfo.constEnd(); ++it )
187 map[
"info_" + it.key()] = it.value();
203 int numStops =
mStops.count() + 2;
205 for ( QgsGradientStopsList::const_iterator it =
mStops.begin();
206 it !=
mStops.end(); ++it )
208 newStops.append(
QgsGradientStop((
double ) i / numStops, it->color ) );
209 if ( i == numStops - 1 )
219 int numStops =
mStops.count() + 2;
221 for ( QgsGradientStopsList::const_iterator it =
mStops.begin();
222 it !=
mStops.end(); ++it )
224 newStops.append(
QgsGradientStop((
double ) i / ( numStops - 2 ), it->color ) );
225 if ( i == numStops - 3 )
241 color1.setAlpha( color1.alpha() * alpha );
242 color2.setAlpha( color2.alpha() * alpha );
244 gradient->setColorAt( 0, color1 );
245 gradient->setColorAt( 1, color2 );
247 for ( QgsGradientStopsList::const_iterator it =
mStops.begin();
248 it !=
mStops.end(); ++it )
250 QColor rampColor = it->color;
253 rampColor.setAlpha( rampColor.alpha() * alpha );
255 gradient->setColorAt( it->offset, rampColor );
264 int satMin,
int satMax,
int valMin,
int valMax )
265 : mCount( count ), mHueMin( hueMin ), mHueMax( hueMax ),
266 mSatMin( satMin ), mSatMax( satMax ), mValMin( valMin ), mValMax( valMax )
278 if ( props.contains(
"count" ) ) count = props[
"count"].toInt();
279 if ( props.contains(
"hueMin" ) ) hueMin = props[
"hueMin"].toInt();
280 if ( props.contains(
"hueMax" ) ) hueMax = props[
"hueMax"].toInt();
281 if ( props.contains(
"satMin" ) ) satMin = props[
"satMin"].toInt();
282 if ( props.contains(
"satMax" ) ) satMax = props[
"satMax"].toInt();
283 if ( props.contains(
"valMin" ) ) valMin = props[
"valMin"].toInt();
284 if ( props.contains(
"valMax" ) ) valMax = props[
"valMax"].toInt();
291 if (
mColors.size() < 1 )
return 0;
292 return index /
mColors.size() - 1;
297 int colorCnt =
mColors.count();
298 int colorIdx = ( int )( value * colorCnt );
300 if ( colorIdx >= 0 && colorIdx < colorCnt )
314 map[
"count"] = QString::number(
mCount );
315 map[
"hueMin"] = QString::number(
mHueMin );
316 map[
"hueMax"] = QString::number(
mHueMax );
317 map[
"satMin"] = QString::number(
mSatMin );
318 map[
"satMax"] = QString::number(
mSatMax );
319 map[
"valMin"] = QString::number(
mValMin );
320 map[
"valMax"] = QString::number(
mValMax );
325 int hueMax,
int hueMin,
int satMax,
int satMin,
int valMax,
int valMin )
328 QList<QColor> colors;
331 int safeHueMax = qMax( hueMin, hueMax );
332 int safeHueMin = qMin( hueMin, hueMax );
333 int safeSatMax = qMax( satMin, satMax );
334 int safeSatMin = qMin( satMin, satMax );
335 int safeValMax = qMax( valMin, valMax );
336 int safeValMin = qMin( valMin, valMax );
339 double currentHueAngle = 360.0 * ( double )qrand() / RAND_MAX;
341 for (
int i = 0; i <
count; i++ )
346 currentHueAngle += 137.50776;
348 h = qBound( 0, qRound(( fmod( currentHueAngle, 360.0 ) / 360.0 ) * ( safeHueMax - safeHueMin ) + safeHueMin ), 359 );
349 s = qBound( 0, ( qrand() % ( safeSatMax - safeSatMin + 1 ) ) + safeValMax, 255 );
350 v = qBound( 0, ( qrand() % ( safeValMax - safeValMin + 1 ) ) + safeValMin, 255 );
351 colors.append( QColor::fromHsv( h, s, v ) );
364 : mTotalColorCount( 0 )
390 int colorIndex = ( !qIsNaN( value ) ? value : 1 ) * (
mTotalColorCount - 1 );
398 int h = 1 + ( int )( 360.0 * qrand() / ( RAND_MAX + 1.0 ) );
400 int v = ( qrand() % ( maxVal - minVal + 1 ) ) + minVal;
401 return QColor::fromHsv( h, s, v );
414 double hueOffset = ( 360.0 * qrand() / ( RAND_MAX + 1.0 ) );
419 double hueStep = 359.0 / colorCount;
420 double currentHue = hueOffset;
423 for (
int idx = 0; idx < colorCount; ++ idx )
425 int h = qRound( currentHue ) % 360;
429 currentHue += hueStep;
438 return "randomcolors";
454 : mSchemeName( schemeName ), mColors( colors )
464 if ( props.contains(
"schemeName" ) )
465 schemeName = props[
"schemeName"];
466 if ( props.contains(
"colors" ) )
467 colors = props[
"colors"].toInt();
489 if (
mPalette.size() < 1 )
return 0;
495 if (
mPalette.isEmpty() || value < 0 || value > 1 )
496 return QColor( 255, 0, 0 );
498 int paletteEntry = ( int )( value *
mPalette.count() );
499 if ( paletteEntry >=
mPalette.count() )
500 paletteEntry =
mPalette.count() - 1;
513 map[
"colors"] = QString::number(
mColors );
524 mSchemeName( schemeName ), mVariantName( variantName ),
525 mVariantList( QStringList() ), mFileLoaded( false ), mMultiStops( false )
529 if ( doLoadFile && ( variantName != QString() ||
mVariantList.isEmpty() ) )
534 QString variantName,
bool doLoadFile )
536 mSchemeName( schemeName ), mVariantName( variantName ),
537 mVariantList( variantList ), mFileLoaded( false ), mMultiStops( false )
543 if ( doLoadFile && ( variantName != QString() ||
mVariantList.isEmpty() ) )
552 if ( props.contains(
"schemeName" ) )
553 schemeName = props[
"schemeName"];
554 if ( props.contains(
"variantName" ) )
555 variantName = props[
"variantName"];
591 info[
"cpt-city-license"] =
"<cpt-city>" + copyingFilename;
643 if ( filename.isNull() )
652 QMap< double, QPair<QColor, QColor> > colorMap =
658 QMap<double, QPair<QColor, QColor> >::const_iterator it, prev;
664 it = prev = colorMap.constBegin();
665 while ( it != colorMap.constEnd() )
668 if ( it != colorMap.constBegin() && ( it.value().first != it.value().second ) )
670 if ( it.value().first == prev.value().second )
686 it = prev = colorMap.constBegin();
687 while ( it != colorMap.constEnd() )
699 ( it.key() != 0.0 && it.key() != 1.0 ) )
709 if ( !
mStops.isEmpty() &&
mStops.first().offset == 0.0 )
711 if ( !
mStops.isEmpty() &&
mStops.last().offset == 1.0 )