QGIS API Documentation
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 
133  QgsFeatureIterator getRelatedFeatures( const QgsFeature& feature ) const;
134 
143  QgsFeatureRequest getRelatedFeaturesRequest( const QgsFeature& feature ) const;
144 
154  QgsFeatureRequest getReferencedFeatureRequest( const QgsAttributes& attributes ) const;
155 
164  QgsFeatureRequest getReferencedFeatureRequest( const QgsFeature& feature ) const;
165 
174  QgsFeature getReferencedFeature( const QgsFeature& feature ) const;
175 
183  QString name() const;
184 
190  QString id() const;
191 
198  QString referencingLayerId() const;
199 
206  QgsVectorLayer* referencingLayer() const;
207 
213  QString referencedLayerId() const;
214 
220  QgsVectorLayer* referencedLayer() const;
221 
229  QList< FieldPair > fieldPairs() const;
230 
237  QgsAttributeList referencedFields() const;
238 
245  QgsAttributeList referencingFields() const;
246 
252  bool isValid() const;
253 
254  protected:
259  void updateRelationStatus();
260 
261  private:
263  QString mRelationId;
265  QString mRelationName;
267  QString mReferencingLayerId;
269  QgsVectorLayer* mReferencingLayer;
271  QString mReferencedLayerId;
273  QgsVectorLayer* mReferencedLayer;
278  QList< FieldPair > mFieldPairs;
279 
280  bool mValid;
281 };
282 
283 // Register QgsRelation for usage with QVariant
284 Q_DECLARE_METATYPE( QgsRelation )
285 
286 #endif // QGSRELATION_H
Wrapper for iterator of features from vector data provider or vector layer.
QString referencedField() const
Get the name of the referenced 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
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 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.