Skip to content
Permalink
Browse files

enforce lower-case qgssettings keys (#4218)

* enforce lower-case qgssettings keys

* add QgsSettings::remove() unit test
  • Loading branch information
nirvn authored and NathanW2 committed Mar 4, 2017
1 parent 651b5c6 commit f11eb3dca8a918654f1165d93cea6ae56a87d03f
Showing with 17 additions and 12 deletions.
  1. +10 −10 src/core/qgssettings.cpp
  2. +7 −2 tests/src/python/test_qgssettings.py
@@ -84,10 +84,10 @@ QgsSettings::~QgsSettings()

void QgsSettings::beginGroup( const QString &prefix )
{
mUserSettings->beginGroup( prefix );
mUserSettings->beginGroup( prefix.toLower() );
if ( mGlobalSettings )
{
mGlobalSettings->beginGroup( prefix );
mGlobalSettings->beginGroup( prefix.toLower() );
}
}

@@ -152,7 +152,7 @@ QStringList QgsSettings::childGroups() const

QVariant QgsSettings::value( const QString &key, const QVariant &defaultValue, const QgsSettings::Section section ) const
{
QString pKey = prefixedKey( key, section );
QString pKey = prefixedKey( key.toLower(), section );
if ( !mUserSettings->value( pKey ).isNull() )
{
return mUserSettings->value( pKey );
@@ -166,7 +166,7 @@ QVariant QgsSettings::value( const QString &key, const QVariant &defaultValue, c

bool QgsSettings::contains( const QString &key, const QgsSettings::Section section ) const
{
QString pKey = prefixedKey( key, section );
QString pKey = prefixedKey( key.toLower(), section );
return mUserSettings->contains( pKey ) ||
( mGlobalSettings && mGlobalSettings->contains( pKey ) );
}
@@ -183,7 +183,7 @@ void QgsSettings::sync()

void QgsSettings::remove( const QString &key )
{
mUserSettings->remove( key );
mUserSettings->remove( key.toLower() );
}

QString QgsSettings::prefixedKey( const QString &key, const Section section ) const
@@ -208,18 +208,18 @@ QString QgsSettings::prefixedKey( const QString &key, const Section section ) co
break;
case Section::NoSection:
default:
return sanitizeKey( key );
return sanitizeKey( key.toLower() );
}
return prefix + "/" + sanitizeKey( key );
return prefix + "/" + sanitizeKey( key.toLower() );
}


int QgsSettings::beginReadArray( const QString &prefix )
{
int size = mUserSettings->beginReadArray( prefix );
int size = mUserSettings->beginReadArray( prefix.toLower() );
if ( 0 == size && mGlobalSettings )
{
size = mGlobalSettings->beginReadArray( prefix );
size = mGlobalSettings->beginReadArray( prefix.toLower() );
mUsingGlobalArray = ( size > 0 );
}
return size;
@@ -250,7 +250,7 @@ void QgsSettings::setArrayIndex( int i )
void QgsSettings::setValue( const QString &key, const QVariant &value, const QgsSettings::Section section )
{
// TODO: add valueChanged signal
mUserSettings->setValue( prefixedKey( key, section ), value );
mUserSettings->setValue( prefixedKey( key.toLower(), section ), value );
}

// To lower case and clean the path
@@ -130,8 +130,7 @@ def test_groups(self):
self.settings.endGroup()
self.settings.beginGroup('testqgissettings/names')
self.settings.setValue('name4', 'qgisrocks-4')
keys = list(self.settings.childKeys())
keys.sort()
keys = sorted(self.settings.childKeys())
self.assertEqual(keys, ['name1', 'name2', 'name3', 'name4'])
self.settings.endGroup()
self.assertEqual('qgisrocks-1', self.settings.value('testqgissettings/names/name1'))
@@ -218,6 +217,12 @@ def test_contains(self):
self.settings.setValue('testqgissettings/name3', 'qgisrocks3')
self.assertTrue(self.settings.contains('testqgissettings/name3'))

def test_remove(self):
self.settings.setValue('testQgisSettings/temp', True)
self.assertEqual(self.settings.value('testqgissettings/temp'), True)
self.settings.remove('testQgisSettings/temp')
self.assertEqual(self.settings.value('testqgissettings/temp'), None)


if __name__ == '__main__':
unittest.main()

0 comments on commit f11eb3d

Please sign in to comment.
You can’t perform that action at this time.