From 5d84490d701a49c32b39bb9fc07fe5a6c5512599 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 16 Sep 2016 11:18:20 +0200 Subject: [PATCH] SettingInheritance manager now has a complete list of all settings that have inheritance overridden CURA-2361 --- cura/Settings/SettingInheritanceManager.py | 76 ++++++++++++++++++++-- resources/qml/Cura.qml | 1 - resources/qml/Settings/SettingCategory.qml | 7 +- 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/cura/Settings/SettingInheritanceManager.py b/cura/Settings/SettingInheritanceManager.py index 0e22835107..a6ec1db909 100644 --- a/cura/Settings/SettingInheritanceManager.py +++ b/cura/Settings/SettingInheritanceManager.py @@ -1,5 +1,6 @@ -from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty +from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal import UM.Settings +from UM.Signal import signalemitter from UM.Application import Application import cura.Settings @@ -13,11 +14,14 @@ class SettingInheritanceManager(QObject): self._active_container_stack = None cura.Settings.ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderChanged) self._onActiveExtruderChanged() - pass + + self._settings_with_inheritance_warning = [] + + settingsWithIntheritanceChanged = pyqtSignal() @pyqtSlot() def test(self): - print("test!") + pass def _onActiveExtruderChanged(self): if self._active_container_stack: @@ -30,6 +34,7 @@ class SettingInheritanceManager(QObject): if new_active_stack != self._active_container_stack: # Check if changed self._active_container_stack = new_active_stack + self._update() # Ensure that the settings_with_inheritance_warning list is populated. self._active_container_stack.propertyChanged.connect(self._onPropertyChanged) def _onPropertyChanged(self, key, property_name): @@ -39,15 +44,59 @@ class SettingInheritanceManager(QObject): if not definitions: return - # Pseudo code; - # Check if the property change caused a inheritance warning to trigger. - pass # We need to do sum maaagic + has_overwritten_inheritance = self._settingIsOverwritingInheritance(key) + + settings_with_inheritance_warning_changed = False + + # Check if the setting needs to be in the list. + if key not in self._settings_with_inheritance_warning and has_overwritten_inheritance: + self._settings_with_inheritance_warning.append(key) + settings_with_inheritance_warning_changed = True + elif key in self._settings_with_inheritance_warning and not has_overwritten_inheritance: + self._settings_with_inheritance_warning.remove(key) + settings_with_inheritance_warning_changed = True + + # Find the topmost parent & add that to the list as well + parent = definitions[0].parent + while parent.parent is not None: + parent = parent.parent + + if parent.key not in self._settings_with_inheritance_warning and has_overwritten_inheritance: + self._settings_with_inheritance_warning.append(parent.key) + settings_with_inheritance_warning_changed = True + + elif parent.key in self._settings_with_inheritance_warning and not has_overwritten_inheritance: + if not self._recursiveCheck(parent): + self._settings_with_inheritance_warning.remove(parent.key) + settings_with_inheritance_warning_changed = True + + # Emit the signal if there was any change to the list. + if settings_with_inheritance_warning_changed: + self.settingsWithIntheritanceChanged.emit() + + def _recursiveCheck(self, definition): + for child in definition.children: + if child.key in self._settings_with_inheritance_warning: + return True + if child.children: + if self._recursiveCheck(child): + return True + return False + + + @pyqtProperty("QVariantList", notify = settingsWithIntheritanceChanged) + def settingsWithInheritanceWarning(self): + return self._settings_with_inheritance_warning # Check if a setting is being overwritten. def _settingIsOverwritingInheritance(self, key): has_setting_function = False stack = self._active_container_stack containers = [] + + has_user_state = self._active_container_stack.getProperty(key, "state") == UM.Settings.InstanceState.User + if not has_user_state: + return False while stack: containers.extend(stack.getContainers()) stack = stack.getNextStack() @@ -62,7 +111,20 @@ class SettingInheritanceManager(QObject): return has_setting_function and not isinstance(self._active_container_stack.getTop().getProperty(key, "value"), UM.Settings.SettingFunction) def _update(self): - pass + self._settings_with_inheritance_warning = [] + for setting_key in self._global_container_stack.getAllKeys(): + override = self._settingIsOverwritingInheritance(setting_key) + if override: + self._settings_with_inheritance_warning.append(setting_key) + definitions = self._global_container_stack.getBottom().findDefinitions(key=setting_key) + parent = definitions[0].parent + if parent is not None and override: + while parent.parent is not None: + parent = parent.parent + # Add the topmost container as well (if this wasn't already the case) + if parent.key not in self._settings_with_inheritance_warning: + self._settings_with_inheritance_warning.append(parent.key) + self.settingsWithIntheritanceChanged.emit() def _onGlobalContainerChanged(self): self._global_container_stack = Application.getInstance().getGlobalContainerStack() diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index 89f58d76f9..5ac22e453c 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -22,7 +22,6 @@ UM.MainWindow Component.onCompleted: { Printer.setMinimumWindowSize(UM.Theme.getSize("window_minimum_size")) - // Workaround silly issues with QML Action's shortcut property. // // Currently, there is no way to define shortcuts as "Application Shortcut". diff --git a/resources/qml/Settings/SettingCategory.qml b/resources/qml/Settings/SettingCategory.qml index 612d448794..27e4c3b455 100644 --- a/resources/qml/Settings/SettingCategory.qml +++ b/resources/qml/Settings/SettingCategory.qml @@ -28,7 +28,6 @@ Button { checked: definition.expanded onClicked: { forceActiveFocus(); definition.expanded ? settingDefinitionsModel.collapse(definition.key) : settingDefinitionsModel.expandAll(definition.key) } - Component.onCompleted: print(definition.label, propertyProvider.isValueUsed) UM.SimpleButton { id: settingsButton @@ -60,7 +59,11 @@ Button { anchors.right: parent.right anchors.rightMargin: UM.Theme.getSize("setting_preferences_button_margin").width - visible: true //false //hiddenValuesCount > 0 + visible: + { + return Cura.SettingInheritanceManager.settingsWithInheritanceWarning.indexOf(definition.key) >= 0; + } + height: parent.height / 2 width: height