QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsrelationmanager.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrelationmanager.h
3  --------------------------------------
4  Date : 1.3.2013
5  Copyright : (C) 2013 Matthias Kuhn
6  Email : matthias at opengis dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSRELATIONMANAGER_H
17 #define QGSRELATIONMANAGER_H
18 
19 #include "qgis_core.h"
20 #include <QObject>
21 #include <QPair>
22 #include <QDomNode>
23 #include <QDomDocument>
24 
25 #include "qgsrelation.h"
26 
27 class QgsProject;
28 class QgsVectorLayer;
29 
34 class CORE_EXPORT QgsRelationManager : public QObject
35 {
36  Q_OBJECT
37 
38  public:
39 
44  explicit QgsRelationManager( QgsProject *project = nullptr );
45 
49  QgsRelationContext context() const;
50 
56  void setRelations( const QList<QgsRelation> &relations );
57 
63  QMap<QString, QgsRelation> relations() const;
64 
72  void addRelation( const QgsRelation &relation );
73 
79  void removeRelation( const QString &id );
80 
86  void removeRelation( const QgsRelation &relation );
87 
96  Q_INVOKABLE QgsRelation relation( const QString &id ) const;
97 
105  QList<QgsRelation> relationsByName( const QString &name ) const;
106 
110  void clear();
111 
120  QList<QgsRelation> referencingRelations( const QgsVectorLayer *layer = nullptr, int fieldIdx = -2 ) const;
121 
129  QList<QgsRelation> referencedRelations( const QgsVectorLayer *layer = nullptr ) const;
130 
139  static QList<QgsRelation> discoverRelations( const QList<QgsRelation> &existingRelations, const QList<QgsVectorLayer *> &layers );
140 
141  signals:
144 
149  void changed();
150 
151  public slots:
152 
156  void updateRelationsStatus();
157 
158  private slots:
159  void readProject( const QDomDocument &doc, QgsReadWriteContext &context );
160  void writeProject( QDomDocument &doc );
161  void layersRemoved( const QStringList &layers );
162 
163  private:
165  QMap<QString, QgsRelation> mRelations;
166 
167  QgsProject *mProject = nullptr;
168 };
169 
170 #endif // QGSRELATIONMANAGER_H
QgsRelationManager
This class manages a set of relations between layers.
Definition: qgsrelationmanager.h:35
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsRelationManager::changed
void changed()
Emitted when relations are added or removed to the manager.
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
QgsRelationManager::relationsLoaded
void relationsLoaded()
Emitted when the relations were loaded after reading a project.
qgsrelation.h
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsRelation
Definition: qgsrelation.h:42
QgsRelationContext
Context for relations.
Definition: qgsrelationcontext.h:32