QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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
120 QString referencingLayerSource() const;
121
129 QString referencingLayerProvider() const;
130
139 QString referencingLayerName() const;
140
148 void setReferencingLayer( const QString &sourceUri, const QString &provider );
149
155 QgsVectorLayerRef referencedLayer() const SIP_SKIP;
156
164 QString referencedLayerSource() const;
165
173 QString referencedLayerProvider() const;
174
183 QString referencedLayerName() const;
184
192 void setReferencedLayer( const QString &sourceUri, const QString &provider );
193
201 QgsVectorLayerRef mappingTable() const SIP_SKIP;
202
210 void setMappingTable( const QgsVectorLayerRef &table ) SIP_SKIP;
211
219 QString mappingTableSource() const;
220
228 QString mappingTableProvider() const;
229
238 QString mappingTableName() const;
239
247 void setMappingTable( const QString &sourceUri, const QString &provider );
248
254 QStringList referencingLayerFields() const { return mReferencingLayerFields; }
255
261 void setReferencingLayerFields( const QStringList &fields ) { mReferencingLayerFields = fields; }
262
270 QStringList mappingReferencingLayerFields() const { return mMappingReferencingLayerFields; }
271
279 void setMappingReferencingLayerFields( const QStringList &fields ) { mMappingReferencingLayerFields = fields; }
280
286 QStringList referencedLayerFields() const { return mReferencedLayerFields; }
287
293 void setReferencedLayerFields( const QStringList &fields ) { mReferencedLayerFields = fields; }
294
302 QStringList mappingReferencedLayerFields() const { return mMappingReferencedLayerFields; }
303
311 void setMappingReferencedLayerFields( const QStringList &fields ) { mMappingReferencedLayerFields = fields; }
312
316 Qgis::RelationshipStrength strength() const;
317
324 Qgis::RelationshipCardinality cardinality() const { return mCardinality; }
325
332 void setCardinality( Qgis::RelationshipCardinality cardinality ) { mCardinality = cardinality; }
333
351 QString forwardPathLabel() const { return mForwardPathLabel; }
352
370 QString backwardPathLabel() const { return mBackwardPathLabel; }
371
389 void setForwardPathLabel( const QString &label ) { mForwardPathLabel = label; }
390
408 void setBackwardPathLabel( const QString &label ) { mBackwardPathLabel = label; }
409
421 QString relatedTableType() const { return mRelatedTableType; }
422
434 void setRelatedTableType( const QString &type ) { mRelatedTableType = type; }
435
445 static QgsWeakRelation readXml( const QgsVectorLayer *layer, WeakRelationType type, const QDomNode &node, const QgsPathResolver resolver );
446
457 static void writeXml( const QgsVectorLayer *layer, WeakRelationType type, const QgsRelation &relation, QDomNode &node, QDomDocument &doc );
458
459#ifdef SIP_RUN
460 SIP_PYOBJECT __repr__();
461 % MethodCode
462
463 QString leftIdentifier;
464 if ( !sipCpp->referencedLayer().source.isEmpty() )
465 leftIdentifier = sipCpp->referencedLayer().source;
466
467 QString rightIdentifier;
468 if ( !sipCpp->referencingLayer().source.isEmpty() )
469 rightIdentifier = sipCpp->referencingLayer().source;
470
471 QString str;
472 if ( leftIdentifier.isEmpty() && rightIdentifier.isEmpty() )
473 str = QStringLiteral( "<QgsWeakRelation: %1>" ).arg( sipCpp->id() );
474 else
475 str = QStringLiteral( "<QgsWeakRelation: %1 - %2 -> %3>" ).arg( sipCpp->id(), leftIdentifier, rightIdentifier );
476
477 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
478 % End
479#endif
480
481 private:
482
483 QgsVectorLayerRef mReferencingLayer;
484 QgsVectorLayerRef mReferencedLayer;
485 QgsVectorLayerRef mMappingTable;
486
487 QString mRelationId;
488 QString mRelationName;
490
491 QStringList mReferencingLayerFields;
492 QStringList mMappingReferencingLayerFields;
493 QStringList mReferencedLayerFields;
494 QStringList mMappingReferencedLayerFields;
495
497 QString mForwardPathLabel;
498 QString mBackwardPathLabel;
499 QString mRelatedTableType;
500
501 friend class TestQgsWeakRelation;
502
503};
504
505#endif // QGSWEAKRELATION_H
RelationshipStrength
Relationship strength.
Definition qgis.h:4108
@ 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:4120
@ 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:107
Represents a relationship between two vector layers.
Definition qgsrelation.h:44
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:39
#define SIP_SKIP
Definition qgis_sip.h:126
MatchType
Flag for match type in weak resolution.