Skip to content

Commit

Permalink
Raster renderer GUI: fix switching between renderers, and potential i…
Browse files Browse the repository at this point in the history
…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 645f2c8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
13 changes: 13 additions & 0 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
8 changes: 1 addition & 7 deletions src/gui/raster/qgsmultibandcolorrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );

}
}

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

Expand Down
13 changes: 13 additions & 0 deletions src/gui/raster/qgsrendererrasterpropertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand Down
3 changes: 1 addition & 2 deletions src/gui/raster/qgssinglebandgrayrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
}
}

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

Expand Down

0 comments on commit 645f2c8

Please sign in to comment.