QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Properties | Friends | 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.
 
 QgsPolymorphicRelation (const QgsPolymorphicRelation &other)
 Copies a relation.
 
 QgsPolymorphicRelation (const QgsRelationContext &context)
 Constructor with context.
 
 ~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.
 
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.
 
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.
 
void generateId ()
 Generate a (project-wide) unique id for this relation.
 
QList< QgsRelationgenerateRelations () const
 Returns a list of generated relations, based on the currently set referencedLayerIds()
 
bool hasEqualDefinition (const QgsPolymorphicRelation &other) const
 Compares the two QgsRelation, ignoring the name and the ID.
 
QString id () const
 A (project-wide) unique id for this relation.
 
bool isValid () const
 Returns the validity of this relation.
 
QString layerRepresentation (const QgsVectorLayer *layer) const
 Returns layer representation as evaluated string.
 
QString name () const
 Returns a human readable name for this relation.
 
QgsPolymorphicRelationoperator= (const QgsPolymorphicRelation &other)
 Copies a relation.
 
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.
 
QString referencedLayerExpression () const
 Returns the expression to identify the parent layer.
 
QString referencedLayerField () const
 Returns the field in the referencing layer where the referenced layer identifier is stored.
 
QStringList referencedLayerIds () const
 Returns a list of layer ids to be used as potential referenced layers.
 
QgsAttributeList referencingFields () const
 Returns a list of attributes used to form the referencing fields (foreign key) on the referencing (child) layer.
 
QgsVectorLayerreferencingLayer () const
 Access the referencing (child) layer This is the layer which has the field(s) which point to another layer.
 
QString referencingLayerId () const
 Access the referencing (child) layer's id This is the layer which has the field(s) which point to another layer.
 
void setId (const QString &id)
 Set an id for this relation.
 
void setName (const QString &name)
 Set a name for this relation.
 
void setReferencedLayerExpression (const QString &expression)
 Sets the expression to identify the parent layer.
 
void setReferencedLayerField (const QString &referencedLayerField)
 Sets the field in the referencing layer where the referenced layer identifier is stored.
 
void setReferencedLayerIds (const QStringList &childRelationIds)
 Sets a list of layer ids to be used as potential referenced layers.
 
void setReferencingLayer (const QString &id)
 Set the referencing (child) layer id.
 
void setRelationStrength (Qgis::RelationshipStrength relationStrength)
 Sets the relation strength for all the generated normal relations.
 
Qgis::RelationshipStrength strength () const
 Returns the relation strength for all the generated normal relations.
 
void updateRelationStatus ()
 Updates the validity status of this relation.
 
void writeXml (QDomNode &node, QDomDocument &doc) const
 Writes a relation to an XML structure.
 

Static Public Member Functions

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

Properties

QString id
 
bool isValid
 
QString name
 
QString referencedLayerExpression
 
QString referencedLayerField
 
QgsVectorLayerreferencingLayer
 

Friends

class QgsRelationManager
 

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 25 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 30 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 38 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 150 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 143 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 51 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 182 of file qgspolymorphicrelation.cpp.

◆ generateId()

void QgsPolymorphicRelation::generateId ( )

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

Definition at line 162 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 377 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 224 of file qgspolymorphicrelation.cpp.

◆ id()

QString QgsPolymorphicRelation::id ( ) const

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

Returns
The id

Definition at line 157 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 219 of file qgspolymorphicrelation.cpp.

◆ layerRepresentation()

QString QgsPolymorphicRelation::layerRepresentation ( const QgsVectorLayer layer) const

Returns layer representation as evaluated string.

Definition at line 429 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 321 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 44 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 187 of file qgspolymorphicrelation.cpp.

◆ referencedLayerExpression()

QString QgsPolymorphicRelation::referencedLayerExpression ( ) const

Returns the expression to identify the parent layer.

Definition at line 348 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 336 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 360 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 207 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 177 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 172 of file qgspolymorphicrelation.cpp.

◆ setId()

void QgsPolymorphicRelation::setId ( const QString &  id)

Set an id for this relation.

Definition at line 124 of file qgspolymorphicrelation.cpp.

◆ setName()

void QgsPolymorphicRelation::setName ( const QString &  name)

Set a name for this relation.

Definition at line 311 of file qgspolymorphicrelation.cpp.

◆ setReferencedLayerExpression()

void QgsPolymorphicRelation::setReferencedLayerExpression ( const QString &  expression)

Sets the expression to identify the parent layer.

Definition at line 341 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 329 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 353 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 135 of file qgspolymorphicrelation.cpp.

◆ setRelationStrength()

void QgsPolymorphicRelation::setRelationStrength ( Qgis::RelationshipStrength  relationStrength)

Sets the relation strength for all the generated normal relations.

Definition at line 370 of file qgspolymorphicrelation.cpp.

◆ strength()

Qgis::RelationshipStrength QgsPolymorphicRelation::strength ( ) const

Returns the relation strength for all the generated normal relations.

Definition at line 365 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 232 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 98 of file qgspolymorphicrelation.cpp.

Friends And Related Symbol Documentation

◆ QgsRelationManager

friend class QgsRelationManager
friend

Definition at line 288 of file qgspolymorphicrelation.h.

Property Documentation

◆ id

QString QgsPolymorphicRelation::id
readwrite

Definition at line 53 of file qgspolymorphicrelation.h.

◆ isValid

bool QgsPolymorphicRelation::isValid
read

Definition at line 58 of file qgspolymorphicrelation.h.

◆ name

QString QgsPolymorphicRelation::name
readwrite

Definition at line 57 of file qgspolymorphicrelation.h.

◆ referencedLayerExpression

QString QgsPolymorphicRelation::referencedLayerExpression
read

Definition at line 56 of file qgspolymorphicrelation.h.

◆ referencedLayerField

QString QgsPolymorphicRelation::referencedLayerField
read

Definition at line 55 of file qgspolymorphicrelation.h.

◆ referencingLayer

QgsVectorLayer * QgsPolymorphicRelation::referencingLayer
read

Definition at line 54 of file qgspolymorphicrelation.h.


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