Skip to content
Permalink
Browse files

Raster renderer GUI: fix switching between renderers, and potential i…

…nfinite 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).
  • Loading branch information
rouault committed Dec 23, 2016
1 parent 9124c73 commit 645f2c82ca47cea8e256717f25f56eea166a4aa3
@@ -549,6 +549,19 @@ void QgsRasterLayerProperties::setRendererWidget( const QString& rendererName )
QgsDebugMsg( "renderer has widgetCreateFunction" );
// Current canvas extent (used to calc min/max) in layer CRS
QgsRectangle myExtent = mMapCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
if ( oldWidget )
{
if ( rendererName == "singlebandgray" )
{
whileBlocking( mRasterLayer )->setRenderer( QgsRasterRendererRegistry::instance()->defaultRendererForDrawingStyle( QgsRaster::SingleBandGray, mRasterLayer->dataProvider() ) );
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
}
else if ( rendererName == "multibandcolor" )
{
whileBlocking( mRasterLayer )->setRenderer( QgsRasterRendererRegistry::instance()->defaultRendererForDrawingStyle( QgsRaster::MultiBandColor, mRasterLayer->dataProvider() ) );
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
}
}
mRendererWidget = rendererEntry.widgetCreateFunction( mRasterLayer, myExtent );
mRendererWidget->setMapCanvas( mMapCanvas );
mRendererStackedWidget->addWidget( mRendererWidget );
@@ -81,13 +81,6 @@ QgsMultiBandColorRendererWidget::QgsMultiBandColorRendererWidget( QgsRasterLayer
onBandChanged( 0 ); // reset mMinMaxWidget bands

connect( mContrastEnhancementAlgorithmComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) );
connect( mRedMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
connect( mRedMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
connect( mGreenMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
connect( mGreenMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
connect( mBlueMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
connect( mBlueMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );

}
}

@@ -267,6 +260,7 @@ void QgsMultiBandColorRendererWidget::minMaxModified()
mContrastEnhancementAlgorithmComboBox->findData(( int ) QgsContrastEnhancement::StretchToMinimumMaximum ) );
}
mMinMaxWidget->userHasSetManualMinMaxValues();
emit widgetChanged();
}
}

@@ -333,6 +333,19 @@ void QgsRendererRasterPropertiesWidget::setRendererWidget( const QString &render
QgsDebugMsg( "renderer has widgetCreateFunction" );
// Current canvas extent (used to calc min/max) in layer CRS
QgsRectangle myExtent = mMapCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
if ( oldWidget )
{
if ( rendererName == "singlebandgray" )
{
whileBlocking( mRasterLayer )->setRenderer( QgsRasterRendererRegistry::instance()->defaultRendererForDrawingStyle( QgsRaster::SingleBandGray, mRasterLayer->dataProvider() ) );
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
}
else if ( rendererName == "multibandcolor" )
{
whileBlocking( mRasterLayer )->setRenderer( QgsRasterRendererRegistry::instance()->defaultRendererForDrawingStyle( QgsRaster::MultiBandColor, mRasterLayer->dataProvider() ) );
whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
}
}
mRendererWidget = rendererEntry.widgetCreateFunction( mRasterLayer, myExtent );
mRendererWidget->setMapCanvas( mMapCanvas );
connect( mRendererWidget, SIGNAL( widgetChanged() ), this, SIGNAL( widgetChanged() ) );
@@ -74,8 +74,6 @@ QgsSingleBandGrayRendererWidget::QgsSingleBandGrayRendererWidget( QgsRasterLayer

connect( mGradientComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) );
connect( mContrastEnhancementComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) );
connect( mMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
connect( mMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) );
}
}

@@ -142,6 +140,7 @@ void QgsSingleBandGrayRendererWidget::minMaxModified()
mContrastEnhancementComboBox->findData(( int ) QgsContrastEnhancement::StretchToMinimumMaximum ) );
}
mMinMaxWidget->userHasSetManualMinMaxValues();
emit widgetChanged();
}
}

0 comments on commit 645f2c8

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