QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
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 "qgis_core.h"
24#include "qgsreadwritecontext.h"
25#include "qgsrelationcontext.h"
26#include "qgsattributes.h"
27
28#include "qgis_sip.h"
29
31class QgsFeature;
33class QgsVectorLayer;
34class QgsRelationPrivate;
36
41class CORE_EXPORT QgsRelation
42{
43 Q_GADGET
44
45 Q_PROPERTY( QString id READ id WRITE setId )
46 Q_PROPERTY( QgsVectorLayer *referencingLayer READ referencingLayer )
47 Q_PROPERTY( QgsVectorLayer *referencedLayer READ referencedLayer )
48 Q_PROPERTY( QString name READ name WRITE setName )
49 Q_PROPERTY( bool isValid READ isValid )
50 Q_PROPERTY( QString polymorphicRelationId READ polymorphicRelationId WRITE setPolymorphicRelationId )
51 Q_PROPERTY( QgsPolymorphicRelation polymorphicRelation READ polymorphicRelation )
52
53 public:
54
55#ifndef SIP_RUN
56
66 class FieldPair : public QPair< QString, QString >
67 {
68 public:
70 FieldPair() = default;
71
73 FieldPair( const QString &referencingField, const QString &referencedField )
74 : QPair< QString, QString >( referencingField, referencedField ) {}
75
77 QString referencingField() const { return first; }
79 QString referencedField() const { return second; }
80
81 bool operator==( const FieldPair &other ) const { return first == other.first && second == other.second; }
82 };
83#endif
84
90
94 QgsRelation( const QgsRelationContext &context );
95
101 QgsRelation( const QgsRelation &other );
102
108 QgsRelation &operator=( const QgsRelation &other );
109
119 static QgsRelation createFromXml( const QDomNode &node, QgsReadWriteContext &context, const QgsRelationContext &relationContext = QgsRelationContext() );
120
127 void writeXml( QDomNode &node, QDomDocument &doc ) const;
128
132 void setId( const QString &id );
133
137 void setName( const QString &name );
138
142 void setStrength( Qgis::RelationshipStrength strength );
143
147 void setReferencingLayer( const QString &id );
148
152 void setReferencedLayer( const QString &id );
153
162 void addFieldPair( const QString &referencingField, const QString &referencedField );
163
172 void addFieldPair( const FieldPair &fieldPair ) SIP_SKIP;
173
184 QgsFeatureIterator getRelatedFeatures( const QgsFeature &feature ) const;
185
196 QgsFeatureRequest getRelatedFeaturesRequest( const QgsFeature &feature ) const;
197
206 QString getRelatedFeaturesFilter( const QgsFeature &feature ) const;
207
216 QgsFeatureRequest getReferencedFeatureRequest( const QgsAttributes &attributes ) const;
217
226 QgsFeatureRequest getReferencedFeatureRequest( const QgsFeature &feature ) const;
227
236 QgsFeature getReferencedFeature( const QgsFeature &feature ) const;
237
245 QString name() const;
246
252 Qgis::RelationshipStrength strength() const;
253
259 QString id() const;
260
264 void generateId();
265
272 QString referencingLayerId() const;
273
280 QgsVectorLayer *referencingLayer() const;
281
287 QString referencedLayerId() const;
288
294 QgsVectorLayer *referencedLayer() const;
295
303#ifndef SIP_RUN
304 QList< QgsRelation::FieldPair > fieldPairs() const;
305#else
306 QMap< QString, QString > fieldPairs() const;
307 % MethodCode
308 const QList< QgsRelation::FieldPair > &pairs = sipCpp->fieldPairs();
309 sipRes = new QMap< QString, QString >();
310 for ( const QgsRelation::FieldPair &pair : pairs )
311 {
312 sipRes->insert( pair.first, pair.second );
313 }
314 % End
315#endif
316
323 QgsAttributeList referencedFields() const;
324
331 QgsAttributeList referencingFields() const;
332
341 bool isValid() const;
342
351 QString validationError() const;
352
359 bool hasEqualDefinition( const QgsRelation &other ) const;
360
365 Q_INVOKABLE QString resolveReferencedField( const QString &referencingField ) const;
366
371 Q_INVOKABLE QString resolveReferencingField( const QString &referencedField ) const;
372
379 void updateRelationStatus();
380
385 void setPolymorphicRelationId( const QString &polymorphicRelationId );
386
391 QString polymorphicRelationId() const;
392
397 QgsPolymorphicRelation polymorphicRelation() const;
398
403 Qgis::RelationshipType type() const;
404
410 static QString cardinalityToDisplayString( Qgis::RelationshipCardinality cardinality );
411
417 static QString strengthToDisplayString( Qgis::RelationshipStrength strength );
418
419 private:
420
421 mutable QExplicitlySharedDataPointer<QgsRelationPrivate> d;
422
423 QgsRelationContext mContext;
424};
425
426// Register QgsRelation for usage with QVariant
428
429#endif // QGSRELATION_H
RelationshipStrength
Relationship strength.
Definition qgis.h:3583
RelationshipType
Relationship types.
Definition qgis.h:3569
RelationshipCardinality
Relationship cardinality.
Definition qgis.h:3595
A vector of attributes.
Wrapper for iterator of features from vector data provider or vector layer.
This class wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:56
A polymorphic relation consists of the same properties like a normal relation except for the referenc...
The class is used as a container of context for various read/write operations on other objects.
Context for relations.
Defines a relation between matching fields of the two involved tables of a relation.
Definition qgsrelation.h:67
QString referencingField() const
Gets the name of the referencing (child) field.
Definition qgsrelation.h:77
QString referencedField() const
Gets the name of the referenced (parent) field.
Definition qgsrelation.h:79
FieldPair(const QString &referencingField, const QString &referencedField)
Constructor which takes two fields.
Definition qgsrelation.h:73
bool operator==(const FieldPair &other) const
Definition qgsrelation.h:81
FieldPair()=default
Default constructor: NULL strings.
Represents a vector layer which manages a vector based data sets.
#define SIP_SKIP
Definition qgis_sip.h:126
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QList< int > QgsAttributeList
Definition qgsfield.h:27