mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-10 16:27:51 -06:00
Optimized SettingInheritanceManager update
Instead of getting all the settings and checking for their state, run only once through all the containers and gather only the keys having a User state. CURA-11475
This commit is contained in:
parent
8308b640ca
commit
5a346e3ce6
1 changed files with 29 additions and 22 deletions
|
@ -1,6 +1,6 @@
|
||||||
# Copyright (c) 2017 Ultimaker B.V.
|
# Copyright (c) 2017 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
from typing import List, Optional, TYPE_CHECKING
|
from typing import List, Optional, Set, TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt6.QtCore import QObject, QTimer, pyqtProperty, pyqtSignal
|
from PyQt6.QtCore import QObject, QTimer, pyqtProperty, pyqtSignal
|
||||||
from UM.FlameProfiler import pyqtSlot
|
from UM.FlameProfiler import pyqtSlot
|
||||||
|
@ -168,27 +168,13 @@ class SettingInheritanceManager(QObject):
|
||||||
def settingsWithInheritanceWarning(self) -> List[str]:
|
def settingsWithInheritanceWarning(self) -> List[str]:
|
||||||
return self._settings_with_inheritance_warning
|
return self._settings_with_inheritance_warning
|
||||||
|
|
||||||
def _settingIsOverwritingInheritance(self, key: str, stack: ContainerStack = None) -> bool:
|
def _userSettingIsOverwritingInheritance(self, key: str, stack: ContainerStack, all_keys: Set[str]) -> bool:
|
||||||
"""Check if a setting has an inheritance function that is overwritten"""
|
"""Check if a setting known as having a User state has an inheritance function that is overwritten"""
|
||||||
|
|
||||||
has_setting_function = False
|
has_setting_function = False
|
||||||
if not stack:
|
|
||||||
stack = self._active_container_stack
|
|
||||||
if not stack: # No active container stack yet!
|
|
||||||
return False
|
|
||||||
|
|
||||||
if self._active_container_stack is None:
|
|
||||||
return False
|
|
||||||
all_keys = self._active_container_stack.getAllKeys()
|
|
||||||
|
|
||||||
containers = [] # type: List[ContainerInterface]
|
containers = [] # type: List[ContainerInterface]
|
||||||
|
|
||||||
has_user_state = stack.getProperty(key, "state") == InstanceState.User
|
|
||||||
"""Check if the setting has a user state. If not, it is never overwritten."""
|
|
||||||
|
|
||||||
if not has_user_state:
|
|
||||||
return False
|
|
||||||
|
|
||||||
# If a setting is not enabled, don't label it as overwritten (It's never visible anyway).
|
# If a setting is not enabled, don't label it as overwritten (It's never visible anyway).
|
||||||
if not stack.getProperty(key, "enabled"):
|
if not stack.getProperty(key, "enabled"):
|
||||||
return False
|
return False
|
||||||
|
@ -229,17 +215,38 @@ class SettingInheritanceManager(QObject):
|
||||||
break # There is a setting function somewhere, stop looking deeper.
|
break # There is a setting function somewhere, stop looking deeper.
|
||||||
return has_setting_function and has_non_function_value
|
return has_setting_function and has_non_function_value
|
||||||
|
|
||||||
|
def _settingIsOverwritingInheritance(self, key: str, stack: ContainerStack = None) -> bool:
|
||||||
|
"""Check if a setting has an inheritance function that is overwritten"""
|
||||||
|
|
||||||
|
if not stack:
|
||||||
|
stack = self._active_container_stack
|
||||||
|
if not stack: # No active container stack yet!
|
||||||
|
return False
|
||||||
|
|
||||||
|
if self._active_container_stack is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
has_user_state = stack.getProperty(key, "state") == InstanceState.User
|
||||||
|
"""Check if the setting has a user state. If not, it is never overwritten."""
|
||||||
|
|
||||||
|
if not has_user_state:
|
||||||
|
return False
|
||||||
|
|
||||||
|
all_keys = self._active_container_stack.getAllKeys()
|
||||||
|
|
||||||
|
return self._userSettingIsOverwritingInheritance(key, stack, all_keys)
|
||||||
|
|
||||||
def _update(self) -> None:
|
def _update(self) -> None:
|
||||||
self._settings_with_inheritance_warning = [] # Reset previous data.
|
self._settings_with_inheritance_warning = [] # Reset previous data.
|
||||||
|
|
||||||
# Make sure that the GlobalStack is not None. sometimes the globalContainerChanged signal gets here late.
|
# Make sure that the GlobalStack is not None. sometimes the globalContainerChanged signal gets here late.
|
||||||
if self._global_container_stack is None:
|
if self._global_container_stack is None or self._active_container_stack is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check all setting keys that we know of and see if they are overridden.
|
# Check all user setting keys that we know of and see if they are overridden.
|
||||||
for setting_key in self._global_container_stack.getAllKeys():
|
all_keys = self._active_container_stack.getAllKeys()
|
||||||
override = self._settingIsOverwritingInheritance(setting_key)
|
for setting_key in self._active_container_stack.getAllKeysWithUserState():
|
||||||
if override:
|
if self._userSettingIsOverwritingInheritance(setting_key, self._active_container_stack, all_keys):
|
||||||
self._settings_with_inheritance_warning.append(setting_key)
|
self._settings_with_inheritance_warning.append(setting_key)
|
||||||
|
|
||||||
# Check all the categories if any of their children have their inheritance overwritten.
|
# Check all the categories if any of their children have their inheritance overwritten.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue