Skip to content
Permalink
Browse files

Fix metadata address element doubles with each project write

elementsByTagName can be dangerous, because it returns children
recursively. In this case the contact "address" element contained
a child element for the street address, also named "address".

So when restoring a project with contact addresses in the metadata,
each address was created twice...

Fixes #17940
  • Loading branch information
nyalldawson committed Jan 24, 2018
1 parent 5812934 commit 36bf093b856128fd3e1c413cef7a4338a4171d24
Showing with 2 additions and 2 deletions.
  1. +2 −2 src/core/metadata/qgslayermetadata.cpp
@@ -440,7 +440,7 @@ bool QgsLayerMetadata::readMetadataXml( const QDomElement &metadataElement )
oneContact.role = mne.namedItem( QStringLiteral( "role" ) ).toElement().text();

QList< QgsLayerMetadata::Address > addresses;
QDomNodeList addressList = mne.elementsByTagName( QStringLiteral( "address" ) );
QDomNodeList addressList = mne.elementsByTagName( QStringLiteral( "contactAddress" ) );
for ( int j = 0; j < addressList.size(); j++ )
{
QDomElement addressElement = addressList.at( j ).toElement();
@@ -663,7 +663,7 @@ bool QgsLayerMetadata::writeMetadataXml( QDomElement &metadataElement, QDomDocum

for ( const QgsLayerMetadata::Address &oneAddress : contact.addresses )
{
QDomElement addressElement = document.createElement( QStringLiteral( "address" ) );
QDomElement addressElement = document.createElement( QStringLiteral( "contactAddress" ) );
QDomElement typeElement = document.createElement( QStringLiteral( "type" ) );
QDomElement addressDetailedElement = document.createElement( QStringLiteral( "address" ) );
QDomElement cityElement = document.createElement( QStringLiteral( "city" ) );

0 comments on commit 36bf093

Please sign in to comment.
You can’t perform that action at this time.