Skip to content

Commit 89c2e85

Browse files
committedMay 29, 2017
Flip QgsGlowEffect from transparency to opacity
1 parent a6d6364 commit 89c2e85

File tree

8 files changed

+82
-56
lines changed

8 files changed

+82
-56
lines changed
 

‎doc/api_break.dox

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,12 @@ QgsGeometrySimplifier {#qgis_api_break_3_0_QgsGeometrySimplifier}
12231223
- simplifyGeometry() has been removed and simplify() must be used instead .
12241224

12251225

1226+
QgsGlowEffect {#qgis_api_break_3_0_QgsGlowEffect}
1227+
-------------
1228+
1229+
- setTransparency and transparency were removed. Use setOpacity and opacity instead.
1230+
1231+
12261232
QgsGradientColorRampDialog {#qgis_api_break_3_0_QgsGradientColorRampDialog}
12271233
---------
12281234

‎python/core/effects/qgsgloweffect.sip

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,20 @@ class QgsGlowEffect : QgsPaintEffect
113113
:rtype: int
114114
%End
115115

116-
void setTransparency( const double transparency );
116+
void setOpacity( const double opacity );
117117
%Docstring
118-
Sets the transparency for the effect
119-
\param transparency double between 0 and 1 inclusive, where 0 is fully opaque
120-
and 1 is fully transparent
121-
.. seealso:: transparency
118+
Sets the ``opacity`` for the effect.
119+
\param opacity double between 0 and 1 inclusive, where 0 is fully transparent
120+
and 1 is fully opaque
121+
.. seealso:: opacity()
122122
%End
123123

124-
double transparency() const;
124+
double opacity() const;
125125
%Docstring
126-
Returns the transparency for the effect
127-
:return: transparency value between 0 and 1 inclusive, where 0 is fully opaque
128-
and 1 is fully transparent
129-
.. seealso:: setTransparency
126+
Returns the opacity for the effect.
127+
:return: opacity value between 0 and 1 inclusive, where 0 is fully transparent
128+
and 1 is fully opaque
129+
.. seealso:: setOpacity().
130130
:rtype: float
131131
%End
132132

‎src/core/effects/qgsgloweffect.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ QgsGlowEffect::QgsGlowEffect()
2727
, mSpreadUnit( QgsUnitTypes::RenderMillimeters )
2828
, mRamp( nullptr )
2929
, mBlurLevel( 3 )
30-
, mTransparency( 0.5 )
3130
, mColor( Qt::white )
3231
, mBlendMode( QPainter::CompositionMode_SourceOver )
3332
, mColorType( SingleColor )
@@ -42,7 +41,7 @@ QgsGlowEffect::QgsGlowEffect( const QgsGlowEffect &other )
4241
, mSpreadMapUnitScale( other.spreadMapUnitScale() )
4342
, mRamp( nullptr )
4443
, mBlurLevel( other.blurLevel() )
45-
, mTransparency( other.transparency() )
44+
, mOpacity( other.opacity() )
4645
, mColor( other.color() )
4746
, mBlendMode( other.blendMode() )
4847
, mColorType( other.colorType() )
@@ -92,7 +91,7 @@ void QgsGlowEffect::draw( QgsRenderContext &context )
9291
QgsImageOperation::stackBlur( im, mBlurLevel );
9392
}
9493

95-
QgsImageOperation::multiplyOpacity( im, 1.0 - mTransparency );
94+
QgsImageOperation::multiplyOpacity( im, mOpacity );
9695

9796
if ( !shadeExterior() )
9897
{
@@ -117,7 +116,7 @@ QgsStringMap QgsGlowEffect::properties() const
117116
props.insert( QStringLiteral( "enabled" ), mEnabled ? "1" : "0" );
118117
props.insert( QStringLiteral( "draw_mode" ), QString::number( int( mDrawMode ) ) );
119118
props.insert( QStringLiteral( "blend_mode" ), QString::number( int( mBlendMode ) ) );
120-
props.insert( QStringLiteral( "transparency" ), QString::number( mTransparency ) );
119+
props.insert( QStringLiteral( "opacity" ), QString::number( mOpacity ) );
121120
props.insert( QStringLiteral( "blur_level" ), QString::number( mBlurLevel ) );
122121
props.insert( QStringLiteral( "spread" ), QString::number( mSpread ) );
123122
props.insert( QStringLiteral( "spread_unit" ), QgsUnitTypes::encodeUnit( mSpreadUnit ) );
@@ -141,10 +140,21 @@ void QgsGlowEffect::readProperties( const QgsStringMap &props )
141140
{
142141
mBlendMode = mode;
143142
}
144-
double transparency = props.value( QStringLiteral( "transparency" ) ).toDouble( &ok );
145-
if ( ok )
143+
if ( props.contains( QStringLiteral( "transparency" ) ) )
144+
{
145+
double transparency = props.value( QStringLiteral( "transparency" ) ).toDouble( &ok );
146+
if ( ok )
147+
{
148+
mOpacity = 1.0 - transparency;
149+
}
150+
}
151+
else
146152
{
147-
mTransparency = transparency;
153+
double opacity = props.value( QStringLiteral( "opacity" ) ).toDouble( &ok );
154+
if ( ok )
155+
{
156+
mOpacity = opacity;
157+
}
148158
}
149159
mEnabled = props.value( QStringLiteral( "enabled" ), QStringLiteral( "1" ) ).toInt();
150160
mDrawMode = static_cast< QgsPaintEffect::DrawMode >( props.value( QStringLiteral( "draw_mode" ), QStringLiteral( "2" ) ).toInt() );
@@ -170,7 +180,7 @@ void QgsGlowEffect::readProperties( const QgsStringMap &props )
170180
mColor = QgsSymbolLayerUtils::decodeColor( props.value( QStringLiteral( "single_color" ) ) );
171181
}
172182

173-
//attempt to create color ramp from props
183+
//attempt to create color ramp from props
174184
delete mRamp;
175185
if ( props.contains( QStringLiteral( "rampType" ) ) && props[QStringLiteral( "rampType" )] == QStringLiteral( "cpt-city" ) )
176186
{
@@ -198,7 +208,7 @@ QgsGlowEffect &QgsGlowEffect::operator=( const QgsGlowEffect &rhs )
198208
mSpread = rhs.spread();
199209
mRamp = rhs.ramp() ? rhs.ramp()->clone() : nullptr;
200210
mBlurLevel = rhs.blurLevel();
201-
mTransparency = rhs.transparency();
211+
mOpacity = rhs.opacity();
202212
mColor = rhs.color();
203213
mBlendMode = rhs.blendMode();
204214
mColorType = rhs.colorType();

‎src/core/effects/qgsgloweffect.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,19 @@ class CORE_EXPORT QgsGlowEffect : public QgsPaintEffect
116116
*/
117117
int blurLevel() const { return mBlurLevel; }
118118

119-
/** Sets the transparency for the effect
120-
* \param transparency double between 0 and 1 inclusive, where 0 is fully opaque
121-
* and 1 is fully transparent
122-
* \see transparency
119+
/** Sets the \a opacity for the effect.
120+
* \param opacity double between 0 and 1 inclusive, where 0 is fully transparent
121+
* and 1 is fully opaque
122+
* \see opacity()
123123
*/
124-
void setTransparency( const double transparency ) { mTransparency = transparency; }
124+
void setOpacity( const double opacity ) { mOpacity = opacity; }
125125

126-
/** Returns the transparency for the effect
127-
* \returns transparency value between 0 and 1 inclusive, where 0 is fully opaque
128-
* and 1 is fully transparent
129-
* \see setTransparency
126+
/** Returns the opacity for the effect.
127+
* \returns opacity value between 0 and 1 inclusive, where 0 is fully transparent
128+
* and 1 is fully opaque
129+
* \see setOpacity().
130130
*/
131-
double transparency() const { return mTransparency; }
131+
double opacity() const { return mOpacity; }
132132

133133
/** Sets the color for the glow. This only applies if the colorType()
134134
* is set to SingleColor. The glow will fade between the specified color and
@@ -216,7 +216,7 @@ class CORE_EXPORT QgsGlowEffect : public QgsPaintEffect
216216
QgsMapUnitScale mSpreadMapUnitScale;
217217
QgsColorRamp *mRamp = nullptr;
218218
int mBlurLevel;
219-
double mTransparency;
219+
double mOpacity = 0.5;
220220
QColor mColor;
221221
QPainter::CompositionMode mBlendMode;
222222
GlowColorType mColorType;

‎src/gui/effects/qgspainteffectwidget.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ QgsGlowWidget::QgsGlowWidget( QWidget *parent )
421421
mColorBtn->setAllowAlpha( false );
422422
mColorBtn->setColorDialogTitle( tr( "Select glow color" ) );
423423
mColorBtn->setContext( QStringLiteral( "symbology" ) );
424+
mOpacitySpnBx->setClearValue( 100.0 );
424425

425426
mSpreadUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPixels << QgsUnitTypes::RenderMapUnits
426427
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
@@ -455,8 +456,8 @@ void QgsGlowWidget::initGui()
455456
mSpreadUnitWidget->setUnit( mEffect->spreadUnit() );
456457
mSpreadUnitWidget->setMapUnitScale( mEffect->spreadMapUnitScale() );
457458
mBlurRadiusSpnBx->setValue( mEffect->blurLevel() );
458-
mTranspSpnBx->setValue( mEffect->transparency() * 100.0 );
459-
mTranspSlider->setValue( mEffect->transparency() * 1000.0 );
459+
mOpacitySpnBx->setValue( mEffect->opacity() * 100.0 );
460+
mOpacitySlider->setValue( mEffect->opacity() * 1000.0 );
460461
mColorBtn->setColor( mEffect->color() );
461462
mBlendCmbBx->setBlendMode( mEffect->blendMode() );
462463

@@ -479,8 +480,8 @@ void QgsGlowWidget::blockSignals( const bool block )
479480
mSpreadSpnBx->blockSignals( block );
480481
mSpreadUnitWidget->blockSignals( block );
481482
mBlurRadiusSpnBx->blockSignals( block );
482-
mTranspSpnBx->blockSignals( block );
483-
mTranspSlider->blockSignals( block );
483+
mOpacitySpnBx->blockSignals( block );
484+
mOpacitySlider->blockSignals( block );
484485
mColorBtn->blockSignals( block );
485486
mBlendCmbBx->blockSignals( block );
486487
btnColorRamp->blockSignals( block );
@@ -529,16 +530,16 @@ void QgsGlowWidget::on_mSpreadUnitWidget_changed()
529530
emit changed();
530531
}
531532

532-
void QgsGlowWidget::on_mTranspSpnBx_valueChanged( double value )
533+
void QgsGlowWidget::on_mOpacitySpnBx_valueChanged( double value )
533534
{
534535
if ( !mEffect )
535536
return;
536537

537-
mTranspSlider->blockSignals( true );
538-
mTranspSlider->setValue( value * 10.0 );
539-
mTranspSlider->blockSignals( false );
538+
mOpacitySlider->blockSignals( true );
539+
mOpacitySlider->setValue( value * 10.0 );
540+
mOpacitySlider->blockSignals( false );
540541

541-
mEffect->setTransparency( value / 100.0 );
542+
mEffect->setOpacity( value / 100.0 );
542543
emit changed();
543544
}
544545

@@ -560,9 +561,9 @@ void QgsGlowWidget::on_mBlurRadiusSpnBx_valueChanged( int value )
560561
emit changed();
561562
}
562563

563-
void QgsGlowWidget::on_mTranspSlider_valueChanged( int value )
564+
void QgsGlowWidget::on_mOpacitySlider_valueChanged( int value )
564565
{
565-
mTranspSpnBx->setValue( value / 10.0 );
566+
mOpacitySpnBx->setValue( value / 10.0 );
566567
}
567568

568569
void QgsGlowWidget::on_mBlendCmbBx_currentIndexChanged( int index )

‎src/gui/effects/qgspainteffectwidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ class GUI_EXPORT QgsGlowWidget : public QgsPaintEffectWidget, private Ui::Widget
190190
void colorModeChanged();
191191
void on_mSpreadSpnBx_valueChanged( double value );
192192
void on_mSpreadUnitWidget_changed();
193-
void on_mTranspSpnBx_valueChanged( double value );
193+
void on_mOpacitySpnBx_valueChanged( double value );
194194
void on_mColorBtn_colorChanged( const QColor &color );
195195
void on_mBlendCmbBx_currentIndexChanged( int index );
196196
void on_mDrawModeComboBox_currentIndexChanged( int index );
197197
void on_mBlurRadiusSpnBx_valueChanged( int value );
198-
void on_mTranspSlider_valueChanged( int value );
198+
void on_mOpacitySlider_valueChanged( int value );
199199
void applyColorRamp();
200200

201201
};

‎src/ui/effects/widget_glow.ui

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<item row="2" column="0">
7878
<widget class="QLabel" name="label_28">
7979
<property name="text">
80-
<string>Transparency</string>
80+
<string>Opacity</string>
8181
</property>
8282
</widget>
8383
</item>
@@ -154,15 +154,15 @@
154154
<height>16777215</height>
155155
</size>
156156
</property>
157-
</widget>
157+
</widget>
158158
</item>
159159
<item row="5" column="1" colspan="2">
160160
<widget class="QgsBlendModeComboBox" name="mBlendCmbBx"/>
161161
</item>
162162
<item row="2" column="1" colspan="2">
163163
<layout class="QHBoxLayout" name="horizontalLayout_28">
164164
<item>
165-
<widget class="QSlider" name="mTranspSlider">
165+
<widget class="QSlider" name="mOpacitySlider">
166166
<property name="enabled">
167167
<bool>true</bool>
168168
</property>
@@ -187,18 +187,24 @@
187187
<property name="pageStep">
188188
<number>100</number>
189189
</property>
190+
<property name="value">
191+
<number>1000</number>
192+
</property>
190193
<property name="orientation">
191194
<enum>Qt::Horizontal</enum>
192195
</property>
193196
</widget>
194197
</item>
195198
<item>
196-
<widget class="QgsDoubleSpinBox" name="mTranspSpnBx">
199+
<widget class="QgsDoubleSpinBox" name="mOpacitySpnBx">
197200
<property name="enabled">
198201
<bool>true</bool>
199202
</property>
200-
<property name="alignment">
201-
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
203+
<property name="minimumSize">
204+
<size>
205+
<width>100</width>
206+
<height>0</height>
207+
</size>
202208
</property>
203209
<property name="suffix">
204210
<string> %</string>
@@ -209,6 +215,9 @@
209215
<property name="maximum">
210216
<double>100.000000000000000</double>
211217
</property>
218+
<property name="value">
219+
<double>100.000000000000000</double>
220+
</property>
212221
</widget>
213222
</item>
214223
</layout>
@@ -287,8 +296,8 @@
287296
<tabstop>mSpreadSpnBx</tabstop>
288297
<tabstop>mSpreadUnitWidget</tabstop>
289298
<tabstop>mBlurRadiusSpnBx</tabstop>
290-
<tabstop>mTranspSlider</tabstop>
291-
<tabstop>mTranspSpnBx</tabstop>
299+
<tabstop>mOpacitySlider</tabstop>
300+
<tabstop>mOpacitySpnBx</tabstop>
292301
<tabstop>radioSingleColor</tabstop>
293302
<tabstop>mColorBtn</tabstop>
294303
<tabstop>radioColorRamp</tabstop>

‎tests/src/core/testqgspainteffect.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ void TestQgsPaintEffect::glow()
528528
QVERIFY( effect );
529529
effect->setBlendMode( QPainter::CompositionMode_ColorBurn );
530530
QCOMPARE( effect->blendMode(), QPainter::CompositionMode_ColorBurn );
531-
effect->setTransparency( 0.5 );
532-
QCOMPARE( effect->transparency(), 0.5 );
531+
effect->setOpacity( 0.5 );
532+
QCOMPARE( effect->opacity(), 0.5 );
533533
effect->setEnabled( false );
534534
QCOMPARE( effect->enabled(), false );
535535
effect->setBlurLevel( 6 );
@@ -555,7 +555,7 @@ void TestQgsPaintEffect::glow()
555555
QgsOuterGlowEffect *copy = new QgsOuterGlowEffect( *effect );
556556
QVERIFY( copy );
557557
QCOMPARE( copy->blendMode(), effect->blendMode() );
558-
QCOMPARE( copy->transparency(), effect->transparency() );
558+
QCOMPARE( copy->opacity(), effect->opacity() );
559559
QCOMPARE( copy->enabled(), effect->enabled() );
560560
QCOMPARE( copy->blurLevel(), effect->blurLevel() );
561561
QCOMPARE( copy->spread(), effect->spread() );
@@ -573,7 +573,7 @@ void TestQgsPaintEffect::glow()
573573
QgsOuterGlowEffect *cloneCast = dynamic_cast<QgsOuterGlowEffect * >( clone );
574574
QVERIFY( cloneCast );
575575
QCOMPARE( cloneCast->blendMode(), effect->blendMode() );
576-
QCOMPARE( cloneCast->transparency(), effect->transparency() );
576+
QCOMPARE( cloneCast->opacity(), effect->opacity() );
577577
QCOMPARE( cloneCast->enabled(), effect->enabled() );
578578
QCOMPARE( cloneCast->blurLevel(), effect->blurLevel() );
579579
QCOMPARE( cloneCast->spread(), effect->spread() );
@@ -592,7 +592,7 @@ void TestQgsPaintEffect::glow()
592592
QgsOuterGlowEffect *readCast = dynamic_cast<QgsOuterGlowEffect * >( readEffect );
593593
QVERIFY( readCast );
594594
QCOMPARE( readCast->blendMode(), effect->blendMode() );
595-
QCOMPARE( readCast->transparency(), effect->transparency() );
595+
QCOMPARE( readCast->opacity(), effect->opacity() );
596596
QCOMPARE( readCast->enabled(), effect->enabled() );
597597
QCOMPARE( readCast->blurLevel(), effect->blurLevel() );
598598
QCOMPARE( readCast->spread(), effect->spread() );

0 commit comments

Comments
 (0)
Please sign in to comment.