Skip to content
Permalink
Browse files

Fix for alphaBand and opacity loss upon renderer switch (style dock &…

… properties window) (#3967)

* [styledock] maintain raster alpha band and opacity when switching renderer

* [raster] fix alphaBand/opacity loss when opening layer properties
(fixes #16044)
  • Loading branch information
nirvn committed Jan 9, 2017
1 parent 015fdf2 commit 632f9c582579590f13a849d4a9791b9dbb35449e
@@ -540,6 +540,16 @@ void QgsRasterLayerProperties::setRendererWidget( const QString& rendererName )
{
QgsDebugMsg( "rendererName = " + rendererName );
QgsRasterRendererWidget* oldWidget = mRendererWidget;
QgsRasterRenderer* oldRenderer = mRasterLayer->renderer();

int alphaBand = -1;
double opacity = 1;
if ( oldRenderer )
{
// Retain alpha band and opacity when switching renderer
alphaBand = oldRenderer->alphaBand();
opacity = oldRenderer->opacity();
}

QgsRasterRendererRegistryEntry rendererEntry;
if ( QgsApplication::rasterRendererRegistry()->rendererData( rendererName, rendererEntry ) )
@@ -562,6 +572,8 @@ void QgsRasterLayerProperties::setRendererWidget( const QString& rendererName )
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
}
}
mRasterLayer->renderer()->setAlphaBand( alphaBand );
mRasterLayer->renderer()->setOpacity( opacity );
mRendererWidget = rendererEntry.widgetCreateFunction( mRasterLayer, myExtent );
mRendererWidget->setMapCanvas( mMapCanvas );
mRendererStackedWidget->addWidget( mRendererWidget );
@@ -1258,7 +1258,11 @@ QDateTime QgsRasterLayer::timestamp() const
void QgsRasterLayer::setRenderer( QgsRasterRenderer* theRenderer )
{
QgsDebugMsgLevel( "Entered", 4 );
if ( !theRenderer ) { return; }
if ( !theRenderer )
{
return;
}

mPipe.set( theRenderer );
emit rendererChanged();
emit styleChanged();
@@ -33,6 +33,8 @@
#include "qgssinglebandgrayrenderer.h"


#include "qgsmessagelog.h"

static void _initRendererWidgetFunctions()
{
static bool initialized = false;
@@ -319,11 +321,21 @@ void QgsRendererRasterPropertiesWidget::setRendererWidget( const QString &render
{
QgsDebugMsg( "rendererName = " + rendererName );
QgsRasterRendererWidget* oldWidget = mRendererWidget;
QgsRasterRenderer* oldRenderer = mRasterLayer->renderer();

int alphaBand = -1;
double opacity = 1;
if ( oldRenderer )
{
// Retain alpha band and opacity when switching renderer
alphaBand = oldRenderer->alphaBand();
opacity = oldRenderer->opacity();
}

QgsRasterRendererRegistryEntry rendererEntry;
if ( QgsApplication::rasterRendererRegistry()->rendererData( rendererName, rendererEntry ) )
{
if ( rendererEntry.widgetCreateFunction ) //single band color data renderer e.g. has no widget
if ( rendererEntry.widgetCreateFunction ) // Single band color data renderer e.g. has no widget
{
QgsDebugMsg( "renderer has widgetCreateFunction" );
// Current canvas extent (used to calc min/max) in layer CRS
@@ -341,22 +353,26 @@ void QgsRendererRasterPropertiesWidget::setRendererWidget( const QString &render
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
}
}
mRasterLayer->renderer()->setAlphaBand( alphaBand );
mRasterLayer->renderer()->setOpacity( opacity );
mRendererWidget = rendererEntry.widgetCreateFunction( mRasterLayer, myExtent );
mRendererWidget->setMapCanvas( mMapCanvas );
connect( mRendererWidget, SIGNAL( widgetChanged() ), this, SIGNAL( widgetChanged() ) );
stackedWidget->addWidget( mRendererWidget );
stackedWidget->setCurrentWidget( mRendererWidget );
if ( oldWidget )
{
//compare used bands in new and old renderer and reset transparency dialog if different
// Compare used bands in new and old renderer and reset transparency dialog if different
QgsRasterRenderer* oldRenderer = oldWidget->renderer();
QgsRasterRenderer* newRenderer = mRendererWidget->renderer();
QList<int> oldBands = oldRenderer->usesBands();
QList<int> newBands = newRenderer->usesBands();

// if ( oldBands != newBands )
// {
// populateTransparencyTable( newRenderer );
// }

delete oldRenderer;
delete newRenderer;
}

0 comments on commit 632f9c5

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