mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Make paletted raster widget behave the same as categorized widget
when changing current band Now the widget asks users if they want to delete existing categories when they switch a band, just like how the categorized renderer widget asks when the categorized field is changed.
This commit is contained in:
parent
c040469ca0
commit
e5b8b32e04
@ -91,6 +91,13 @@ Returns number of colors
|
||||
.. versionadded:: 2.1
|
||||
%End
|
||||
|
||||
int band() const;
|
||||
%Docstring
|
||||
Returns the raster band used for rendering the raster.
|
||||
.. versionadded:: 3.0
|
||||
:rtype: int
|
||||
%End
|
||||
|
||||
virtual void writeXml( QDomDocument &doc, QDomElement &parentElem ) const;
|
||||
|
||||
|
||||
|
@ -88,6 +88,12 @@ class CORE_EXPORT QgsPalettedRasterRenderer: public QgsRasterRenderer
|
||||
* \since QGIS 2.1 */
|
||||
void setLabel( int idx, const QString &label );
|
||||
|
||||
/**
|
||||
* Returns the raster band used for rendering the raster.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
int band() const { return mBand; }
|
||||
|
||||
void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
|
||||
|
||||
void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems SIP_OUT ) const override;
|
||||
|
@ -113,7 +113,7 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, con
|
||||
}
|
||||
|
||||
connect( QgsProject::instance(), static_cast < void ( QgsProject::* )( QgsMapLayer * ) >( &QgsProject::layerWillBeRemoved ), this, &QgsPalettedRendererWidget::layerWillBeRemoved );
|
||||
connect( mBandComboBox, &QgsRasterBandComboBox::bandChanged, this, &QgsPalettedRendererWidget::loadFromLayer );
|
||||
connect( mBandComboBox, &QgsRasterBandComboBox::bandChanged, this, &QgsPalettedRendererWidget::bandChanged );
|
||||
}
|
||||
|
||||
QgsPalettedRendererWidget::~QgsPalettedRendererWidget()
|
||||
@ -143,6 +143,9 @@ void QgsPalettedRendererWidget::setFromRenderer( const QgsRasterRenderer *r )
|
||||
const QgsPalettedRasterRenderer *pr = dynamic_cast<const QgsPalettedRasterRenderer *>( r );
|
||||
if ( pr )
|
||||
{
|
||||
mBand = pr->band();
|
||||
whileBlocking( mBandComboBox )->setBand( mBand );
|
||||
|
||||
//read values and colors and fill into tree widget
|
||||
mModel->setClassData( pr->classes() );
|
||||
|
||||
@ -440,6 +443,32 @@ void QgsPalettedRendererWidget::loadFromLayer()
|
||||
}
|
||||
}
|
||||
|
||||
void QgsPalettedRendererWidget::bandChanged( int band )
|
||||
{
|
||||
if ( band == mBand )
|
||||
return;
|
||||
|
||||
bool deleteExisting = false;
|
||||
if ( !mModel->classData().isEmpty() )
|
||||
{
|
||||
int res = QMessageBox::question( this,
|
||||
tr( "Confirm Delete" ),
|
||||
tr( "The classification band was changed from %1 to %2.\n"
|
||||
"Should the existing classes be deleted?" ).arg( mBand ).arg( band ),
|
||||
QMessageBox::Yes | QMessageBox::No );
|
||||
|
||||
deleteExisting = ( res == QMessageBox::Yes );
|
||||
}
|
||||
|
||||
mBand = band;
|
||||
mModel->blockSignals( true );
|
||||
if ( deleteExisting )
|
||||
mModel->deleteAll();
|
||||
|
||||
mModel->blockSignals( false );
|
||||
emit widgetChanged();
|
||||
}
|
||||
|
||||
void QgsPalettedRendererWidget::gatheredClasses()
|
||||
{
|
||||
if ( !mGatherer || mGatherer->wasCanceled() )
|
||||
|
@ -207,6 +207,8 @@ class GUI_EXPORT QgsPalettedRendererWidget: public QgsRasterRendererWidget, priv
|
||||
//! Background class gatherer thread
|
||||
QgsPalettedRendererClassGatherer *mGatherer = nullptr;
|
||||
|
||||
int mBand = -1;
|
||||
|
||||
void setSelectionColor( const QItemSelection &selection, const QColor &color );
|
||||
|
||||
private slots:
|
||||
@ -221,6 +223,7 @@ class GUI_EXPORT QgsPalettedRendererWidget: public QgsRasterRendererWidget, priv
|
||||
void saveColorTable();
|
||||
void classify();
|
||||
void loadFromLayer();
|
||||
void bandChanged( int band );
|
||||
|
||||
void gatheredClasses();
|
||||
void gathererThreadFinished();
|
||||
|
Loading…
x
Reference in New Issue
Block a user