QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsrelation.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrelation.h
3  --------------------------------------
4  Date : 29.4.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 QGSRELATION_H
17 #define QGSRELATION_H
18 
19 #include <QList>
20 #include <QDomNode>
21 #include <QPair>
22 
23 #include "qgsfield.h"
24 #include "qgsfeatureiterator.h"
25 
26 class QgsVectorLayer;
27 
31 class CORE_EXPORT QgsRelation
32 {
33  public:
42  class FieldPair : public QPair< QString, QString >
43  {
44  public:
47  : QPair< QString, QString >() {}
48 
50  FieldPair( const QString& referencingField, const QString& referencedField )
51  : QPair< QString, QString >( referencingField, referencedField ) {}
52 
54  QString referencingField() const { return first; }
56  QString referencedField() const { return second; }
57  };
58 
62  QgsRelation();
63 
71  static QgsRelation createFromXML( const QDomNode& node );
72 
79  void writeXML( QDomNode& node, QDomDocument& doc ) const;
80 
86  void setRelationId( const QString& id );
87 
93  void setRelationName( const QString& name );
94 
100  void setReferencingLayer( const QString& id );
101 
107  void setReferencedLayer( const QString& id );
108 
117  void addFieldPair( const QString& referencingField, const QString& referencedField );
118 
127  void addFieldPair( const FieldPair& fieldPair );
128 
139  QgsFeatureIterator getRelatedFeatures( const QgsFeature& feature ) const;
140 
151  QgsFeatureRequest getRelatedFeaturesRequest( const QgsFeature& feature ) const;
152 
161  QString getRelatedFeaturesFilter( const QgsFeature& feature ) const;
162 
172  QgsFeatureRequest getReferencedFeatureRequest( const QgsAttributes& attributes ) const;
173 
182  QgsFeatureRequest getReferencedFeatureRequest( const QgsFeature& feature ) const;
183 
192  QgsFeature getReferencedFeature( const QgsFeature& feature ) const;
193 
201  QString name() const;
202 
208  QString id() const;
209 
216  QString referencingLayerId() const;
217 
224  QgsVectorLayer* referencingLayer() const;
225 
231  QString referencedLayerId() const;
232 
238  QgsVectorLayer* referencedLayer() const;
239 
247  QList< FieldPair > fieldPairs() const;
248 
255  QgsAttributeList referencedFields() const;
256 
263  QgsAttributeList referencingFields() const;
264 
270  bool isValid() const;
271 
272  protected:
277  void updateRelationStatus();
278 
279  private:
281  QString mRelationId;
283  QString mRelationName;
285  QString mReferencingLayerId;
287  QgsVectorLayer* mReferencingLayer;
289  QString mReferencedLayerId;
291  QgsVectorLayer* mReferencedLayer;
296  QList< FieldPair > mFieldPairs;
297 
298  bool mValid;
299 };
300 
301 // Register QgsRelation for usage with QVariant
303 
304 #endif // QGSRELATION_H
Wrapper for iterator of features from vector data provider or vector layer.
Q_DECLARE_METATYPE(QgsMimeDataUtils::UriList)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
FieldPair()
Default constructor: NULL strings.
Definition: qgsrelation.h:46
Defines a relation between matching fields of the two involved tables of a relation.
Definition: qgsrelation.h:42
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QString referencedField() const
Get the name of the referenced (parent) field.
Definition: qgsrelation.h:56
FieldPair(const QString &referencingField, const QString &referencedField)
Constructor which takes two fields.
Definition: qgsrelation.h:50
A vector of attributes.
Definition: qgsfeature.h:115
Represents a vector layer which manages a vector based data sets.
QString referencingField() const
Get the name of the referencing (child) field.
Definition: qgsrelation.h:54