QGIS API Documentation  2.99.0-Master (e077efd)
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 "qgsfields.h"
24 
25 class QgsVectorLayer;
26 class QgsFeatureIterator;
27 class QgsFeature;
28 class QgsFeatureRequest;
29 class QgsAttributes;
30 
34 class CORE_EXPORT QgsRelation
35 {
36  public:
37 
46  class FieldPair : public QPair< QString, QString >
47  {
48  public:
51  : QPair< QString, QString >() {}
52 
54  FieldPair( const QString& referencingField, const QString& referencedField )
55  : QPair< QString, QString >( referencingField, referencedField ) {}
56 
58  QString referencingField() const { return first; }
60  QString referencedField() const { return second; }
61 
62  bool operator==( const FieldPair& other ) const { return first == other.first && second == other.second; }
63  };
64 
68  QgsRelation();
69 
77  static QgsRelation createFromXml( const QDomNode& node );
78 
85  void writeXml( QDomNode& node, QDomDocument& doc ) const;
86 
92  void setRelationId( const QString& id );
93 
99  void setRelationName( const QString& name );
100 
106  void setReferencingLayer( const QString& id );
107 
113  void setReferencedLayer( const QString& id );
114 
123  void addFieldPair( const QString& referencingField, const QString& referencedField );
124 
133  void addFieldPair( const FieldPair& fieldPair );
134 
145  QgsFeatureIterator getRelatedFeatures( const QgsFeature& feature ) const;
146 
157  QgsFeatureRequest getRelatedFeaturesRequest( const QgsFeature& feature ) const;
158 
167  QString getRelatedFeaturesFilter( const QgsFeature& feature ) const;
168 
178  QgsFeatureRequest getReferencedFeatureRequest( const QgsAttributes& attributes ) const;
179 
188  QgsFeatureRequest getReferencedFeatureRequest( const QgsFeature& feature ) const;
189 
198  QgsFeature getReferencedFeature( const QgsFeature& feature ) const;
199 
207  QString name() const;
208 
214  QString id() const;
215 
220  void generateId();
221 
228  QString referencingLayerId() const;
229 
236  QgsVectorLayer* referencingLayer() const;
237 
243  QString referencedLayerId() const;
244 
250  QgsVectorLayer* referencedLayer() const;
251 
259  QList< FieldPair > fieldPairs() const;
260 
267  QgsAttributeList referencedFields() const;
268 
275  QgsAttributeList referencingFields() const;
276 
282  bool isValid() const;
283 
291  bool hasEqualDefinition( const QgsRelation& other ) const;
292 
293  protected:
294 
299  void updateRelationStatus();
300 
301  private:
303  QString mRelationId;
305  QString mRelationName;
307  QString mReferencingLayerId;
309  QgsVectorLayer* mReferencingLayer;
311  QString mReferencedLayerId;
313  QgsVectorLayer* mReferencedLayer;
314 
319  QList< FieldPair > mFieldPairs;
320 
321  bool mValid;
322 };
323 
324 // Register QgsRelation for usage with QVariant
326 
327 #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:135
FieldPair()
Default constructor: NULL strings.
Definition: qgsrelation.h:50
Defines a relation between matching fields of the two involved tables of a relation.
Definition: qgsrelation.h:46
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:62
QString referencedField() const
Get the name of the referenced (parent) field.
Definition: qgsrelation.h:60
FieldPair(const QString &referencingField, const QString &referencedField)
Constructor which takes two fields.
Definition: qgsrelation.h:54
A vector of attributes.
Definition: qgsfeature.h:55
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:58