Skip to content

Commit

Permalink
[raster] re-compute min/max when band(s) changed (#3923)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn authored Dec 30, 2016
1 parent 882878b commit 46a69df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/gui/raster/qgsrasterminmaxwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ QgsRasterMinMaxWidget::QgsRasterMinMaxWidget( QgsRasterLayer* theLayer, QWidget
, mLayer( theLayer )
, mCanvas( nullptr )
, mLastRectangleValid( false )
, mBandsChanged( false )
{
QgsDebugMsg( "Entered." );
setupUi( this );
Expand All @@ -56,6 +57,12 @@ QgsMapCanvas* QgsRasterMinMaxWidget::mapCanvas()
return mCanvas;
}

void QgsRasterMinMaxWidget::setBands( const QList<int> & theBands )
{
mBandsChanged = theBands != mBands;
mBands = theBands;
}

QgsRectangle QgsRasterMinMaxWidget::extent()
{
const int nExtentIdx = mStatisticsExtentCombo->currentIndex();
Expand Down Expand Up @@ -178,7 +185,8 @@ void QgsRasterMinMaxWidget::doComputations()

QgsRasterMinMaxOrigin newMinMaxOrigin = minMaxOrigin();
if ( mLastRectangleValid && mLastRectangle == myExtent &&
mLastMinMaxOrigin == newMinMaxOrigin )
mLastMinMaxOrigin == newMinMaxOrigin &&
!mBandsChanged )
{
QgsDebugMsg( "Does not need to redo statistics computations" );
return;
Expand All @@ -187,6 +195,7 @@ void QgsRasterMinMaxWidget::doComputations()
mLastRectangleValid = true;
mLastRectangle = myExtent;
mLastMinMaxOrigin = newMinMaxOrigin;
mBandsChanged = false;

Q_FOREACH ( int myBand, mBands )
{
Expand Down
4 changes: 3 additions & 1 deletion src/gui/raster/qgsrasterminmaxwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GUI_EXPORT QgsRasterMinMaxWidget: public QWidget, private Ui::QgsRasterMin
*/
QgsMapCanvas* mapCanvas();

void setBands( const QList<int> & theBands ) { mBands = theBands; }
void setBands( const QList<int> & theBands );

/** Return the extent selected by the user.
* Either an empty extent for 'full' or the current visible extent.
Expand Down Expand Up @@ -125,6 +125,8 @@ class GUI_EXPORT QgsRasterMinMaxWidget: public QWidget, private Ui::QgsRasterMin
bool mLastRectangleValid;
QgsRectangle mLastRectangle;
QgsRasterMinMaxOrigin mLastMinMaxOrigin;

bool mBandsChanged;
};

#endif // QGSRASTERMINMAXWIDGET_H

0 comments on commit 46a69df

Please sign in to comment.