QGIS API Documentation  3.20.0-Odense (decaadbb31)
Public Member Functions | Static Public Member Functions | Properties | List of all members
QgsPolymorphicRelation Class Reference

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. More...

#include <qgspolymorphicrelation.h>

Public Member Functions

 QgsPolymorphicRelation ()
 Default constructor. More...
 
 QgsPolymorphicRelation (const QgsPolymorphicRelation &other)
 Copies a relation. More...
 
 QgsPolymorphicRelation (const QgsRelationContext &context)
 Constructor with context. More...
 
 ~QgsPolymorphicRelation ()
 
void addFieldPair (const QgsRelation::FieldPair &fieldPair)
 Add a field pair which is part of this relation The first element of each pair are the field names of the foreign key. More...
 
void addFieldPair (const QString &referencingField, const QString &referencedField)
 Add a field pair which is part of this relation The first element of each pair are the field names of the foreign key. More...
 
QList< QgsRelation::FieldPairfieldPairs () const
 Returns the field pairs which form this relation The first element of each pair are the field names of the foreign key. More...
 
void generateId ()
 Generate a (project-wide) unique id for this relation. More...
 
QList< QgsRelationgenerateRelations () const
 Returns a list of generated relations, based on the currently set referencedLayerIds() More...
 
bool hasEqualDefinition (const QgsPolymorphicRelation &other) const
 Compares the two QgsRelation, ignoring the name and the ID. More...
 
QString id () const
 A (project-wide) unique id for this relation. More...
 
bool isValid () const
 Returns the validity of this relation. More...
 
QString layerRepresentation (const QgsVectorLayer *layer) const
 Returns layer representation as evaluated string. More...
 
QString name () const
 Returns a human readable name for this relation. More...
 
QgsPolymorphicRelationoperator= (const QgsPolymorphicRelation &other)
 Copies a relation. More...
 
QgsAttributeList referencedFields (const QString &layerId) const
 Returns a list of attributes used to form the referenced fields (most likely primary key) on the referenced (parent) layer. More...
 
QString referencedLayerExpression () const
 Returns the expression to identify the parent layer. More...
 
QString referencedLayerField () const
 Returns the field in the referencing layer where the referenced layer identifier is stored. More...
 
QStringList referencedLayerIds () const
 Returns a list of layer ids to be used as potential referenced layers. More...
 
QgsAttributeList referencingFields () const
 Returns a list of attributes used to form the referencing fields (foreign key) on the referencing (child) layer. More...
 
QgsVectorLayerreferencingLayer () const
 Access the referencing (child) layer This is the layer which has the field(s) which point to another layer. More...
 
QString referencingLayerId () const
 Access the referencing (child) layer's id This is the layer which has the field(s) which point to another layer. More...
 
void setId (const QString &id)
 Set an id for this relation. More...
 
void setName (const QString &name)
 Set a name for this relation. More...
 
void setReferencedLayerExpression (const QString &expression)
 Sets the expression to identify the parent layer. More...
 
void setReferencedLayerField (const QString &referencedLayerField)
 Sets the field in the referencing layer where the referenced layer identifier is stored. More...
 
void setReferencedLayerIds (const QStringList &childRelationIds)
 Sets a list of layer ids to be used as potential referenced layers. More...
 
void setReferencingLayer (const QString &id)
 Set the referencing (child) layer id. More...
 
void setRelationStrength (QgsRelation::RelationStrength relationStrength)
 Sets the relation strength for all the generated normal relations. More...
 
QgsRelation::RelationStrength strength () const
 Returns the relation strength for all the generated normal relations. More...
 
void updateRelationStatus ()
 Updates the validity status of this relation. More...
 
void writeXml (QDomNode &node, QDomDocument &doc) const
 Writes a relation to an XML structure. More...
 

Static Public Member Functions

static QgsPolymorphicRelation createFromXml (const QDomNode &node, QgsReadWriteContext &context, const QgsRelationContext &relationContext=QgsRelationContext())
 Creates a relation from an XML structure. More...
 

Properties

Q_GADGET QString id
 
bool isValid
 
QString name
 
QString referencedLayerExpression
 
QString referencedLayerField
 
QgsVectorLayerreferencingLayer
 

Detailed Description

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, ...

Since
QGIS 3.18

Definition at line 49 of file qgspolymorphicrelation.h.

Constructor & Destructor Documentation

◆ QgsPolymorphicRelation() [1/3]

QgsPolymorphicRelation::QgsPolymorphicRelation ( )

Default constructor.

Creates an invalid relation.

Definition at line 26 of file qgspolymorphicrelation.cpp.

◆ ~QgsPolymorphicRelation()

QgsPolymorphicRelation::~QgsPolymorphicRelation ( )
default

◆ QgsPolymorphicRelation() [2/3]

QgsPolymorphicRelation::QgsPolymorphicRelation ( const QgsRelationContext context)

Constructor with context.

Creates an invalid relation.

Definition at line 31 of file qgspolymorphicrelation.cpp.

◆ QgsPolymorphicRelation() [3/3]

QgsPolymorphicRelation::QgsPolymorphicRelation ( const QgsPolymorphicRelation other)

Copies a relation.

This makes a shallow copy, relations are implicitly shared and only duplicated when the copy is changed.

Definition at line 39 of file qgspolymorphicrelation.cpp.

Member Function Documentation

◆ addFieldPair() [1/2]

void QgsPolymorphicRelation::addFieldPair ( const QgsRelation::FieldPair fieldPair)

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
fieldPairA pair of two strings
Note
not available in Python bindings

Definition at line 151 of file qgspolymorphicrelation.cpp.

◆ addFieldPair() [2/2]

void QgsPolymorphicRelation::addFieldPair ( const QString &  referencingField,
const QString &  referencedField 
)

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
referencingFieldThe field name on the referencing (child) layer (FK)
referencedFieldThe field name on the referenced (parent) layer (PK)

Definition at line 144 of file qgspolymorphicrelation.cpp.

◆ createFromXml()

QgsPolymorphicRelation QgsPolymorphicRelation::createFromXml ( const QDomNode &  node,
QgsReadWriteContext context,
const QgsRelationContext relationContext = QgsRelationContext() 
)
static

Creates a relation from an XML structure.

Used for reading .qgs projects.

Parameters
nodeThe dom node containing the relation information
contextto pass project translator
relationContexta relation context
Returns
A relation

Definition at line 52 of file qgspolymorphicrelation.cpp.

◆ fieldPairs()

QList< QgsRelation::FieldPair > QgsPolymorphicRelation::fieldPairs ( ) const

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.

Returns
The fields forming the relation

Definition at line 183 of file qgspolymorphicrelation.cpp.

◆ generateId()

void QgsPolymorphicRelation::generateId ( )

Generate a (project-wide) unique id for this relation.

Since
QGIS 3.0

Definition at line 163 of file qgspolymorphicrelation.cpp.

◆ generateRelations()

QList< QgsRelation > QgsPolymorphicRelation::generateRelations ( ) const

Returns a list of generated relations, based on the currently set referencedLayerIds()

Definition at line 378 of file qgspolymorphicrelation.cpp.

◆ hasEqualDefinition()

bool QgsPolymorphicRelation::hasEqualDefinition ( const QgsPolymorphicRelation other) const

Compares the two QgsRelation, ignoring the name and the ID.

Parameters
otherThe other relation
Returns
true if they are similar

Definition at line 225 of file qgspolymorphicrelation.cpp.

◆ id()

QString QgsPolymorphicRelation::id ( ) const

A (project-wide) unique id for this relation.

Returns
The id

Definition at line 158 of file qgspolymorphicrelation.cpp.

◆ isValid()

bool QgsPolymorphicRelation::isValid ( ) const

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.

Returns
true if the relation is valid

Definition at line 220 of file qgspolymorphicrelation.cpp.

◆ layerRepresentation()

QString QgsPolymorphicRelation::layerRepresentation ( const QgsVectorLayer layer) const

Returns layer representation as evaluated string.

Definition at line 412 of file qgspolymorphicrelation.cpp.

◆ name()

QString QgsPolymorphicRelation::name ( ) const

Returns a human readable name for this relation.

Mostly used as title for the children.

See also
id()
Returns
A name

Definition at line 322 of file qgspolymorphicrelation.cpp.

◆ operator=()

QgsPolymorphicRelation & QgsPolymorphicRelation::operator= ( const QgsPolymorphicRelation other)

Copies a relation.

This makes a shallow copy, relations are implicitly shared and only duplicated when the copy is changed.

Definition at line 45 of file qgspolymorphicrelation.cpp.

◆ referencedFields()

QgsAttributeList QgsPolymorphicRelation::referencedFields ( const QString &  layerId) const

Returns a list of attributes used to form the referenced fields (most likely primary key) on the referenced (parent) layer.

Returns
A list of attributes

Definition at line 188 of file qgspolymorphicrelation.cpp.

◆ referencedLayerExpression()

QString QgsPolymorphicRelation::referencedLayerExpression ( ) const

Returns the expression to identify the parent layer.

Definition at line 349 of file qgspolymorphicrelation.cpp.

◆ referencedLayerField()

QString QgsPolymorphicRelation::referencedLayerField ( ) const

Returns the field in the referencing layer where the referenced layer identifier is stored.

Definition at line 337 of file qgspolymorphicrelation.cpp.

◆ referencedLayerIds()

QStringList QgsPolymorphicRelation::referencedLayerIds ( ) const

Returns a list of layer ids to be used as potential referenced layers.

Definition at line 361 of file qgspolymorphicrelation.cpp.

◆ referencingFields()

QgsAttributeList QgsPolymorphicRelation::referencingFields ( ) const

Returns a list of attributes used to form the referencing fields (foreign key) on the referencing (child) layer.

Returns
A list of attributes

Definition at line 208 of file qgspolymorphicrelation.cpp.

◆ referencingLayer()

QgsVectorLayer * QgsPolymorphicRelation::referencingLayer ( ) const

Access the referencing (child) layer This is the layer which has the field(s) which point to another layer.

Returns
The referencing layer

Definition at line 178 of file qgspolymorphicrelation.cpp.

◆ referencingLayerId()

QString QgsPolymorphicRelation::referencingLayerId ( ) const

Access the referencing (child) layer's id This is the layer which has the field(s) which point to another layer.

Returns
The id of the referencing layer

Definition at line 173 of file qgspolymorphicrelation.cpp.

◆ setId()

void QgsPolymorphicRelation::setId ( const QString &  id)

Set an id for this relation.

Definition at line 125 of file qgspolymorphicrelation.cpp.

◆ setName()

void QgsPolymorphicRelation::setName ( const QString &  name)

Set a name for this relation.

Definition at line 312 of file qgspolymorphicrelation.cpp.

◆ setReferencedLayerExpression()

void QgsPolymorphicRelation::setReferencedLayerExpression ( const QString &  expression)

Sets the expression to identify the parent layer.

Definition at line 342 of file qgspolymorphicrelation.cpp.

◆ setReferencedLayerField()

void QgsPolymorphicRelation::setReferencedLayerField ( const QString &  referencedLayerField)

Sets the field in the referencing layer where the referenced layer identifier is stored.

Definition at line 330 of file qgspolymorphicrelation.cpp.

◆ setReferencedLayerIds()

void QgsPolymorphicRelation::setReferencedLayerIds ( const QStringList &  childRelationIds)

Sets a list of layer ids to be used as potential referenced layers.

Definition at line 354 of file qgspolymorphicrelation.cpp.

◆ setReferencingLayer()

void QgsPolymorphicRelation::setReferencingLayer ( const QString &  id)

Set the referencing (child) layer id.

This layer will be searched in the registry.

Definition at line 136 of file qgspolymorphicrelation.cpp.

◆ setRelationStrength()

void QgsPolymorphicRelation::setRelationStrength ( QgsRelation::RelationStrength  relationStrength)

Sets the relation strength for all the generated normal relations.

Definition at line 371 of file qgspolymorphicrelation.cpp.

◆ strength()

QgsRelation::RelationStrength QgsPolymorphicRelation::strength ( ) const

Returns the relation strength for all the generated normal relations.

Definition at line 366 of file qgspolymorphicrelation.cpp.

◆ updateRelationStatus()

void QgsPolymorphicRelation::updateRelationStatus ( )

Updates the validity status of this relation.

Will be called internally whenever a member is changed.

Definition at line 233 of file qgspolymorphicrelation.cpp.

◆ writeXml()

void QgsPolymorphicRelation::writeXml ( QDomNode &  node,
QDomDocument &  doc 
) const

Writes a relation to an XML structure.

Used for saving .qgs projects

Parameters
nodeThe parent node in which the relation will be created
docThe document in which the relation will be saved

Definition at line 99 of file qgspolymorphicrelation.cpp.

Property Documentation

◆ id

Q_GADGET QString QgsPolymorphicRelation::id
readwrite

Definition at line 51 of file qgspolymorphicrelation.h.

◆ isValid

bool QgsPolymorphicRelation::isValid
read

Definition at line 51 of file qgspolymorphicrelation.h.

◆ name

QString QgsPolymorphicRelation::name
readwrite

Definition at line 51 of file qgspolymorphicrelation.h.

◆ referencedLayerExpression

QString QgsPolymorphicRelation::referencedLayerExpression
read

Definition at line 51 of file qgspolymorphicrelation.h.

◆ referencedLayerField

QString QgsPolymorphicRelation::referencedLayerField
read

Definition at line 51 of file qgspolymorphicrelation.h.

◆ referencingLayer

QgsVectorLayer * QgsPolymorphicRelation::referencingLayer
read

Definition at line 51 of file qgspolymorphicrelation.h.


The documentation for this class was generated from the following files: