Class: QgsRelationManager¶
Manages a set of relations between layers.
Class Hierarchy¶
Base classes¶
- 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.
- signal changed[source]¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- 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:
- 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:
- 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:
- 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:
- Returns:
a list of matching relations
See also
- signal relationsLoaded[source]¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- 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) Remove a relation.- Parameters:
relation – The relation to remove.
- setPolymorphicRelations(self, relations: Iterable[QgsPolymorphicRelation])[source]¶
Sets the specified polymorphic
relationsand 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.