QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
61#ifndef SIP_RUN
62
68 QgsWeakRelation( const QString &relationId,
69 const QString &relationName,
70 const Qgis::RelationshipStrength strength,
71 const QString &referencingLayerId,
72 const QString &referencingLayerName,
73 const QString &referencingLayerSource,
74 const QString &referencingLayerProviderKey,
75 const QString &referencedLayerId,
76 const QString &referencedLayerName,
77 const QString &referencedLayerSource,
78 const QString &referencedLayerProviderKey
79 );
80#endif
81
89#ifndef SIP_RUN
90 QList< QgsRelation > resolvedRelations( const QgsProject *project, QgsVectorLayerRef::MatchType matchType = QgsVectorLayerRef::MatchType::All ) const;
91#else
92 QList< QgsRelation > resolvedRelations( const QgsProject *project ) const;
93#endif
94
100 QString id() const { return mRelationId; }
101
107 QString name() const { return mRelationName; }
108
114 QgsVectorLayerRef referencingLayer() const SIP_SKIP;
115
121 QString referencingLayerSource() const;
122
128 QString referencingLayerProvider() const;
129
138 QString referencingLayerName() const;
139
145 QgsVectorLayerRef referencedLayer() const SIP_SKIP;
146
152 QString referencedLayerSource() const;
153
159 QString referencedLayerProvider() const;
160
169 QString referencedLayerName() const;
170
178 QgsVectorLayerRef mappingTable() const SIP_SKIP;
179
187 void setMappingTable( const QgsVectorLayerRef &table ) SIP_SKIP;
188
194 QString mappingTableSource() const;
195
201 QString mappingTableProvider() const;
202
211 QString mappingTableName() const;
212
218 QStringList referencingLayerFields() const { return mReferencingLayerFields; }
219
225 void setReferencingLayerFields( const QStringList &fields ) { mReferencingLayerFields = fields; }
226
234 QStringList mappingReferencingLayerFields() const { return mMappingReferencingLayerFields; }
235
243 void setMappingReferencingLayerFields( const QStringList &fields ) { mMappingReferencingLayerFields = fields; }
244
250 QStringList referencedLayerFields() const { return mReferencedLayerFields; }
251
257 void setReferencedLayerFields( const QStringList &fields ) { mReferencedLayerFields = fields; }
258
266 QStringList mappingReferencedLayerFields() const { return mMappingReferencedLayerFields; }
267
275 void setMappingReferencedLayerFields( const QStringList &fields ) { mMappingReferencedLayerFields = fields; }
276
280 Qgis::RelationshipStrength strength() const;
281
288 Qgis::RelationshipCardinality cardinality() const { return mCardinality; }
289
296 void setCardinality( Qgis::RelationshipCardinality cardinality ) { mCardinality = cardinality; }
297
315 QString forwardPathLabel() const { return mForwardPathLabel; }
316
334 QString backwardPathLabel() const { return mBackwardPathLabel; }
335
353 void setForwardPathLabel( const QString &label ) { mForwardPathLabel = label; }
354
372 void setBackwardPathLabel( const QString &label ) { mBackwardPathLabel = label; }
373
385 QString relatedTableType() const { return mRelatedTableType; }
386
398 void setRelatedTableType( const QString &type ) { mRelatedTableType = type; }
399
409 static QgsWeakRelation readXml( const QgsVectorLayer *layer, WeakRelationType type, const QDomNode &node, const QgsPathResolver resolver );
410
421 static void writeXml( const QgsVectorLayer *layer, WeakRelationType type, const QgsRelation &relation, QDomNode &node, QDomDocument &doc );
422
423#ifdef SIP_RUN
424 SIP_PYOBJECT __repr__();
425 % MethodCode
426
427 QString leftIdentifier;
428 if ( !sipCpp->referencedLayer().source.isEmpty() )
429 leftIdentifier = sipCpp->referencedLayer().source;
430
431 QString rightIdentifier;
432 if ( !sipCpp->referencingLayer().source.isEmpty() )
433 rightIdentifier = sipCpp->referencingLayer().source;
434
435 QString str;
436 if ( leftIdentifier.isEmpty() && rightIdentifier.isEmpty() )
437 str = QStringLiteral( "<QgsWeakRelation: %1>" ).arg( sipCpp->id() );
438 else
439 str = QStringLiteral( "<QgsWeakRelation: %1 - %2 -> %3>" ).arg( sipCpp->id(), leftIdentifier, rightIdentifier );
440
441 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
442 % End
443#endif
444
445 private:
446
447 QgsVectorLayerRef mReferencingLayer;
448 QgsVectorLayerRef mReferencedLayer;
449 QgsVectorLayerRef mMappingTable;
450
451 QString mRelationId;
452 QString mRelationName;
454
455 QStringList mReferencingLayerFields;
456 QStringList mMappingReferencingLayerFields;
457 QStringList mReferencedLayerFields;
458 QStringList mMappingReferencedLayerFields;
459
461 QString mForwardPathLabel;
462 QString mBackwardPathLabel;
463 QString mRelatedTableType;
464
465 friend class TestQgsWeakRelation;
466
467};
468
469#endif // QGSWEAKRELATION_H
RelationshipStrength
Relationship strength.
Definition: qgis.h:2215
@ 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:2227
@ 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:104
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.