mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
[processing] store settings using QSettings instead of in a dedicated file
This commit is contained in:
parent
a3a36357ec
commit
dce4a771ff
@ -90,7 +90,7 @@ class Processing:
|
||||
try:
|
||||
provider.initializeSettings()
|
||||
Processing.providers.append(provider)
|
||||
ProcessingConfig.loadSettings()
|
||||
ProcessingConfig.readSettings()
|
||||
if updateList:
|
||||
Processing.updateAlgsList()
|
||||
except:
|
||||
@ -110,7 +110,7 @@ class Processing:
|
||||
try:
|
||||
provider.unload()
|
||||
Processing.providers.remove(provider)
|
||||
ProcessingConfig.loadSettings()
|
||||
ProcessingConfig.readSettings()
|
||||
Processing.updateAlgsList()
|
||||
except:
|
||||
# This try catch block is here to avoid problems if the
|
||||
@ -157,7 +157,7 @@ class Processing:
|
||||
AlgorithmDecorator.loadClassification()
|
||||
ProcessingLog.startLogging()
|
||||
ProcessingConfig.initialize()
|
||||
ProcessingConfig.loadSettings()
|
||||
ProcessingConfig.readSettings()
|
||||
RenderingStyles.loadStyles()
|
||||
Processing.loadFromProviders()
|
||||
|
||||
|
||||
@ -129,6 +129,7 @@ class ProcessingConfig:
|
||||
|
||||
@staticmethod
|
||||
def getSettings():
|
||||
'''Return settings as a dict with group names as keys and lists of settings as values'''
|
||||
settings = {}
|
||||
for setting in ProcessingConfig.settings.values():
|
||||
if not setting.group in settings:
|
||||
@ -139,34 +140,12 @@ class ProcessingConfig:
|
||||
group.append(setting)
|
||||
return settings
|
||||
|
||||
@staticmethod
|
||||
def configFile():
|
||||
return os.path.join(userFolder(), 'processing.conf')
|
||||
|
||||
@staticmethod
|
||||
def loadSettings():
|
||||
if not os.path.isfile(ProcessingConfig.configFile()):
|
||||
return
|
||||
lines = open(ProcessingConfig.configFile())
|
||||
line = lines.readline().strip('\n')
|
||||
while line != '':
|
||||
tokens = line.split('=')
|
||||
if tokens[0] in ProcessingConfig.settings.keys():
|
||||
setting = ProcessingConfig.settings[tokens[0]]
|
||||
if isinstance(setting.value, bool):
|
||||
setting.value = tokens[1].strip('\n\r ') == str(True)
|
||||
else:
|
||||
setting.value = tokens[1].strip('\n\r ')
|
||||
ProcessingConfig.addSetting(setting)
|
||||
line = lines.readline().strip('\n')
|
||||
lines.close()
|
||||
|
||||
@staticmethod
|
||||
def saveSettings():
|
||||
fout = open(ProcessingConfig.configFile(), 'w')
|
||||
def readSettings():
|
||||
for setting in ProcessingConfig.settings.values():
|
||||
fout.write(str(setting) + '\n')
|
||||
fout.close()
|
||||
setting.read()
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getSetting(name):
|
||||
@ -179,7 +158,7 @@ class ProcessingConfig:
|
||||
def setSettingValue(name, value):
|
||||
if name in ProcessingConfig.settings.keys():
|
||||
ProcessingConfig.settings[name].value = value
|
||||
ProcessingConfig.saveSettings()
|
||||
ProcessingConfig.settings[name].save()
|
||||
|
||||
|
||||
class Setting:
|
||||
@ -192,11 +171,23 @@ class Setting:
|
||||
def __init__(self, group, name, description, default, hidden=False, valuetype = None):
|
||||
self.group = group
|
||||
self.name = name
|
||||
self.qname = "Processing/Configuration/" + self.name
|
||||
self.description = description
|
||||
self.default = default
|
||||
self.value = default
|
||||
self.hidden = hidden
|
||||
self.valuetype = valuetype
|
||||
|
||||
def read(self):
|
||||
qsettings = QSettings()
|
||||
value = qsettings.value(self.qname, None)
|
||||
if value is not None:
|
||||
if isinstance(self.value, bool):
|
||||
value = str(value).lower() == str(True).lower()
|
||||
self.value = value
|
||||
|
||||
def save(self):
|
||||
QSettings().setValue(self.qname, self.value)
|
||||
|
||||
def __str__(self):
|
||||
return self.name + '=' + str(self.value)
|
||||
|
||||
@ -145,8 +145,9 @@ class ConfigDialog(QDialog, Ui_DlgConfig):
|
||||
return
|
||||
else:
|
||||
setting.value = unicode(self.items[setting].text())
|
||||
ProcessingConfig.addSetting(setting)
|
||||
ProcessingConfig.saveSettings()
|
||||
setting.save()
|
||||
#ProcessingConfig.addSetting(setting)
|
||||
#ProcessingConfig.saveSettings()
|
||||
self.toolbox.updateTree()
|
||||
|
||||
QDialog.accept(self)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user