QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgsweakrelation.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsweakrelation.h - QgsWeakRelation
3
4 ---------------------
5 begin : 5.12.2019
6 copyright : (C) 2019 by Alessandro Pasotti
7 email : elpaso at itopen dot it
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSWEAKRELATION_H
17#define QGSWEAKRELATION_H
18
19#include "qgis_core.h"
20#include "qgsrelation.h"
21#include "qgsvectorlayerref.h"
22
42class CORE_EXPORT QgsWeakRelation
43{
44 public:
45
51 {
53 Referenced
54 };
55
60
66 QgsWeakRelation( const QString &relationId,
67 const QString &relationName,
68 const Qgis::RelationshipStrength strength,
69 const QString &referencingLayerId,
70 const QString &referencingLayerName,
71 const QString &referencingLayerSource,
72 const QString &referencingLayerProviderKey,
73 const QString &referencedLayerId,
74 const QString &referencedLayerName,
75 const QString &referencedLayerSource,
76 const QString &referencedLayerProviderKey
77 );
78
86#ifndef SIP_RUN
87 QList< QgsRelation > resolvedRelations( const QgsProject *project, QgsVectorLayerRef::MatchType matchType = QgsVectorLayerRef::MatchType::All ) const;
88#else
89 QList< QgsRelation > resolvedRelations( const QgsProject *project ) const;
90#endif
91
97 QString id() const { return mRelationId; }
98
104 QString name() const { return mRelationName; }
105
111 QgsVectorLayerRef referencingLayer() const SIP_SKIP;
112
118 QString referencingLayerSource() const;
119
125 QString referencingLayerProvider() const;
126
135 QString referencingLayerName() const;
136
142 QgsVectorLayerRef referencedLayer() const SIP_SKIP;
143
149 QString referencedLayerSource() const;
150
156 QString referencedLayerProvider() const;
157
166 QString referencedLayerName() const;
167
175 QgsVectorLayerRef mappingTable() const SIP_SKIP;
176
184 void setMappingTable( const QgsVectorLayerRef &table ) SIP_SKIP;
185
191 QString mappingTableSource() const;
192
198 QString mappingTableProvider() const;
199
208 QString mappingTableName() const;
209
215 QStringList referencingLayerFields() const { return mReferencingLayerFields; }
216
222 void setReferencingLayerFields( const QStringList &fields ) { mReferencingLayerFields = fields; }
223
231 QStringList mappingReferencingLayerFields() const { return mMappingReferencingLayerFields; }
232
240 void setMappingReferencingLayerFields( const QStringList &fields ) { mMappingReferencingLayerFields = fields; }
241
247 QStringList referencedLayerFields() const { return mReferencedLayerFields; }
248
254 void setReferencedLayerFields( const QStringList &fields ) { mReferencedLayerFields = fields; }
255
263 QStringList mappingReferencedLayerFields() const { return mMappingReferencedLayerFields; }
264
272 void setMappingReferencedLayerFields( const QStringList &fields ) { mMappingReferencedLayerFields = fields; }
273
277 Qgis::RelationshipStrength strength() const;
278
285 Qgis::RelationshipCardinality cardinality() const { return mCardinality; }
286
293 void setCardinality( Qgis::RelationshipCardinality cardinality ) { mCardinality = cardinality; }
294
312 QString forwardPathLabel() const { return mForwardPathLabel; }
313
331 QString backwardPathLabel() const { return mBackwardPathLabel; }
332
350 void setForwardPathLabel( const QString &label ) { mForwardPathLabel = label; }
351
369 void setBackwardPathLabel( const QString &label ) { mBackwardPathLabel = label; }
370
382 QString relatedTableType() const { return mRelatedTableType; }
383
395 void setRelatedTableType( const QString &type ) { mRelatedTableType = type; }
396
406 static QgsWeakRelation readXml( const QgsVectorLayer *layer, WeakRelationType type, const QDomNode &node, const QgsPathResolver resolver );
407
418 static void writeXml( const QgsVectorLayer *layer, WeakRelationType type, const QgsRelation &relation, QDomNode &node, QDomDocument &doc );
419
420#ifdef SIP_RUN
421 SIP_PYOBJECT __repr__();
422 % MethodCode
423
424 QString leftIdentifier;
425 if ( !sipCpp->referencedLayer().source.isEmpty() )
426 leftIdentifier = sipCpp->referencedLayer().source;
427
428 QString rightIdentifier;
429 if ( !sipCpp->referencingLayer().source.isEmpty() )
430 rightIdentifier = sipCpp->referencingLayer().source;
431
432 QString str;
433 if ( leftIdentifier.isEmpty() && rightIdentifier.isEmpty() )
434 str = QStringLiteral( "<QgsWeakRelation: %1>" ).arg( sipCpp->id() );
435 else
436 str = QStringLiteral( "<QgsWeakRelation: %1 - %2 -> %3>" ).arg( sipCpp->id(), leftIdentifier, rightIdentifier );
437
438 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
439 % End
440#endif
441
442 private:
443
444 QgsVectorLayerRef mReferencingLayer;
445 QgsVectorLayerRef mReferencedLayer;
446 QgsVectorLayerRef mMappingTable;
447
448 QString mRelationId;
449 QString mRelationName;
451
452 QStringList mReferencingLayerFields;
453 QStringList mMappingReferencingLayerFields;
454 QStringList mReferencedLayerFields;
455 QStringList mMappingReferencedLayerFields;
456
458 QString mForwardPathLabel;
459 QString mBackwardPathLabel;
460 QString mRelatedTableType;
461
462 friend class TestQgsWeakRelation;
463
464};
465
466#endif // QGSWEAKRELATION_H
RelationshipStrength
Relationship strength.
Definition: qgis.h:2642
@ Association
Loose relation, related elements are not part of the parent and a parent copy will not copy any child...
RelationshipCardinality
Relationship cardinality.
Definition: qgis.h:2654
@ OneToMany
One to many relationship.
Resolves relative paths into absolute paths and vice versa.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:105
Represents a vector layer which manages a vector based data sets.
The QgsWeakRelation class represent a QgsRelation with possibly unresolved layers or unmatched fields...
WeakRelationType
Enum to distinguish if the layer is referenced or referencing.
@ Referencing
The layer is referencing (or the "child" / "right" layer in the relationship)
QStringList mappingReferencingLayerFields() const
Returns the list of fields from the mappingTable() involved in the relationship.
void setForwardPathLabel(const QString &label)
Sets the label of the forward path for the relationship.
QgsWeakRelation()
Default constructor for an invalid relation.
void setMappingReferencingLayerFields(const QStringList &fields)
Sets the list of fields from the mappingTable() involved in the relationship.
void setBackwardPathLabel(const QString &label)
Sets the label of the backward path for the relationship.
QString relatedTableType() const
Returns the type string of the related table.
void setReferencingLayerFields(const QStringList &fields)
Sets the list of fields from the referencingLayer() involved in the relationship.
QString name() const
Returns the relationship's name.
QString backwardPathLabel() const
Returns the label of the backward path for the relationship.
void setMappingReferencedLayerFields(const QStringList &fields)
Sets the list of fields from the mappingTable() involved in the relationship.
QString id() const
Returns the relationship's ID.
QString forwardPathLabel() const
Returns the label of the forward path for the relationship.
Qgis::RelationshipCardinality cardinality() const
Returns the relationship's cardinality.
void setCardinality(Qgis::RelationshipCardinality cardinality)
Sets the relationship's cardinality.
QStringList referencedLayerFields() const
Returns the list of fields from the referencedLayer() involved in the relationship.
QStringList mappingReferencedLayerFields() const
Returns the list of fields from the mappingTable() involved in the relationship.
void setRelatedTableType(const QString &type)
Sets the type string of the related table.
void setReferencedLayerFields(const QStringList &fields)
Sets the list of fields from the referencedLayer() involved in the relationship.
#define str(x)
Definition: qgis.cpp:37
#define SIP_SKIP
Definition: qgis_sip.h:126
MatchType
Flag for match type in weak resolution.