QGIS API Documentation  2.4.0-Chugiak
 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;
220  QList< FieldPair > mFieldPairs;
221 
222  bool mValid;
223 };
224 
225 // Register QgsRelation for usage with QVariant
227 
228 #endif // QGSRELATION_H
Wrapper for iterator of features from vector data provider or vector layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
FieldPair()
Default constructor: NULL strings.
Definition: qgsrelation.h:42
QString mRelationId
Unique Id.
Definition: qgsrelation.h:205
Defines a relation between matchin fields of the two involved tables of a relation.
Definition: qgsrelation.h:38
This class wraps a request for features to a vector layer (or directly its vector data provider)...
FieldPair(QString referencingField, QString referencedField)
Constructor which takes two fields.
Definition: qgsrelation.h:46
QgsVectorLayer * mReferencingLayer
The child layer.
Definition: qgsrelation.h:211
const QString & referencingField() const
Get the name of the referencing field.
Definition: qgsrelation.h:50
QString mRelationName
Human redable name.
Definition: qgsrelation.h:207
QString mReferencedLayerId
The parent layer id.
Definition: qgsrelation.h:213
QString mReferencingLayerId
The child layer.
Definition: qgsrelation.h:209
QgsVectorLayer * mReferencedLayer
The parent layer.
Definition: qgsrelation.h:215
Represents a vector layer which manages a vector based data sets.
Q_DECLARE_METATYPE(QgsExpression::Interval)
const QString & referencedField() const
Get the name of the referenced field.
Definition: qgsrelation.h:52
QList< FieldPair > mFieldPairs
A list of fields which define the relation.
Definition: qgsrelation.h:220