Class: QgsRelationManager¶
- class qgis.core.QgsRelationManager¶
Bases:
PyQt5.QtCore.QObject
This class manages a set of relations between layers.
QgsRelationManager(project:
QgsProject
= None) Constructor for QgsRelationManager.- Parameters
project –
associated project (used to notify project of changes)
Methods
Adds a new polymorphic relation.
Add a relation.
Remove any relation managed by this class.
Gets the relation context
Discover all the relations available from the current layers.
Returns the list of relations associated with a polymorphic relation
Returns all the polymorphic relations
Gets all relations where this layer is the referenced part (i.e.
Gets all relations where the specified layer (and field) is the referencing part (i.e.
Gets access to a relation by its id.
Gets access to the relations managed by this class.
Returns a list of relations with matching names.
Removes an existing polymorphic relation and it's generated relations.
Remove a relation.
Sets the specified polymorphic
relations
and removes any polymorphic relations currently set.Will set the specified relations and remove any relation currently set.
Updates relations status
Signals
Emitted when relations are added or removed to the manager.
Emitted when the relations were loaded after reading a project [signal]
- addPolymorphicRelation(self, polymorphicRelation: QgsPolymorphicRelation)¶
Adds a new polymorphic relation. The generated relations are not available, they will be created automatically.
- Parameters
polymorphicRelation (QgsPolymorphicRelation) –
- addRelation(self, relation: QgsRelation)¶
Add a relation. Invalid relations are added only if both referencing layer and referenced layer exist.
- Parameters
relation (QgsRelation) – The relation to add.
- changed¶
Emitted when relations are added or removed to the manager.
New in version 2.5: [signal]
- childEvent(self, QChildEvent)¶
- clear(self)¶
Remove any relation managed by this class.
- connectNotify(self, QMetaMethod)¶
- context(self) QgsRelationContext ¶
Gets the relation context
- Return type
- customEvent(self, QEvent)¶
- disconnectNotify(self, QMetaMethod)¶
- discoverRelations(existingRelations: Iterable[QgsRelation], layers: Iterable[QgsVectorLayer]) List[QgsRelation] ¶
Discover all the relations available from the current layers.
- Parameters
existingRelations (Iterable[QgsRelation]) – the existing relations to filter them out
layers (Iterable[QgsVectorLayer]) – the current layers
- Return type
List[QgsRelation]
- Returns
the list of discovered relations
New in version 3.0.
- isSignalConnected(self, QMetaMethod) bool ¶
- polymorphicRelation(self, polymorphicRelationId: str) QgsPolymorphicRelation ¶
Returns the list of relations associated with a polymorphic relation
- Parameters
polymorphicRelationId (str) –
- Return type
- polymorphicRelations(self) Dict[str, QgsPolymorphicRelation] ¶
Returns all the polymorphic relations
- Return type
Dict[str, QgsPolymorphicRelation]
- receivers(self, PYQT_SIGNAL) int ¶
- 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 (
QgsVectorLayer
= None) – The layer which should be searched for.- Return type
List[QgsRelation]
- 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 (
QgsVectorLayer
= None) – The layer which should be searched for.fieldIdx (int = -2) – The field which should be part of the foreign key. If not set will return all relations.
- Return type
List[QgsRelation]
- 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 (str) – The id to search for
- Return type
- Returns
A relation. Invalid if not found.
See also
- relations(self) Dict[str, QgsRelation] ¶
Gets access to the relations managed by this class.
- Return type
Dict[str, QgsRelation]
- 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 (str) – relation name to search for. Searching is case insensitive.
- Return type
List[QgsRelation]
- Returns
a list of matching relations
See also
New in version 2.16.
- relationsLoaded¶
Emitted when the relations were loaded after reading a project [signal]
- removePolymorphicRelation(self, polymorphicRelationId: str)¶
Removes an existing polymorphic relation and it’s generated relations.
- Parameters
polymorphicRelationId (str) –
- removeRelation(self, id: str)¶
Remove a relation.
- Parameters
id (str) – The id of the relation to remove.
removeRelation(self, relation:
QgsRelation
) Remove a relation.- Parameters
relation – The relation to remove.
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setPolymorphicRelations(self, relations: Iterable[QgsPolymorphicRelation])¶
Sets the specified polymorphic
relations
and removes any polymorphic relations currently set. Will remove any generated relations and recreate them.- Parameters
relations (Iterable[QgsPolymorphicRelation]) –
- setRelations(self, relations: Iterable[QgsRelation])¶
Will set the specified relations and remove any relation currently set.
- Parameters
relations (Iterable[QgsRelation]) – A list of relations to set.
- timerEvent(self, QTimerEvent)¶
- updateRelationsStatus(self)¶
Updates relations status