QGIS API Documentation  2.15.0-Master (972fc9f)
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 
28 class CORE_EXPORT QgsRelation
29 {
30  public:
38  class FieldPair : public QPair< QString, QString >
39  {
40  public:
43  : QPair< QString, QString >() {}
44 
46  FieldPair( const QString& referencingField, const QString& referencedField )
47  : QPair< QString, QString >( referencingField, referencedField ) {}
48 
50  QString referencingField() const { return first; }
52  QString referencedField() const { return second; }
53  };
54 
58  QgsRelation();
59 
67  static QgsRelation createFromXML( const QDomNode& node );
68 
75  void writeXML( QDomNode& node, QDomDocument& doc ) const;
76 
82  void setRelationId( const QString& id );
83 
89  void setRelationName( const QString& name );
90 
96  void setReferencingLayer( const QString& id );
97 
103  void setReferencedLayer( const QString& id );
104 
113  void addFieldPair( const QString& referencingField, const QString& referencedField );
114 
123  void addFieldPair( const FieldPair& fieldPair );
124 
135  QgsFeatureIterator getRelatedFeatures( const QgsFeature& feature ) const;
136 
147  QgsFeatureRequest getRelatedFeaturesRequest( const QgsFeature& feature ) const;
148 
157  QString getRelatedFeaturesFilter( const QgsFeature& feature ) const;
158 
168  QgsFeatureRequest getReferencedFeatureRequest( const QgsAttributes& attributes ) const;
169 
178  QgsFeatureRequest getReferencedFeatureRequest( const QgsFeature& feature ) const;
179 
188  QgsFeature getReferencedFeature( const QgsFeature& feature ) const;
189 
197  QString name() const;
198 
204  QString id() const;
205 
212  QString referencingLayerId() const;
213 
220  QgsVectorLayer* referencingLayer() const;
221 
227  QString referencedLayerId() const;
228 
234  QgsVectorLayer* referencedLayer() const;
235 
243  QList< FieldPair > fieldPairs() const;
244 
251  QgsAttributeList referencedFields() const;
252 
259  QgsAttributeList referencingFields() const;
260 
266  bool isValid() const;
267 
268  protected:
273  void updateRelationStatus();
274 
275  private:
277  QString mRelationId;
279  QString mRelationName;
281  QString mReferencingLayerId;
283  QgsVectorLayer* mReferencingLayer;
285  QString mReferencedLayerId;
287  QgsVectorLayer* mReferencedLayer;
292  QList< FieldPair > mFieldPairs;
293 
294  bool mValid;
295 };
296 
297 // Register QgsRelation for usage with QVariant
299 
300 #endif // QGSRELATION_H
Wrapper for iterator of features from vector data provider or vector layer.
QString referencedField() const
Get the name of the referenced (parent) field.
Definition: qgsrelation.h:52
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
Q_DECLARE_METATYPE(QModelIndex)
FieldPair()
Default constructor: NULL strings.
Definition: qgsrelation.h:42
Defines a relation between matching fields of the two involved tables of a relation.
Definition: qgsrelation.h:38
QString referencingField() const
Get the name of the referencing (child) field.
Definition: qgsrelation.h:50
This class wraps a request for features to a vector layer (or directly its vector data provider)...
FieldPair(const QString &referencingField, const QString &referencedField)
Constructor which takes two fields.
Definition: qgsrelation.h:46
A vector of attributes.
Definition: qgsfeature.h:115
Represents a vector layer which manages a vector based data sets.