3535#include " qgsrubberband.h"
3636#include " qgsproject.h"
3737#include " qgsvectorlayer.h"
38+ #include " qgsmaplayerregistry.h"
3839
3940#include < QAction>
4041#include < QFileInfo>
@@ -57,7 +58,7 @@ static const QString pluginVersion = QObject::tr( "Version 0.1" );
5758 * @param theQgisInterFace Pointer to the QGIS interface object
5859 */
5960QgsGrassPlugin::QgsGrassPlugin ( QgisInterface * theQgisInterFace ):
60- qGisInterface( theQgisInterFace )
61+ qGisInterface( theQgisInterFace ), mEdit( NULL ), mTools( NULL )
6162{
6263 /* * Initialize the plugin and set the required attributes */
6364 pluginNameQString = tr ( " GrassVector" );
@@ -68,6 +69,7 @@ QgsGrassPlugin::QgsGrassPlugin( QgisInterface * theQgisInterFace ):
6869QgsGrassPlugin::~QgsGrassPlugin ()
6970{
7071 if ( mTools ) mTools ->closeTools ();
72+ if ( mEdit ) mEdit ->closeEdit ();
7173 QString err = QgsGrass::closeMapset ();
7274}
7375
@@ -411,18 +413,21 @@ void QgsGrassPlugin::edit()
411413 }
412414
413415 mEditAction ->setEnabled ( false );
414- QgsGrassEdit *ed = new QgsGrassEdit ( qGisInterface, qGisInterface->activeLayer (), false ,
416+ mEdit = new QgsGrassEdit ( qGisInterface, qGisInterface->activeLayer (), false ,
415417 qGisInterface->mainWindow (), Qt::Dialog );
416418
417- if ( ed ->isValid () )
419+ if ( mEdit ->isValid () )
418420 {
419- ed ->show ();
421+ mEdit ->show ();
420422 mCanvas ->refresh ();
421- connect ( ed, SIGNAL ( finished () ), this , SLOT ( setEditAction () ) );
422- }
423+ connect ( mEdit , SIGNAL ( finished () ), this , SLOT ( setEditAction () ) );
424+ connect ( mEdit , SIGNAL (finished ()), this , SLOT (cleanUp ()));
425+ connect ( QgsMapLayerRegistry::instance (), SIGNAL (layerWillBeRemoved (QString)), this , SLOT (closeEdit (QString)));
426+ }
423427 else
424428 {
425- delete ed;
429+ delete mEdit ;
430+ mEdit = NULL ;
426431 mEditAction ->setEnabled ( true );
427432 }
428433}
@@ -443,6 +448,18 @@ void QgsGrassPlugin::setEditAction()
443448 }
444449}
445450
451+ void QgsGrassPlugin::closeEdit (QString layerId)
452+ {
453+ if (mEdit ->layer ()->getLayerID () == layerId){
454+ mEdit ->closeEdit ();
455+ }
456+ }
457+
458+ void QgsGrassPlugin::cleanUp ()
459+ {
460+ disconnect ( QgsMapLayerRegistry::instance (), SIGNAL (layerWillBeRemoved (QString)), this , SLOT (closeEdit (QString)));
461+ }
462+
446463void QgsGrassPlugin::newVector ()
447464{
448465// QgsDebugMsg("entered.");
0 commit comments