Skip to content

Commit

Permalink
Flip QgsShadowEffect from transparency to opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 29, 2017
1 parent 6f4c549 commit ac39320
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 56 deletions.
7 changes: 7 additions & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,13 @@ QgsServer {#qgis_api_break_3_0_QgsServer}
- QgsServer::handleRequest( const QString &urlstr ) has been removed in favour of the new
- QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &response ) has been added


QgsShadowEffect {#qgis_api_break_3_0_QgsShadowEffect}
---------------

- setTransparency and transparency were removed. Use setOpacity and opacity instead.


QgsShortcutsManager {#qgis_api_break_3_0_QgsShortcutsManager}
-------------------

Expand Down
4 changes: 2 additions & 2 deletions python/core/effects/qgspainteffect.sip
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@ class QgsDrawSourceEffect : QgsPaintEffect
void setOpacity( const double opacity );
%Docstring
Sets the ``opacity`` for the effect.
\param transparency double between 0 and 1 inclusive, where 0 is fully transparent
\param opacity double between 0 and 1 inclusive, where 0 is fully transparent
and 1 is fully opaque
.. seealso:: opacity()
%End

double opacity() const;
%Docstring
Returns the transparency for the effect
Returns the opacity for the effect
:return: opacity value between 0 and 1 inclusive, where 0 is fully transparent
and 1 is fully opaque
.. seealso:: setOpacity()
Expand Down
20 changes: 10 additions & 10 deletions python/core/effects/qgsshadoweffect.sip
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,20 @@ class QgsShadowEffect : QgsPaintEffect
:rtype: QColor
%End

void setTransparency( const double transparency );
void setOpacity( const double opacity );
%Docstring
Sets the transparency for the effect
\param transparency double between 0 and 1 inclusive, where 0 is fully opaque
and 1 is fully transparent
.. seealso:: transparency
Sets the ``opacity`` for the effect.
\param opacity double between 0 and 1 inclusive, where 0 is fully transparent
and 1 is fully opaque
.. seealso:: opacity()
%End

double transparency() const;
double opacity() const;
%Docstring
Returns the transparency for the effect
:return: transparency value between 0 and 1 inclusive, where 0 is fully opaque
and 1 is fully transparent
.. seealso:: setTransparency
Returns the opacity for the effect.
:return: opacity value between 0 and 1 inclusive, where 0 is fully transparent
and 1 is fully opaque
.. seealso:: setOpacity()
:rtype: float
%End

Expand Down
4 changes: 2 additions & 2 deletions src/core/effects/qgspainteffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,13 @@ class CORE_EXPORT QgsDrawSourceEffect : public QgsPaintEffect
virtual void readProperties( const QgsStringMap &props ) override;

/** Sets the \a opacity for the effect.
* \param transparency double between 0 and 1 inclusive, where 0 is fully transparent
* \param opacity double between 0 and 1 inclusive, where 0 is fully transparent
* and 1 is fully opaque
* \see opacity()
*/
void setOpacity( const double opacity ) { mOpacity = opacity; }

/** Returns the transparency for the effect
/** Returns the opacity for the effect
* \returns opacity value between 0 and 1 inclusive, where 0 is fully transparent
* and 1 is fully opaque
* \see setOpacity()
Expand Down
22 changes: 16 additions & 6 deletions src/core/effects/qgsshadoweffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ QgsShadowEffect::QgsShadowEffect()
, mOffsetAngle( 135 )
, mOffsetDist( 2.0 )
, mOffsetUnit( QgsUnitTypes::RenderMillimeters )
, mTransparency( 0.0 )
, mColor( Qt::black )
, mBlendMode( QPainter::CompositionMode_Multiply )
{
Expand Down Expand Up @@ -61,7 +60,7 @@ void QgsShadowEffect::draw( QgsRenderContext &context )
-offsetDist * sin( angleRad + M_PI / 2 ) );

//transparency, scale
QgsImageOperation::multiplyOpacity( colorisedIm, 1.0 - mTransparency );
QgsImageOperation::multiplyOpacity( colorisedIm, mOpacity );

if ( !exteriorShadow() )
{
Expand Down Expand Up @@ -93,7 +92,7 @@ QgsStringMap QgsShadowEffect::properties() const
props.insert( QStringLiteral( "enabled" ), mEnabled ? "1" : "0" );
props.insert( QStringLiteral( "draw_mode" ), QString::number( int( mDrawMode ) ) );
props.insert( QStringLiteral( "blend_mode" ), QString::number( int( mBlendMode ) ) );
props.insert( QStringLiteral( "transparency" ), QString::number( mTransparency ) );
props.insert( QStringLiteral( "opacity" ), QString::number( mOpacity ) );
props.insert( QStringLiteral( "blur_level" ), QString::number( mBlurLevel ) );
props.insert( QStringLiteral( "offset_angle" ), QString::number( mOffsetAngle ) );
props.insert( QStringLiteral( "offset_distance" ), QString::number( mOffsetDist ) );
Expand All @@ -111,10 +110,21 @@ void QgsShadowEffect::readProperties( const QgsStringMap &props )
{
mBlendMode = mode;
}
double transparency = props.value( QStringLiteral( "transparency" ) ).toDouble( &ok );
if ( ok )
if ( props.contains( QStringLiteral( "transparency" ) ) )
{
double transparency = props.value( QStringLiteral( "transparency" ) ).toDouble( &ok );
if ( ok )
{
mOpacity = 1.0 - transparency;
}
}
else
{
mTransparency = transparency;
double opacity = props.value( QStringLiteral( "opacity" ) ).toDouble( &ok );
if ( ok )
{
mOpacity = opacity;
}
}
mEnabled = props.value( QStringLiteral( "enabled" ), QStringLiteral( "1" ) ).toInt();
mDrawMode = static_cast< QgsPaintEffect::DrawMode >( props.value( QStringLiteral( "draw_mode" ), QStringLiteral( "2" ) ).toInt() );
Expand Down
22 changes: 11 additions & 11 deletions src/core/effects/qgsshadoweffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ class CORE_EXPORT QgsShadowEffect : public QgsPaintEffect
*/
QColor color() const { return mColor; }

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

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

/** Sets the blend mode for the effect
* \param mode blend mode used for drawing the effect on to a destination
Expand Down Expand Up @@ -173,7 +173,7 @@ class CORE_EXPORT QgsShadowEffect : public QgsPaintEffect
double mOffsetDist;
QgsUnitTypes::RenderUnit mOffsetUnit;
QgsMapUnitScale mOffsetMapUnitScale;
double mTransparency;
double mOpacity = 1.0;
QColor mColor;
QPainter::CompositionMode mBlendMode;

Expand Down
23 changes: 12 additions & 11 deletions src/gui/effects/qgspainteffectwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ QgsShadowEffectWidget::QgsShadowEffectWidget( QWidget *parent )
mShadowColorBtn->setAllowAlpha( false );
mShadowColorBtn->setColorDialogTitle( tr( "Select shadow color" ) );
mShadowColorBtn->setContext( QStringLiteral( "symbology" ) );
mShadowOpacitySpnBx->setClearValue( 100.0 );

mOffsetUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPixels << QgsUnitTypes::RenderMapUnits
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
Expand Down Expand Up @@ -287,8 +288,8 @@ void QgsShadowEffectWidget::initGui()
mOffsetUnitWidget->setUnit( mEffect->offsetUnit() );
mOffsetUnitWidget->setMapUnitScale( mEffect->offsetMapUnitScale() );
mShadowRadiuSpnBx->setValue( mEffect->blurLevel() );
mShadowTranspSpnBx->setValue( mEffect->transparency() * 100.0 );
mShadowTranspSlider->setValue( mEffect->transparency() * 1000.0 );
mShadowOpacitySpnBx->setValue( mEffect->opacity() * 100.0 );
mShadowOpacitySlider->setValue( mEffect->opacity() * 1000.0 );
mShadowColorBtn->setColor( mEffect->color() );
mShadowBlendCmbBx->setBlendMode( mEffect->blendMode() );
mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
Expand All @@ -303,10 +304,10 @@ void QgsShadowEffectWidget::blockSignals( const bool block )
mShadowOffsetSpnBx->blockSignals( block );
mOffsetUnitWidget->blockSignals( block );
mShadowRadiuSpnBx->blockSignals( block );
mShadowTranspSpnBx->blockSignals( block );
mShadowOpacitySpnBx->blockSignals( block );
mShadowColorBtn->blockSignals( block );
mShadowBlendCmbBx->blockSignals( block );
mShadowTranspSlider->blockSignals( block );
mShadowOpacitySlider->blockSignals( block );
mDrawModeComboBox->blockSignals( block );
}

Expand Down Expand Up @@ -349,16 +350,16 @@ void QgsShadowEffectWidget::on_mOffsetUnitWidget_changed()
emit changed();
}

void QgsShadowEffectWidget::on_mShadowTranspSpnBx_valueChanged( double value )
void QgsShadowEffectWidget::on_mShadowOpacitySpnBx_valueChanged( double value )
{
if ( !mEffect )
return;

mShadowTranspSlider->blockSignals( true );
mShadowTranspSlider->setValue( value * 10.0 );
mShadowTranspSlider->blockSignals( false );
mShadowOpacitySlider->blockSignals( true );
mShadowOpacitySlider->setValue( value * 10.0 );
mShadowOpacitySlider->blockSignals( false );

mEffect->setTransparency( value / 100.0 );
mEffect->setOpacity( value / 100.0 );
emit changed();
}

Expand All @@ -380,9 +381,9 @@ void QgsShadowEffectWidget::on_mShadowRadiuSpnBx_valueChanged( int value )
emit changed();
}

void QgsShadowEffectWidget::on_mShadowTranspSlider_valueChanged( int value )
void QgsShadowEffectWidget::on_mShadowOpacitySlider_valueChanged( int value )
{
mShadowTranspSpnBx->setValue( value / 10.0 );
mShadowOpacitySpnBx->setValue( value / 10.0 );
}

void QgsShadowEffectWidget::on_mDrawModeComboBox_currentIndexChanged( int index )
Expand Down
4 changes: 2 additions & 2 deletions src/gui/effects/qgspainteffectwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ class GUI_EXPORT QgsShadowEffectWidget : public QgsPaintEffectWidget, private Ui
void on_mShadowOffsetAngleDial_valueChanged( int value );
void on_mShadowOffsetSpnBx_valueChanged( double value );
void on_mOffsetUnitWidget_changed();
void on_mShadowTranspSpnBx_valueChanged( double value );
void on_mShadowOpacitySpnBx_valueChanged( double value );
void on_mShadowColorBtn_colorChanged( const QColor &color );
void on_mDrawModeComboBox_currentIndexChanged( int index );
void on_mShadowBlendCmbBx_currentIndexChanged( int index );
void on_mShadowRadiuSpnBx_valueChanged( int value );
void on_mShadowTranspSlider_valueChanged( int value );
void on_mShadowOpacitySlider_valueChanged( int value );
};


Expand Down
23 changes: 16 additions & 7 deletions src/ui/effects/widget_shadoweffect.ui
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<item row="3" column="0">
<widget class="QLabel" name="label_28">
<property name="text">
<string>Transparency</string>
<string>Opacity</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -142,7 +142,7 @@
<item row="3" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_28">
<item>
<widget class="QSlider" name="mShadowTranspSlider">
<widget class="QSlider" name="mShadowOpacitySlider">
<property name="enabled">
<bool>true</bool>
</property>
Expand All @@ -167,18 +167,24 @@
<property name="pageStep">
<number>100</number>
</property>
<property name="value">
<number>1000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QgsDoubleSpinBox" name="mShadowTranspSpnBx">
<widget class="QgsDoubleSpinBox" name="mShadowOpacitySpnBx">
<property name="enabled">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="suffix">
<string> %</string>
Expand All @@ -189,6 +195,9 @@
<property name="maximum">
<double>100.000000000000000</double>
</property>
<property name="value">
<double>100.000000000000000</double>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -314,8 +323,8 @@
<tabstop>mShadowOffsetSpnBx</tabstop>
<tabstop>mOffsetUnitWidget</tabstop>
<tabstop>mShadowRadiuSpnBx</tabstop>
<tabstop>mShadowTranspSlider</tabstop>
<tabstop>mShadowTranspSpnBx</tabstop>
<tabstop>mShadowOpacitySlider</tabstop>
<tabstop>mShadowOpacitySpnBx</tabstop>
<tabstop>mShadowColorBtn</tabstop>
<tabstop>mShadowBlendCmbBx</tabstop>
<tabstop>mDrawModeComboBox</tabstop>
Expand Down
10 changes: 5 additions & 5 deletions tests/src/core/testqgspainteffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ void TestQgsPaintEffect::dropShadow()
QVERIFY( effect );
effect->setBlendMode( QPainter::CompositionMode_ColorBurn );
QCOMPARE( effect->blendMode(), QPainter::CompositionMode_ColorBurn );
effect->setTransparency( 0.5 );
QCOMPARE( effect->transparency(), 0.5 );
effect->setOpacity( 0.5 );
QCOMPARE( effect->opacity(), 0.5 );
effect->setEnabled( false );
QCOMPARE( effect->enabled(), false );
effect->setBlurLevel( 6 );
Expand All @@ -455,7 +455,7 @@ void TestQgsPaintEffect::dropShadow()
QgsDropShadowEffect *copy = new QgsDropShadowEffect( *effect );
QVERIFY( copy );
QCOMPARE( copy->blendMode(), effect->blendMode() );
QCOMPARE( copy->transparency(), effect->transparency() );
QCOMPARE( copy->opacity(), effect->opacity() );
QCOMPARE( copy->enabled(), effect->enabled() );
QCOMPARE( copy->blurLevel(), effect->blurLevel() );
QCOMPARE( copy->offsetAngle(), effect->offsetAngle() );
Expand All @@ -472,7 +472,7 @@ void TestQgsPaintEffect::dropShadow()
QgsDropShadowEffect *cloneCast = dynamic_cast<QgsDropShadowEffect * >( clone );
QVERIFY( cloneCast );
QCOMPARE( cloneCast->blendMode(), effect->blendMode() );
QCOMPARE( cloneCast->transparency(), effect->transparency() );
QCOMPARE( cloneCast->opacity(), effect->opacity() );
QCOMPARE( cloneCast->enabled(), effect->enabled() );
QCOMPARE( cloneCast->blurLevel(), effect->blurLevel() );
QCOMPARE( cloneCast->offsetAngle(), effect->offsetAngle() );
Expand All @@ -490,7 +490,7 @@ void TestQgsPaintEffect::dropShadow()
QgsDropShadowEffect *readCast = dynamic_cast<QgsDropShadowEffect * >( readEffect );
QVERIFY( readCast );
QCOMPARE( readCast->blendMode(), effect->blendMode() );
QCOMPARE( readCast->transparency(), effect->transparency() );
QCOMPARE( readCast->opacity(), effect->opacity() );
QCOMPARE( readCast->enabled(), effect->enabled() );
QCOMPARE( readCast->blurLevel(), effect->blurLevel() );
QCOMPARE( readCast->offsetAngle(), effect->offsetAngle() );
Expand Down

0 comments on commit ac39320

Please sign in to comment.