QGIS API Documentation 4.3.0-Master (09d73a2b827)
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 "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgsfields.h"
22#include "qgsreadwritecontext.h"
23#include "qgsrelation.h"
24#include "qgsrelationcontext.h"
25
26#include <QDomNode>
27#include <QList>
28#include <QPair>
29
31class QgsFeature;
33class QgsAttributes;
34class QgsVectorLayer;
35class QgsPolymorphicRelationPrivate;
37
51class CORE_EXPORT QgsPolymorphicRelation
52{
53 Q_GADGET
54
55 Q_PROPERTY( QString id READ id WRITE setId )
57 Q_PROPERTY( QString referencedLayerField READ referencedLayerField )
59 Q_PROPERTY( QString name READ name WRITE setName )
60 Q_PROPERTY( bool isValid READ isValid )
61
62 public:
68
73
81
87 QgsPolymorphicRelation &operator=( const QgsPolymorphicRelation &other );
89
90 // TODO QGIS 5.0 -- Remove the deprecated createFromXml method without the relationContext parameter
100 Q_DECL_DEPRECATED static QgsPolymorphicRelation createFromXml( const QDomNode &node, QgsReadWriteContext &context ) SIP_DEPRECATED;
101
111 static QgsPolymorphicRelation createFromXml( const QDomNode &node, QgsReadWriteContext &context, const QgsRelationContext &relationContext );
112
119 void writeXml( QDomNode &node, QDomDocument &doc ) const;
120
124 void setId( const QString &id );
125
129 void setName( const QString &name );
130
134 void setReferencingLayer( const QString &id );
135
144 void addFieldPair( const QString &referencingField, const QString &referencedField );
145
154 void addFieldPair( const QgsRelation::FieldPair &fieldPair ) SIP_SKIP;
155
163 QString name() const;
164
170 QString id() const;
171
175 void generateId();
176
183 QString referencingLayerId() const;
184
192
200#ifndef SIP_RUN
201 QList< QgsRelation::FieldPair > fieldPairs() const;
202#else
203 // clang-format off
204 QMap< QString, QString > fieldPairs() const;
205 % MethodCode
206 const QList< QgsRelation::FieldPair > &pairs = sipCpp->fieldPairs();
207 sipRes = new QMap< QString, QString >();
208 for ( const QgsRelation::FieldPair &pair : pairs )
209 {
210 sipRes->insert( pair.first, pair.second );
211 }
212 % End
213// clang-format on
214#endif
215
222 QgsAttributeList referencedFields( const QString &layerId ) const;
223
230 QgsAttributeList referencingFields() const;
231
238 bool isValid() const;
239
246 bool hasEqualDefinition( const QgsPolymorphicRelation &other ) const;
247
252 void updateRelationStatus();
253
257 void setReferencedLayerField( const QString &referencedLayerField );
258
262 QString referencedLayerField() const;
263
267 void setReferencedLayerExpression( const QString &expression );
268
272 QString referencedLayerExpression() const;
273
277 void setReferencedLayerIds( const QStringList &childRelationIds );
278
282 QStringList referencedLayerIds() const;
283
287 QList<QgsRelation> generateRelations() const;
288
292 QString layerRepresentation( const QgsVectorLayer *layer ) const;
293
297 Qgis::RelationshipStrength strength() const;
298
302 void setRelationStrength( Qgis::RelationshipStrength relationStrength );
303
304 private:
305 friend class QgsRelationManager;
306
308 QString upgradeGeneratedRelationId( const QString &oldRelationId ) const;
309
310 QExplicitlySharedDataPointer<QgsPolymorphicRelationPrivate> d;
311
312 QgsRelationContext mContext;
313};
314
315// Register QgsPolymorphicRelation for usage with QVariant
317
318#endif // QGSPOLYMORPHICRELATION_H
RelationshipStrength
Relationship strength.
Definition qgis.h:4863
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:60
A relation where the referenced (parent) layer is calculated based on fields from the referencing (ch...
void generateId()
Generate a (project-wide) unique id for this relation.
void setReferencingLayer(const QString &id)
Set the referencing (child) layer id.
QList< QgsRelation::FieldPair > fieldPairs() const
Returns the field pairs which form this relation The first element of each pair are the field names o...
void writeXml(QDomNode &node, QDomDocument &doc) const
Writes a relation to an XML structure.
void addFieldPair(const QString &referencingField, const QString &referencedField)
Add a field pair which is part of this relation The first element of each pair are the field names of...
static Q_DECL_DEPRECATED QgsPolymorphicRelation createFromXml(const QDomNode &node, QgsReadWriteContext &context)
Creates a relation from an XML structure.
QString referencingLayerId() const
Access the referencing (child) layer's id This is the layer which has the field(s) which point to ano...
QgsPolymorphicRelation()
Default constructor.
void setName(const QString &name)
Set a name for this relation.
void setId(const QString &id)
Set an id for this relation.
A container for the context for various read/write operations on objects.
Context for relations.
Defines a relation between matching fields of the two involved tables of a relation.
Definition qgsrelation.h:71
Represents a relationship between two vector layers.
Definition qgsrelation.h:42
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:138
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QList< int > QgsAttributeList
Definition qgsfield.h:30