17 #include <QApplication>
23 const QString &referencingLayerId,
const QString &referencingLayerName,
const QString &referencingLayerSource,
const QString &referencingLayerProviderKey,
24 const QString &referencedLayerId,
const QString &referencedLayerName,
const QString &referencedLayerSource,
const QString &referencedLayerProviderKey,
25 const QList<QgsRelation::FieldPair> &fieldPairs )
26 : mReferencingLayer( referencingLayerId, referencingLayerName, referencingLayerSource, referencingLayerProviderKey )
27 , mReferencedLayer( referencedLayerId, referencedLayerName, referencedLayerSource, referencedLayerProviderKey )
28 , mRelationId( relationId )
29 , mRelationName( relationName )
30 , mStrength( strength )
31 , mFieldPairs( fieldPairs )
38 relation.
setId( mRelationId );
39 relation.
setName( mRelationName );
53 for (
const auto &fp : std::as_const( mFieldPairs ) )
62 return mReferencingLayer;
67 return mReferencedLayer;
82 QDomElement relationElement = node.toElement();
84 if ( relationElement.tagName() != QLatin1String(
"relation" ) )
86 QgsLogger::warning( QApplication::translate(
"QgsRelation",
"Cannot create relation. Unexpected tag '%1'" ).arg( relationElement.tagName() ) );
90 const QDomNodeList fieldPairNodes { relationElement.elementsByTagName( QStringLiteral(
"fieldRef" ) ) };
91 for (
int j = 0; j < fieldPairNodes.length(); ++j )
93 const QDomElement fieldPairElement = fieldPairNodes.at( j ).toElement();
94 fieldPairs.push_back( { fieldPairElement.attribute( QStringLiteral(
"referencingField" ) ),
95 fieldPairElement.attribute( QStringLiteral(
"referencedField" ) )
102 return QgsWeakRelation { relationElement.attribute( QStringLiteral(
"id" ) ),
103 relationElement.attribute( QStringLiteral(
"name" ) ),
111 relationElement.attribute( QStringLiteral(
"layerId" ) ),
112 relationElement.attribute( QStringLiteral(
"layerName" ) ),
113 relationElement.attribute( QStringLiteral(
"dataSource" ) ),
114 relationElement.attribute( QStringLiteral(
"providerKey" ) ),
118 return QgsWeakRelation { relationElement.attribute( QStringLiteral(
"id" ) ),
119 relationElement.attribute( QStringLiteral(
"name" ) ),
122 relationElement.attribute( QStringLiteral(
"layerId" ) ),
123 relationElement.attribute( QStringLiteral(
"layerName" ) ),
124 relationElement.attribute( QStringLiteral(
"dataSource" ) ),
125 relationElement.attribute( QStringLiteral(
"providerKey" ) ),
135 return QgsWeakRelation( QString(), QString(), QgsRelation::RelationStrength::Association, QString(), QString(), QString(),
136 QString(), QString(), QString(), QString(), QString(), QList< QgsRelation::FieldPair >() );
150 QDomNodeList relationsNodeList = node.toElement().elementsByTagName( QStringLiteral(
"relation" ) );
151 QDomElement relationElement;
153 for (
int i = 0; i < relationsNodeList.size(); ++i )
155 relationElement = relationsNodeList.at( i ).toElement();
156 if ( relationElement.hasAttribute( QStringLiteral(
"id" ) ) && relationElement.attribute( QStringLiteral(
"id" ) ) == relation.
id() )
162 relationElement.setAttribute( QStringLiteral(
"layerId" ), relation.
referencedLayer()->
id() );
163 relationElement.setAttribute( QStringLiteral(
"layerName" ), relation.
referencedLayer()->
name() );
170 relationElement.setAttribute( QStringLiteral(
"layerId" ), relation.
referencingLayer()->
id() );
171 relationElement.setAttribute( QStringLiteral(
"layerName" ), relation.
referencingLayer()->
name() );