Skip to content

Commit a0c2c7a

Browse files
committedMar 21, 2014
Fix gradient fills using color ramps not respecting symbol transparency
1 parent 6685932 commit a0c2c7a

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed
 

‎python/core/symbology-ng/qgsvectorcolorrampv2.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class QgsVectorGradientColorRampV2 : QgsVectorColorRampV2
8383

8484
/**copy color ramp stops to a QGradient
8585
* @note added in 2.1 */
86-
void addStopsToGradient( QGradient* gradient );
86+
void addStopsToGradient( QGradient* gradient, double alpha = 1 );
8787
};
8888

8989
class QgsVectorRandomColorRampV2 : QgsVectorColorRampV2

‎src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ void QgsGradientFillSymbolLayerV2::applyGradient( const QgsSymbolV2RenderContext
678678
{
679679
//color ramp gradient
680680
QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>( gradientRamp );
681-
gradRamp->addStopsToGradient( &gradient );
681+
gradRamp->addStopsToGradient( &gradient, context.alpha() );
682682
}
683683
else
684684
{

‎src/core/symbology-ng/qgsvectorcolorrampv2.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,28 @@ void QgsVectorGradientColorRampV2::convertToDiscrete( bool discrete )
219219
mDiscrete = discrete;
220220
}
221221

222-
void QgsVectorGradientColorRampV2::addStopsToGradient( QGradient* gradient )
222+
void QgsVectorGradientColorRampV2::addStopsToGradient( QGradient* gradient, double alpha )
223223
{
224224
//copy color ramp stops to a QGradient
225-
gradient->setColorAt( 0, mColor1 );
226-
gradient->setColorAt( 1, mColor2 );
225+
QColor color1 = mColor1;
226+
QColor color2 = mColor2;
227+
if ( alpha < 1 )
228+
{
229+
color1.setAlpha( color1.alpha() * alpha );
230+
color2.setAlpha( color2.alpha() * alpha );
231+
}
232+
gradient->setColorAt( 0, color1 );
233+
gradient->setColorAt( 1, color2 );
227234

228235
for ( QgsGradientStopsList::const_iterator it = mStops.begin();
229236
it != mStops.end(); ++it )
230237
{
231-
gradient->setColorAt( it->offset , it->color );
238+
QColor rampColor = it->color;
239+
if ( alpha < 1 )
240+
{
241+
rampColor.setAlpha( rampColor.alpha() * alpha );
242+
}
243+
gradient->setColorAt( it->offset , rampColor );
232244
}
233245
}
234246

‎src/core/symbology-ng/qgsvectorcolorrampv2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class CORE_EXPORT QgsVectorGradientColorRampV2 : public QgsVectorColorRampV2
9494

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

9999
protected:
100100
QColor mColor1, mColor2;

0 commit comments

Comments
 (0)
Please sign in to comment.