QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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
49class CORE_EXPORT QgsPolymorphicRelation
50{
51 Q_GADGET
52
53 Q_PROPERTY( QString id READ id WRITE setId )
54 Q_PROPERTY( QgsVectorLayer *referencingLayer READ referencingLayer )
55 Q_PROPERTY( QString referencedLayerField READ referencedLayerField )
56 Q_PROPERTY( QString referencedLayerExpression READ referencedLayerExpression )
57 Q_PROPERTY( QString name READ name WRITE setName )
58 Q_PROPERTY( bool isValid READ isValid )
59
60 public:
61
67
72
79
85 QgsPolymorphicRelation &operator=( const QgsPolymorphicRelation &other );
86
96 static QgsPolymorphicRelation createFromXml( const QDomNode &node, QgsReadWriteContext &context, const QgsRelationContext &relationContext = QgsRelationContext() );
97
104 void writeXml( QDomNode &node, QDomDocument &doc ) const;
105
109 void setId( const QString &id );
110
114 void setName( const QString &name );
115
119 void setReferencingLayer( const QString &id );
120
129 void addFieldPair( const QString &referencingField, const QString &referencedField );
130
139 void addFieldPair( const QgsRelation::FieldPair &fieldPair ) SIP_SKIP;
140
148 QString name() const;
149
155 QString id() const;
156
160 void generateId();
161
168 QString referencingLayerId() const;
169
176 QgsVectorLayer *referencingLayer() const;
177
185#ifndef SIP_RUN
186 QList< QgsRelation::FieldPair > fieldPairs() const;
187#else
188 QMap< QString, QString > fieldPairs() const;
189 % MethodCode
190 const QList< QgsRelation::FieldPair > &pairs = sipCpp->fieldPairs();
191 sipRes = new QMap< QString, QString >();
192 for ( const QgsRelation::FieldPair &pair : pairs )
193 {
194 sipRes->insert( pair.first, pair.second );
195 }
196 % End
197#endif
198
205 QgsAttributeList referencedFields( const QString &layerId ) const;
206
213 QgsAttributeList referencingFields() const;
214
221 bool isValid() const;
222
229 bool hasEqualDefinition( const QgsPolymorphicRelation &other ) const;
230
235 void updateRelationStatus();
236
240 void setReferencedLayerField( const QString &referencedLayerField );
241
245 QString referencedLayerField() const;
246
250 void setReferencedLayerExpression( const QString &expression );
251
255 QString referencedLayerExpression() const;
256
260 void setReferencedLayerIds( const QStringList &childRelationIds );
261
265 QStringList referencedLayerIds() const;
266
270 QList<QgsRelation> generateRelations() const;
271
275 QString layerRepresentation( const QgsVectorLayer *layer ) const;
276
280 Qgis::RelationshipStrength strength() const;
281
285 void setRelationStrength( Qgis::RelationshipStrength relationStrength );
286
287 private:
288 friend class QgsRelationManager;
289
291 QString upgradeGeneratedRelationId( const QString &oldRelationId ) const;
292
293 QExplicitlySharedDataPointer<QgsPolymorphicRelationPrivate> d;
294
295 QgsRelationContext mContext;
296
297};
298
299// Register QgsPolymorphicRelation for usage with QVariant
301
302#endif // QGSPOLYMORPHICRELATION_H
RelationshipStrength
Relationship strength.
Definition qgis.h:4100
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.
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:58
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.
This class 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 data sets.
#define SIP_SKIP
Definition qgis_sip.h:126
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QList< int > QgsAttributeList
Definition qgsfield.h:27