QGIS API Documentation  3.0.2-Girona (307d082)
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 
65  void addRelation( const QgsRelation &relation );
66 
72  void removeRelation( const QString &id );
73 
79  void removeRelation( const QgsRelation &relation );
80 
89  Q_INVOKABLE QgsRelation relation( const QString &id ) const;
90 
98  QList<QgsRelation> relationsByName( const QString &name ) const;
99 
103  void clear();
104 
113  QList<QgsRelation> referencingRelations( const QgsVectorLayer *layer = nullptr, int fieldIdx = -2 ) const;
114 
122  QList<QgsRelation> referencedRelations( QgsVectorLayer *layer = nullptr ) const;
123 
132  static QList<QgsRelation> discoverRelations( const QList<QgsRelation> &existingRelations, const QList<QgsVectorLayer *> &layers );
133 
134  signals:
136  void relationsLoaded();
137 
142  void changed();
143 
144  private slots:
145  void readProject( const QDomDocument &doc );
146  void writeProject( QDomDocument &doc );
147  void layersRemoved( const QStringList &layers );
148 
149  private:
151  QMap<QString, QgsRelation> mRelations;
152 
153  QgsProject *mProject = nullptr;
154 };
155 
156 #endif // QGSRELATIONMANAGER_H
Reads and writes project states.
Definition: qgsproject.h:82
This class manages a set of relations between layers.
Represents a vector layer which manages a vector based data sets.