Skip to content
Permalink
Browse files

Fix loss of transparency information in style dock (fixes #15229)

  • Loading branch information
wonder-sk committed Jul 7, 2016
1 parent 5ae7802 commit cca79aa2f4838f0907390ee9de1e31461ba21027
@@ -57,6 +57,11 @@ class QgsRasterRenderer : QgsRasterInterface
/** Sets base class members from xml. Usually called from create() methods of subclasses*/
void readXML( const QDomElement& rendererElem );

/** Copies common properties like opacity / transparency data from other renderer.
* Useful when cloning renderers.
* @note added in 2.16 */
void copyCommonProperties( const QgsRasterRenderer* other );

/** Returns a list of band numbers used by the renderer*/
virtual QList<int> usesBands() const;

@@ -38,12 +38,10 @@ QgsHillshadeRenderer::QgsHillshadeRenderer( QgsRasterInterface *input, int band,
QgsHillshadeRenderer *QgsHillshadeRenderer::clone() const
{
QgsHillshadeRenderer* r = new QgsHillshadeRenderer( nullptr, mBand, mLightAzimuth, mLightAngle );
r->copyCommonProperties( this );

r->setZFactor( mZFactor );
r->setMultiDirectional( mMultiDirectional );
// "Effects"
r->setOpacity( mOpacity );
r->setAlphaBand( mAlphaBand );
r->setRasterTransparency( mRasterTransparency ? new QgsRasterTransparency( *mRasterTransparency ) : nullptr );
return r;
}

@@ -48,6 +48,8 @@ QgsMultiBandColorRenderer::~QgsMultiBandColorRenderer()
QgsMultiBandColorRenderer* QgsMultiBandColorRenderer::clone() const
{
QgsMultiBandColorRenderer * renderer = new QgsMultiBandColorRenderer( nullptr, mRedBand, mGreenBand, mBlueBand );
renderer->copyCommonProperties( this );

if ( mRedContrastEnhancement )
{
renderer->setRedContrastEnhancement( new QgsContrastEnhancement( *mRedContrastEnhancement ) );
@@ -60,9 +62,6 @@ QgsMultiBandColorRenderer* QgsMultiBandColorRenderer::clone() const
{
renderer->setBlueContrastEnhancement( new QgsContrastEnhancement( *mBlueContrastEnhancement ) );
}
renderer->setOpacity( mOpacity );
renderer->setAlphaBand( mAlphaBand );
renderer->setRasterTransparency( mRasterTransparency ? new QgsRasterTransparency( *mRasterTransparency ) : nullptr );

return renderer;
}
@@ -49,9 +49,8 @@ QgsPalettedRasterRenderer::~QgsPalettedRasterRenderer()
QgsPalettedRasterRenderer* QgsPalettedRasterRenderer::clone() const
{
QgsPalettedRasterRenderer * renderer = new QgsPalettedRasterRenderer( nullptr, mBand, rgbArray(), mNColors );
renderer->setOpacity( mOpacity );
renderer->setAlphaBand( mAlphaBand );
renderer->setRasterTransparency( mRasterTransparency ? new QgsRasterTransparency( *mRasterTransparency ) : nullptr );
renderer->copyCommonProperties( this );

renderer->mLabels = mLabels;
return renderer;
}
@@ -134,6 +134,16 @@ void QgsRasterRenderer::readXML( const QDomElement& rendererElem )
}
}

void QgsRasterRenderer::copyCommonProperties( const QgsRasterRenderer* other )
{
if ( !other )
return;

setOpacity( other->opacity() );
setAlphaBand( other->alphaBand() );
setRasterTransparency( other->rasterTransparency() ? new QgsRasterTransparency( *other->rasterTransparency() ) : nullptr );
}

QString QgsRasterRenderer::minMaxOriginName( int theOrigin )
{
if ( theOrigin == MinMaxUnknown )
@@ -88,6 +88,11 @@ class CORE_EXPORT QgsRasterRenderer : public QgsRasterInterface
/** Sets base class members from xml. Usually called from create() methods of subclasses*/
void readXML( const QDomElement& rendererElem ) override;

/** Copies common properties like opacity / transparency data from other renderer.
* Useful when cloning renderers.
* @note added in 2.16 */
void copyCommonProperties( const QgsRasterRenderer* other );

/** Returns a list of band numbers used by the renderer*/
virtual QList<int> usesBands() const { return QList<int>(); }

@@ -35,9 +35,7 @@ QgsSingleBandColorDataRenderer::~QgsSingleBandColorDataRenderer()
QgsSingleBandColorDataRenderer* QgsSingleBandColorDataRenderer::clone() const
{
QgsSingleBandColorDataRenderer * renderer = new QgsSingleBandColorDataRenderer( nullptr, mBand );
renderer->setOpacity( mOpacity );
renderer->setAlphaBand( mAlphaBand );
renderer->setRasterTransparency( mRasterTransparency ? new QgsRasterTransparency( *mRasterTransparency ) : nullptr );
renderer->copyCommonProperties( this );
return renderer;
}

@@ -35,9 +35,8 @@ QgsSingleBandGrayRenderer::~QgsSingleBandGrayRenderer()
QgsSingleBandGrayRenderer* QgsSingleBandGrayRenderer::clone() const
{
QgsSingleBandGrayRenderer * renderer = new QgsSingleBandGrayRenderer( nullptr, mGrayBand );
renderer->setOpacity( mOpacity );
renderer->setAlphaBand( mAlphaBand );
renderer->setRasterTransparency( mRasterTransparency ? new QgsRasterTransparency( *mRasterTransparency ) : nullptr );
renderer->copyCommonProperties( this );

renderer->setGradient( mGradient );
if ( mContrastEnhancement )
{
@@ -69,10 +69,7 @@ QgsSingleBandPseudoColorRenderer* QgsSingleBandPseudoColorRenderer::clone() cons
}
}
QgsSingleBandPseudoColorRenderer * renderer = new QgsSingleBandPseudoColorRenderer( nullptr, mBand, shader );

renderer->setOpacity( mOpacity );
renderer->setAlphaBand( mAlphaBand );
renderer->setRasterTransparency( mRasterTransparency ? new QgsRasterTransparency( *mRasterTransparency ) : nullptr );
renderer->copyCommonProperties( this );

return renderer;
}
@@ -133,7 +133,15 @@ void QgsRendererRasterPropertiesWidget::apply()
QgsRasterRendererWidget* rendererWidget = dynamic_cast<QgsRasterRendererWidget*>( stackedWidget->currentWidget() );
if ( rendererWidget )
{
mRasterLayer->setRenderer( rendererWidget->renderer() );
QgsRasterRenderer* newRenderer = rendererWidget->renderer();

// there are transparency related data stored in renderer instances, but they
// are not configured in the widget, so we need to copy them over from existing renderer
QgsRasterRenderer* oldRenderer = mRasterLayer->renderer();
if ( oldRenderer )
newRenderer->copyCommonProperties( oldRenderer );

mRasterLayer->setRenderer( newRenderer );
}

// Hue and saturation controls

0 comments on commit cca79aa

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