QGIS API Documentation  2.3.0-Master
 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
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:114
FieldPair()
Default constructor: NULL strings.
Definition: qgsrelation.h:42
QString mRelationId
Unique Id.
Definition: qgsrelation.h:204
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:210
const QString & referencingField() const
Get the name of the referencing field.
Definition: qgsrelation.h:50
QString mRelationName
Human redable name.
Definition: qgsrelation.h:206
QString mReferencedLayerId
The parent layer id.
Definition: qgsrelation.h:212
QString mReferencingLayerId
The child layer.
Definition: qgsrelation.h:208
QgsVectorLayer * mReferencedLayer
The parent layer.
Definition: qgsrelation.h:214
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:219