Subgroup: Relation

Class: QgsRelationManager

class qgis.core.QgsRelationManager(project: QgsProject = None)

Bases: PyQt5.QtCore.QObject

Constructor for QgsRelationManager.

Parameters:project – associated project (used to notify project of changes)

This class manages a set of relations between layers.

Methods

addRelation Add a relation.
childEvent
clear Remove any relation managed by this class.
connectNotify
customEvent
disconnectNotify
discoverRelations Discover all the relations available from the current layers.
isSignalConnected
receivers
referencedRelations Get all relations where this layer is the referenced part (i.
referencingRelations Get all relations where the specified layer (and field) is the referencing part (i.
relation Get access to a relation by its id.
relations Get access to the relations managed by this class.
relationsByName Returns a list of relations with matching names.
removeRelation Remove a relation.
sender
senderSignalIndex
setRelations Will set the specified relations and remove any relation currently set.
timerEvent

Signals

changed Emitted when relations are added or removed to the manager.
relationsLoaded This signal is emitted when the relations were loaded after reading a project [signal]

Attributes

addRelation(self, relation: QgsRelation)

Add a relation.

Parameters:relation – The relation to add.
changed

Emitted when relations are added or removed to the manager.

New in version 2.5: [signal]

childEvent()
clear(self)

Remove any relation managed by this class.

connectNotify()
customEvent()
disconnectNotify()
discoverRelations(existingRelations: Iterable[QgsRelation], layers: Iterable[QgsVectorLayer]) → List[QgsRelation]

Discover all the relations available from the current layers.

Parameters:
  • existingRelations – the existing relations to filter them out
  • layers – the current layers
Returns:

the list of discovered relations

New in version 3.0.

isSignalConnected()
receivers()
referencedRelations(self, layer: QgsVectorLayer = None) → List[QgsRelation]

Get all relations where this layer is the referenced part (i.e. the parent table with the primary key being referenced from another layer).

Parameters:layer – The layer which should be searched for.
Returns:A list of relations where the specified layer is the referenced part.
referencingRelations(self, layer: QgsVectorLayer = None, fieldIdx: int = -2) → List[QgsRelation]

Get all relations where the specified layer (and field) is the referencing part (i.e. the child table with the foreign key).

Parameters:
  • layer – The layer which should be searched for.
  • fieldIdx – The field which should be part of the foreign key. If not set will return all relations.
Returns:

A list of relations matching the given layer and fieldIdx.

relation(self, id: str) → QgsRelation

Get access to a relation by its id.

Parameters:id – The id to search for
Returns:A relation. Invalid if not found.
relations(self) → object

Get access to the relations managed by this class.

Returns:A QMap where the key is the relation id, the value the relation object.
relationsByName(self, name: str) → List[QgsRelation]

Returns a list of relations with matching names.

Parameters:name – relation name to search for. Searching is case insensitive.
Returns:a list of matching relations

New in version 2.16.

See also

relation()

relationsLoaded

This signal is emitted when the relations were loaded after reading a project [signal]

removeRelation(self, id: str)

Remove a relation.

Parameters:id – The id of the relation to remove.

removeRelation(self, relation: QgsRelation) Remove a relation.

Parameters:relation – The relation to remove.
sender()
senderSignalIndex()
setRelations(self, relations: Iterable[QgsRelation])

Will set the specified relations and remove any relation currently set.

Parameters:relations – A list of relations to set.
timerEvent()