Skip to content

Commit dee3bab

Browse files
committedSep 29, 2015
[GRASS] fixed crash on plugin unload + reload
1 parent 712354e commit dee3bab

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed
 

‎src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ QgsGrassPlugin::~QgsGrassPlugin()
102102
// -> do not call mTools here
103103
//if ( mTools )
104104
// mTools->closeTools();
105-
disconnect( QgsGrass::instance(), SIGNAL( mapsetChanged() ), this, SLOT( mapsetChanged() ) );
106105
QgsGrass::instance()->closeMapsetWarn();
107106
}
108107

@@ -147,13 +146,6 @@ void QgsGrassPlugin::initGui()
147146
mNewMapset = 0;
148147

149148
mCanvas = qGisInterface->mapCanvas();
150-
QWidget* qgis = qGisInterface->mainWindow();
151-
152-
connect( mCanvas, SIGNAL( destinationCrsChanged() ), this, SLOT( setTransform() ) );
153-
154-
// Connect project
155-
connect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
156-
connect( qgis, SIGNAL( newProject() ), this, SLOT( newProject() ) );
157149

158150
// Create region rubber band
159151
mRegionBand = new QgsRubberBand( mCanvas, QGis::Polygon );
@@ -179,12 +171,12 @@ void QgsGrassPlugin::initGui()
179171
mOptionsAction = new QAction( QIcon(), tr( "GRASS Options" ), this );
180172
mOptionsAction->setObjectName( "mOptionsAction" );
181173

182-
// Connect the action
183-
connect( mOpenToolsAction, SIGNAL( triggered() ), this, SLOT( openTools() ) );
184-
connect( mRegionAction, SIGNAL( toggled( bool ) ), this, SLOT( switchRegion( bool ) ) );
174+
// Connect the actions
185175
connect( mOpenMapsetAction, SIGNAL( triggered() ), this, SLOT( openMapset() ) );
186176
connect( mNewMapsetAction, SIGNAL( triggered() ), this, SLOT( newMapset() ) );
187177
connect( mCloseMapsetAction, SIGNAL( triggered() ), SLOT( closeMapset() ) );
178+
connect( mOpenToolsAction, SIGNAL( triggered() ), this, SLOT( openTools() ) );
179+
connect( mRegionAction, SIGNAL( toggled( bool ) ), this, SLOT( switchRegion( bool ) ) );
188180
connect( mOptionsAction, SIGNAL( triggered() ), QgsGrass::instance(), SLOT( openOptions() ) );
189181

190182
// Add actions to a GRASS plugin menu
@@ -262,11 +254,18 @@ void QgsGrassPlugin::initGui()
262254
mAddArea = new QgsGrassAddFeature( qGisInterface->mapCanvas(), QgsMapToolAdvancedDigitizing::CapturePolygon );
263255
mAddArea->setAction( mAddAreaAction );
264256

257+
// Connect project
258+
QWidget* qgis = qGisInterface->mainWindow();
259+
connect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
260+
connect( qgis, SIGNAL( newProject() ), this, SLOT( newProject() ) );
261+
265262
// Set icons to current theme
266263
setCurrentTheme( "" );
267264
// Connect theme change signal
268265
connect( qGisInterface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
269266

267+
connect( mCanvas, SIGNAL( destinationCrsChanged() ), this, SLOT( setTransform() ) );
268+
270269
// Connect display region
271270
connect( mCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( postRender( QPainter * ) ) );
272271

@@ -522,14 +521,6 @@ void QgsGrassPlugin::mapsetChanged()
522521
// Open tools
523522
void QgsGrassPlugin::openTools()
524523
{
525-
#if 0
526-
if ( !mTools )
527-
{
528-
mTools = new QgsGrassTools( qGisInterface, qGisInterface->mainWindow(), 0, Qt::Dialog );
529-
530-
connect( mTools, SIGNAL( regionChanged() ), this, SLOT( redrawRegion() ) );
531-
}
532-
#endif
533524
mTools->show();
534525
}
535526

@@ -766,6 +757,40 @@ void QgsGrassPlugin::unload()
766757
// Close mapset
767758
QgsGrass::instance()->closeMapsetWarn();
768759

760+
// disconnect slots of QgsGrassPlugin so they're not fired also after unload
761+
QWidget* qgis = qGisInterface->mainWindow();
762+
disconnect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
763+
disconnect( qgis, SIGNAL( newProject() ), this, SLOT( newProject() ) );
764+
disconnect( qGisInterface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
765+
disconnect( mCanvas, SIGNAL( destinationCrsChanged() ), this, SLOT( setTransform() ) );
766+
disconnect( mCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( postRender( QPainter * ) ) );
767+
768+
disconnect( QgsGrass::instance(), SIGNAL( gisbaseChanged() ), this, SLOT( onGisbaseChanged() ) );
769+
disconnect( QgsGrass::instance(), SIGNAL( mapsetChanged() ), this, SLOT( mapsetChanged() ) );
770+
disconnect( QgsGrass::instance(), SIGNAL( regionChanged() ), this, SLOT( displayRegion() ) );
771+
disconnect( QgsGrass::instance(), SIGNAL( regionPenChanged() ), this, SLOT( displayRegion() ) );
772+
disconnect( QgsGrass::instance(), SIGNAL( newLayer( QString, QString ) ), this, SLOT( onNewLayer( QString, QString ) ) );
773+
774+
disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( onLayerWasAdded( QgsMapLayer* ) ) );
775+
776+
disconnect( qGisInterface->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ),
777+
this, SLOT( onCurrentLayerChanged( QgsMapLayer* ) ) );
778+
779+
foreach ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers().values() )
780+
{
781+
if ( !layer || layer->type() != QgsMapLayer::VectorLayer )
782+
{
783+
continue;
784+
}
785+
786+
QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layer );
787+
if ( vectorLayer && vectorLayer->providerType() == "grass" )
788+
{
789+
disconnect( vectorLayer, SIGNAL( editingStarted() ), this, SLOT( onEditingStarted() ) );
790+
disconnect( vectorLayer, SIGNAL( editingStopped() ), this, SLOT( onEditingStopped() ) );
791+
}
792+
}
793+
769794
// remove the GUI
770795
qGisInterface->removePluginMenu( tr( "&GRASS" ), mOpenMapsetAction );
771796
qGisInterface->removePluginMenu( tr( "&GRASS" ), mNewMapsetAction );
@@ -781,7 +806,6 @@ void QgsGrassPlugin::unload()
781806
delete mRegionAction;
782807
delete mOptionsAction;
783808

784-
delete mAddFeatureAction;
785809
delete mAddPointAction;
786810
delete mAddLineAction;
787811
delete mAddBoundaryAction;
@@ -797,13 +821,6 @@ void QgsGrassPlugin::unload()
797821
delete mToolBarPointer;
798822
mToolBarPointer = 0;
799823

800-
// disconnect slots of QgsGrassPlugin so they're not fired also after unload
801-
disconnect( mCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( postRender( QPainter * ) ) );
802-
803-
QWidget* qgis = qGisInterface->mainWindow();
804-
disconnect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
805-
disconnect( qgis, SIGNAL( newProject() ), this, SLOT( newProject() ) );
806-
807824
delete mTools;
808825
mTools = 0;
809826
}

0 commit comments

Comments
 (0)
Please sign in to comment.