Skip to content
Permalink
Browse files

[raster] don't auto-classify upon customizing values tree (fixes #17102)

  • Loading branch information
nirvn committed Jan 29, 2018
1 parent 77163ba commit 51c5805e13db55a30802ec49fe3313b27d832ee5
@@ -40,6 +40,10 @@ Executes the single band pseudo raster classficiation
void loadMinMax( int bandNo, double min, double max );
%Docstring
called when new min/max values are loaded
%End
void loadMinMaxFromTree();
%Docstring
called when the color ramp tree has changed
%End

};
@@ -41,12 +41,12 @@

QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer *layer, const QgsRectangle &extent )
: QgsRasterRendererWidget( layer, extent )
, mDisableMinMaxWidgetRefresh( false )
, mMinMaxOrigin( 0 )
{
QgsSettings settings;

setupUi( this );

connect( mAddEntryButton, &QPushButton::clicked, this, &QgsSingleBandPseudoColorRendererWidget::mAddEntryButton_clicked );
connect( mDeleteEntryButton, &QPushButton::clicked, this, &QgsSingleBandPseudoColorRendererWidget::mDeleteEntryButton_clicked );
connect( mLoadFromBandButton, &QPushButton::clicked, this, &QgsSingleBandPseudoColorRendererWidget::mLoadFromBandButton_clicked );
@@ -98,9 +98,6 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
mMinMaxContainerWidget->setLayout( layout );
layout->addWidget( mMinMaxWidget );

connect( mMinMaxWidget, &QgsRasterMinMaxWidget::widgetChanged, this, &QgsSingleBandPseudoColorRendererWidget::widgetChanged );
connect( mMinMaxWidget, &QgsRasterMinMaxWidget::load, this, &QgsSingleBandPseudoColorRendererWidget::loadMinMax );

mBandComboBox->setLayer( mRasterLayer );

mColorInterpolationComboBox->addItem( tr( "Discrete" ), QgsColorRampShader::Discrete );
@@ -117,6 +114,9 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(

setFromRenderer( layer->renderer() );

connect( mMinMaxWidget, &QgsRasterMinMaxWidget::widgetChanged, this, &QgsSingleBandPseudoColorRendererWidget::widgetChanged );
connect( mMinMaxWidget, &QgsRasterMinMaxWidget::load, this, &QgsSingleBandPseudoColorRendererWidget::loadMinMax );

// If there is currently no min/max, load default with user current default options
if ( mMinLineEdit->text().isEmpty() || mMaxLineEdit->text().isEmpty() )
{
@@ -189,8 +189,6 @@ QgsRasterRenderer *QgsSingleBandPseudoColorRendererWidget::renderer()
void QgsSingleBandPseudoColorRendererWidget::doComputations()
{
mMinMaxWidget->doComputations();
if ( mColormapTreeWidget->topLevelItemCount() == 0 )
applyColorRamp();
}

void QgsSingleBandPseudoColorRendererWidget::setMapCanvas( QgsMapCanvas *canvas )
@@ -319,6 +317,8 @@ void QgsSingleBandPseudoColorRendererWidget::mAddEntryButton_clicked()
this, &QgsSingleBandPseudoColorRendererWidget::mColormapTreeWidget_itemEdited );
mColormapTreeWidget->sortItems( ValueColumn, Qt::AscendingOrder );
autoLabel();

loadMinMaxFromTree();
emit widgetChanged();
}

@@ -335,6 +335,8 @@ void QgsSingleBandPseudoColorRendererWidget::mDeleteEntryButton_clicked()
{
delete item;
}

loadMinMaxFromTree();
emit widgetChanged();
}

@@ -449,6 +451,8 @@ void QgsSingleBandPseudoColorRendererWidget::mLoadFromBandButton_clicked()
{
QMessageBox::warning( this, tr( "Load Color Map" ), tr( "The color map for band %1 has no entries" ).arg( bandIndex ) );
}

loadMinMaxFromTree();
emit widgetChanged();
}

@@ -539,6 +543,8 @@ void QgsSingleBandPseudoColorRendererWidget::mLoadFromFileButton_clicked()
{
QMessageBox::warning( this, tr( "Read access denied" ), tr( "Read access denied. Adjust the file permissions and try again.\n\n" ) );
}

loadMinMaxFromTree();
emit widgetChanged();
}

@@ -645,6 +651,9 @@ void QgsSingleBandPseudoColorRendererWidget::mColormapTreeWidget_itemEdited( QTr
{
mColormapTreeWidget->sortItems( ValueColumn, Qt::AscendingOrder );
autoLabel();

loadMinMaxFromTree();

emit widgetChanged();
}
else if ( column == LabelColumn )
@@ -756,26 +765,48 @@ void QgsSingleBandPseudoColorRendererWidget::loadMinMax( int bandNo, double min,
Q_UNUSED( bandNo );
QgsDebugMsg( QString( "theBandNo = %1 min = %2 max = %3" ).arg( bandNo ).arg( min ).arg( max ) );

mDisableMinMaxWidgetRefresh = true;
double oldMin = lineEditValue( mMinLineEdit );
double oldMax = lineEditValue( mMaxLineEdit );

if ( std::isnan( min ) )
{
mMinLineEdit->clear();
whileBlocking( mMinLineEdit )->clear();
}
else
{
mMinLineEdit->setText( QString::number( min ) );
whileBlocking( mMinLineEdit )->setText( QString::number( min ) );
}

if ( std::isnan( max ) )
{
mMaxLineEdit->clear();
whileBlocking( mMaxLineEdit )->clear();
}
else
{
mMaxLineEdit->setText( QString::number( max ) );
whileBlocking( mMaxLineEdit )->setText( QString::number( max ) );
}

if ( oldMin != min || oldMax != max )
{
classify();
}
mDisableMinMaxWidgetRefresh = false;
classify();
}

void QgsSingleBandPseudoColorRendererWidget::loadMinMaxFromTree()
{
QTreeWidgetItem *item = mColormapTreeWidget->topLevelItem( 0 );
if ( !item )
{
return;
}

double min = item->text( ValueColumn ).toDouble();
item = mColormapTreeWidget->topLevelItem( mColormapTreeWidget->topLevelItemCount() - 1 );
double max = item->text( ValueColumn ).toDouble();

whileBlocking( mMinLineEdit )->setText( QString::number( min ) );
whileBlocking( mMaxLineEdit )->setText( QString::number( max ) );
minMaxModified();
}

void QgsSingleBandPseudoColorRendererWidget::setLineEditValue( QLineEdit *lineEdit, double value )
@@ -871,8 +902,5 @@ void QgsSingleBandPseudoColorRendererWidget::mMaxLineEdit_textEdited( const QStr

void QgsSingleBandPseudoColorRendererWidget::minMaxModified()
{
if ( !mDisableMinMaxWidgetRefresh )
{
mMinMaxWidget->userHasSetManualMinMaxValues();
}
mMinMaxWidget->userHasSetManualMinMaxValues();
}
@@ -56,6 +56,8 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
void classify();
//! called when new min/max values are loaded
void loadMinMax( int bandNo, double min, double max );
//! called when the color ramp tree has changed
void loadMinMaxFromTree();

private:

@@ -107,7 +109,6 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
double lineEditValue( const QLineEdit *lineEdit ) const;
void resetClassifyButton();
QgsRasterMinMaxWidget *mMinMaxWidget = nullptr;
bool mDisableMinMaxWidgetRefresh;
int mMinMaxOrigin;

void minMaxModified();

0 comments on commit 51c5805

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