QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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 setReferencedLayerFields (const QStringList &fields)
 Sets the list of fields from the referencedLayer() involved in the relationship.
 
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 331 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 285 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 312 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 263 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 231 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 178 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 198 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.

Since
QGIS 3.28

Definition at line 193 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.

Since
QGIS 3.28

Definition at line 188 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 212 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 154 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 247 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 169 of file qgsweakrelation.cpp.

◆ referencedLayerProvider()

QString QgsWeakRelation::referencedLayerProvider ( ) const

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

Since
QGIS 3.28

Definition at line 164 of file qgsweakrelation.cpp.

◆ referencedLayerSource()

QString QgsWeakRelation::referencedLayerSource ( ) const

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

Since
QGIS 3.28

Definition at line 159 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 215 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 145 of file qgsweakrelation.cpp.

◆ referencingLayerProvider()

QString QgsWeakRelation::referencingLayerProvider ( ) const

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

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.

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 382 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 369 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 293 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 350 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 272 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 240 of file qgsweakrelation.h.

◆ setMappingTable()

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 183 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 254 of file qgsweakrelation.h.

◆ 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 222 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 395 of file qgsweakrelation.h.

◆ strength()

Qgis::RelationshipStrength QgsWeakRelation::strength ( ) const

Returns the strength of the relation.

Definition at line 207 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 280 of file qgsweakrelation.cpp.

Friends And Related Symbol Documentation

◆ TestQgsWeakRelation

friend class TestQgsWeakRelation
friend

Definition at line 462 of file qgsweakrelation.h.


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