mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
SettingInheritance manager now has a complete list of all settings that have inheritance overridden
CURA-2361
This commit is contained in:
parent
50f7c41ae4
commit
5d84490d70
3 changed files with 74 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty
|
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
|
||||||
import UM.Settings
|
import UM.Settings
|
||||||
|
from UM.Signal import signalemitter
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
import cura.Settings
|
import cura.Settings
|
||||||
|
|
||||||
|
@ -13,11 +14,14 @@ class SettingInheritanceManager(QObject):
|
||||||
self._active_container_stack = None
|
self._active_container_stack = None
|
||||||
cura.Settings.ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderChanged)
|
cura.Settings.ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderChanged)
|
||||||
self._onActiveExtruderChanged()
|
self._onActiveExtruderChanged()
|
||||||
pass
|
|
||||||
|
self._settings_with_inheritance_warning = []
|
||||||
|
|
||||||
|
settingsWithIntheritanceChanged = pyqtSignal()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def test(self):
|
def test(self):
|
||||||
print("test!")
|
pass
|
||||||
|
|
||||||
def _onActiveExtruderChanged(self):
|
def _onActiveExtruderChanged(self):
|
||||||
if self._active_container_stack:
|
if self._active_container_stack:
|
||||||
|
@ -30,6 +34,7 @@ class SettingInheritanceManager(QObject):
|
||||||
if new_active_stack != self._active_container_stack:
|
if new_active_stack != self._active_container_stack:
|
||||||
# Check if changed
|
# Check if changed
|
||||||
self._active_container_stack = new_active_stack
|
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)
|
self._active_container_stack.propertyChanged.connect(self._onPropertyChanged)
|
||||||
|
|
||||||
def _onPropertyChanged(self, key, property_name):
|
def _onPropertyChanged(self, key, property_name):
|
||||||
|
@ -39,15 +44,59 @@ class SettingInheritanceManager(QObject):
|
||||||
if not definitions:
|
if not definitions:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Pseudo code;
|
has_overwritten_inheritance = self._settingIsOverwritingInheritance(key)
|
||||||
# Check if the property change caused a inheritance warning to trigger.
|
|
||||||
pass # We need to do sum maaagic
|
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.
|
# Check if a setting is being overwritten.
|
||||||
def _settingIsOverwritingInheritance(self, key):
|
def _settingIsOverwritingInheritance(self, key):
|
||||||
has_setting_function = False
|
has_setting_function = False
|
||||||
stack = self._active_container_stack
|
stack = self._active_container_stack
|
||||||
containers = []
|
containers = []
|
||||||
|
|
||||||
|
has_user_state = self._active_container_stack.getProperty(key, "state") == UM.Settings.InstanceState.User
|
||||||
|
if not has_user_state:
|
||||||
|
return False
|
||||||
while stack:
|
while stack:
|
||||||
containers.extend(stack.getContainers())
|
containers.extend(stack.getContainers())
|
||||||
stack = stack.getNextStack()
|
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)
|
return has_setting_function and not isinstance(self._active_container_stack.getTop().getProperty(key, "value"), UM.Settings.SettingFunction)
|
||||||
|
|
||||||
def _update(self):
|
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):
|
def _onGlobalContainerChanged(self):
|
||||||
self._global_container_stack = Application.getInstance().getGlobalContainerStack()
|
self._global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
|
|
|
@ -22,7 +22,6 @@ UM.MainWindow
|
||||||
Component.onCompleted:
|
Component.onCompleted:
|
||||||
{
|
{
|
||||||
Printer.setMinimumWindowSize(UM.Theme.getSize("window_minimum_size"))
|
Printer.setMinimumWindowSize(UM.Theme.getSize("window_minimum_size"))
|
||||||
|
|
||||||
// Workaround silly issues with QML Action's shortcut property.
|
// Workaround silly issues with QML Action's shortcut property.
|
||||||
//
|
//
|
||||||
// Currently, there is no way to define shortcuts as "Application Shortcut".
|
// Currently, there is no way to define shortcuts as "Application Shortcut".
|
||||||
|
|
|
@ -28,7 +28,6 @@ Button {
|
||||||
checked: definition.expanded
|
checked: definition.expanded
|
||||||
|
|
||||||
onClicked: { forceActiveFocus(); definition.expanded ? settingDefinitionsModel.collapse(definition.key) : settingDefinitionsModel.expandAll(definition.key) }
|
onClicked: { forceActiveFocus(); definition.expanded ? settingDefinitionsModel.collapse(definition.key) : settingDefinitionsModel.expandAll(definition.key) }
|
||||||
Component.onCompleted: print(definition.label, propertyProvider.isValueUsed)
|
|
||||||
UM.SimpleButton
|
UM.SimpleButton
|
||||||
{
|
{
|
||||||
id: settingsButton
|
id: settingsButton
|
||||||
|
@ -60,7 +59,11 @@ Button {
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.rightMargin: UM.Theme.getSize("setting_preferences_button_margin").width
|
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
|
height: parent.height / 2
|
||||||
width: height
|
width: height
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue