Skip to content
Permalink
Browse files
Fix potential crash in stats dock widget, avoid unnecessary recalc
  • Loading branch information
nyalldawson committed Jun 10, 2015
1 parent 3d193e3 commit bf25186a76d251accb589aa772e7b24ddec3fcf7
Showing with 25 additions and 7 deletions.
  1. +23 −7 src/app/qgsstatisticalsummarydockwidget.cpp
  2. +2 −0 src/app/qgsstatisticalsummarydockwidget.h
@@ -14,6 +14,7 @@
***************************************************************************/
#include "qgsstatisticalsummarydockwidget.h"
#include "qgsstatisticalsummary.h"
#include "qgsmaplayerregistry.h"
#include <QTableWidget>
#include <QAction>
#include <QSettings>
@@ -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 )
@@ -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 );
@@ -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();
}
@@ -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:

0 comments on commit bf25186

Please sign in to comment.