Skip to content
Snippets Groups Projects
Commit f377a8af authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Add method to remove a key

parent 96f3ba89
No related branches found
No related tags found
No related merge requests found
...@@ -68,6 +68,12 @@ class ConfigUserTest(TestCase): ...@@ -68,6 +68,12 @@ class ConfigUserTest(TestCase):
self.assertFalse(self.cfg.has('main', 'missing-key')) self.assertFalse(self.cfg.has('main', 'missing-key'))
self.assertFalse(self.cfg.has('main/missing-key')) self.assertFalse(self.cfg.has('main/missing-key'))
def test_remove_key(self):
self.cfg.set('main', 'key1', 1)
self.assertTrue(self.cfg.has('main/key1'))
self.cfg.remove('main/key1')
self.assertFalse(self.cfg.has('main/key1'))
# ---------------------------------------------- # ----------------------------------------------
# Failure tests # Failure tests
# ---------------------------------------------- # ----------------------------------------------
......
...@@ -114,6 +114,13 @@ class UserConfig(object): ...@@ -114,6 +114,13 @@ class UserConfig(object):
value = extra value = extra
self.qsettings.setValue(option, value) self.qsettings.setValue(option, value)
def remove(self, option, second=None):
"""Removes a key from the settings. Key not existing returns without effect.
"""
option = self._check_section_option_is_valid(option, second)
if self.has(option):
self.qsettings.remove(option)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# "Private" methods # "Private" methods
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment