Skip to content
Permalink
Browse files
QgsRendererRasterPropertiesWidget's syncToLayer takes care of not
overwriting existing QgsRasterRenderers with a default renderer

modified test_qgsrendererrasterpropertieswidget.py to check if an
existing band-number > 1 is used to update the render widget

fixes #34602
  • Loading branch information
jakimowb authored and nyalldawson committed Oct 29, 2021
1 parent 8ac5383 commit 84808e48a5ae87b49ad4af9b14ee7dcf4070c788
Showing with 17 additions and 12 deletions.
  1. +13 −8 src/gui/raster/qgsrendererrasterpropertieswidget.cpp
  2. +4 −4 tests/src/python/test_qgsrendererrasterpropertieswidget.py
@@ -296,16 +296,21 @@ void QgsRendererRasterPropertiesWidget::setRendererWidget( const QString &render
const QgsRectangle myExtent = mMapCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
if ( oldWidget )
{
if ( rendererName == QLatin1String( "singlebandgray" ) )
{
whileBlocking( mRasterLayer )->setRenderer( QgsApplication::rasterRendererRegistry()->defaultRendererForDrawingStyle( QgsRaster::SingleBandGray, mRasterLayer->dataProvider() ) );
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
}
else if ( rendererName == QLatin1String( "multibandcolor" ) )
QgsRasterRenderer *oldRenderer = oldWidget->renderer();
if (!oldRenderer || oldRenderer->type() != rendererName)
{
whileBlocking( mRasterLayer )->setRenderer( QgsApplication::rasterRendererRegistry()->defaultRendererForDrawingStyle( QgsRaster::MultiBandColor, mRasterLayer->dataProvider() ) );
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
if ( rendererName == QLatin1String( "singlebandgray" ) )
{
whileBlocking( mRasterLayer )->setRenderer( QgsApplication::rasterRendererRegistry()->defaultRendererForDrawingStyle( QgsRaster::SingleBandGray, mRasterLayer->dataProvider() ) );
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
}
else if ( rendererName == QLatin1String( "multibandcolor" ) )
{
whileBlocking( mRasterLayer )->setRenderer( QgsApplication::rasterRendererRegistry()->defaultRendererForDrawingStyle( QgsRaster::MultiBandColor, mRasterLayer->dataProvider() ) );
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
}
}
delete oldRenderer;
}
mRasterLayer->renderer()->setAlphaBand( alphaBand );
mRasterLayer->renderer()->setOpacity( opacity );
@@ -30,14 +30,14 @@ def multibandRasterLayer(self) -> QgsRasterLayer:
def test_syncToLayer_SingleBandGray(self):

lyr = self.multibandRasterLayer()
lyr.setRenderer(QgsSingleBandGrayRenderer(lyr.dataProvider(), 1))
lyr.setRenderer(QgsSingleBandGrayRenderer(lyr.dataProvider(), 2))
c = QgsMapCanvas()
w = QgsRendererRasterPropertiesWidget(lyr, c)
assert isinstance(w.currentRenderWidget().renderer(), QgsSingleBandGrayRenderer)
assert w.currentRenderWidget().renderer().grayBand() == 1
lyr.renderer().setGrayBand(2)
w.syncToLayer(lyr)
assert w.currentRenderWidget().renderer().grayBand() == 2
lyr.renderer().setGrayBand(1)
w.syncToLayer(lyr)
assert w.currentRenderWidget().renderer().grayBand() == 1

def test_syncToLayer_MultiBand(self):

0 comments on commit 84808e4

Please sign in to comment.