From 1e53f585227b476f3bca22aa93b3cb69f634d9a1 Mon Sep 17 00:00:00 2001 From: rugginoso Date: Mon, 27 Jul 2009 16:22:13 +0000 Subject: [PATCH] Fix for #1712. git-svn-id: http://svn.osgeo.org/qgis/trunk@11185 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/plugins/grass/qgsgrassplugin.cpp | 31 +++++++++++++++++++++------- src/plugins/grass/qgsgrassplugin.h | 6 ++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/plugins/grass/qgsgrassplugin.cpp b/src/plugins/grass/qgsgrassplugin.cpp index 52fd9e00533c..3b839fe220e6 100644 --- a/src/plugins/grass/qgsgrassplugin.cpp +++ b/src/plugins/grass/qgsgrassplugin.cpp @@ -35,6 +35,7 @@ #include "qgsrubberband.h" #include "qgsproject.h" #include "qgsvectorlayer.h" +#include "qgsmaplayerregistry.h" #include #include @@ -57,7 +58,7 @@ static const QString pluginVersion = QObject::tr( "Version 0.1" ); * @param theQgisInterFace Pointer to the QGIS interface object */ QgsGrassPlugin::QgsGrassPlugin( QgisInterface * theQgisInterFace ): - qGisInterface( theQgisInterFace ) + qGisInterface( theQgisInterFace ), mEdit(NULL), mTools(NULL) { /** Initialize the plugin and set the required attributes */ pluginNameQString = tr( "GrassVector" ); @@ -68,6 +69,7 @@ QgsGrassPlugin::QgsGrassPlugin( QgisInterface * theQgisInterFace ): QgsGrassPlugin::~QgsGrassPlugin() { if ( mTools ) mTools->closeTools(); + if ( mEdit ) mEdit->closeEdit(); QString err = QgsGrass::closeMapset(); } @@ -411,18 +413,21 @@ void QgsGrassPlugin::edit() } mEditAction->setEnabled( false ); - QgsGrassEdit *ed = new QgsGrassEdit( qGisInterface, qGisInterface->activeLayer(), false, + mEdit = new QgsGrassEdit( qGisInterface, qGisInterface->activeLayer(), false, qGisInterface->mainWindow(), Qt::Dialog ); - if ( ed->isValid() ) + if ( mEdit->isValid() ) { - ed->show(); + mEdit->show(); mCanvas->refresh(); - connect( ed, SIGNAL( finished() ), this, SLOT( setEditAction() ) ); - } + connect( mEdit, SIGNAL( finished() ), this, SLOT( setEditAction() ) ); + connect( mEdit, SIGNAL(finished()), this, SLOT(cleanUp())); + connect( QgsMapLayerRegistry::instance(), SIGNAL(layerWillBeRemoved(QString)), this, SLOT(closeEdit(QString))); + } else { - delete ed; + delete mEdit; + mEdit = NULL; mEditAction->setEnabled( true ); } } @@ -443,6 +448,18 @@ void QgsGrassPlugin::setEditAction() } } +void QgsGrassPlugin::closeEdit(QString layerId) +{ + if(mEdit->layer()->getLayerID() == layerId){ + mEdit->closeEdit(); + } +} + +void QgsGrassPlugin::cleanUp() +{ + disconnect( QgsMapLayerRegistry::instance(), SIGNAL(layerWillBeRemoved(QString)), this, SLOT(closeEdit(QString))); +} + void QgsGrassPlugin::newVector() { // QgsDebugMsg("entered."); diff --git a/src/plugins/grass/qgsgrassplugin.h b/src/plugins/grass/qgsgrassplugin.h index 3ea9ed1d936d..0d4fa0a3fc10 100644 --- a/src/plugins/grass/qgsgrassplugin.h +++ b/src/plugins/grass/qgsgrassplugin.h @@ -23,6 +23,7 @@ class QgsGrassTools; class QgsGrassNewMapset; class QgsGrassRegion; +class QgsGrassEdit; class QgsMapCanvas; class QgsRubberBand; @@ -118,6 +119,10 @@ class QgsGrassPlugin: public QObject, public QgisPlugin void saveMapset(); //! Set edit action void setEditAction(); + //! Close the edit if layer is removed + void closeEdit(QString layerId); + //! Cleanup the Grass Edit + void cleanUp(); //! update plugin icons when the app tells us its theme is changed void setCurrentTheme( QString theThemeName ); private: @@ -148,6 +153,7 @@ class QgsGrassPlugin: public QObject, public QgisPlugin QgsGrassTools *mTools; //! Pointer to QgsGrassNewMapset QgsGrassNewMapset *mNewMapset; + QgsGrassEdit *mEdit; // Actions QAction *mOpenMapsetAction;