Skip to content

Commit

Permalink
Fix potential crash in stats dock widget, avoid unnecessary recalc
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 10, 2015
1 parent 3d193e3 commit bf25186
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/app/qgsstatisticalsummarydockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
***************************************************************************/
#include "qgsstatisticalsummarydockwidget.h"
#include "qgsstatisticalsummary.h"
#include "qgsmaplayerregistry.h"
#include <QTableWidget>
#include <QAction>
#include <QSettings>
Expand Down Expand Up @@ -45,15 +46,15 @@ QgsStatisticalSummaryDockWidget::QgsStatisticalSummaryDockWidget( QWidget *paren

mLayerComboBox->setFilters( QgsMapLayerProxyModel::VectorLayer );
mFieldExpressionWidget->setFilters( QgsFieldProxyModel::Numeric );

mLayerComboBox->setLayer( mLayerComboBox->layer( 0 ) );
mFieldExpressionWidget->setLayer( mLayerComboBox->layer( 0 ) );

connect( mLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( layerChanged( QgsMapLayer* ) ) );
connect( mFieldExpressionWidget, SIGNAL( fieldChanged( QString ) ), this, SLOT( refreshStatistics() ) );
connect( mSelectedOnlyCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( refreshStatistics() ) );
connect( mButtonRefresh, SIGNAL( clicked( bool ) ), this, SLOT( refreshStatistics() ) );

if ( mLayerComboBox->currentLayer() )
{
mFieldExpressionWidget->setLayer( mLayerComboBox->currentLayer() );
}
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersRemoved( QStringList ) ) );

QSettings settings;
foreach ( QgsStatisticalSummary::Statistic stat, mDisplayStats )
Expand Down Expand Up @@ -166,14 +167,14 @@ void QgsStatisticalSummaryDockWidget::layerChanged( QgsMapLayer *layer )
QgsVectorLayer* newLayer = dynamic_cast< QgsVectorLayer* >( layer );
if ( mLayer && mLayer != newLayer )
{
disconnect( mLayer, SIGNAL( selectionChanged() ), this, SLOT( refreshStatistics() ) );
disconnect( mLayer, SIGNAL( selectionChanged() ), this, SLOT( layerSelectionChanged() ) );
}

mLayer = newLayer;

if ( mLayer )
{
connect( mLayer, SIGNAL( selectionChanged() ), this, SLOT( refreshStatistics() ) );
connect( mLayer, SIGNAL( selectionChanged() ), this, SLOT( layerSelectionChanged() ) );
}

mFieldExpressionWidget->setLayer( mLayer );
Expand Down Expand Up @@ -204,3 +205,18 @@ void QgsStatisticalSummaryDockWidget::statActionTriggered( bool checked )
settings.setValue( QString( "/StatisticalSummaryDock/checked_missing_values" ).arg( stat ), checked );
}
}

void QgsStatisticalSummaryDockWidget::layersRemoved( QStringList layers )
{
if ( mLayer && layers.contains( mLayer->id() ) )
{
disconnect( mLayer, SIGNAL( selectionChanged() ), this, SLOT( layerSelectionChanged() ) );
mLayer = 0;
}
}

void QgsStatisticalSummaryDockWidget::layerSelectionChanged()
{
if ( mSelectedOnlyCheckBox->isChecked() )
refreshStatistics();
}
2 changes: 2 additions & 0 deletions src/app/qgsstatisticalsummarydockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class APP_EXPORT QgsStatisticalSummaryDockWidget : public QDockWidget, private U

void layerChanged( QgsMapLayer* layer );
void statActionTriggered( bool checked );
void layersRemoved( QStringList layers );
void layerSelectionChanged();

private:

Expand Down

0 comments on commit bf25186

Please sign in to comment.