QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 dot kuhn at gmx 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( QString referencingField, QString referencedField )
47  : QPair< QString, QString >( referencingField, referencedField ) {}
48 
50  const QString& referencingField() const { return first; }
52  const 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( QString id );
83 
89  void setRelationName( QString name );
90 
96  void setReferencingLayer( QString id );
97 
103  void setReferencedLayer( QString id );
104 
113  void addFieldPair( QString referencingField, QString referencedField );
114 
123  void addFieldPair( FieldPair fieldPair );
124 
133  QgsFeatureIterator getRelatedFeatures( const QgsFeature& feature ) const;
134 
143  QgsFeatureRequest getRelatedFeaturesRequest( const QgsFeature& feature ) const;
144 
145  const QString name() const;
146 
151  const QString& id() const;
152 
159  QString referencingLayerId() const;
160 
167  QgsVectorLayer* referencingLayer() const;
168 
174  QString referencedLayerId() const;
175 
181  QgsVectorLayer* referencedLayer() const;
182 
190  QList< FieldPair > fieldPairs() const;
191 
197  bool isValid() const;
198 
199  protected:
200  void updateRelationStatus();
201  void runChecks();
202 
203  private:
205  QString mRelationId;
207  QString mRelationName;
209  QString mReferencingLayerId;
211  QgsVectorLayer* mReferencingLayer;
213  QString mReferencedLayerId;
215  QgsVectorLayer* mReferencedLayer;
220  QList< FieldPair > mFieldPairs;
221 
222  bool mValid;
223 };
224 
225 // Register QgsRelation for usage with QVariant
227 
228 #endif // QGSRELATION_H