Skip to content

Commit a24c9e1

Browse files
committed
If layer changes in stats summary dock, reset field to empty
This prevents a stats gatherer task immediately firing off on a random field. Otherwise if the current layer is removed from the project, a new (random) layer will be selected in the stats dock and a task will fire off gathering (unwanted) stats for it. If multiple layers are removed this can trigger many gatherers, all of which are unwanted.
1 parent 77eafc0 commit a24c9e1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/app/qgsstatisticalsummarydockwidget.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void QgsStatisticalSummaryDockWidget::copyStatistics()
154154

155155
void QgsStatisticalSummaryDockWidget::refreshStatistics()
156156
{
157-
if ( !mLayer || ( mFieldExpressionWidget->isExpression() && !mFieldExpressionWidget->isValidExpression() ) )
157+
if ( !mLayer || mFieldExpressionWidget->currentField().isEmpty() || ( mFieldExpressionWidget->isExpression() && !mFieldExpressionWidget->isValidExpression() ) )
158158
{
159159
mStatisticsTable->setRowCount( 0 );
160160
return;
@@ -346,13 +346,15 @@ void QgsStatisticalSummaryDockWidget::layerChanged( QgsMapLayer *layer )
346346

347347
mLayer = newLayer;
348348

349+
// clear expression, so that we don't force an unwanted recalculation
350+
mFieldExpressionWidget->setExpression( QString() );
351+
mFieldExpressionWidget->setLayer( mLayer );
352+
349353
if ( mLayer )
350354
{
351355
connect( mLayer, &QgsVectorLayer::selectionChanged, this, &QgsStatisticalSummaryDockWidget::layerSelectionChanged );
352356
}
353357

354-
mFieldExpressionWidget->setLayer( mLayer );
355-
356358
if ( mGatherer )
357359
{
358360
mGatherer->cancel();

0 commit comments

Comments
 (0)