QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
Public Slots | Signals | Public Member Functions | Static Public Member Functions | List of all members
QgsRelationManager Class Reference

This class manages a set of relations between layers. More...

#include <qgsrelationmanager.h>

Inheritance diagram for QgsRelationManager:
Inheritance graph
[legend]

Public Slots

void updateRelationsStatus ()
 Updates relations status.
 

Signals

void changed ()
 Emitted when relations are added or removed to the manager.
 
void relationsLoaded ()
 Emitted when the relations were loaded after reading a project.
 

Public Member Functions

 QgsRelationManager (QgsProject *project=nullptr)
 Constructor for QgsRelationManager.
 
void addPolymorphicRelation (const QgsPolymorphicRelation &polymorphicRelation)
 Adds a new polymorphic relation.
 
void addRelation (const QgsRelation &relation)
 Add a relation.
 
void clear ()
 Remove any relation managed by this class.
 
QgsRelationContext context () const
 Gets the relation context.
 
QgsPolymorphicRelation polymorphicRelation (const QString &polymorphicRelationId) const
 Returns the list of relations associated with a polymorphic relation.
 
QMap< QString, QgsPolymorphicRelationpolymorphicRelations () const
 Returns all the polymorphic relations.
 
QList< QgsRelationreferencedRelations (const QgsVectorLayer *layer=nullptr) const
 Gets all relations where this layer is the referenced part (i.e.
 
QList< QgsRelationreferencingRelations (const QgsVectorLayer *layer=nullptr, int fieldIdx=-2) const
 Gets all relations where the specified layer (and field) is the referencing part (i.e.
 
Q_INVOKABLE QgsRelation relation (const QString &id) const
 Gets access to a relation by its id.
 
QMap< QString, QgsRelationrelations () const
 Gets access to the relations managed by this class.
 
QList< QgsRelationrelationsByName (const QString &name) const
 Returns a list of relations with matching names.
 
void removePolymorphicRelation (const QString &polymorphicRelationId)
 Removes an existing polymorphic relation and it's generated relations.
 
void removeRelation (const QgsRelation &relation)
 Remove a relation.
 
void removeRelation (const QString &id)
 Remove a relation.
 
void setPolymorphicRelations (const QList< QgsPolymorphicRelation > &relations)
 Sets the specified polymorphic relations and removes any polymorphic relations currently set.
 
void setRelations (const QList< QgsRelation > &relations)
 Will set the specified relations and remove any relation currently set.
 

Static Public Member Functions

static QList< QgsRelationdiscoverRelations (const QList< QgsRelation > &existingRelations, const QList< QgsVectorLayer * > &layers)
 Discover all the relations available from the current layers.
 

Detailed Description

This class manages a set of relations between layers.

Definition at line 35 of file qgsrelationmanager.h.

Constructor & Destructor Documentation

◆ QgsRelationManager()

QgsRelationManager::QgsRelationManager ( QgsProject project = nullptr)
explicit

Constructor for QgsRelationManager.

Parameters
projectassociated project (used to notify project of changes)

Definition at line 24 of file qgsrelationmanager.cpp.

Member Function Documentation

◆ addPolymorphicRelation()

void QgsRelationManager::addPolymorphicRelation ( const QgsPolymorphicRelation polymorphicRelation)

Adds a new polymorphic relation.

The generated relations are not available, they will be created automatically.

Definition at line 337 of file qgsrelationmanager.cpp.

◆ addRelation()

void QgsRelationManager::addRelation ( const QgsRelation relation)

Add a relation.

Invalid relations are added only if both referencing layer and referenced layer exist.

Parameters
relationThe relation to add.

Definition at line 59 of file qgsrelationmanager.cpp.

◆ changed

void QgsRelationManager::changed ( )
signal

Emitted when relations are added or removed to the manager.

◆ clear()

void QgsRelationManager::clear ( )

Remove any relation managed by this class.

Definition at line 127 of file qgsrelationmanager.cpp.

◆ context()

QgsRelationContext QgsRelationManager::context ( ) const

Gets the relation context.

Definition at line 39 of file qgsrelationmanager.cpp.

◆ discoverRelations()

QList< QgsRelation > QgsRelationManager::discoverRelations ( const QList< QgsRelation > &  existingRelations,
const QList< QgsVectorLayer * > &  layers 
)
static

Discover all the relations available from the current layers.

Parameters
existingRelationsthe existing relations to filter them out
layersthe current layers
Returns
the list of discovered relations

Definition at line 307 of file qgsrelationmanager.cpp.

◆ polymorphicRelation()

QgsPolymorphicRelation QgsRelationManager::polymorphicRelation ( const QString &  polymorphicRelationId) const

Returns the list of relations associated with a polymorphic relation.

Definition at line 332 of file qgsrelationmanager.cpp.

◆ polymorphicRelations()

QMap< QString, QgsPolymorphicRelation > QgsRelationManager::polymorphicRelations ( ) const

Returns all the polymorphic relations.

Definition at line 327 of file qgsrelationmanager.cpp.

◆ referencedRelations()

QList< QgsRelation > QgsRelationManager::referencedRelations ( const QgsVectorLayer layer = nullptr) const

Gets all relations where this layer is the referenced part (i.e.

the parent table with the primary key being referenced from another layer).

Parameters
layerThe layer which should be searched for.
Returns
A list of relations where the specified layer is the referenced part.

Definition at line 171 of file qgsrelationmanager.cpp.

◆ referencingRelations()

QList< QgsRelation > QgsRelationManager::referencingRelations ( const QgsVectorLayer layer = nullptr,
int  fieldIdx = -2 
) const

Gets all relations where the specified layer (and field) is the referencing part (i.e.

the child table with the foreign key).

Parameters
layerThe layer which should be searched for.
fieldIdxThe field which should be part of the foreign key. If not set will return all relations.
Returns
A list of relations matching the given layer and fieldIdx.

Definition at line 133 of file qgsrelationmanager.cpp.

◆ relation()

QgsRelation QgsRelationManager::relation ( const QString &  id) const

Gets access to a relation by its id.

Parameters
idThe id to search for
Returns
A relation. Invalid if not found.
See also
relationsByName()

Definition at line 95 of file qgsrelationmanager.cpp.

◆ relations()

QMap< QString, QgsRelation > QgsRelationManager::relations ( ) const

Gets access to the relations managed by this class.

Returns
A QMap where the key is the relation id, the value the relation object.

Definition at line 54 of file qgsrelationmanager.cpp.

◆ relationsByName()

QList< QgsRelation > QgsRelationManager::relationsByName ( const QString &  name) const

Returns a list of relations with matching names.

Parameters
namerelation name to search for. Searching is case insensitive.
Returns
a list of matching relations
See also
relation()

Definition at line 114 of file qgsrelationmanager.cpp.

◆ relationsLoaded

void QgsRelationManager::relationsLoaded ( )
signal

Emitted when the relations were loaded after reading a project.

◆ removePolymorphicRelation()

void QgsRelationManager::removePolymorphicRelation ( const QString &  polymorphicRelationId)

Removes an existing polymorphic relation and it's generated relations.

Definition at line 349 of file qgsrelationmanager.cpp.

◆ removeRelation() [1/2]

void QgsRelationManager::removeRelation ( const QgsRelation relation)

Remove a relation.

Parameters
relationThe relation to remove.

Definition at line 89 of file qgsrelationmanager.cpp.

◆ removeRelation() [2/2]

void QgsRelationManager::removeRelation ( const QString &  id)

Remove a relation.

Parameters
idThe id of the relation to remove.

Definition at line 83 of file qgsrelationmanager.cpp.

◆ setPolymorphicRelations()

void QgsRelationManager::setPolymorphicRelations ( const QList< QgsPolymorphicRelation > &  relations)

Sets the specified polymorphic relations and removes any polymorphic relations currently set.

Will remove any generated relations and recreate them.

Definition at line 358 of file qgsrelationmanager.cpp.

◆ setRelations()

void QgsRelationManager::setRelations ( const QList< QgsRelation > &  relations)

Will set the specified relations and remove any relation currently set.

Parameters
relationsA list of relations to set.

Definition at line 44 of file qgsrelationmanager.cpp.

◆ updateRelationsStatus

void QgsRelationManager::updateRelationsStatus ( )
slot

Updates relations status.

Definition at line 74 of file qgsrelationmanager.cpp.


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