From fa850a11ba88b9ead5662657b4a9d8d5f2fffe3b Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Mon, 8 Apr 2019 13:05:04 +0200 Subject: [PATCH 1/3] Save project properties in predictable order --- src/core/qgsprojectproperty.cpp | 15 ++++++++------- src/core/qgsprojectproperty.h | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/core/qgsprojectproperty.cpp b/src/core/qgsprojectproperty.cpp index c0cc9f84dfb5..68b4e7ddd23e 100644 --- a/src/core/qgsprojectproperty.cpp +++ b/src/core/qgsprojectproperty.cpp @@ -17,6 +17,8 @@ #include "qgsprojectproperty.h" #include "qgslogger.h" +#include "qgis.h" +#include "qgsmessagelog.h" #include #include @@ -407,14 +409,13 @@ bool QgsProjectPropertyKey::writeXml( QString const &nodeName, QDomElement &elem if ( ! mProperties.isEmpty() ) { - QHashIterator < QString, QgsProjectProperty * > i( mProperties ); - while ( i.hasNext() ) + auto keys = mProperties.keys(); + std::sort( keys.begin(), keys.end() ); + + for ( const auto &key : qgis::as_const( keys ) ) { - i.next(); - if ( !i.value()->writeXml( i.key(), keyElement, document ) ) - { - return false; - } + if ( !mProperties.value( key )->writeXml( key, keyElement, document ) ) + QgsMessageLog::logMessage( tr( "Failed to save project property %1" ).arg( key ) ); } } diff --git a/src/core/qgsprojectproperty.h b/src/core/qgsprojectproperty.h index 5b20d8f63e73..6a7fc2cdf9ee 100644 --- a/src/core/qgsprojectproperty.h +++ b/src/core/qgsprojectproperty.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "qgis_core.h" @@ -181,6 +182,8 @@ class CORE_EXPORT QgsProjectPropertyValue : public QgsProjectProperty */ class CORE_EXPORT QgsProjectPropertyKey : public QgsProjectProperty { + Q_DECLARE_TR_FUNCTIONS( QgsProjectPropertyKey ) + public: /** From 4fc6176f5f32ee32b97fdd0ae8581fb2a8d82db2 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Tue, 9 Apr 2019 16:02:14 +0200 Subject: [PATCH 2/3] Stabilize XML for layer settings and map themes --- src/core/qgsmapthemecollection.cpp | 11 +++++++---- src/core/qgsobjectcustomproperties.cpp | 18 ++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/core/qgsmapthemecollection.cpp b/src/core/qgsmapthemecollection.cpp index 5bb308d1e98c..0ef89852319d 100644 --- a/src/core/qgsmapthemecollection.cpp +++ b/src/core/qgsmapthemecollection.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() ) diff --git a/src/core/qgsobjectcustomproperties.cpp b/src/core/qgsobjectcustomproperties.cpp index 1f8a9890cf3f..c3ec4e221e44 100644 --- a/src/core/qgsobjectcustomproperties.cpp +++ b/src/core/qgsobjectcustomproperties.cpp @@ -16,6 +16,7 @@ ***************************************************************************/ #include "qgsobjectcustomproperties.h" +#include "qgis.h" #include #include @@ -118,17 +119,22 @@ void QgsObjectCustomProperties::writeXml( QDomNode &parentNode, QDomDocument &do QDomElement propsElement = doc.createElement( QStringLiteral( "customproperties" ) ); - for ( QMap::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() ) + propElement.setAttribute( QStringLiteral( "key" ), key ); + const QVariant value = mMap.value( key ); + if ( value.canConvert() ) { - propElement.setAttribute( QStringLiteral( "value" ), it.value().toString() ); + propElement.setAttribute( QStringLiteral( "value" ), value.toString() ); } - else if ( it.value().canConvert() ) + else if ( value.canConvert() ) { - const auto constToStringList = it.value().toStringList(); + const auto constToStringList = value.toStringList(); for ( const QString &value : constToStringList ) { QDomElement itemElement = doc.createElement( QStringLiteral( "value" ) ); From 54d58d9fa3ddcedd5de87747e47cfa424b02e803 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Tue, 9 Apr 2019 23:39:32 +0200 Subject: [PATCH 3/3] const list cannot be sorted --- src/core/qgsmapthemecollection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/qgsmapthemecollection.cpp b/src/core/qgsmapthemecollection.cpp index 0ef89852319d..a89fa291d42a 100644 --- a/src/core/qgsmapthemecollection.cpp +++ b/src/core/qgsmapthemecollection.cpp @@ -528,7 +528,7 @@ void QgsMapThemeCollection::writeXml( QDomDocument &doc ) { QDomElement visPresetsElem = doc.createElement( QStringLiteral( "visibility-presets" ) ); - const auto keys = mMapThemes.keys(); + auto keys = mMapThemes.keys(); std::sort( keys.begin(), keys.end() );