Skip to content

Commit

Permalink
Remove relations when a involved layer gets deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 6, 2014
1 parent e6c00fc commit 0e3ada3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/core/qgsrelationmanager.cpp
Expand Up @@ -17,6 +17,7 @@

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

Expand All @@ -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 )
Expand Down Expand Up @@ -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() );
}
}
}
}
1 change: 1 addition & 0 deletions src/core/qgsrelationmanager.h
Expand Up @@ -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 */
Expand Down

0 comments on commit 0e3ada3

Please sign in to comment.