Skip to content
Permalink
Browse files

[FEATURE] cpt-city catalog support in color ramp's gradient-only mode (

…#3832)

cpt-city catalog ramps are now available for gradient-only:
- shapeburst fill
- gradient fill
- inner/outer glow effect
  • Loading branch information
nirvn committed Dec 4, 2016
1 parent e94a352 commit 08ee1806a63fdb6b0360eca85fb048be3981bc54
@@ -176,7 +176,14 @@ void QgsGlowEffect::readProperties( const QgsStringMap &props )

//attempt to create color ramp from props
delete mRamp;
mRamp = QgsGradientColorRamp::create( props );
if ( props.contains( QStringLiteral( "gradientType" ) ) && props[QStringLiteral( "gradientType" )] == QStringLiteral( "cpt-city" ) )
{
mRamp = QgsCptCityColorRamp::create( props );
}
else
{
mRamp = QgsGradientColorRamp::create( props );
}
}

void QgsGlowEffect::setRamp( QgsColorRamp *ramp )
@@ -218,6 +218,7 @@ QgsStringMap QgsGradientColorRamp::properties() const
map["info_" + it.key()] = it.value();
}

map[QStringLiteral( "gradientType" )] = type();
return map;
}
void QgsGradientColorRamp::convertToDiscrete( bool discrete )
@@ -367,6 +368,7 @@ QgsStringMap QgsLimitedRandomColorRamp::properties() const
map[QStringLiteral( "satMax" )] = QString::number( mSatMax );
map[QStringLiteral( "valMin" )] = QString::number( mValMin );
map[QStringLiteral( "valMax" )] = QString::number( mValMax );
map[QStringLiteral( "gradientType" )] = type();
return map;
}

@@ -584,6 +586,7 @@ QgsStringMap QgsColorBrewerColorRamp::properties() const
map[QStringLiteral( "schemeName" )] = mSchemeName;
map[QStringLiteral( "colors" )] = QString::number( mColors );
map[QStringLiteral( "inverted" )] = QString::number( mInverted );
map[QStringLiteral( "gradientType" )] = type();
return map;
}

@@ -672,6 +675,7 @@ QgsStringMap QgsCptCityColorRamp::properties() const
QgsStringMap map;
map[QStringLiteral( "schemeName" )] = mSchemeName;
map[QStringLiteral( "variantName" )] = mVariantName;
map[QStringLiteral( "gradientType" )] = type();
return map;
}

@@ -886,6 +890,7 @@ QgsStringMap QgsPresetSchemeColorRamp::properties() const
props.insert( QStringLiteral( "preset_color_%1" ).arg( i ), QgsSymbolLayerUtils::encodeColor( mColors.at( i ).first ) );
props.insert( QStringLiteral( "preset_color_name_%1" ).arg( i ), mColors.at( i ).second );
}
props[QStringLiteral( "gradientType" )] = type();
return props;
}

@@ -538,7 +538,15 @@ QgsSymbolLayer* QgsGradientFillSymbolLayer::create( const QgsStringMap& props )
offset = QgsSymbolLayerUtils::decodePoint( props[QStringLiteral( "offset" )] );

//attempt to create color ramp from props
QgsColorRamp* gradientRamp = QgsGradientColorRamp::create( props );
QgsColorRamp* gradientRamp;
if ( props.contains( QStringLiteral( "gradientType" ) ) && props[QStringLiteral( "gradientType" )] == QStringLiteral( "cpt-city" ) )
{
gradientRamp = QgsCptCityColorRamp::create( props );
}
else
{
gradientRamp = QgsGradientColorRamp::create( props );
}

//create a new gradient fill layer with desired properties
QgsGradientFillSymbolLayer* sl = new QgsGradientFillSymbolLayer( color, color2, colorType, type, coordinateMode, gradientSpread );
@@ -815,7 +823,8 @@ void QgsGradientFillSymbolLayer::applyGradient( const QgsSymbolRenderContext &co
}

//add stops to gradient
if ( gradientColorType == QgsGradientFillSymbolLayer::ColorRamp && gradientRamp && gradientRamp->type() == QLatin1String( "gradient" ) )
if ( gradientColorType == QgsGradientFillSymbolLayer::ColorRamp && gradientRamp &&
( gradientRamp->type() == QLatin1String( "gradient" ) || gradientRamp->type() == QLatin1String( "cpt-city" ) ) )
{
//color ramp gradient
QgsGradientColorRamp* gradRamp = static_cast<QgsGradientColorRamp*>( gradientRamp );
@@ -1017,7 +1026,15 @@ QgsSymbolLayer* QgsShapeburstFillSymbolLayer::create( const QgsStringMap& props
}

//attempt to create color ramp from props
QgsColorRamp* gradientRamp = QgsGradientColorRamp::create( props );
QgsColorRamp* gradientRamp;
if ( props.contains( QStringLiteral( "gradientType" ) ) && props["gradientType"] == QStringLiteral( "cpt-city" ) )
{
gradientRamp = QgsCptCityColorRamp::create( props );
}
else
{
gradientRamp = QgsGradientColorRamp::create( props );
}

//create a new shapeburst fill layer with desired properties
QgsShapeburstFillSymbolLayer* sl = new QgsShapeburstFillSymbolLayer( color, color2, colorType, blurRadius, useWholeShape, maxDistance );
@@ -278,7 +278,7 @@ void QgsColorRampButton::prepareMenu()
{
QScopedPointer< QgsColorRamp > ramp( mStyle->colorRamp( *it ) );

if ( !mShowGradientOnly || ramp->type() == QLatin1String( "gradient" ) )
if ( !mShowGradientOnly || ( ramp->type() == QLatin1String( "gradient" ) || ramp->type() == QLatin1String( "cpt-city" ) ) )
{
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), QSize( 16, 16 ) );
QAction* ra = new QAction( *it, this );
@@ -298,7 +298,7 @@ void QgsColorRampButton::prepareMenu()
{
QScopedPointer< QgsColorRamp > ramp( mStyle->colorRamp( *it ) );

if ( !mShowGradientOnly || ramp->type() == QLatin1String( "gradient" ) )
if ( !mShowGradientOnly || ( ramp->type() == QLatin1String( "gradient" ) || ramp->type() == QLatin1String( "cpt-city" ) ) )
{
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), QSize( 16, 16 ) );
QAction* ra = new QAction( *it, this );

0 comments on commit 08ee180

Please sign in to comment.
You can’t perform that action at this time.