QGIS API Documentation 3.41.0-Master (3291e9ff48b)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
QgsWeakRelation Class Reference

The QgsWeakRelation class represent a QgsRelation with possibly unresolved layers or unmatched fields. More...

#include <qgsweakrelation.h>

Public Types

enum  WeakRelationType { Referencing , Referenced }
 Enum to distinguish if the layer is referenced or referencing. More...
 

Public Member Functions

 QgsWeakRelation ()
 Default constructor for an invalid relation.
 
 QgsWeakRelation (const QString &relationId, const QString &relationName, const Qgis::RelationshipStrength strength, const QString &referencingLayerId, const QString &referencingLayerName, const QString &referencingLayerSource, const QString &referencingLayerProviderKey, const QString &referencedLayerId, const QString &referencedLayerName, const QString &referencedLayerSource, const QString &referencedLayerProviderKey)
 Creates a QgsWeakRelation.
 
QString backwardPathLabel () const
 Returns the label of the backward path for the relationship.
 
Qgis::RelationshipCardinality cardinality () const
 Returns the relationship's cardinality.
 
QString forwardPathLabel () const
 Returns the label of the forward path for the relationship.
 
QString id () const
 Returns the relationship's ID.
 
QStringList mappingReferencedLayerFields () const
 Returns the list of fields from the mappingTable() involved in the relationship.
 
QStringList mappingReferencingLayerFields () const
 Returns the list of fields from the mappingTable() involved in the relationship.
 
QgsVectorLayerRef mappingTable () const
 Returns a weak reference to the mapping table, which forms the middle table in many-to-many relationships.
 
QString mappingTableName () const
 Returns the layer name of the mapping table, which forms the middle table in many-to-many relationships.
 
QString mappingTableProvider () const
 Returns the provider ID for the mapping table, which forms the middle table in many-to-many relationships.
 
QString mappingTableSource () const
 Returns the source URI for the mapping table, which forms the middle table in many-to-many relationships.
 
QString name () const
 Returns the relationship's name.
 
QgsVectorLayerRef referencedLayer () const
 Returns a weak reference to the referenced (or "parent" / "left") layer.
 
QStringList referencedLayerFields () const
 Returns the list of fields from the referencedLayer() involved in the relationship.
 
QString referencedLayerName () const
 Returns the layer name of the referenced (or "parent" / "left") layer.
 
QString referencedLayerProvider () const
 Returns the provider ID for the referenced (or "parent" / "left") layer.
 
QString referencedLayerSource () const
 Returns the source URI for the referenced (or "parent" / "left") layer.
 
QgsVectorLayerRef referencingLayer () const
 Returns a weak reference to the referencing (or "child" / "right") layer.
 
QStringList referencingLayerFields () const
 Returns the list of fields from the referencingLayer() involved in the relationship.
 
QString referencingLayerName () const
 Returns the layer name of the referencing (or "child" / "right") layer.
 
QString referencingLayerProvider () const
 Returns the provider ID for the referencing (or "child" / "right") layer.
 
QString referencingLayerSource () const
 Returns the source URI for the referencing (or "child" / "right") layer.
 
QString relatedTableType () const
 Returns the type string of the related table.
 
QList< QgsRelationresolvedRelations (const QgsProject *project, QgsVectorLayerRef::MatchType matchType=QgsVectorLayerRef::MatchType::All) const
 Resolves a weak relation in the given project returning a list of possibly invalid QgsRelations and without performing any kind of validity check.
 
void setBackwardPathLabel (const QString &label)
 Sets the label of the backward path for the relationship.
 
void setCardinality (Qgis::RelationshipCardinality cardinality)
 Sets the relationship's cardinality.
 
void setForwardPathLabel (const QString &label)
 Sets the label of the forward path for the relationship.
 
void setMappingReferencedLayerFields (const QStringList &fields)
 Sets the list of fields from the mappingTable() involved in the relationship.
 
void setMappingReferencingLayerFields (const QStringList &fields)
 Sets the list of fields from the mappingTable() involved in the relationship.
 
void setMappingTable (const QgsVectorLayerRef &table)
 Sets a weak reference to the mapping table, which forms the middle table in many-to-many relationships.
 
void setMappingTable (const QString &sourceUri, const QString &provider)
 Sets the source for the mapping table, which forms the middle table in many-to-many relationships, by sourceUri and provider ID.
 
void setReferencedLayer (const QString &sourceUri, const QString &provider)
 Sets the source for the referenced (or "parent" / "left") layer, by sourceUri and provider ID.
 
void setReferencedLayerFields (const QStringList &fields)
 Sets the list of fields from the referencedLayer() involved in the relationship.
 
void setReferencingLayer (const QString &sourceUri, const QString &provider)
 Sets the source for the referencing (or "child" / "right") layer, by sourceUri and provider ID.
 
void setReferencingLayerFields (const QStringList &fields)
 Sets the list of fields from the referencingLayer() involved in the relationship.
 
void setRelatedTableType (const QString &type)
 Sets the type string of the related table.
 
Qgis::RelationshipStrength strength () const
 Returns the strength of the relation.
 

Static Public Member Functions

static QgsWeakRelation readXml (const QgsVectorLayer *layer, WeakRelationType type, const QDomNode &node, const QgsPathResolver resolver)
 Returns a weak relation for the given layer.
 
static void writeXml (const QgsVectorLayer *layer, WeakRelationType type, const QgsRelation &relation, QDomNode &node, QDomDocument &doc)
 Writes a weak relation infoto an XML structure.
 

Friends

class TestQgsWeakRelation
 

Detailed Description

The QgsWeakRelation class represent a QgsRelation with possibly unresolved layers or unmatched fields.

This class is used to store relation information attached to a layer style, a method to attempt relation resolution is also implemented and can be used to create a QgsRelation after the dependent layers are loaded and available.

In contrast to QgsRelation, QgsWeakRelation can be used to encapsulate information about a relationship which does not currently exist in a QGIS project. E.g. it can be used to represent a relationship which exists in a database backend (but not within a QGIS project). Accordingly, some properties available in QgsWeakRelation are included for informational purposes only, and cannot be translated to QgsRelations or respected in QGIS relationships.

Since
QGIS 3.12

Definition at line 42 of file qgsweakrelation.h.

Member Enumeration Documentation

◆ WeakRelationType

Enum to distinguish if the layer is referenced or referencing.

Since
QGIS 3.16
Enumerator
Referencing 

The layer is referencing (or the "child" / "right" layer in the relationship)

Referenced 

The layer is referenced (or the "parent" / "left" left in the relationship)

Definition at line 50 of file qgsweakrelation.h.

Constructor & Destructor Documentation

◆ QgsWeakRelation() [1/2]

QgsWeakRelation::QgsWeakRelation ( )
default

Default constructor for an invalid relation.

◆ QgsWeakRelation() [2/2]

QgsWeakRelation::QgsWeakRelation ( const QString &  relationId,
const QString &  relationName,
const Qgis::RelationshipStrength  strength,
const QString &  referencingLayerId,
const QString &  referencingLayerName,
const QString &  referencingLayerSource,
const QString &  referencingLayerProviderKey,
const QString &  referencedLayerId,
const QString &  referencedLayerName,
const QString &  referencedLayerSource,
const QString &  referencedLayerProviderKey 
)

Creates a QgsWeakRelation.

Since
QGIS 3.30

Definition at line 25 of file qgsweakrelation.cpp.

Member Function Documentation

◆ backwardPathLabel()

QString QgsWeakRelation::backwardPathLabel ( ) const
inline

Returns the label of the backward path for the relationship.

The forward and backward path labels are free-form, user-friendly strings which can be used to generate descriptions of the relationship between features from the right and left tables.

E.g. when the left table contains buildings and the right table contains furniture, the forward path label could be "contains" and the backward path label could be "is located within". A client could then generate a user friendly description string such as "fire hose 1234 is located within building 15a".

See also
setBackwardPathLabel()
forwardPathLabel()
Since
QGIS 3.28

Definition at line 370 of file qgsweakrelation.h.

◆ cardinality()

Qgis::RelationshipCardinality QgsWeakRelation::cardinality ( ) const
inline

Returns the relationship's cardinality.

See also
setCardinality()
Since
QGIS 3.28

Definition at line 324 of file qgsweakrelation.h.

◆ forwardPathLabel()

QString QgsWeakRelation::forwardPathLabel ( ) const
inline

Returns the label of the forward path for the relationship.

The forward and backward path labels are free-form, user-friendly strings which can be used to generate descriptions of the relationship between features from the right and left tables.

E.g. when the left table contains buildings and the right table contains furniture, the forward path label could be "contains" and the backward path label could be "is located within". A client could then generate a user friendly description string such as "fire hose 1234 is located within building 15a".

See also
setForwardPathLabel()
backwardPathLabel()
Since
QGIS 3.28

Definition at line 351 of file qgsweakrelation.h.

◆ id()

QString QgsWeakRelation::id ( ) const
inline

Returns the relationship's ID.

Since
QGIS 3.28

Definition at line 97 of file qgsweakrelation.h.

◆ mappingReferencedLayerFields()

QStringList QgsWeakRelation::mappingReferencedLayerFields ( ) const
inline

Returns the list of fields from the mappingTable() involved in the relationship.

These fields will be matched to the referencedLayerFields() in many-to-many joins.

Since
QGIS 3.28

Definition at line 302 of file qgsweakrelation.h.

◆ mappingReferencingLayerFields()

QStringList QgsWeakRelation::mappingReferencingLayerFields ( ) const
inline

Returns the list of fields from the mappingTable() involved in the relationship.

These fields will be matched to the referencingLayerFields() in many-to-many joins.

Since
QGIS 3.28

Definition at line 270 of file qgsweakrelation.h.

◆ mappingTable()

QgsVectorLayerRef QgsWeakRelation::mappingTable ( ) const

Returns a weak reference to the mapping table, which forms the middle table in many-to-many relationships.

Note
Not available in Python bindings.
Since
QGIS 3.28

Definition at line 190 of file qgsweakrelation.cpp.

◆ mappingTableName()

QString QgsWeakRelation::mappingTableName ( ) const

Returns the layer name of the mapping table, which forms the middle table in many-to-many relationships.

Note
the layer name refers to the layer name used in the datasource, not in any associated QgsVectorLayer.
Since
QGIS 3.28

Definition at line 210 of file qgsweakrelation.cpp.

◆ mappingTableProvider()

QString QgsWeakRelation::mappingTableProvider ( ) const

Returns the provider ID for the mapping table, which forms the middle table in many-to-many relationships.

See also
mappingTableSource()
setMappingTable()
Since
QGIS 3.28

Definition at line 205 of file qgsweakrelation.cpp.

◆ mappingTableSource()

QString QgsWeakRelation::mappingTableSource ( ) const

Returns the source URI for the mapping table, which forms the middle table in many-to-many relationships.

See also
mappingTableProvider()
setMappingTable()
Since
QGIS 3.28

Definition at line 200 of file qgsweakrelation.cpp.

◆ name()

QString QgsWeakRelation::name ( ) const
inline

Returns the relationship's name.

Since
QGIS 3.28

Definition at line 104 of file qgsweakrelation.h.

◆ readXml()

QgsWeakRelation QgsWeakRelation::readXml ( const QgsVectorLayer layer,
WeakRelationType  type,
const QDomNode &  node,
const QgsPathResolver  resolver 
)
static

Returns a weak relation for the given layer.

Parameters
layerthe layer of the weak relation
typedetermines if the layer is referencing or referenced
nodethe QDomNode
resolverthe path resolver
Since
QGIS 3.16

Definition at line 230 of file qgsweakrelation.cpp.

◆ referencedLayer()

QgsVectorLayerRef QgsWeakRelation::referencedLayer ( ) const

Returns a weak reference to the referenced (or "parent" / "left") layer.

Note
Not available in Python bindings.

Definition at line 160 of file qgsweakrelation.cpp.

◆ referencedLayerFields()

QStringList QgsWeakRelation::referencedLayerFields ( ) const
inline

Returns the list of fields from the referencedLayer() involved in the relationship.

Since
QGIS 3.28

Definition at line 286 of file qgsweakrelation.h.

◆ referencedLayerName()

QString QgsWeakRelation::referencedLayerName ( ) const

Returns the layer name of the referenced (or "parent" / "left") layer.

Note
the layer name refers to the layer name used in the datasource, not in any associated QgsVectorLayer.
Since
QGIS 3.28

Definition at line 175 of file qgsweakrelation.cpp.

◆ referencedLayerProvider()

QString QgsWeakRelation::referencedLayerProvider ( ) const

Returns the provider ID for the referenced (or "parent" / "left") layer.

See also
referencedLayerSource()
setReferencedLayer()
Since
QGIS 3.28

Definition at line 170 of file qgsweakrelation.cpp.

◆ referencedLayerSource()

QString QgsWeakRelation::referencedLayerSource ( ) const

Returns the source URI for the referenced (or "parent" / "left") layer.

See also
referencedLayerProvider()
setReferencedLayer()
Since
QGIS 3.28

Definition at line 165 of file qgsweakrelation.cpp.

◆ referencingLayer()

QgsVectorLayerRef QgsWeakRelation::referencingLayer ( ) const

Returns a weak reference to the referencing (or "child" / "right") layer.

Note
Not available in Python bindings.

Definition at line 130 of file qgsweakrelation.cpp.

◆ referencingLayerFields()

QStringList QgsWeakRelation::referencingLayerFields ( ) const
inline

Returns the list of fields from the referencingLayer() involved in the relationship.

Since
QGIS 3.28

Definition at line 254 of file qgsweakrelation.h.

◆ referencingLayerName()

QString QgsWeakRelation::referencingLayerName ( ) const

Returns the layer name of the referencing (or "child" / "right") layer.

Note
the layer name refers to the layer name used in the datasource, not in any associated QgsVectorLayer.
Since
QGIS 3.28

Definition at line 151 of file qgsweakrelation.cpp.

◆ referencingLayerProvider()

QString QgsWeakRelation::referencingLayerProvider ( ) const

Returns the provider ID for the referencing (or "child" / "right") layer.

See also
referencingLayerSource()
setReferencingLayer()
Since
QGIS 3.28

Definition at line 140 of file qgsweakrelation.cpp.

◆ referencingLayerSource()

QString QgsWeakRelation::referencingLayerSource ( ) const

Returns the source URI for the referencing (or "child" / "right") layer.

See also
referencingLayerProvider()
setReferencingLayer()
Since
QGIS 3.28

Definition at line 135 of file qgsweakrelation.cpp.

◆ relatedTableType()

QString QgsWeakRelation::relatedTableType ( ) const
inline

Returns the type string of the related table.

This a free-form string representing the type of related features, where the exact interpretation is format dependent. For instance, table types from GeoPackage relationships will directly reflect the categories from the GeoPackage related tables extension (i.e. "media", "simple attributes", "features", "attributes" and "tiles").

See also
setRelatedTableType()
Since
QGIS 3.28

Definition at line 421 of file qgsweakrelation.h.

◆ resolvedRelations()

QList< QgsRelation > QgsWeakRelation::resolvedRelations ( const QgsProject project,
QgsVectorLayerRef::MatchType  matchType = QgsVectorLayerRef::MatchType::All 
) const

Resolves a weak relation in the given project returning a list of possibly invalid QgsRelations and without performing any kind of validity check.

Note
Client code should never assume that the returned relations are valid and the layer components are not NULL.

Definition at line 36 of file qgsweakrelation.cpp.

◆ setBackwardPathLabel()

void QgsWeakRelation::setBackwardPathLabel ( const QString &  label)
inline

Sets the label of the backward path for the relationship.

The forward and backward path labels are free-form, user-friendly strings which can be used to generate descriptions of the relationship between features from the right and left tables.

E.g. when the left table contains buildings and the right table contains furniture, the forward path label could be "contains" and the backward path label could be "is located within". A client could then generate a user friendly description string such as "fire hose 1234 is located within building 15a".

See also
backwardPathLabel()
setForwardPathLabel()
Since
QGIS 3.28

Definition at line 408 of file qgsweakrelation.h.

◆ setCardinality()

void QgsWeakRelation::setCardinality ( Qgis::RelationshipCardinality  cardinality)
inline

Sets the relationship's cardinality.

See also
cardinality()
Since
QGIS 3.28

Definition at line 332 of file qgsweakrelation.h.

◆ setForwardPathLabel()

void QgsWeakRelation::setForwardPathLabel ( const QString &  label)
inline

Sets the label of the forward path for the relationship.

The forward and backward path labels are free-form, user-friendly strings which can be used to generate descriptions of the relationship between features from the right and left tables.

E.g. when the left table contains buildings and the right table contains furniture, the forward path label could be "contains" and the backward path label could be "is located within". A client could then generate a user friendly description string such as "fire hose 1234 is located within building 15a".

See also
forwardPathLabel()
setBackwardPathLabel()
Since
QGIS 3.28

Definition at line 389 of file qgsweakrelation.h.

◆ setMappingReferencedLayerFields()

void QgsWeakRelation::setMappingReferencedLayerFields ( const QStringList &  fields)
inline

Sets the list of fields from the mappingTable() involved in the relationship.

These fields will be matched to the referencedLayerFields() in many-to-many joins.

Since
QGIS 3.28

Definition at line 311 of file qgsweakrelation.h.

◆ setMappingReferencingLayerFields()

void QgsWeakRelation::setMappingReferencingLayerFields ( const QStringList &  fields)
inline

Sets the list of fields from the mappingTable() involved in the relationship.

These fields will be matched to the referencingLayerFields() in many-to-many joins.

Since
QGIS 3.28

Definition at line 279 of file qgsweakrelation.h.

◆ setMappingTable() [1/2]

void QgsWeakRelation::setMappingTable ( const QgsVectorLayerRef table)

Sets a weak reference to the mapping table, which forms the middle table in many-to-many relationships.

Note
Not available in Python bindings.
Since
QGIS 3.28

Definition at line 195 of file qgsweakrelation.cpp.

◆ setMappingTable() [2/2]

void QgsWeakRelation::setMappingTable ( const QString &  sourceUri,
const QString &  provider 
)

Sets the source for the mapping table, which forms the middle table in many-to-many relationships, by sourceUri and provider ID.

See also
mappingTableSource()
mappingTableProvider()
Since
QGIS 3.36

Definition at line 219 of file qgsweakrelation.cpp.

◆ setReferencedLayer()

void QgsWeakRelation::setReferencedLayer ( const QString &  sourceUri,
const QString &  provider 
)

Sets the source for the referenced (or "parent" / "left") layer, by sourceUri and provider ID.

See also
referencedLayerSource()
referencedLayerProvider()
Since
QGIS 3.36

Definition at line 184 of file qgsweakrelation.cpp.

◆ setReferencedLayerFields()

void QgsWeakRelation::setReferencedLayerFields ( const QStringList &  fields)
inline

Sets the list of fields from the referencedLayer() involved in the relationship.

Since
QGIS 3.28

Definition at line 293 of file qgsweakrelation.h.

◆ setReferencingLayer()

void QgsWeakRelation::setReferencingLayer ( const QString &  sourceUri,
const QString &  provider 
)

Sets the source for the referencing (or "child" / "right") layer, by sourceUri and provider ID.

See also
referencingLayerSource()
referencingLayerProvider()
Since
QGIS 3.36

Definition at line 145 of file qgsweakrelation.cpp.

◆ setReferencingLayerFields()

void QgsWeakRelation::setReferencingLayerFields ( const QStringList &  fields)
inline

Sets the list of fields from the referencingLayer() involved in the relationship.

Since
QGIS 3.28

Definition at line 261 of file qgsweakrelation.h.

◆ setRelatedTableType()

void QgsWeakRelation::setRelatedTableType ( const QString &  type)
inline

Sets the type string of the related table.

This a free-form string representing the type of related features, where the exact interpretation is format dependent. For instance, table types from GeoPackage relationships will directly reflect the categories from the GeoPackage related tables extension (i.e. "media", "simple attributes", "features", "attributes" and "tiles").

See also
relatedTableType()
Since
QGIS 3.28

Definition at line 434 of file qgsweakrelation.h.

◆ strength()

Qgis::RelationshipStrength QgsWeakRelation::strength ( ) const

Returns the strength of the relation.

Definition at line 225 of file qgsweakrelation.cpp.

◆ writeXml()

void QgsWeakRelation::writeXml ( const QgsVectorLayer layer,
WeakRelationType  type,
const QgsRelation relation,
QDomNode &  node,
QDomDocument &  doc 
)
static

Writes a weak relation infoto an XML structure.

Used for saving .qgs projects

Parameters
layerthe layer which we save the weak relation for
typedetermines if the layer is referencing or referenced
relationthe relation to save as a weak relation
nodeThe parent node in which the relation will be created
docThe document in which the relation will be saved
Since
QGIS 3.16

Definition at line 298 of file qgsweakrelation.cpp.

Friends And Related Symbol Documentation

◆ TestQgsWeakRelation

friend class TestQgsWeakRelation
friend

Definition at line 501 of file qgsweakrelation.h.


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