@@ -197,11 +197,13 @@ QgsProjectProperty *findKey_( const QString &scope,
197
197
\param key key name
198
198
\param rootProperty is the property from which to start adding
199
199
\param value the value associated with the key
200
+ \param propertiesModified the parameter will be set to true if the written entry modifies pre-existing properties
200
201
*/
201
202
QgsProjectProperty *addKey_ ( const QString &scope,
202
203
const QString &key,
203
204
QgsProjectPropertyKey *rootProperty,
204
- const QVariant &value )
205
+ const QVariant &value,
206
+ bool &propertiesModified )
205
207
{
206
208
QStringList keySequence = makeKeyTokens_ ( scope, key );
207
209
@@ -210,6 +212,7 @@ QgsProjectProperty *addKey_( const QString &scope,
210
212
QgsProjectProperty *nextProperty; // link to next property down hierarchy
211
213
QgsProjectPropertyKey *newPropertyKey = nullptr ;
212
214
215
+ propertiesModified = false ;
213
216
while ( ! keySequence.isEmpty () )
214
217
{
215
218
// if the current head of the sequence list matches the property name,
@@ -223,14 +226,24 @@ QgsProjectProperty *addKey_( const QString &scope,
223
226
// name to store the value
224
227
if ( 1 == keySequence.count () )
225
228
{
226
- currentProperty->setValue ( keySequence.front (), value );
229
+ QgsProjectProperty *property = currentProperty->find ( keySequence.front () );
230
+ if ( !property || property->value () != value )
231
+ {
232
+ currentProperty->setValue ( keySequence.front (), value );
233
+ propertiesModified = true ;
234
+ }
235
+
227
236
return currentProperty;
228
237
}
229
238
// we're at the top element if popping the keySequence element
230
239
// will leave it empty; in that case, just add the key
231
240
else if ( keySequence.isEmpty () )
232
241
{
233
- currentProperty->setValue ( value );
242
+ if ( currentProperty->value () != value )
243
+ {
244
+ currentProperty->setValue ( value );
245
+ propertiesModified = true ;
246
+ }
234
247
235
248
return currentProperty;
236
249
}
@@ -263,7 +276,6 @@ QgsProjectProperty *addKey_( const QString &scope,
263
276
}
264
277
265
278
return nullptr ;
266
-
267
279
}
268
280
269
281
@@ -325,7 +337,6 @@ void removeKey_( const QString &scope,
325
337
return ;
326
338
}
327
339
}
328
-
329
340
}
330
341
331
342
QgsProject::QgsProject ( QObject *parent )
@@ -1899,37 +1910,57 @@ bool QgsProject::writeProjectFile( const QString &filename )
1899
1910
1900
1911
bool QgsProject::writeEntry ( const QString &scope, QString const &key, bool value )
1901
1912
{
1902
- setDirty ( true );
1913
+ bool propertiesModified;
1914
+ bool success = addKey_ ( scope, key, &mProperties , value, propertiesModified );
1915
+
1916
+ if ( propertiesModified )
1917
+ setDirty ( true );
1903
1918
1904
- return addKey_ ( scope, key, & mProperties , value ) ;
1919
+ return success ;
1905
1920
}
1906
1921
1907
1922
bool QgsProject::writeEntry ( const QString &scope, const QString &key, double value )
1908
1923
{
1909
- setDirty ( true );
1924
+ bool propertiesModified;
1925
+ bool success = addKey_ ( scope, key, &mProperties , value, propertiesModified );
1926
+
1927
+ if ( propertiesModified )
1928
+ setDirty ( true );
1910
1929
1911
- return addKey_ ( scope, key, & mProperties , value ) ;
1930
+ return success ;
1912
1931
}
1913
1932
1914
1933
bool QgsProject::writeEntry ( const QString &scope, QString const &key, int value )
1915
1934
{
1916
- setDirty ( true );
1935
+ bool propertiesModified;
1936
+ bool success = addKey_ ( scope, key, &mProperties , value, propertiesModified );
1937
+
1938
+ if ( propertiesModified )
1939
+ setDirty ( true );
1917
1940
1918
- return addKey_ ( scope, key, & mProperties , value ) ;
1941
+ return success ;
1919
1942
}
1920
1943
1921
1944
bool QgsProject::writeEntry ( const QString &scope, const QString &key, const QString &value )
1922
1945
{
1923
- setDirty ( true );
1946
+ bool propertiesModified;
1947
+ bool success = addKey_ ( scope, key, &mProperties , value, propertiesModified );
1948
+
1949
+ if ( propertiesModified )
1950
+ setDirty ( true );
1924
1951
1925
- return addKey_ ( scope, key, & mProperties , value ) ;
1952
+ return success ;
1926
1953
}
1927
1954
1928
1955
bool QgsProject::writeEntry ( const QString &scope, const QString &key, const QStringList &value )
1929
1956
{
1930
- setDirty ( true );
1957
+ bool propertiesModified;
1958
+ bool success = addKey_ ( scope, key, &mProperties , value, propertiesModified );
1959
+
1960
+ if ( propertiesModified )
1961
+ setDirty ( true );
1931
1962
1932
- return addKey_ ( scope, key, & mProperties , value ) ;
1963
+ return success ;
1933
1964
}
1934
1965
1935
1966
QStringList QgsProject::readListEntry ( const QString &scope,
0 commit comments