Skip to content

Commit

Permalink
[raster] don't auto-classify upon customizing values tree (fixes #17102)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jan 29, 2018
1 parent 77163ba commit 51c5805
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
Expand Up @@ -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

};
Expand Down
62 changes: 45 additions & 17 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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() )
{
Expand Down Expand Up @@ -189,8 +189,6 @@ QgsRasterRenderer *QgsSingleBandPseudoColorRendererWidget::renderer()
void QgsSingleBandPseudoColorRendererWidget::doComputations()
{
mMinMaxWidget->doComputations();
if ( mColormapTreeWidget->topLevelItemCount() == 0 )
applyColorRamp();
}

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

loadMinMaxFromTree();
emit widgetChanged();
}

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

loadMinMaxFromTree();
emit widgetChanged();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

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

loadMinMaxFromTree();

emit widgetChanged();
}
else if ( column == LabelColumn )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -871,8 +902,5 @@ void QgsSingleBandPseudoColorRendererWidget::mMaxLineEdit_textEdited( const QStr

void QgsSingleBandPseudoColorRendererWidget::minMaxModified()
{
if ( !mDisableMinMaxWidgetRefresh )
{
mMinMaxWidget->userHasSetManualMinMaxValues();
}
mMinMaxWidget->userHasSetManualMinMaxValues();
}
3 changes: 2 additions & 1 deletion src/gui/raster/qgssinglebandpseudocolorrendererwidget.h
Expand Up @@ -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:

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 51c5805

Please sign in to comment.