Skip to content
Permalink
Browse files

Fix gradient fills using color ramps not respecting symbol transparency

  • Loading branch information
nyalldawson committed Mar 21, 2014
1 parent 6685932 commit a0c2c7aaad922c74e2341f509effea01f1208634
@@ -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
@@ -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
{
@@ -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 );
}
}

@@ -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;

0 comments on commit a0c2c7a

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