QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
51  void setRelations( const QList<QgsRelation> &relations );
52 
58  QMap<QString, QgsRelation> relations() const;
59 
67  void addRelation( const QgsRelation &relation );
68 
74  void removeRelation( const QString &id );
75 
81  void removeRelation( const QgsRelation &relation );
82 
91  Q_INVOKABLE QgsRelation relation( const QString &id ) const;
92 
100  QList<QgsRelation> relationsByName( const QString &name ) const;
101 
105  void clear();
106 
115  QList<QgsRelation> referencingRelations( const QgsVectorLayer *layer = nullptr, int fieldIdx = -2 ) const;
116 
124  QList<QgsRelation> referencedRelations( QgsVectorLayer *layer = nullptr ) const;
125 
134  static QList<QgsRelation> discoverRelations( const QList<QgsRelation> &existingRelations, const QList<QgsVectorLayer *> &layers );
135 
136  signals:
138  void relationsLoaded();
139 
144  void changed();
145 
146  public slots:
147 
151  void updateRelationsStatus();
152 
153  private slots:
154  void readProject( const QDomDocument &doc, QgsReadWriteContext &context );
155  void writeProject( QDomDocument &doc );
156  void layersRemoved( const QStringList &layers );
157 
158  private:
160  QMap<QString, QgsRelation> mRelations;
161 
162  QgsProject *mProject = nullptr;
163 };
164 
165 #endif // QGSRELATIONMANAGER_H
The class is used as a container of context for various read/write operations on other objects...
Reads and writes project states.
Definition: qgsproject.h:89
This class manages a set of relations between layers.
Represents a vector layer which manages a vector based data sets.