Navigation Menu

Skip to content

Commit

Permalink
Stabilize XML for layer settings and map themes
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 9, 2019
1 parent fa850a1 commit 4fc6176
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/core/qgsmapthemecollection.cpp
Expand Up @@ -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() )
Expand Down
18 changes: 12 additions & 6 deletions src/core/qgsobjectcustomproperties.cpp
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

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

#include <QDomNode>
#include <QStringList>
Expand Down Expand Up @@ -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" ) );
Expand Down

0 comments on commit 4fc6176

Please sign in to comment.