Skip to content

Commit 645f2c8

Browse files
committedDec 23, 2016
Raster renderer GUI: fix switching between renderers, and potential infinite signal notifications.
Fixes #3871 (comment), ie switching between renderers in the raster layer properties dialog or in the style dock result in non optimal parameters, so better switch to default parameters that would be the ones used when adding a layer of the new renderer type to the canvas. This issue already existed in 2.18 Also fixes a potential infinite notification cycle when having both the style dock and layer properties dialog opened, and applying changes in the layer properties dialog. (related to #3871).
1 parent 9124c73 commit 645f2c8

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed
 

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,19 @@ void QgsRasterLayerProperties::setRendererWidget( const QString& rendererName )
549549
QgsDebugMsg( "renderer has widgetCreateFunction" );
550550
// Current canvas extent (used to calc min/max) in layer CRS
551551
QgsRectangle myExtent = mMapCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
552+
if ( oldWidget )
553+
{
554+
if ( rendererName == "singlebandgray" )
555+
{
556+
whileBlocking( mRasterLayer )->setRenderer( QgsRasterRendererRegistry::instance()->defaultRendererForDrawingStyle( QgsRaster::SingleBandGray, mRasterLayer->dataProvider() ) );
557+
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
558+
}
559+
else if ( rendererName == "multibandcolor" )
560+
{
561+
whileBlocking( mRasterLayer )->setRenderer( QgsRasterRendererRegistry::instance()->defaultRendererForDrawingStyle( QgsRaster::MultiBandColor, mRasterLayer->dataProvider() ) );
562+
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
563+
}
564+
}
552565
mRendererWidget = rendererEntry.widgetCreateFunction( mRasterLayer, myExtent );
553566
mRendererWidget->setMapCanvas( mMapCanvas );
554567
mRendererStackedWidget->addWidget( mRendererWidget );

‎src/gui/raster/qgsmultibandcolorrendererwidget.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,6 @@ QgsMultiBandColorRendererWidget::QgsMultiBandColorRendererWidget( QgsRasterLayer
8181
onBandChanged( 0 ); // reset mMinMaxWidget bands
8282

8383
connect( mContrastEnhancementAlgorithmComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) );
84-
connect( mRedMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
85-
connect( mRedMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
86-
connect( mGreenMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
87-
connect( mGreenMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
88-
connect( mBlueMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
89-
connect( mBlueMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
90-
9184
}
9285
}
9386

@@ -267,6 +260,7 @@ void QgsMultiBandColorRendererWidget::minMaxModified()
267260
mContrastEnhancementAlgorithmComboBox->findData(( int ) QgsContrastEnhancement::StretchToMinimumMaximum ) );
268261
}
269262
mMinMaxWidget->userHasSetManualMinMaxValues();
263+
emit widgetChanged();
270264
}
271265
}
272266

‎src/gui/raster/qgsrendererrasterpropertieswidget.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,19 @@ void QgsRendererRasterPropertiesWidget::setRendererWidget( const QString &render
333333
QgsDebugMsg( "renderer has widgetCreateFunction" );
334334
// Current canvas extent (used to calc min/max) in layer CRS
335335
QgsRectangle myExtent = mMapCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
336+
if ( oldWidget )
337+
{
338+
if ( rendererName == "singlebandgray" )
339+
{
340+
whileBlocking( mRasterLayer )->setRenderer( QgsRasterRendererRegistry::instance()->defaultRendererForDrawingStyle( QgsRaster::SingleBandGray, mRasterLayer->dataProvider() ) );
341+
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
342+
}
343+
else if ( rendererName == "multibandcolor" )
344+
{
345+
whileBlocking( mRasterLayer )->setRenderer( QgsRasterRendererRegistry::instance()->defaultRendererForDrawingStyle( QgsRaster::MultiBandColor, mRasterLayer->dataProvider() ) );
346+
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
347+
}
348+
}
336349
mRendererWidget = rendererEntry.widgetCreateFunction( mRasterLayer, myExtent );
337350
mRendererWidget->setMapCanvas( mMapCanvas );
338351
connect( mRendererWidget, SIGNAL( widgetChanged() ), this, SIGNAL( widgetChanged() ) );

‎src/gui/raster/qgssinglebandgrayrendererwidget.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ QgsSingleBandGrayRendererWidget::QgsSingleBandGrayRendererWidget( QgsRasterLayer
7474

7575
connect( mGradientComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) );
7676
connect( mContrastEnhancementComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) );
77-
connect( mMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
78-
connect( mMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
7977
}
8078
}
8179

@@ -142,6 +140,7 @@ void QgsSingleBandGrayRendererWidget::minMaxModified()
142140
mContrastEnhancementComboBox->findData(( int ) QgsContrastEnhancement::StretchToMinimumMaximum ) );
143141
}
144142
mMinMaxWidget->userHasSetManualMinMaxValues();
143+
emit widgetChanged();
145144
}
146145
}
147146

0 commit comments

Comments
 (0)