Class: QgsPolymorphicRelation¶
- class qgis.core.QgsPolymorphicRelation¶
Bases:
sip.wrapper
A polymorphic relation consists of the same properties like a normal relation except for the referenced layer which is calculated based on one or several fields of the referencing layer.
In its most simple form, the referencing layer will just insert the layer name of the referenced layer into this field. To be more precise, a polymorphic relation is a set of normal relations having the same referencing layer but having the referenced layer dynamically defined. The polymorphic setting of the layer is solved by using an expression which has to match some properties of the the referenced layer like the table name, schema, uri, layer id, …
New in version 3.18.
QgsPolymorphicRelation() Default constructor. Creates an invalid relation.
QgsPolymorphicRelation(context:
QgsRelationContext
) Constructor with context. Creates an invalid relation.QgsPolymorphicRelation(other:
QgsPolymorphicRelation
) Copies a relation. This makes a shallow copy, relations are implicitly shared and only duplicated when the copy is changed.Methods
Add a field pair which is part of this relation The first element of each pair are the field names of the foreign key.
Creates a relation from an XML structure.
Returns the field pairs which form this relation The first element of each pair are the field names of the foreign key.
Generate a (project-wide) unique id for this relation
Returns a list of generated relations, based on the currently set
referencedLayerIds()
Compares the two
QgsRelation
, ignoring the name and the ID.A (project-wide) unique id for this relation
Returns the validity of this relation.
Returns layer representation as evaluated string
Returns a human readable name for this relation.
Returns a list of attributes used to form the referenced fields (most likely primary key) on the referenced (parent) layer.
Returns the expression to identify the parent layer
Returns the field in the referencing layer where the referenced layer identifier is stored
Returns a list of layer ids to be used as potential referenced layers
Returns a list of attributes used to form the referencing fields (foreign key) on the referencing (child) layer.
Access the referencing (child) layer This is the layer which has the field(s) which point to another layer
Access the referencing (child) layer's id This is the layer which has the field(s) which point to another layer
Set an id for this relation
Set a name for this relation
Sets the
expression
to identify the parent layerSets the field in the referencing layer where the referenced layer identifier is stored
Sets a list of layer ids to be used as potential referenced layers
Set the referencing (child) layer id.
Sets the relation strength for all the generated normal relations
Returns the relation strength for all the generated normal relations
Updates the validity status of this relation.
Writes a relation to an XML structure.
Attributes
- addFieldPair(self, referencingField: str, referencedField: str)¶
Add a field pair which is part of this relation The first element of each pair are the field names of the foreign key. The second element of each pair are the field names of the matching primary key.
- Parameters:
referencingField (str) – The field name on the referencing (child) layer (FK)
referencedField (str) – The field name on the referenced (parent) layer (PK)
- createFromXml(node: QDomNode, context: QgsReadWriteContext, relationContext: QgsRelationContext = QgsRelationContext()) QgsPolymorphicRelation ¶
Creates a relation from an XML structure. Used for reading .qgs projects.
- Parameters:
node (QDomNode) – The dom node containing the relation information
context (QgsReadWriteContext) – to pass project translator
relationContext (
QgsRelationContext
= QgsRelationContext()) – a relation context
- Return type:
- Returns:
A relation
- fieldPairs(self) Dict[str, str] ¶
Returns the field pairs which form this relation The first element of each pair are the field names of the foreign key. The second element of each pair are the field names of the matching primary key.
- Return type:
Dict[str, str]
- Returns:
The fields forming the relation
- generateId(self)¶
Generate a (project-wide) unique id for this relation
New in version 3.0.
- generateRelations(self) List[QgsRelation] ¶
Returns a list of generated relations, based on the currently set
referencedLayerIds()
- Return type:
List[QgsRelation]
- hasEqualDefinition(self, other: QgsPolymorphicRelation) bool ¶
Compares the two
QgsRelation
, ignoring the name and the ID.- Parameters:
other (QgsPolymorphicRelation) – The other relation
- Return type:
bool
- Returns:
True
if they are similar
- id(self) str ¶
A (project-wide) unique id for this relation
- Return type:
str
- Returns:
The id
- isValid(self) bool ¶
Returns the validity of this relation. Don’t use the information if it’s not valid. A relation is considered valid if both referenced and referencig layers are valid.
- Return type:
bool
- Returns:
True
if the relation is valid
- layerRepresentation(self, layer: QgsVectorLayer) str ¶
Returns layer representation as evaluated string
- Parameters:
layer (QgsVectorLayer) –
- Return type:
str
- name(self) str ¶
Returns a human readable name for this relation. Mostly used as title for the children.
See also
- Return type:
str
- Returns:
A name
- referencedFields(self, layerId: str) List[int] ¶
Returns a list of attributes used to form the referenced fields (most likely primary key) on the referenced (parent) layer.
- Return type:
List[int]
- Returns:
A list of attributes
- Parameters:
layerId (str) –
- referencedLayerExpression(self) str ¶
Returns the expression to identify the parent layer
- Return type:
str
- referencedLayerField(self) str ¶
Returns the field in the referencing layer where the referenced layer identifier is stored
- Return type:
str
- referencedLayerIds(self) List[str] ¶
Returns a list of layer ids to be used as potential referenced layers
- Return type:
List[str]
- referencingFields(self) List[int] ¶
Returns a list of attributes used to form the referencing fields (foreign key) on the referencing (child) layer.
- Return type:
List[int]
- Returns:
A list of attributes
- referencingLayer(self) QgsVectorLayer ¶
Access the referencing (child) layer This is the layer which has the field(s) which point to another layer
- Return type:
- Returns:
The referencing layer
- referencingLayerId(self) str ¶
Access the referencing (child) layer’s id This is the layer which has the field(s) which point to another layer
- Return type:
str
- Returns:
The id of the referencing layer
- setId(self, id: str)¶
Set an id for this relation
- Parameters:
id (str) –
- setName(self, name: str)¶
Set a name for this relation
- Parameters:
name (str) –
- setReferencedLayerExpression(self, expression: str)¶
Sets the
expression
to identify the parent layer- Parameters:
expression (str) –
- setReferencedLayerField(self, referencedLayerField: str)¶
Sets the field in the referencing layer where the referenced layer identifier is stored
- Parameters:
referencedLayerField (str) –
- setReferencedLayerIds(self, childRelationIds: Iterable[str])¶
Sets a list of layer ids to be used as potential referenced layers
- Parameters:
childRelationIds (Iterable[str]) –
- setReferencingLayer(self, id: str)¶
Set the referencing (child) layer id. This layer will be searched in the registry.
- Parameters:
id (str) –
- setRelationStrength(self, relationStrength: QgsRelation.RelationStrength)¶
Sets the relation strength for all the generated normal relations
- Parameters:
relationStrength (QgsRelation.RelationStrength) –
- staticMetaObject = <PyQt5.QtCore.QMetaObject object>¶
- strength(self) QgsRelation.RelationStrength ¶
Returns the relation strength for all the generated normal relations
- Return type:
- updateRelationStatus(self)¶
Updates the validity status of this relation. Will be called internally whenever a member is changed.
- writeXml(self, node: QDomNode, doc: QDomDocument)¶
Writes a relation to an XML structure. Used for saving .qgs projects
- Parameters:
node (QDomNode) – The parent node in which the relation will be created
doc (QDomDocument) – The document in which the relation will be saved