Skip to content
Permalink
Browse files
If statistics summary dock is NOT visible, then don't calculate
statistics

Instead defer their calculation until the dock is made visible.
No point doing all that work when the results aren't wanted/visible!
  • Loading branch information
nyalldawson committed Jul 6, 2021
1 parent 6ab8c16 commit ab713e2b7c1d9759827d1152ec51662ab990e7ae
Showing with 18 additions and 0 deletions.
  1. +16 −0 src/app/qgsstatisticalsummarydockwidget.cpp
  2. +2 −0 src/app/qgsstatisticalsummarydockwidget.h
@@ -82,6 +82,12 @@ QgsStatisticalSummaryDockWidget::QgsStatisticalSummaryDockWidget( QWidget *paren
mFieldType = DataType::Numeric;
mPreviousFieldType = DataType::Numeric;
refreshStatisticsMenu();

connect( this, &QgsDockWidget::visibilityChanged, this, [ = ]( bool visible )
{
if ( mPendingCalculate && visible )
refreshStatistics();
} );
}

QgsStatisticalSummaryDockWidget::~QgsStatisticalSummaryDockWidget()
@@ -137,6 +143,16 @@ void QgsStatisticalSummaryDockWidget::refreshStatistics()
return;
}

if ( !isUserVisible() )
{
//defer calculation until dock is visible -- no point calculating stats if the user can't
//see them!
mPendingCalculate = true;
return;
}

mPendingCalculate = false;

// determine field type
mFieldType = DataType::Numeric;
if ( !mFieldExpressionWidget->isExpression() )
@@ -132,6 +132,8 @@ class APP_EXPORT QgsStatisticalSummaryDockWidget : public QgsDockWidget, private
QString mExpression;

QgsStatisticsValueGatherer *mGatherer = nullptr;

bool mPendingCalculate = false;
};

#endif // QGSSTATISTICALSUMMARYDOCKWIDGET_H

0 comments on commit ab713e2

Please sign in to comment.