Skip to content

Commit a3ff4e6

Browse files
committed
Added a long comment to the setValue method
Also removed leftover unused (renamed) variable
1 parent c81526c commit a3ff4e6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/core/qgssettings.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,19 @@ void QgsSettings::setValue( const QString &key, const QVariant &value, const Qgs
282282
{
283283
// TODO: add valueChanged signal
284284
// Do not store if it hasn't changed from default value
285-
QVariant v = QgsSettings::value( prefixedKey( key, section ) );
285+
// Fist check if the values are different and if at least one of them is valid.
286+
// The valid check is required because different invalid QVariant flavours
287+
// like QVariant(QVariant::String) and QVariant(QVariant::Int ))
288+
// may be considered different and we don't want to store the value in that case.
286289
QVariant currentValue { QgsSettings::value( prefixedKey( key, section ) ) };
287290
if ( ( currentValue.isValid() || value.isValid() ) && ( currentValue != value ) )
288291
{
289292
mUserSettings->setValue( prefixedKey( key, section ), value );
290293
}
294+
// Deliberately an "else if" because we want to remove a value from the user settings
295+
// only if the value is different than the one stored in the global settings (because
296+
// it would be the default anyway). The first check is necessary because the global settings
297+
// might be a nullptr (for example in case of standalone scripts or apps).
291298
else if ( mGlobalSettings && mGlobalSettings->value( prefixedKey( key, section ) ) == currentValue )
292299
{
293300
mUserSettings->remove( prefixedKey( key, section ) );

0 commit comments

Comments
 (0)