mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Added SettingsInheritanceManager
CURA-2361
This commit is contained in:
parent
d0ad654108
commit
50f7c41ae4
4 changed files with 85 additions and 3 deletions
|
@ -122,6 +122,7 @@ class CuraApplication(QtApplication):
|
|||
|
||||
self._machine_action_manager = MachineActionManager.MachineActionManager()
|
||||
self._machine_manager = None # This is initialized on demand.
|
||||
self._setting_inheritance_manager = None
|
||||
|
||||
self._additional_components = {} # Components to add to certain areas in the interface
|
||||
|
||||
|
@ -426,7 +427,7 @@ class CuraApplication(QtApplication):
|
|||
# Initialise extruder so as to listen to global container stack changes before the first global container stack is set.
|
||||
cura.Settings.ExtruderManager.getInstance()
|
||||
qmlRegisterSingletonType(cura.Settings.MachineManager, "Cura", 1, 0, "MachineManager", self.getMachineManager)
|
||||
|
||||
qmlRegisterSingletonType(cura.Settings.SettingInheritanceManager, "Cura", 1, 0, "SettingInheritanceManager", self.getSettingInheritanceManager)
|
||||
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager)
|
||||
self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
|
||||
self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles))
|
||||
|
@ -449,6 +450,11 @@ class CuraApplication(QtApplication):
|
|||
self._machine_manager = cura.Settings.MachineManager.createMachineManager()
|
||||
return self._machine_manager
|
||||
|
||||
def getSettingInheritanceManager(self, *args):
|
||||
if self._setting_inheritance_manager is None:
|
||||
self._setting_inheritance_manager = cura.Settings.SettingInheritanceManager.createSettingInheritanceManager()
|
||||
return self._setting_inheritance_manager
|
||||
|
||||
## Get the machine action manager
|
||||
# We ignore any *args given to this, as we also register the machine manager as qml singleton.
|
||||
# It wants to give this function an engine and script engine, but we don't care about that.
|
||||
|
|
72
cura/Settings/SettingInheritanceManager.py
Normal file
72
cura/Settings/SettingInheritanceManager.py
Normal file
|
@ -0,0 +1,72 @@
|
|||
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty
|
||||
import UM.Settings
|
||||
from UM.Application import Application
|
||||
import cura.Settings
|
||||
|
||||
class SettingInheritanceManager(QObject):
|
||||
def __init__(self, parent = None):
|
||||
super().__init__(parent)
|
||||
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerChanged)
|
||||
self._global_container_stack = None
|
||||
self._onGlobalContainerChanged()
|
||||
|
||||
self._active_container_stack = None
|
||||
cura.Settings.ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderChanged)
|
||||
self._onActiveExtruderChanged()
|
||||
pass
|
||||
|
||||
@pyqtSlot()
|
||||
def test(self):
|
||||
print("test!")
|
||||
|
||||
def _onActiveExtruderChanged(self):
|
||||
if self._active_container_stack:
|
||||
self._active_container_stack.propertyChanged.disconnect(self._onPropertyChanged)
|
||||
|
||||
new_active_stack = cura.Settings.ExtruderManager.getInstance().getActiveExtruderStack()
|
||||
if not new_active_stack:
|
||||
new_active_stack = self._global_container_stack
|
||||
|
||||
if new_active_stack != self._active_container_stack:
|
||||
# Check if changed
|
||||
self._active_container_stack = new_active_stack
|
||||
self._active_container_stack.propertyChanged.connect(self._onPropertyChanged)
|
||||
|
||||
def _onPropertyChanged(self, key, property_name):
|
||||
if property_name == "value" and self._global_container_stack:
|
||||
|
||||
definitions = self._global_container_stack.getBottom().findDefinitions(key = key)
|
||||
if not definitions:
|
||||
return
|
||||
|
||||
# Pseudo code;
|
||||
# Check if the property change caused a inheritance warning to trigger.
|
||||
pass # We need to do sum maaagic
|
||||
|
||||
# Check if a setting is being overwritten.
|
||||
def _settingIsOverwritingInheritance(self, key):
|
||||
has_setting_function = False
|
||||
stack = self._active_container_stack
|
||||
containers = []
|
||||
while stack:
|
||||
containers.extend(stack.getContainers())
|
||||
stack = stack.getNextStack()
|
||||
|
||||
for container in containers:
|
||||
try:
|
||||
has_setting_function = isinstance(container.getProperty(key, "value"), UM.Settings.SettingFunction)
|
||||
except AttributeError:
|
||||
continue
|
||||
if has_setting_function:
|
||||
break
|
||||
return has_setting_function and not isinstance(self._active_container_stack.getTop().getProperty(key, "value"), UM.Settings.SettingFunction)
|
||||
|
||||
def _update(self):
|
||||
pass
|
||||
|
||||
def _onGlobalContainerChanged(self):
|
||||
self._global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
|
||||
@staticmethod
|
||||
def createSettingInheritanceManager(engine=None, script_engine=None):
|
||||
return SettingInheritanceManager()
|
|
@ -11,3 +11,4 @@ from .MachineManager import MachineManager
|
|||
from .MaterialSettingsVisibilityHandler import MaterialSettingsVisibilityHandler
|
||||
from .SettingOverrideDecorator import SettingOverrideDecorator
|
||||
from .QualitySettingsModel import QualitySettingsModel
|
||||
from .SettingInheritanceManager import SettingInheritanceManager
|
|
@ -17,15 +17,18 @@ Button {
|
|||
signal showTooltip(string text);
|
||||
signal hideTooltip();
|
||||
signal contextMenuRequested()
|
||||
signal showAllHiddenInheritedSettings()
|
||||
|
||||
text: definition.label
|
||||
iconSource: UM.Theme.getIcon(definition.icon)
|
||||
|
||||
|
||||
|
||||
checkable: true
|
||||
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
|
||||
|
@ -57,7 +60,7 @@ Button {
|
|||
anchors.right: parent.right
|
||||
anchors.rightMargin: UM.Theme.getSize("setting_preferences_button_margin").width
|
||||
|
||||
visible: false //hiddenValuesCount > 0
|
||||
visible: true //false //hiddenValuesCount > 0
|
||||
height: parent.height / 2
|
||||
width: height
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue