QGIS API Documentation  2.13.0-Master
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 
153  QgsFeatureRequest getReferencedFeatureRequest( const QgsAttributes& attributes ) const;
154 
163  QgsFeatureRequest getReferencedFeatureRequest( const QgsFeature& feature ) const;
164 
173  QgsFeature getReferencedFeature( const QgsFeature& feature ) const;
174 
182  QString name() const;
183 
189  QString id() const;
190 
197  QString referencingLayerId() const;
198 
205  QgsVectorLayer* referencingLayer() const;
206 
212  QString referencedLayerId() const;
213 
219  QgsVectorLayer* referencedLayer() const;
220 
228  QList< FieldPair > fieldPairs() const;
229 
236  QgsAttributeList referencedFields() const;
237 
244  QgsAttributeList referencingFields() const;
245 
251  bool isValid() const;
252 
253  protected:
258  void updateRelationStatus();
259 
260  private:
262  QString mRelationId;
264  QString mRelationName;
266  QString mReferencingLayerId;
268  QgsVectorLayer* mReferencingLayer;
270  QString mReferencedLayerId;
272  QgsVectorLayer* mReferencedLayer;
277  QList< FieldPair > mFieldPairs;
278 
279  bool mValid;
280 };
281 
282 // Register QgsRelation for usage with QVariant
283 Q_DECLARE_METATYPE( QgsRelation )
284 
285 #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.