mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-12 00:02:25 -04:00
Fix potential crash in stats dock widget, avoid unnecessary recalc
This commit is contained in:
parent
3d193e3026
commit
bf25186a76
@ -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:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user