Update per-object settings list when a setting changes

The event triggers a refresh of the global_only property. I think it shouldn't affect the computation time too much but it feels sluggish when you change a setting. Does it feel sluggish for you too, reviewer? It has been feeling sluggish for a while so I don't know if that's due to this change.

Contributes to issue CURA-458.
This commit is contained in:
Ghostkeeper 2016-02-22 12:55:03 +01:00
parent 2d22b79d7a
commit 12bace54b1
2 changed files with 35 additions and 1 deletions

View file

@ -66,6 +66,7 @@ Item {
description: model.description; description: model.description;
unit: model.unit; unit: model.unit;
valid: model.valid; valid: model.valid;
visible: !model.global_only
options: model.options options: model.options
indent: false indent: false

View file

@ -18,6 +18,7 @@ class SettingOverrideModel(ListModel):
OptionsRole = Qt.UserRole + 8 OptionsRole = Qt.UserRole + 8
WarningDescriptionRole = Qt.UserRole + 9 WarningDescriptionRole = Qt.UserRole + 9
ErrorDescriptionRole = Qt.UserRole + 10 ErrorDescriptionRole = Qt.UserRole + 10
GlobalOnlyRole = Qt.UserRole + 11
def __init__(self, node, parent = None): def __init__(self, node, parent = None):
super().__init__(parent) super().__init__(parent)
@ -28,6 +29,10 @@ class SettingOverrideModel(ListModel):
self._node.decoratorsChanged.connect(self._onDecoratorsChanged) self._node.decoratorsChanged.connect(self._onDecoratorsChanged)
self._onDecoratorsChanged(None) self._onDecoratorsChanged(None)
self._activeProfile = Application.getInstance().getMachineManager().getWorkingProfile() #To be able to get notified when a setting changes.
self._activeProfile.settingValueChanged.connect(self._onProfileSettingValueChanged)
Application.getInstance().getMachineManager().activeProfileChanged.connect(self._onProfileChanged)
self.addRoleName(self.KeyRole, "key") self.addRoleName(self.KeyRole, "key")
self.addRoleName(self.LabelRole, "label") self.addRoleName(self.LabelRole, "label")
self.addRoleName(self.DescriptionRole, "description") self.addRoleName(self.DescriptionRole, "description")
@ -38,6 +43,7 @@ class SettingOverrideModel(ListModel):
self.addRoleName(self.OptionsRole, "options") self.addRoleName(self.OptionsRole, "options")
self.addRoleName(self.WarningDescriptionRole, "warning_description") self.addRoleName(self.WarningDescriptionRole, "warning_description")
self.addRoleName(self.ErrorDescriptionRole, "error_description") self.addRoleName(self.ErrorDescriptionRole, "error_description")
self.addRoleName(self.GlobalOnlyRole, "global_only")
@pyqtSlot(str, "QVariant") @pyqtSlot(str, "QVariant")
def setSettingValue(self, key, value): def setSettingValue(self, key, value):
@ -68,6 +74,31 @@ class SettingOverrideModel(ListModel):
model.appendItem({"value": str(value), "name": str(name)}) model.appendItem({"value": str(value), "name": str(name)})
return model return model
## Updates the active profile in this model if the active profile is
# changed.
#
# This links the settingValueChanged of the new profile to this model's
# _onSettingValueChanged function, so that it properly listens to those
# events again.
def _onProfileChanged(self):
if self._activeProfile: #Unlink from the old profile.
self._activeProfile.settingValueChanged.disconnect(self._onProfileSettingValueChanged)
self._activeProfile = Application.getInstance().getMachineManager().getWorkingProfile()
self._activeProfile.settingValueChanged.connect(self._onProfileSettingValueChanged) #Re-link to the new profile.
self._onProfileSettingValueChanged() #Also update the settings for the new profile!
## Updates the global_only property of a setting once a setting value
# changes.
#
# This method should only get called on settings that are dependent on the
# changed setting.
#
# \param setting_name The setting that needs to be updated.
def _onProfileSettingValueChanged(self, setting_name):
index = self.find("key", setting_name)
if index != -1:
self.setProperty(index, "global_only", Application.getInstance().getMachineManager().getActiveMachineInstance().getMachineDefinition().getSetting(setting_name).getGlobalOnly())
def _onSettingsChanged(self): def _onSettingsChanged(self):
self.clear() self.clear()
@ -84,7 +115,8 @@ class SettingOverrideModel(ListModel):
"valid": setting.validate(value), "valid": setting.validate(value),
"options": self._createOptionsModel(setting.getOptions()), "options": self._createOptionsModel(setting.getOptions()),
"warning_description": setting.getWarningDescription(), "warning_description": setting.getWarningDescription(),
"error_description": setting.getErrorDescription() "error_description": setting.getErrorDescription(),
"global_only": setting.getGlobalOnly()
}) })
items.sort(key = lambda i: i["key"]) items.sort(key = lambda i: i["key"])
@ -98,3 +130,4 @@ class SettingOverrideModel(ListModel):
if index != -1: if index != -1:
self.setProperty(index, "value", str(value)) self.setProperty(index, "value", str(value))
self.setProperty(index, "valid", setting.validate(value)) self.setProperty(index, "valid", setting.validate(value))
self.setProperty(index, "global_only", setting.getGlobalOnly())