QGIS API Documentation  2.2.0-Valmiera
 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 
122  void addFieldPair( FieldPair fieldPair );
123 
132  QgsFeatureIterator getRelatedFeatures( const QgsFeature& feature ) const;
133 
142  QgsFeatureRequest getRelatedFeaturesRequest( const QgsFeature& feature ) const;
143 
144  const QString name() const;
145 
150  const QString& id() const;
151 
158  QString referencingLayerId() const;
159 
166  QgsVectorLayer* referencingLayer() const;
167 
173  QString referencedLayerId() const;
174 
180  QgsVectorLayer* referencedLayer() const;
181 
189  QList< FieldPair > fieldPairs() const;
190 
196  bool isValid() const;
197 
198  protected:
199  void updateRelationStatus();
200  void runChecks();
201 
202  private:
204  QString mRelationId;
206  QString mRelationName;
219  QList< FieldPair > mFieldPairs;
220 
221  bool mValid;
222 };
223 
224 // Register QgsRelation for usage with QVariant
226 
227 #endif // QGSRELATION_H