Skip to content
Permalink
Browse files

Add a changed signal to QgsRelationManager

  • Loading branch information
nyalldawson committed Sep 20, 2014
1 parent 808464f commit fb2279f620c7b9821f8af5537dd205753a6022cf
Showing with 25 additions and 1 deletion.
  1. +6 −0 python/core/qgsrelationmanager.sip
  2. +13 −1 src/core/qgsrelationmanager.cpp
  3. +6 −0 src/core/qgsrelationmanager.h
@@ -22,4 +22,10 @@ class QgsRelationManager : QObject

signals:
void relationsLoaded();

/**
* Emitted when relations are added or removed to the manager.
* @note added in QGIS 2.5
*/
void changed();
};
@@ -37,6 +37,7 @@ void QgsRelationManager::setRelations( const QList<QgsRelation>& relations )
{
addRelation( rel );
}
emit changed();
}

const QMap<QString, QgsRelation>& QgsRelationManager::relations() const
@@ -52,16 +53,19 @@ void QgsRelationManager::addRelation( const QgsRelation& relation )
mRelations.insert( relation.id(), relation );

mProject->dirty( true );
emit changed();
}

void QgsRelationManager::removeRelation( const QString& name )
{
mRelations.remove( name );
emit changed();
}

void QgsRelationManager::removeRelation( const QgsRelation& relation )
{
mRelations.remove( relation.id() );
emit changed();
}

QgsRelation QgsRelationManager::relation( const QString& id ) const
@@ -72,6 +76,7 @@ QgsRelation QgsRelationManager::relation( const QString& id ) const
void QgsRelationManager::clear()
{
mRelations.clear();
emit changed();
}

QList<QgsRelation> QgsRelationManager::referencingRelations( QgsVectorLayer* layer, int fieldIdx ) const
@@ -152,6 +157,7 @@ void QgsRelationManager::readProject( const QDomDocument & doc )
}

emit( relationsLoaded() );
emit changed();
}

void QgsRelationManager::writeProject( QDomDocument & doc )
@@ -175,7 +181,8 @@ void QgsRelationManager::writeProject( QDomDocument & doc )

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

@@ -187,7 +194,12 @@ void QgsRelationManager::layersRemoved( const QStringList& layers )
|| it.value().referencingLayerId() == layer )
{
mRelations.remove( it.key() );
relationsChanged = true;
}
}
}
if ( relationsChanged )
{
emit changed();
}
}
@@ -107,6 +107,12 @@ class CORE_EXPORT QgsRelationManager : public QObject
signals:
void relationsLoaded();

/**
* Emitted when relations are added or removed to the manager.
* @note added in QGIS 2.5
*/
void changed();

private slots:
void readProject( const QDomDocument &doc );
void writeProject( QDomDocument &doc );

4 comments on commit fb2279f

@m-kuhn

This comment has been minimized.

Copy link
Member

@m-kuhn m-kuhn replied Sep 22, 2014

What do you think about relationAdded( const QgsRelation& ) and relationRemoved( id ) signals? This would allow for more specific reactions.

@nyalldawson

This comment has been minimized.

Copy link
Contributor Author

@nyalldawson nyalldawson replied Sep 22, 2014

@m-kuhn they would definitely be useful, but I think there's merit in an all-encompassing "changed" signal too.

@m-kuhn

This comment has been minimized.

Copy link
Member

@m-kuhn m-kuhn replied Sep 22, 2014

@nyalldawson I agree, there are use-cases for this as well.
I just fear that people will start to implement the logic to calculate the delta of the change operation all over the place (or will get it wrong and connect multiple times to signals of already existing relations).
Would it be possible to add the other signals as well?

@nyalldawson

This comment has been minimized.

Copy link
Contributor Author

@nyalldawson nyalldawson replied Sep 22, 2014

@m-kuhn ahh... I thought you were volunteering to do this ;) The biggest issue is with QgsRelationManager::setRelations, as that method clears the existing relations and totally rebuilds them. This makes it harder to correctly emit removed/added signals, as you'd need to manually check whether each has been added or removed before clearing the list. Unfortunately this is the method which the project properties dialog uses to set the relations. It's more work to tackle than I've got time left for the 2.6 freeze!

Please sign in to comment.
You can’t perform that action at this time.