86   mRelations.remove( 
id );
    92   mRelations.remove( relation.
id() );
    98   return mRelations.value( 
id );
   105   const auto constMRelations = mRelations;
   108     if ( QString::compare( rel.name(), name, Qt::CaseInsensitive ) == 0 )
   125     return mRelations.values();
   130   const auto constMRelations = mRelations;
   133     if ( rel.referencingLayer() == layer )
   135       if ( fieldIdx != -2 )
   137         bool containsField = 
false;
   138         const auto constFieldPairs = rel.fieldPairs();
   143             containsField = 
true;
   148         if ( !containsField )
   153       relations.append( rel );
   164     return mRelations.values();
   169   const auto constMRelations = mRelations;
   172     if ( rel.referencedLayer() == layer )
   174       relations.append( rel );
   185   QDomNodeList nodes = doc.elementsByTagName( QStringLiteral( 
"relations" ) );
   190     QDomNode node = nodes.item( 0 );
   191     QDomNodeList relationNodes = node.childNodes();
   192     int relCount = relationNodes.count();
   193     for ( 
int i = 0; i < relCount; ++i )
   200     QgsDebugMsg( QStringLiteral( 
"No relations data present in this document" ) );
   207 void QgsRelationManager::writeProject( QDomDocument &doc )
   209   QDomNodeList nl = doc.elementsByTagName( QStringLiteral( 
"qgis" ) );
   212     QgsDebugMsg( QStringLiteral( 
"Unable to find qgis element in project file" ) );
   215   QDomNode qgisNode = nl.item( 0 );  
   217   QDomElement relationsNode = doc.createElement( QStringLiteral( 
"relations" ) );
   218   qgisNode.appendChild( relationsNode );
   220   const auto constMRelations = mRelations;
   227 void QgsRelationManager::layersRemoved( 
const QStringList &layers )
   229   bool relationsChanged = 
false;
   230   const auto constLayers = layers;
   231   for ( 
const QString &layer : constLayers )
   233     QMapIterator<QString, QgsRelation> it( mRelations );
   235     while ( it.hasNext() )
   239       if ( it.value().referencedLayerId() == layer
   240            || it.value().referencingLayerId() == layer )
   242         mRelations.remove( it.key() );
   243         relationsChanged = 
true;
   247   if ( relationsChanged )
   253 static bool hasRelationWithEqualDefinition( 
const QList<QgsRelation> &existingRelations, 
const QgsRelation &
relation )
   255   const auto constExistingRelations = existingRelations;
   256   for ( 
const QgsRelation &cur : constExistingRelations )
   258     if ( cur.hasEqualDefinition( relation ) ) 
return true;
   265   QList<QgsRelation> result;
   266   const auto constLayers = layers;
   269     const auto constDiscoverRelations = layer->dataProvider()->discoverRelations( layer, layers );
   270     for ( 
const QgsRelation &relation : constDiscoverRelations )
   272       if ( !hasRelationWithEqualDefinition( existingRelations, relation ) )
   274         result.append( relation );
 int lookupField(const QString &fieldName) const
Looks up field's index from the field name. 
 
QgsRelationContext context() const
Gets the relation context. 
 
void setDirty(bool b=true)
Flag the project as dirty (modified). 
 
The class is used as a container of context for various read/write operations on other objects...
 
QList< QgsRelation > referencingRelations(const QgsVectorLayer *layer=nullptr, int fieldIdx=-2) const
Gets all relations where the specified layer (and field) is the referencing part (i.e. 
 
void layersRemoved(const QStringList &layerIds)
Emitted after one or more layers were removed from the registry. 
 
QgsVectorLayer referencingLayer
 
void updateRelationsStatus()
Updates relations status. 
 
QList< QgsRelation > referencedRelations(const QgsVectorLayer *layer=nullptr) const
Gets all relations where this layer is the referenced part (i.e. 
 
void clear()
Remove any relation managed by this class. 
 
void setRelations(const QList< QgsRelation > &relations)
Will set the specified relations and remove any relation currently set. 
 
void readProjectWithContext(const QDomDocument &, QgsReadWriteContext &context)
Emitted when a project is being read. 
 
QgsFields fields() const FINAL
Returns the list of fields of this layer. 
 
Defines a relation between matching fields of the two involved tables of a relation. 
 
QList< QgsRelation > relationsByName(const QString &name) const
Returns a list of relations with matching names. 
 
QMap< QString, QgsRelation > relations() const
Gets access to the relations managed by this class. 
 
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc. 
 
QgsVectorLayer referencedLayer
 
void relationsLoaded()
Emitted when the relations were loaded after reading a project. 
 
void writeProject(QDomDocument &)
Emitted when the project is being written. 
 
void changed()
Emitted when relations are added or removed to the manager. 
 
static QgsRelation createFromXml(const QDomNode &node, QgsReadWriteContext &context, const QgsRelationContext &relationContext=QgsRelationContext())
Creates a relation from an XML structure. 
 
static QList< QgsRelation > discoverRelations(const QList< QgsRelation > &existingRelations, const QList< QgsVectorLayer *> &layers)
Discover all the relations available from the current layers. 
 
void removeRelation(const QString &id)
Remove a relation. 
 
QgsRelationManager(QgsProject *project=nullptr)
Constructor for QgsRelationManager. 
 
Q_INVOKABLE QgsRelation relation(const QString &id) const
Gets access to a relation by its id. 
 
Represents a vector layer which manages a vector based data sets. 
 
void writeXml(QDomNode &node, QDomDocument &doc) const
Writes a relation to an XML structure. 
 
void updateRelationStatus()
Updates the validity status of this relation. 
 
void addRelation(const QgsRelation &relation)
Add a relation.