Skip to content

Commit 4fc6176

Browse files
committedApr 9, 2019
Stabilize XML for layer settings and map themes
1 parent fa850a1 commit 4fc6176

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed
 

‎src/core/qgsmapthemecollection.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,14 @@ void QgsMapThemeCollection::readXml( const QDomDocument &doc )
527527
void QgsMapThemeCollection::writeXml( QDomDocument &doc )
528528
{
529529
QDomElement visPresetsElem = doc.createElement( QStringLiteral( "visibility-presets" ) );
530-
MapThemeRecordMap::const_iterator it = mMapThemes.constBegin();
531-
for ( ; it != mMapThemes.constEnd(); ++ it )
530+
531+
const auto keys = mMapThemes.keys();
532+
533+
std::sort( keys.begin(), keys.end() );
534+
535+
for ( const QString &grpName : qgis::as_const( keys ) )
532536
{
533-
QString grpName = it.key();
534-
const MapThemeRecord &rec = it.value();
537+
const MapThemeRecord &rec = mMapThemes.value( grpName );
535538
QDomElement visPresetElem = doc.createElement( QStringLiteral( "visibility-preset" ) );
536539
visPresetElem.setAttribute( QStringLiteral( "name" ), grpName );
537540
if ( rec.hasExpandedStateInfo() )

‎src/core/qgsobjectcustomproperties.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
***************************************************************************/
1717

1818
#include "qgsobjectcustomproperties.h"
19+
#include "qgis.h"
1920

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

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

121-
for ( QMap<QString, QVariant>::const_iterator it = mMap.constBegin(); it != mMap.constEnd(); ++it )
122+
auto keys = mMap.keys();
123+
124+
std::sort( keys.begin(), keys.end() );
125+
126+
for ( const auto &key : qgis::as_const( keys ) )
122127
{
123128
QDomElement propElement = doc.createElement( QStringLiteral( "property" ) );
124-
propElement.setAttribute( QStringLiteral( "key" ), it.key() );
125-
if ( it.value().canConvert<QString>() )
129+
propElement.setAttribute( QStringLiteral( "key" ), key );
130+
const QVariant value = mMap.value( key );
131+
if ( value.canConvert<QString>() )
126132
{
127-
propElement.setAttribute( QStringLiteral( "value" ), it.value().toString() );
133+
propElement.setAttribute( QStringLiteral( "value" ), value.toString() );
128134
}
129-
else if ( it.value().canConvert<QStringList>() )
135+
else if ( value.canConvert<QStringList>() )
130136
{
131-
const auto constToStringList = it.value().toStringList();
137+
const auto constToStringList = value.toStringList();
132138
for ( const QString &value : constToStringList )
133139
{
134140
QDomElement itemElement = doc.createElement( QStringLiteral( "value" ) );

0 commit comments

Comments
 (0)
Please sign in to comment.