QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
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"
21#include "qgsrelation.h"
22
23#include <QDomDocument>
24#include <QDomNode>
25#include <QObject>
26#include <QPair>
27
28class QgsProject;
29class QgsVectorLayer;
30
35class CORE_EXPORT QgsRelationManager : public QObject
36{
37 Q_OBJECT
38
39 public:
44 explicit QgsRelationManager( QgsProject *project = nullptr );
45
50
56 void setRelations( const QList<QgsRelation> &relations );
57
63 QMap<QString, QgsRelation> relations() const;
64
72 Q_INVOKABLE void addRelation( const QgsRelation &relation );
73
79 Q_INVOKABLE void removeRelation( const QString &id );
80
86 void removeRelation( const QgsRelation &relation );
87
96 Q_INVOKABLE QgsRelation relation( const QString &id ) const;
97
104 QList<QgsRelation> relationsByName( const QString &name ) const;
105
109 void clear();
110
119 QList<QgsRelation> referencingRelations( const QgsVectorLayer *layer = nullptr, int fieldIdx = -2 ) const;
120
128 QList<QgsRelation> referencedRelations( const QgsVectorLayer *layer = nullptr ) const;
129
137 static QList<QgsRelation> discoverRelations( const QList<QgsRelation> &existingRelations, const QList<QgsVectorLayer *> &layers );
138
142 QMap<QString, QgsPolymorphicRelation> polymorphicRelations() const;
143
147 QgsPolymorphicRelation polymorphicRelation( const QString &polymorphicRelationId ) const;
148
153
157 void removePolymorphicRelation( const QString &polymorphicRelationId );
158
163 void setPolymorphicRelations( const QList<QgsPolymorphicRelation> &relations );
164
165 signals:
168
172 void changed();
173
174 public slots:
175
180
181 private slots:
182 void readProject( const QDomDocument &doc, QgsReadWriteContext &context );
183 void writeProject( QDomDocument &doc );
184 void layersRemoved( const QStringList &layers );
185
186 private:
188 QMap<QString, QgsRelation> mRelations;
189 QMap<QString, QgsPolymorphicRelation> mPolymorphicRelations;
190
191 QgsProject *mProject = nullptr;
192};
193
194#endif // QGSRELATIONMANAGER_H
A relation where the referenced (parent) layer is calculated based on fields from the referencing (ch...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:113
A container for the context for various read/write operations on objects.
Context for relations.
QList< QgsRelation > referencedRelations(const QgsVectorLayer *layer=nullptr) const
Gets all relations where this layer is the referenced part (i.e.
static QList< QgsRelation > discoverRelations(const QList< QgsRelation > &existingRelations, const QList< QgsVectorLayer * > &layers)
Discover all the relations available from the current layers.
QList< QgsRelation > relationsByName(const QString &name) const
Returns a list of relations with matching names.
void addPolymorphicRelation(const QgsPolymorphicRelation &polymorphicRelation)
Adds a new polymorphic relation.
QgsPolymorphicRelation polymorphicRelation(const QString &polymorphicRelationId) const
Returns the list of relations associated with a polymorphic relation.
void setPolymorphicRelations(const QList< QgsPolymorphicRelation > &relations)
Sets the specified polymorphic relations and removes any polymorphic relations currently set.
QMap< QString, QgsPolymorphicRelation > polymorphicRelations() const
Returns all the polymorphic relations.
QgsRelationManager(QgsProject *project=nullptr)
Constructor for QgsRelationManager.
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....
void clear()
Remove any relation managed by this class.
void changed()
Emitted when relations are added or removed to the manager.
QgsRelationContext context() const
Gets the relation context.
void updateRelationsStatus()
Updates relations status.
Q_INVOKABLE void removeRelation(const QString &id)
Remove a relation.
void setRelations(const QList< QgsRelation > &relations)
Will set the specified relations and remove any relation currently set.
void removePolymorphicRelation(const QString &polymorphicRelationId)
Removes an existing polymorphic relation and it's generated relations.
Q_INVOKABLE void addRelation(const QgsRelation &relation)
Add a relation.
QMap< QString, QgsRelation > relations() const
Gets access to the relations managed by this class.
void relationsLoaded()
Emitted when the relations were loaded after reading a project.
Q_INVOKABLE QgsRelation relation(const QString &id) const
Gets access to a relation by its id.
Represents a relationship between two vector layers.
Definition qgsrelation.h:42
Represents a vector layer which manages a vector based dataset.