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.

Enums

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

Gets all relations where this layer is the referenced part (i.e.

referencingRelations

Gets all relations where the specified layer (and field) is the referencing part (i.e.

relation

Gets access to a relation by its id.

relations

Gets 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

updateRelationsStatus

Updates relations status

Signals

changed

Emitted when relations are added or removed to the manager.

relationsLoaded

Emitted when the relations were loaded after reading a project [signal]

Attributes

addRelation(self, relation: QgsRelation)

Add a relation. Invalid relations are added only if both referencing layer and referenced layer exist.

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]

Gets 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]

Gets 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

Gets access to a relation by its id.

Parameters

id – The id to search for

Returns

A relation. Invalid if not found.

relations(self) → object

Gets 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

See also

relation()

New in version 2.16.

relationsLoaded

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()
updateRelationsStatus(self)

Updates relations status