mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 15:07:28 -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.
|
||||
# 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 UM.FlameProfiler import pyqtSlot
|
||||
|
@ -168,27 +168,13 @@ class SettingInheritanceManager(QObject):
|
|||
def settingsWithInheritanceWarning(self) -> List[str]:
|
||||
return self._settings_with_inheritance_warning
|
||||
|
||||
def _settingIsOverwritingInheritance(self, key: str, stack: ContainerStack = None) -> bool:
|
||||
"""Check if a setting has an inheritance function that is overwritten"""
|
||||
def _userSettingIsOverwritingInheritance(self, key: str, stack: ContainerStack, all_keys: Set[str]) -> bool:
|
||||
"""Check if a setting known as having a User state has an inheritance function that is overwritten"""
|
||||
|
||||
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]
|
||||
|
||||
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 not stack.getProperty(key, "enabled"):
|
||||
return False
|
||||
|
@ -229,17 +215,38 @@ class SettingInheritanceManager(QObject):
|
|||
break # There is a setting function somewhere, stop looking deeper.
|
||||
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:
|
||||
self._settings_with_inheritance_warning = [] # Reset previous data.
|
||||
|
||||
# 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
|
||||
|
||||
# Check all setting keys that we know of and see if they are overridden.
|
||||
for setting_key in self._global_container_stack.getAllKeys():
|
||||
override = self._settingIsOverwritingInheritance(setting_key)
|
||||
if override:
|
||||
# Check all user setting keys that we know of and see if they are overridden.
|
||||
all_keys = self._active_container_stack.getAllKeys()
|
||||
for setting_key in self._active_container_stack.getAllKeysWithUserState():
|
||||
if self._userSettingIsOverwritingInheritance(setting_key, self._active_container_stack, all_keys):
|
||||
self._settings_with_inheritance_warning.append(setting_key)
|
||||
|
||||
# Check all the categories if any of their children have their inheritance overwritten.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue