QGIS API Documentation 3.99.0-Master (26c88405ac0)
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:
40
45 explicit QgsRelationManager( QgsProject *project = nullptr );
46
51
57 void setRelations( const QList<QgsRelation> &relations );
58
64 QMap<QString, QgsRelation> relations() const;
65
73 Q_INVOKABLE void addRelation( const QgsRelation &relation );
74
80 Q_INVOKABLE void removeRelation( const QString &id );
81
87 void removeRelation( const QgsRelation &relation );
88
97 Q_INVOKABLE QgsRelation relation( const QString &id ) const;
98
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
138 static QList<QgsRelation> discoverRelations( const QList<QgsRelation> &existingRelations, const QList<QgsVectorLayer *> &layers );
139
143 QMap<QString, QgsPolymorphicRelation> polymorphicRelations() const;
144
148 QgsPolymorphicRelation polymorphicRelation( const QString &polymorphicRelationId ) const;
149
154
158 void removePolymorphicRelation( const QString &polymorphicRelationId );
159
164 void setPolymorphicRelations( const QList<QgsPolymorphicRelation> &relations );
165
166 signals:
169
173 void changed();
174
175 public slots:
176
181
182 private slots:
183 void readProject( const QDomDocument &doc, QgsReadWriteContext &context );
184 void writeProject( QDomDocument &doc );
185 void layersRemoved( const QStringList &layers );
186
187 private:
189 QMap<QString, QgsRelation> mRelations;
190 QMap<QString, QgsPolymorphicRelation> mPolymorphicRelations;
191
192 QgsProject *mProject = nullptr;
193};
194
195#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:109
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.