Skip to content

Commit f11eb3d

Browse files
nirvnNathanW2
authored andcommittedMar 4, 2017
enforce lower-case qgssettings keys (#4218)
* enforce lower-case qgssettings keys * add QgsSettings::remove() unit test
1 parent 651b5c6 commit f11eb3d

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed
 

‎src/core/qgssettings.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ QgsSettings::~QgsSettings()
8484

8585
void QgsSettings::beginGroup( const QString &prefix )
8686
{
87-
mUserSettings->beginGroup( prefix );
87+
mUserSettings->beginGroup( prefix.toLower() );
8888
if ( mGlobalSettings )
8989
{
90-
mGlobalSettings->beginGroup( prefix );
90+
mGlobalSettings->beginGroup( prefix.toLower() );
9191
}
9292
}
9393

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

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

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

184184
void QgsSettings::remove( const QString &key )
185185
{
186-
mUserSettings->remove( key );
186+
mUserSettings->remove( key.toLower() );
187187
}
188188

189189
QString QgsSettings::prefixedKey( const QString &key, const Section section ) const
@@ -208,18 +208,18 @@ QString QgsSettings::prefixedKey( const QString &key, const Section section ) co
208208
break;
209209
case Section::NoSection:
210210
default:
211-
return sanitizeKey( key );
211+
return sanitizeKey( key.toLower() );
212212
}
213-
return prefix + "/" + sanitizeKey( key );
213+
return prefix + "/" + sanitizeKey( key.toLower() );
214214
}
215215

216216

217217
int QgsSettings::beginReadArray( const QString &prefix )
218218
{
219-
int size = mUserSettings->beginReadArray( prefix );
219+
int size = mUserSettings->beginReadArray( prefix.toLower() );
220220
if ( 0 == size && mGlobalSettings )
221221
{
222-
size = mGlobalSettings->beginReadArray( prefix );
222+
size = mGlobalSettings->beginReadArray( prefix.toLower() );
223223
mUsingGlobalArray = ( size > 0 );
224224
}
225225
return size;
@@ -250,7 +250,7 @@ void QgsSettings::setArrayIndex( int i )
250250
void QgsSettings::setValue( const QString &key, const QVariant &value, const QgsSettings::Section section )
251251
{
252252
// TODO: add valueChanged signal
253-
mUserSettings->setValue( prefixedKey( key, section ), value );
253+
mUserSettings->setValue( prefixedKey( key.toLower(), section ), value );
254254
}
255255

256256
// To lower case and clean the path

‎tests/src/python/test_qgssettings.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ def test_groups(self):
130130
self.settings.endGroup()
131131
self.settings.beginGroup('testqgissettings/names')
132132
self.settings.setValue('name4', 'qgisrocks-4')
133-
keys = list(self.settings.childKeys())
134-
keys.sort()
133+
keys = sorted(self.settings.childKeys())
135134
self.assertEqual(keys, ['name1', 'name2', 'name3', 'name4'])
136135
self.settings.endGroup()
137136
self.assertEqual('qgisrocks-1', self.settings.value('testqgissettings/names/name1'))
@@ -218,6 +217,12 @@ def test_contains(self):
218217
self.settings.setValue('testqgissettings/name3', 'qgisrocks3')
219218
self.assertTrue(self.settings.contains('testqgissettings/name3'))
220219

220+
def test_remove(self):
221+
self.settings.setValue('testQgisSettings/temp', True)
222+
self.assertEqual(self.settings.value('testqgissettings/temp'), True)
223+
self.settings.remove('testQgisSettings/temp')
224+
self.assertEqual(self.settings.value('testqgissettings/temp'), None)
225+
221226

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

0 commit comments

Comments
 (0)
Please sign in to comment.