Skip to content
Permalink
Browse files
Fix QgsRendererRasterPropertiesWidget().syncToLayer
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 committed Oct 29, 2021
1 parent 1bbc7c5 commit cd6efa170b5bfcafccaef1c2af2712c6df53446d
Showing with 16 additions and 12 deletions.
  1. +12 −8 src/gui/raster/qgsrendererrasterpropertieswidget.cpp
  2. +4 −4 tests/src/python/test_qgsrendererrasterpropertieswidget.py
@@ -296,15 +296,19 @@ void QgsRendererRasterPropertiesWidget::setRendererWidget( const QString &render
const QgsRectangle myExtent = mMapCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
if ( oldWidget )
{
if ( rendererName == QLatin1String( "singlebandgray" ) )
std::unique_ptr< QgsRasterRenderer > oldRenderer( oldWidget->renderer() );
if ( !oldRenderer || oldRenderer->type() != rendererName )
{
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();
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();
}
}
}
mRasterLayer->renderer()->setAlphaBand( alphaBand );
@@ -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 cd6efa1

Please sign in to comment.