From 12bace54b120d3006baa4e9ca68ad6d7bd623a14 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 22 Feb 2016 12:55:03 +0100 Subject: [PATCH] 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. --- .../PerObjectSettingsPanel.qml | 1 + .../SettingOverrideModel.py | 35 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml b/plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml index 41f9bdd779..f64e3d4935 100644 --- a/plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml +++ b/plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml @@ -66,6 +66,7 @@ Item { description: model.description; unit: model.unit; valid: model.valid; + visible: !model.global_only options: model.options indent: false diff --git a/plugins/PerObjectSettingsTool/SettingOverrideModel.py b/plugins/PerObjectSettingsTool/SettingOverrideModel.py index 74696f0ee6..c5e4200a75 100644 --- a/plugins/PerObjectSettingsTool/SettingOverrideModel.py +++ b/plugins/PerObjectSettingsTool/SettingOverrideModel.py @@ -18,6 +18,7 @@ class SettingOverrideModel(ListModel): OptionsRole = Qt.UserRole + 8 WarningDescriptionRole = Qt.UserRole + 9 ErrorDescriptionRole = Qt.UserRole + 10 + GlobalOnlyRole = Qt.UserRole + 11 def __init__(self, node, parent = None): super().__init__(parent) @@ -28,6 +29,10 @@ class SettingOverrideModel(ListModel): self._node.decoratorsChanged.connect(self._onDecoratorsChanged) 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.LabelRole, "label") self.addRoleName(self.DescriptionRole, "description") @@ -38,6 +43,7 @@ class SettingOverrideModel(ListModel): self.addRoleName(self.OptionsRole, "options") self.addRoleName(self.WarningDescriptionRole, "warning_description") self.addRoleName(self.ErrorDescriptionRole, "error_description") + self.addRoleName(self.GlobalOnlyRole, "global_only") @pyqtSlot(str, "QVariant") def setSettingValue(self, key, value): @@ -68,6 +74,31 @@ class SettingOverrideModel(ListModel): model.appendItem({"value": str(value), "name": str(name)}) 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): self.clear() @@ -84,7 +115,8 @@ class SettingOverrideModel(ListModel): "valid": setting.validate(value), "options": self._createOptionsModel(setting.getOptions()), "warning_description": setting.getWarningDescription(), - "error_description": setting.getErrorDescription() + "error_description": setting.getErrorDescription(), + "global_only": setting.getGlobalOnly() }) items.sort(key = lambda i: i["key"]) @@ -98,3 +130,4 @@ class SettingOverrideModel(ListModel): if index != -1: self.setProperty(index, "value", str(value)) self.setProperty(index, "valid", setting.validate(value)) + self.setProperty(index, "global_only", setting.getGlobalOnly()) \ No newline at end of file