Skip to content
Permalink
Browse files
Remove relations when a involved layer gets deleted
  • Loading branch information
m-kuhn committed Jun 6, 2014
1 parent e6c00fc commit 0e3ada3c4ea716e690739378f34ab86327003aa5
Showing with 22 additions and 0 deletions.
  1. +21 −0 src/core/qgsrelationmanager.cpp
  2. +1 −0 src/core/qgsrelationmanager.h
@@ -17,6 +17,7 @@

#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"

@@ -26,6 +27,7 @@ QgsRelationManager::QgsRelationManager( QgsProject* project )
{
connect( project, SIGNAL( readProject( const QDomDocument& ) ), SLOT( readProject( const QDomDocument& ) ) );
connect( project, SIGNAL( writeProject( QDomDocument& ) ), SLOT( writeProject( QDomDocument& ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersRemoved(QStringList) ), this, SLOT( layersRemoved(QStringList)) );
}

void QgsRelationManager::setRelations( const QList<QgsRelation>& relations )
@@ -170,3 +172,22 @@ void QgsRelationManager::writeProject( QDomDocument & doc )
relation.writeXML( relationsNode, doc );
}
}

void QgsRelationManager::layersRemoved( const QStringList& layers )
{
Q_FOREACH( const QString& layer, layers )
{
QMapIterator<QString, QgsRelation> it( mRelations );

while ( it.hasNext() )
{
it.next();

if ( it.value().referencedLayerId() == layer
|| it.value().referencingLayerId() == layer )
{
mRelations.remove( it.key() );
}
}
}
}
@@ -53,6 +53,7 @@ class CORE_EXPORT QgsRelationManager : public QObject
private slots:
void readProject( const QDomDocument &doc );
void writeProject( QDomDocument &doc );
void layersRemoved( const QStringList& layers );

private:
/** The references */

0 comments on commit 0e3ada3

Please sign in to comment.