From 0857017ac6730d26d8aac5a5f49f175f6e243c53 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Thu, 21 Jul 2016 11:21:35 +0200 Subject: [PATCH] Add a context-menu item to copy a value to all extruders. CURA-1758 --- cura/Settings/MachineManager.py | 13 ++++++++++ resources/qml/Settings/SettingView.qml | 36 +++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 9fe60f3ef1..50d390dabc 100644 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -505,6 +505,19 @@ class MachineManager(QObject): return True return containers[0].isReadOnly() + ## Copy the value of the setting of the current extruder to all other extruders as well as the global container. + @pyqtSlot(str) + def copyValueToExtruders(self, key): + if not self._active_container_stack or self._global_container_stack.getProperty("machine_extruder_count", "value") <= 1: + return + + new_value = self._active_container_stack.getProperty(key, "value") + stacks = [stack for stack in self._extruder_manager.getMachineExtruders(self._global_container_stack.getId())] + stacks.append(self._global_container_stack) + for extruder_stack in stacks: + if extruder_stack != self._active_container_stack and extruder_stack.getProperty(key, "value") != new_value: + extruder_stack.getTop().setProperty(key, "value", new_value) + @pyqtSlot(result = str) def newQualityContainerFromQualityAndUser(self): new_container_id = self.duplicateContainer(self.activeQualityId) diff --git a/resources/qml/Settings/SettingView.qml b/resources/qml/Settings/SettingView.qml index a2aa5be197..7551ec2345 100644 --- a/resources/qml/Settings/SettingView.qml +++ b/resources/qml/Settings/SettingView.qml @@ -102,7 +102,12 @@ ScrollView Connections { target: item - onContextMenuRequested: { contextMenu.key = model.key; contextMenu.popup() } + onContextMenuRequested: + { + contextMenu.key = model.key; + contextMenu.provider = provider + contextMenu.popup(); + } onShowTooltip: base.showTooltip(delegate, { x: 0, y: delegate.height / 2 }, text) onHideTooltip: base.hideTooltip() } @@ -134,9 +139,24 @@ ScrollView Menu { - id: contextMenu; + id: contextMenu - property string key; + property string key + property var provider + + MenuItem + { + //: Settings context menu action + text: catalog.i18nc("@action:menu", "Copy value to all extruders") + visible: machineExtruderCount.properties.value > 1 + enabled: contextMenu.provider.properties.settable_per_extruder != "False" + onTriggered: Cura.MachineManager.copyValueToExtruders(contextMenu.key) + } + + MenuSeparator + { + visible: machineExtruderCount.properties.value > 1 + } MenuItem { @@ -152,5 +172,15 @@ ScrollView onTriggered: Cura.Actions.configureSettingVisibility.trigger(contextMenu); } } + + UM.SettingPropertyProvider + { + id: machineExtruderCount + + containerStackId: Cura.MachineManager.activeMachineId + key: "machine_extruder_count" + watchedProperties: [ "value" ] + storeIndex: 0 + } } }