QGIS API Documentation 3.43.0-Master (b60ef06885e)
qgspolymorphicrelation.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspolymorphicrelation.h
3 --------------------------------------
4 Date : December 2020
5 Copyright : (C) 2020 Ivan Ivanov
6 Email : ivan 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 QGSPOLYMORPHICRELATION_H
17#define QGSPOLYMORPHICRELATION_H
18
19#include <QList>
20#include <QDomNode>
21#include <QPair>
22
23#include "qgis_core.h"
24#include "qgsfields.h"
25#include "qgsreadwritecontext.h"
26#include "qgsrelationcontext.h"
27#include "qgsrelation.h"
28
29#include "qgis_sip.h"
30
32class QgsFeature;
34class QgsAttributes;
35class QgsVectorLayer;
36class QgsPolymorphicRelationPrivate;
38
52class CORE_EXPORT QgsPolymorphicRelation
53{
54 Q_GADGET
55
56 Q_PROPERTY( QString id READ id WRITE setId )
57 Q_PROPERTY( QgsVectorLayer *referencingLayer READ referencingLayer )
58 Q_PROPERTY( QString referencedLayerField READ referencedLayerField )
59 Q_PROPERTY( QString referencedLayerExpression READ referencedLayerExpression )
60 Q_PROPERTY( QString name READ name WRITE setName )
61 Q_PROPERTY( bool isValid READ isValid )
62
63 public:
64
70
75
82
88 QgsPolymorphicRelation &operator=( const QgsPolymorphicRelation &other );
89
99 static QgsPolymorphicRelation createFromXml( const QDomNode &node, QgsReadWriteContext &context, const QgsRelationContext &relationContext = QgsRelationContext() );
100
107 void writeXml( QDomNode &node, QDomDocument &doc ) const;
108
112 void setId( const QString &id );
113
117 void setName( const QString &name );
118
122 void setReferencingLayer( const QString &id );
123
132 void addFieldPair( const QString &referencingField, const QString &referencedField );
133
142 void addFieldPair( const QgsRelation::FieldPair &fieldPair ) SIP_SKIP;
143
151 QString name() const;
152
158 QString id() const;
159
163 void generateId();
164
171 QString referencingLayerId() const;
172
179 QgsVectorLayer *referencingLayer() const;
180
188#ifndef SIP_RUN
189 QList< QgsRelation::FieldPair > fieldPairs() const;
190#else
191 QMap< QString, QString > fieldPairs() const;
192 % MethodCode
193 const QList< QgsRelation::FieldPair > &pairs = sipCpp->fieldPairs();
194 sipRes = new QMap< QString, QString >();
195 for ( const QgsRelation::FieldPair &pair : pairs )
196 {
197 sipRes->insert( pair.first, pair.second );
198 }
199 % End
200#endif
201
208 QgsAttributeList referencedFields( const QString &layerId ) const;
209
216 QgsAttributeList referencingFields() const;
217
224 bool isValid() const;
225
232 bool hasEqualDefinition( const QgsPolymorphicRelation &other ) const;
233
238 void updateRelationStatus();
239
243 void setReferencedLayerField( const QString &referencedLayerField );
244
248 QString referencedLayerField() const;
249
253 void setReferencedLayerExpression( const QString &expression );
254
258 QString referencedLayerExpression() const;
259
263 void setReferencedLayerIds( const QStringList &childRelationIds );
264
268 QStringList referencedLayerIds() const;
269
273 QList<QgsRelation> generateRelations() const;
274
278 QString layerRepresentation( const QgsVectorLayer *layer ) const;
279
283 Qgis::RelationshipStrength strength() const;
284
288 void setRelationStrength( Qgis::RelationshipStrength relationStrength );
289
290 private:
291 friend class QgsRelationManager;
292
294 QString upgradeGeneratedRelationId( const QString &oldRelationId ) const;
295
296 QExplicitlySharedDataPointer<QgsPolymorphicRelationPrivate> d;
297
298 QgsRelationContext mContext;
299
300};
301
302// Register QgsPolymorphicRelation for usage with QVariant
304
305#endif // QGSPOLYMORPHICRELATION_H
RelationshipStrength
Relationship strength.
Definition qgis.h:4255
A vector of attributes.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Wrapper for iterator of features from vector data provider or vector layer.
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:58
A relation where the referenced (parent) layer is calculated based on fields from the referencing (ch...
A container for the context for various read/write operations on objects.
Context for relations.
Manages a set of relations between layers.
Defines a relation between matching fields of the two involved tables of a relation.
Definition qgsrelation.h:69
Represents a relationship between two vector layers.
Definition qgsrelation.h:44
Represents a vector layer which manages a vector based dataset.
#define SIP_SKIP
Definition qgis_sip.h:126
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QList< int > QgsAttributeList
Definition qgsfield.h:27