Skip to content
Permalink
Browse files

Do not refresh stats when opening the stat summary field combo box

Without this change, stats are calculated when users simply
open the combo box to select a new field. With large datasets,
it freezes QGIS for a long time, and the combo box end up
never opening.
  • Loading branch information
nirvn committed Feb 5, 2018
1 parent 7bf0a7f commit 3883547da4d2b9b34d09e4830627c4f94ecb434b
Showing with 13 additions and 1 deletion.
  1. +10 −1 src/app/qgsstatisticalsummarydockwidget.cpp
  2. +3 −0 src/app/qgsstatisticalsummarydockwidget.h
@@ -88,7 +88,7 @@ QgsStatisticalSummaryDockWidget::QgsStatisticalSummaryDockWidget( QWidget *paren
mFieldExpressionWidget->setLayer( mLayerComboBox->layer( 0 ) );

connect( mLayerComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsStatisticalSummaryDockWidget::layerChanged );
connect( mFieldExpressionWidget, static_cast<void ( QgsFieldExpressionWidget::* )( const QString & )>( &QgsFieldExpressionWidget::fieldChanged ), this, &QgsStatisticalSummaryDockWidget::refreshStatistics );
connect( mFieldExpressionWidget, static_cast<void ( QgsFieldExpressionWidget::* )( const QString & )>( &QgsFieldExpressionWidget::fieldChanged ), this, &QgsStatisticalSummaryDockWidget::fieldChanged );
connect( mSelectedOnlyCheckBox, &QAbstractButton::toggled, this, &QgsStatisticalSummaryDockWidget::refreshStatistics );
connect( mButtonRefresh, &QAbstractButton::clicked, this, &QgsStatisticalSummaryDockWidget::refreshStatistics );
connect( QgsProject::instance(), static_cast<void ( QgsProject::* )( const QStringList & )>( &QgsProject::layersWillBeRemoved ), this, &QgsStatisticalSummaryDockWidget::layersRemoved );
@@ -101,6 +101,15 @@ QgsStatisticalSummaryDockWidget::QgsStatisticalSummaryDockWidget( QWidget *paren
refreshStatisticsMenu();
}

void QgsStatisticalSummaryDockWidget::fieldChanged()
{
if ( mFieldExpressionWidget->expression() != mExpression )
{
mExpression = mFieldExpressionWidget->expression();
refreshStatistics();
}
}

void QgsStatisticalSummaryDockWidget::refreshStatistics()
{
if ( !mLayer || ( mFieldExpressionWidget->isExpression() && !mFieldExpressionWidget->isValidExpression() ) )
@@ -58,6 +58,7 @@ class APP_EXPORT QgsStatisticalSummaryDockWidget : public QgsDockWidget, private
private slots:

void layerChanged( QgsMapLayer *layer );
void fieldChanged();
void statActionTriggered( bool checked );
void layersRemoved( const QStringList &layers );
void layerSelectionChanged();
@@ -92,6 +93,8 @@ class APP_EXPORT QgsStatisticalSummaryDockWidget : public QgsDockWidget, private
QMenu *mStatisticsMenu = nullptr;
DataType mFieldType;
DataType mPreviousFieldType;

QString mExpression;
};

#endif // QGSSTATISTICALSUMMARYDOCKWIDGET_H

0 comments on commit 3883547

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