Skip to content

Commit

Permalink
[FEATURE] cpt-city catalog support in color ramp's gradient-only mode (
Browse files Browse the repository at this point in the history
…#3832)

cpt-city catalog ramps are now available for gradient-only:
- shapeburst fill
- gradient fill
- inner/outer glow effect
  • Loading branch information
nirvn authored Dec 4, 2016
1 parent e94a352 commit 08ee180
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/core/effects/qgsgloweffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgscolorramp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

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

Expand Down Expand Up @@ -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;
}

Expand Down
23 changes: 20 additions & 3 deletions src/core/symbology-ng/qgsfillsymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgscolorrampbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down

0 comments on commit 08ee180

Please sign in to comment.