QGIS API Documentation 3.99.0-Master (8e76e220402)
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
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
45class CORE_EXPORT QgsWeakRelation
46{
47 public:
48
58
63
69 QgsWeakRelation( const QString &relationId,
70 const QString &relationName,
72 const QString &referencingLayerId,
73 const QString &referencingLayerName,
74 const QString &referencingLayerSource,
75 const QString &referencingLayerProviderKey,
76 const QString &referencedLayerId,
77 const QString &referencedLayerName,
78 const QString &referencedLayerSource,
79 const QString &referencedLayerProviderKey
80 );
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
123 QString referencingLayerSource() const;
124
132 QString referencingLayerProvider() const;
133
142 QString referencingLayerName() const;
143
151 void setReferencingLayer( const QString &sourceUri, const QString &provider );
152
158 QgsVectorLayerRef referencedLayer() const SIP_SKIP;
159
167 QString referencedLayerSource() const;
168
176 QString referencedLayerProvider() const;
177
186 QString referencedLayerName() const;
187
195 void setReferencedLayer( const QString &sourceUri, const QString &provider );
196
204 QgsVectorLayerRef mappingTable() const SIP_SKIP;
205
213 void setMappingTable( const QgsVectorLayerRef &table ) SIP_SKIP;
214
222 QString mappingTableSource() const;
223
231 QString mappingTableProvider() const;
232
241 QString mappingTableName() const;
242
250 void setMappingTable( const QString &sourceUri, const QString &provider );
251
257 QStringList referencingLayerFields() const { return mReferencingLayerFields; }
258
264 void setReferencingLayerFields( const QStringList &fields ) { mReferencingLayerFields = fields; }
265
273 QStringList mappingReferencingLayerFields() const { return mMappingReferencingLayerFields; }
274
282 void setMappingReferencingLayerFields( const QStringList &fields ) { mMappingReferencingLayerFields = fields; }
283
289 QStringList referencedLayerFields() const { return mReferencedLayerFields; }
290
296 void setReferencedLayerFields( const QStringList &fields ) { mReferencedLayerFields = fields; }
297
305 QStringList mappingReferencedLayerFields() const { return mMappingReferencedLayerFields; }
306
314 void setMappingReferencedLayerFields( const QStringList &fields ) { mMappingReferencedLayerFields = fields; }
315
319 Qgis::RelationshipStrength strength() const;
320
327 Qgis::RelationshipCardinality cardinality() const { return mCardinality; }
328
336
354 QString forwardPathLabel() const { return mForwardPathLabel; }
355
373 QString backwardPathLabel() const { return mBackwardPathLabel; }
374
392 void setForwardPathLabel( const QString &label ) { mForwardPathLabel = label; }
393
411 void setBackwardPathLabel( const QString &label ) { mBackwardPathLabel = label; }
412
424 QString relatedTableType() const { return mRelatedTableType; }
425
437 void setRelatedTableType( const QString &type ) { mRelatedTableType = type; }
438
448 static QgsWeakRelation readXml( const QgsVectorLayer *layer, WeakRelationType type, const QDomNode &node, const QgsPathResolver resolver );
449
460 static void writeXml( const QgsVectorLayer *layer, WeakRelationType type, const QgsRelation &relation, QDomNode &node, QDomDocument &doc );
461
462#ifdef SIP_RUN
463 SIP_PYOBJECT __repr__();
464 % MethodCode
465
466 QString leftIdentifier;
467 if ( !sipCpp->referencedLayer().source.isEmpty() )
468 leftIdentifier = sipCpp->referencedLayer().source;
469
470 QString rightIdentifier;
471 if ( !sipCpp->referencingLayer().source.isEmpty() )
472 rightIdentifier = sipCpp->referencingLayer().source;
473
474 QString str;
475 if ( leftIdentifier.isEmpty() && rightIdentifier.isEmpty() )
476 str = u"<QgsWeakRelation: %1>"_s.arg( sipCpp->id() );
477 else
478 str = u"<QgsWeakRelation: %1 - %2 -> %3>"_s.arg( sipCpp->id(), leftIdentifier, rightIdentifier );
479
480 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
481 % End
482#endif
483
484 private:
485
486 QgsVectorLayerRef mReferencingLayer;
487 QgsVectorLayerRef mReferencedLayer;
488 QgsVectorLayerRef mMappingTable;
489
490 QString mRelationId;
491 QString mRelationName;
493
494 QStringList mReferencingLayerFields;
495 QStringList mMappingReferencingLayerFields;
496 QStringList mReferencedLayerFields;
497 QStringList mMappingReferencedLayerFields;
498
500 QString mForwardPathLabel;
501 QString mBackwardPathLabel;
502 QString mRelatedTableType;
503
505
506};
507
508#endif // QGSWEAKRELATION_H
RelationshipStrength
Relationship strength.
Definition qgis.h:4499
@ Association
Loose relation, related elements are not part of the parent and a parent copy will not copy any child...
Definition qgis.h:4500
RelationshipCardinality
Relationship cardinality.
Definition qgis.h:4511
@ OneToMany
One to many relationship.
Definition qgis.h:4513
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:113
Represents a relationship between two vector layers.
Definition qgsrelation.h:42
Represents a vector layer which manages a vector based dataset.
Represent a QgsRelation with possibly unresolved layers or unmatched fields.
QList< QgsRelation > resolvedRelations(const QgsProject *project, QgsVectorLayerRef::MatchType matchType=QgsVectorLayerRef::MatchType::All) const
Resolves a weak relation in the given project returning a list of possibly invalid QgsRelations and w...
WeakRelationType
Enum to distinguish if the layer is referenced or referencing.
@ Referencing
The layer is referencing (or the "child" / "right" layer in the relationship).
@ Referenced
The layer is referenced (or the "parent" / "left" left 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.
QString referencedLayerName() const
Returns the layer name of the referenced (or "parent" / "left") layer.
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 referencedLayerSource() const
Returns the source URI for the referenced (or "parent" / "left") layer.
QString referencingLayerSource() const
Returns the source URI for the referencing (or "child" / "right") layer.
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.
friend class TestQgsWeakRelation
QString referencingLayerName() const
Returns the layer name of the referencing (or "child" / "right") layer.
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.
QStringList referencingLayerFields() const
Returns the list of fields from the referencingLayer() involved in the relationship.
void setReferencedLayerFields(const QStringList &fields)
Sets the list of fields from the referencedLayer() involved in the relationship.
Qgis::RelationshipStrength strength() const
Returns the strength of the relation.
#define SIP_SKIP
Definition qgis_sip.h:134
_LayerRef< QgsVectorLayer > QgsVectorLayerRef