Class: QgsRelationManager¶
Manages a set of relations between layers.
Class Hierarchy¶
Base classes¶
Methods
Adds a new polymorphic relation. |
|
Add a relation. |
|
Remove any relation managed by this class. |
|
Gets the relation context |
|
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. the parent table with the primary key being referenced from another layer). |
|
Gets all relations where the specified layer (and field) is the referencing part (i.e. the child table with the foreign key). |
|
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 |
Static Methods
Discover all the relations available from the current layers. |
Signals
Emitted when relations are added or removed to the manager. |
|
Emitted when the relations were loaded after reading a project |
- class qgis.core.QgsRelationManager[source]¶
Bases:
QObject
- __init__(project: QgsProject | None = None)
Constructor for QgsRelationManager.
- Parameters:
project (Optional[QgsProject] = None) – associated project (used to notify project of changes)
- addPolymorphicRelation(self, polymorphicRelation: QgsPolymorphicRelation)[source]¶
Adds a new polymorphic relation. The generated relations are not available, they will be created automatically.
- Parameters:
polymorphicRelation (QgsPolymorphicRelation)
- addRelation(self, relation: QgsRelation)[source]¶
Add a relation. Invalid relations are added only if both referencing layer and referenced layer exist.
- Parameters:
relation (QgsRelation) – The relation to add.
- context(self) QgsRelationContext [source]¶
Gets the relation context
- Return type:
- static 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
- polymorphicRelation(self, polymorphicRelationId: str | None) QgsPolymorphicRelation [source]¶
Returns the list of relations associated with a polymorphic relation
- Parameters:
polymorphicRelationId (Optional[str])
- Return type:
- polymorphicRelations(self) Dict[str, QgsPolymorphicRelation] ¶
Returns all the polymorphic relations
- Return type:
Dict[str, QgsPolymorphicRelation]
- referencedRelations(self, layer: QgsVectorLayer | None = 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 (Optional[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 = 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 (Optional[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 | None) QgsRelation [source]¶
Gets access to a relation by its id.
- Parameters:
id (Optional[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 | None) List[QgsRelation] ¶
Returns a list of relations with matching names.
- Parameters:
name (Optional[str]) – relation name to search for. Searching is case insensitive.
- Return type:
List[QgsRelation]
- Returns:
a list of matching relations
See also
- removePolymorphicRelation(self, polymorphicRelationId: str | None)[source]¶
Removes an existing polymorphic relation and it’s generated relations.
- Parameters:
polymorphicRelationId (Optional[str])
- removeRelation(self, id: str | None)[source]¶
Remove a relation.
- Parameters:
id (Optional[str]) – The id of the relation to remove.
- removeRelation(self, relation: QgsRelation)[source]
Remove a relation.
- Parameters:
relation (
QgsRelation
) – The relation to remove.
- setPolymorphicRelations(self, relations: Iterable[QgsPolymorphicRelation])[source]¶
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])[source]¶
Will set the specified relations and remove any relation currently set.
- Parameters:
relations (Iterable[QgsRelation]) – A list of relations to set.