QGIS API Documentation  2.99.0-Master (7fe5405)
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 "qgis_core.h"
20 #include <QList>
21 #include <QDomNode>
22 #include <QPair>
23 
24 #include "qgsfields.h"
25 
26 class QgsVectorLayer;
27 class QgsFeatureIterator;
28 class QgsFeature;
29 class QgsFeatureRequest;
30 class QgsAttributes;
31 
35 class CORE_EXPORT QgsRelation
36 {
37  public:
38 
47  class FieldPair : public QPair< QString, QString >
48  {
49  public:
52  : QPair< QString, QString >() {}
53 
55  FieldPair( const QString& referencingField, const QString& referencedField )
56  : QPair< QString, QString >( referencingField, referencedField ) {}
57 
59  QString referencingField() const { return first; }
61  QString referencedField() const { return second; }
62 
63  bool operator==( const FieldPair& other ) const { return first == other.first && second == other.second; }
64  };
65 
69  QgsRelation();
70 
78  static QgsRelation createFromXml( const QDomNode& node );
79 
86  void writeXml( QDomNode& node, QDomDocument& doc ) const;
87 
93  void setRelationId( const QString& id );
94 
100  void setRelationName( const QString& name );
101 
107  void setReferencingLayer( const QString& id );
108 
114  void setReferencedLayer( const QString& id );
115 
124  void addFieldPair( const QString& referencingField, const QString& referencedField );
125 
134  void addFieldPair( const FieldPair& fieldPair );
135 
146  QgsFeatureIterator getRelatedFeatures( const QgsFeature& feature ) const;
147 
158  QgsFeatureRequest getRelatedFeaturesRequest( const QgsFeature& feature ) const;
159 
168  QString getRelatedFeaturesFilter( const QgsFeature& feature ) const;
169 
179  QgsFeatureRequest getReferencedFeatureRequest( const QgsAttributes& attributes ) const;
180 
189  QgsFeatureRequest getReferencedFeatureRequest( const QgsFeature& feature ) const;
190 
199  QgsFeature getReferencedFeature( const QgsFeature& feature ) const;
200 
208  QString name() const;
209 
215  QString id() const;
216 
221  void generateId();
222 
229  QString referencingLayerId() const;
230 
237  QgsVectorLayer* referencingLayer() const;
238 
244  QString referencedLayerId() const;
245 
251  QgsVectorLayer* referencedLayer() const;
252 
260  QList< FieldPair > fieldPairs() const;
261 
268  QgsAttributeList referencedFields() const;
269 
276  QgsAttributeList referencingFields() const;
277 
283  bool isValid() const;
284 
292  bool hasEqualDefinition( const QgsRelation& other ) const;
293 
294  protected:
295 
300  void updateRelationStatus();
301 
302  private:
304  QString mRelationId;
306  QString mRelationName;
308  QString mReferencingLayerId;
310  QgsVectorLayer* mReferencingLayer;
312  QString mReferencedLayerId;
314  QgsVectorLayer* mReferencedLayer;
315 
320  QList< FieldPair > mFieldPairs;
321 
322  bool mValid;
323 };
324 
325 // Register QgsRelation for usage with QVariant
327 
328 #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:136
FieldPair()
Default constructor: NULL strings.
Definition: qgsrelation.h:51
Defines a relation between matching fields of the two involved tables of a relation.
Definition: qgsrelation.h:47
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
bool operator==(const FieldPair &other) const
Definition: qgsrelation.h:63
QString referencedField() const
Get the name of the referenced (parent) field.
Definition: qgsrelation.h:61
FieldPair(const QString &referencingField, const QString &referencedField)
Constructor which takes two fields.
Definition: qgsrelation.h:55
A vector of attributes.
Definition: qgsfeature.h:56
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:59