QGIS API Documentation  2.99.0-Master (dcec6bb)
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 
33 class CORE_EXPORT QgsRelationManager : public QObject
34 {
35  Q_OBJECT
36 
37  public:
38 
42  explicit QgsRelationManager( QgsProject *project = nullptr );
43 
49  void setRelations( const QList<QgsRelation> &relations );
50 
56  QMap<QString, QgsRelation> relations() const;
57 
63  void addRelation( const QgsRelation &relation );
64 
70  void removeRelation( const QString &id );
71 
77  void removeRelation( const QgsRelation &relation );
78 
87  Q_INVOKABLE QgsRelation relation( const QString &id ) const;
88 
95  QList<QgsRelation> relationsByName( const QString &name ) const;
96 
100  void clear();
101 
110  QList<QgsRelation> referencingRelations( const QgsVectorLayer *layer = nullptr, int fieldIdx = -2 ) const;
111 
119  QList<QgsRelation> referencedRelations( QgsVectorLayer *layer = nullptr ) const;
120 
129  static QList<QgsRelation> discoverRelations( const QList<QgsRelation> &existingRelations, const QList<QgsVectorLayer *> &layers );
130 
131  signals:
133  void relationsLoaded();
134 
139  void changed();
140 
141  private slots:
142  void readProject( const QDomDocument &doc );
143  void writeProject( QDomDocument &doc );
144  void layersRemoved( const QStringList &layers );
145 
146  private:
148  QMap<QString, QgsRelation> mRelations;
149 
150  QgsProject *mProject = nullptr;
151 };
152 
153 #endif // QGSRELATIONMANAGER_H
Reads and writes project states.
Definition: qgsproject.h:78
This class manages a set of relations between layers.
Represents a vector layer which manages a vector based data sets.