Skip to content

Class RelationUtils

ClassList > RelationUtils

Inherits the following classes: QObject

Public Functions

Type Name
RelationUtils (QObject * parent=nullptr)
Q_INVOKABLE QgsPolymorphicRelation addPolymorphicRelation (QgsProject * project, const QVariantList & referencedLayers, const QgsVectorLayer * referencingLayer, const QVariantMap & fieldPairs, const QString & referencedLayerField, const QString & referencedLayerExpression)
Q_INVOKABLE QgsPolymorphicRelation createPolymorphicRelation (const QVariantList & referencedLayers, const QgsVectorLayer * referencingLayer, const QVariantMap & fieldPairs, const QString & referencedLayerField, const QString & referencedLayerExpression)
Q_INVOKABLE QgsRelation createRelation (const QgsVectorLayer * referencedLayer, const QgsVectorLayer * referencingLayer, const QVariantMap & fieldPairs)
Q_INVOKABLE QgsRelation resolveReferencingRelation (QgsProject * project, QgsVectorLayer * layer, const QString & fieldName, const QString & relationId)

Public Functions Documentation

function RelationUtils

explicit RelationUtils::RelationUtils (
    QObject * parent=nullptr
) 

function addPolymorphicRelation

Q_INVOKABLE QgsPolymorphicRelation RelationUtils::addPolymorphicRelation (
    QgsProject * project,
    const QVariantList & referencedLayers,
    const QgsVectorLayer * referencingLayer,
    const QVariantMap & fieldPairs,
    const QString & referencedLayerField,
    const QString & referencedLayerExpression
) 

Creates and adds a polymorphic relation to the project. This is a convenience function that creates the relation and adds it to the project's relation manager.

Parameters:

  • project The project to add the relation to
  • referencedLayers The list of referenced (parent) layers
  • referencingLayer The referencing (child) layer
  • fieldPairs A map where keys are referenced field names and values are referencing field names
  • referencedLayerField The field name in the child layer that stores the parent layer name
  • referencedLayerExpression The expression to identify the parent layer name (e.g., "@layer_name")

Returns:

A QgsPolymorphicRelation object


function createPolymorphicRelation

Q_INVOKABLE QgsPolymorphicRelation RelationUtils::createPolymorphicRelation (
    const QVariantList & referencedLayers,
    const QgsVectorLayer * referencingLayer,
    const QVariantMap & fieldPairs,
    const QString & referencedLayerField,
    const QString & referencedLayerExpression
) 

Creates a polymorphic relation between multiple referenced layers and a referencing layer. Note: Layers must be added to the project first

Parameters:

  • referencedLayers The list of referenced (parent) layers
  • referencingLayer The referencing (child) layer
  • fieldPairs A map where keys are referenced field names and values are referencing field names
  • referencedLayerField The field name in the child layer that stores the parent layer name
  • referencedLayerExpression The expression to identify the parent layer name (e.g., "@layer_name")

Returns:

A QgsPolymorphicRelation object


function createRelation

Q_INVOKABLE QgsRelation RelationUtils::createRelation (
    const QgsVectorLayer * referencedLayer,
    const QgsVectorLayer * referencingLayer,
    const QVariantMap & fieldPairs
) 

Creates a relation between referenced and referencing layers. Note: Layers must be added to the project first

Parameters:

  • referencedLayer The referenced (parent) layer
  • referencingLayer The referencing (child) layer
  • fieldPairs A map where keys are referenced field names and values are referencing field names

Returns:

A QgsRelation object


function resolveReferencingRelation

Q_INVOKABLE QgsRelation RelationUtils::resolveReferencingRelation (
    QgsProject * project,
    QgsVectorLayer * layer,
    const QString & fieldName,
    const QString & relationId
) 


The documentation for this class was generated from the following file src/core/utils/relationutils.h