Skip to content

Commit

Permalink
If layer changes in stats summary dock, reset field to empty
Browse files Browse the repository at this point in the history
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.

(cherry-picked from a24c9e1)
  • Loading branch information
nyalldawson committed Jul 17, 2018
1 parent efcf97a commit fd8d06d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/app/qgsstatisticalsummarydockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void QgsStatisticalSummaryDockWidget::copyStatistics()

void QgsStatisticalSummaryDockWidget::refreshStatistics()
{
if ( !mLayer || ( mFieldExpressionWidget->isExpression() && !mFieldExpressionWidget->isValidExpression() ) )
if ( !mLayer || mFieldExpressionWidget->currentField().isEmpty() || ( mFieldExpressionWidget->isExpression() && !mFieldExpressionWidget->isValidExpression() ) )
{
mStatisticsTable->setRowCount( 0 );
return;
Expand Down Expand Up @@ -346,13 +346,15 @@ void QgsStatisticalSummaryDockWidget::layerChanged( QgsMapLayer *layer )

mLayer = newLayer;

// clear expression, so that we don't force an unwanted recalculation
mFieldExpressionWidget->setExpression( QString() );
mFieldExpressionWidget->setLayer( mLayer );

if ( mLayer )
{
connect( mLayer, &QgsVectorLayer::selectionChanged, this, &QgsStatisticalSummaryDockWidget::layerSelectionChanged );
}

mFieldExpressionWidget->setLayer( mLayer );

if ( mGatherer )
{
mGatherer->cancel();
Expand Down

0 comments on commit fd8d06d

Please sign in to comment.