Skip to content
Permalink
Browse files

Stabilize XML for layer settings and map themes

  • Loading branch information
m-kuhn committed Apr 9, 2019
1 parent fa850a1 commit 4fc6176f5f32ee32b97fdd0ae8581fb2a8d82db2
Showing with 19 additions and 10 deletions.
  1. +7 −4 src/core/qgsmapthemecollection.cpp
  2. +12 −6 src/core/qgsobjectcustomproperties.cpp
@@ -527,11 +527,14 @@ void QgsMapThemeCollection::readXml( const QDomDocument &doc )
void QgsMapThemeCollection::writeXml( QDomDocument &doc )
{
QDomElement visPresetsElem = doc.createElement( QStringLiteral( "visibility-presets" ) );
MapThemeRecordMap::const_iterator it = mMapThemes.constBegin();
for ( ; it != mMapThemes.constEnd(); ++ it )

const auto keys = mMapThemes.keys();

std::sort( keys.begin(), keys.end() );

for ( const QString &grpName : qgis::as_const( keys ) )
{
QString grpName = it.key();
const MapThemeRecord &rec = it.value();
const MapThemeRecord &rec = mMapThemes.value( grpName );
QDomElement visPresetElem = doc.createElement( QStringLiteral( "visibility-preset" ) );
visPresetElem.setAttribute( QStringLiteral( "name" ), grpName );
if ( rec.hasExpandedStateInfo() )
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsobjectcustomproperties.h"
#include "qgis.h"

#include <QDomNode>
#include <QStringList>
@@ -118,17 +119,22 @@ void QgsObjectCustomProperties::writeXml( QDomNode &parentNode, QDomDocument &do

QDomElement propsElement = doc.createElement( QStringLiteral( "customproperties" ) );

for ( QMap<QString, QVariant>::const_iterator it = mMap.constBegin(); it != mMap.constEnd(); ++it )
auto keys = mMap.keys();

std::sort( keys.begin(), keys.end() );

for ( const auto &key : qgis::as_const( keys ) )
{
QDomElement propElement = doc.createElement( QStringLiteral( "property" ) );
propElement.setAttribute( QStringLiteral( "key" ), it.key() );
if ( it.value().canConvert<QString>() )
propElement.setAttribute( QStringLiteral( "key" ), key );
const QVariant value = mMap.value( key );
if ( value.canConvert<QString>() )
{
propElement.setAttribute( QStringLiteral( "value" ), it.value().toString() );
propElement.setAttribute( QStringLiteral( "value" ), value.toString() );
}
else if ( it.value().canConvert<QStringList>() )
else if ( value.canConvert<QStringList>() )
{
const auto constToStringList = it.value().toStringList();
const auto constToStringList = value.toStringList();
for ( const QString &value : constToStringList )
{
QDomElement itemElement = doc.createElement( QStringLiteral( "value" ) );

0 comments on commit 4fc6176

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