Skip to content

Commit

Permalink
Fix gradient fills using color ramps not respecting symbol transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 21, 2014
1 parent 6685932 commit a0c2c7a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgsvectorcolorrampv2.sip
Expand Up @@ -83,7 +83,7 @@ class QgsVectorGradientColorRampV2 : QgsVectorColorRampV2

/**copy color ramp stops to a QGradient
* @note added in 2.1 */
void addStopsToGradient( QGradient* gradient );
void addStopsToGradient( QGradient* gradient, double alpha = 1 );
};

class QgsVectorRandomColorRampV2 : QgsVectorColorRampV2
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -678,7 +678,7 @@ void QgsGradientFillSymbolLayerV2::applyGradient( const QgsSymbolV2RenderContext
{
//color ramp gradient
QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>( gradientRamp );
gradRamp->addStopsToGradient( &gradient );
gradRamp->addStopsToGradient( &gradient, context.alpha() );
}
else
{
Expand Down
20 changes: 16 additions & 4 deletions src/core/symbology-ng/qgsvectorcolorrampv2.cpp
Expand Up @@ -219,16 +219,28 @@ void QgsVectorGradientColorRampV2::convertToDiscrete( bool discrete )
mDiscrete = discrete;
}

void QgsVectorGradientColorRampV2::addStopsToGradient( QGradient* gradient )
void QgsVectorGradientColorRampV2::addStopsToGradient( QGradient* gradient, double alpha )
{
//copy color ramp stops to a QGradient
gradient->setColorAt( 0, mColor1 );
gradient->setColorAt( 1, mColor2 );
QColor color1 = mColor1;
QColor color2 = mColor2;
if ( alpha < 1 )
{
color1.setAlpha( color1.alpha() * alpha );
color2.setAlpha( color2.alpha() * alpha );
}
gradient->setColorAt( 0, color1 );
gradient->setColorAt( 1, color2 );

for ( QgsGradientStopsList::const_iterator it = mStops.begin();
it != mStops.end(); ++it )
{
gradient->setColorAt( it->offset , it->color );
QColor rampColor = it->color;
if ( alpha < 1 )
{
rampColor.setAlpha( rampColor.alpha() * alpha );
}
gradient->setColorAt( it->offset , rampColor );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsvectorcolorrampv2.h
Expand Up @@ -94,7 +94,7 @@ class CORE_EXPORT QgsVectorGradientColorRampV2 : public QgsVectorColorRampV2

/**copy color ramp stops to a QGradient
* @note added in 2.1 */
void addStopsToGradient( QGradient* gradient );
void addStopsToGradient( QGradient* gradient, double alpha = 1 );

protected:
QColor mColor1, mColor2;
Expand Down

0 comments on commit a0c2c7a

Please sign in to comment.