Skip to content
Permalink
Browse files

[processing] config dialog: only save menu configuration if needed

Conflicts:
	python/plugins/processing/gui/ConfigDialog.py
  • Loading branch information
volaya committed Dec 12, 2016
1 parent f852603 commit 4c31bc407ec9071892d95935cb9befaf4755aa41
Showing with 31 additions and 22 deletions.
  1. +31 −22 python/plugins/processing/gui/ConfigDialog.py
@@ -31,8 +31,7 @@

from qgis.PyQt import uic
from qgis.PyQt.QtCore import (Qt,
QEvent
)
QEvent)
from qgis.PyQt.QtWidgets import (QFileDialog,
QDialog,
QStyle,
@@ -46,7 +45,9 @@
QPushButton)
from qgis.PyQt.QtGui import (QIcon,
QStandardItemModel,
QStandardItem)
QStandardItem,
QApplication,
QCursor)

from qgis.gui import (QgsDoubleSpinBox,
QgsSpinBox
@@ -58,8 +59,7 @@
Setting)
from processing.core.Processing import Processing
from processing.gui.DirectorySelectorDialog import DirectorySelectorDialog
from processing.gui.menus import defaultMenuEntries, updateMenus
from processing.gui.menus import menusSettingsGroup
from processing.gui.menus import defaultMenuEntries, updateMenus, menusSettingsGroup


pluginPath = os.path.split(os.path.dirname(__file__))[0]
@@ -93,7 +93,8 @@ def __init__(self, toolbox):

self.fillTree()

self.tree.expanded.connect(self.adjustColumns)
self.saveMenus = False
self.tree.expanded.connect(self.itemExpanded)

def textChanged(self):
text = str(self.searchBox.text().lower())
@@ -192,14 +193,14 @@ def fillTreeUsingProviders(self):
"""
Filter 'Menus' items
"""
menusItem = QStandardItem(self.tr('Menus'))
self.menusItem = QStandardItem(self.tr('Menus'))
icon = QIcon(os.path.join(pluginPath, 'images', 'menu.png'))
menusItem.setIcon(icon)
menusItem.setEditable(False)
self.menusItem.setIcon(icon)
self.menusItem.setEditable(False)
emptyItem = QStandardItem()
emptyItem.setEditable(False)

rootItem.insertRow(0, [menusItem, emptyItem])
rootItem.insertRow(0, [self.menusItem, emptyItem])

button = QPushButton(self.tr('Reset to defaults'))
button.clicked.connect(self.resetMenusToDefaults)
@@ -248,7 +249,7 @@ def fillTreeUsingProviders(self):
emptyItem = QStandardItem()
emptyItem.setEditable(False)

menusItem.appendRow([groupItem, emptyItem])
self.menusItem.appendRow([groupItem, emptyItem])

self.tree.sortByColumn(0, Qt.AscendingOrder)
self.adjustColumns()
@@ -261,24 +262,32 @@ def resetMenusToDefaults(self):
setting = ProcessingConfig.settings["MENU_" + alg.commandLineName()]
item = self.items[setting]
item.setData(d, Qt.EditRole)
self.saveMenus = True

def accept(self):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
for setting in list(self.items.keys()):
if isinstance(setting.value, bool):
setting.setValue(self.items[setting].checkState() == Qt.Checked)
else:
try:
setting.setValue(str(self.items[setting].text()))
except ValueError as e:
QMessageBox.warning(self, self.tr('Wrong value'),
self.tr('Wrong value for parameter "%s":\n\n%s' % (setting.description, str(e))))
return
setting.save()
if setting.group != menusSettingsGroup or self.saveMenus:
if isinstance(setting.value, bool):
setting.setValue(self.items[setting].checkState() == Qt.Checked)
else:
try:
setting.setValue(str(self.items[setting].text()))
except ValueError as e:
QMessageBox.warning(self, self.tr('Wrong value'),
self.tr('Wrong value for parameter "%s":\n\n%s' % (setting.description, str(e))))
return
setting.save()
Processing.updateAlgsList()
settingsWatcher.settingsChanged.emit()

QApplication.restoreOverrideCursor()
QDialog.accept(self)

def itemExpanded(self, idx):
if idx == self.menusItem.index():
self.saveMenus = True
self.adjustColumns()

def adjustColumns(self):
self.tree.resizeColumnToContents(0)
self.tree.resizeColumnToContents(1)

0 comments on commit 4c31bc4

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