From 676099ccf6455576cfe444e9823817c678ed29d9 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Tue, 9 Jan 2024 10:29:45 +0100 Subject: [PATCH] Removed singleton UM.OperationStack, merged with CuraActions Removed ActiveTool singleton added to controller singleton CURA-7812 --- cura/CuraActions.py | 26 ++++++++++++++++++- .../PerObjectSettingsTool/PerObjectItem.qml | 2 +- .../PerObjectSettingsPanel.qml | 22 ++++++++-------- resources/qml/Actions.qml | 8 +++--- .../Custom/CustomPrintSetup.qml | 2 +- resources/qml/Settings/SettingTextField.qml | 2 +- resources/qml/Toolbar.qml | 4 +-- 7 files changed, 45 insertions(+), 21 deletions(-) diff --git a/cura/CuraActions.py b/cura/CuraActions.py index 9a61a1c4f0..36c69618dd 100644 --- a/cura/CuraActions.py +++ b/cura/CuraActions.py @@ -3,10 +3,11 @@ from typing import List, cast -from PyQt6.QtCore import QObject, QUrl, QMimeData +from PyQt6.QtCore import QObject, QUrl, pyqtSignal, pyqtProperty from PyQt6.QtGui import QDesktopServices from PyQt6.QtWidgets import QApplication +from UM.Application import Application from UM.Event import CallFunctionEvent from UM.FlameProfiler import pyqtSlot from UM.Math.Vector import Vector @@ -37,6 +38,10 @@ class CuraActions(QObject): def __init__(self, parent: QObject = None) -> None: super().__init__(parent) + self._operation_stack = Application.getInstance().getOperationStack() + self._operation_stack.changed.connect(self._onUndoStackChanged) + + undoStackChanged = pyqtSignal() @pyqtSlot() def openDocumentation(self) -> None: # Starting a web browser from a signal handler connected to a menu will crash on windows. @@ -45,6 +50,25 @@ class CuraActions(QObject): event = CallFunctionEvent(self._openUrl, [QUrl("https://ultimaker.com/en/resources/manuals/software?utm_source=cura&utm_medium=software&utm_campaign=dropdown-documentation")], {}) cura.CuraApplication.CuraApplication.getInstance().functionEvent(event) + @pyqtProperty(bool, notify=undoStackChanged) + def canUndo(self): + return self._operation_stack.canUndo() + + @pyqtProperty(bool, notify=undoStackChanged) + def canRedo(self): + return self._operation_stack.canRedo() + + @pyqtSlot() + def undo(self): + self._operation_stack.undo() + + @pyqtSlot() + def redo(self): + self._operation_stack.redo() + + def _onUndoStackChanged(self): + self.undoStackChanged.emit() + @pyqtSlot() def openBugReportPage(self) -> None: event = CallFunctionEvent(self._openUrl, [QUrl("https://github.com/Ultimaker/Cura/issues/new/choose")], {}) diff --git a/plugins/PerObjectSettingsTool/PerObjectItem.qml b/plugins/PerObjectSettingsTool/PerObjectItem.qml index b6cf13943b..cd406c80af 100644 --- a/plugins/PerObjectSettingsTool/PerObjectItem.qml +++ b/plugins/PerObjectSettingsTool/PerObjectItem.qml @@ -25,7 +25,7 @@ UM.TooltipArea onClicked: { addedSettingsModel.setVisible(model.key, checked); - UM.ActiveTool.forceUpdate(); + UM.Controller.forceUpdate(); } } diff --git a/plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml b/plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml index 0ddedee897..78d6643034 100644 --- a/plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml +++ b/plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml @@ -23,7 +23,7 @@ Item readonly property string infillMeshType: "infill_mesh" readonly property string antiOverhangMeshType: "anti_overhang_mesh" - property var currentMeshType: UM.ActiveTool.properties.getValue("MeshType") + property var currentMeshType: UM.Controller.properties.getValue("MeshType") // Update the view every time the currentMeshType changes onCurrentMeshTypeChanged: @@ -56,7 +56,7 @@ Item function setMeshType(type) { - UM.ActiveTool.setProperty("MeshType", type) + UM.Controller.setProperty("MeshType", type) updateMeshTypeCheckedState(type) } @@ -224,7 +224,7 @@ Item visibilityHandler: Cura.PerObjectSettingVisibilityHandler { id: visibility_handler - selectedObjectId: UM.ActiveTool.properties.getValue("SelectedObjectId") + selectedObjectId: UM.Controller.properties.getValue("SelectedObjectId") } // For some reason the model object is updated after removing him from the memory and @@ -320,7 +320,7 @@ Item { id: provider - containerStackId: UM.ActiveTool.properties.getValue("ContainerID") + containerStackId: UM.Controller.properties.getValue("ContainerID") key: model.key watchedProperties: [ "value", "enabled", "validationState" ] storeIndex: 0 @@ -330,7 +330,7 @@ Item UM.SettingPropertyProvider { id: inheritStackProvider - containerStackId: UM.ActiveTool.properties.getValue("ContainerID") + containerStackId: UM.Controller.properties.getValue("ContainerID") key: model.key watchedProperties: [ "limit_to_extruder" ] } @@ -381,22 +381,22 @@ Item Connections { - target: UM.ActiveTool + target: UM.Controller function onPropertiesChanged() { - // the values cannot be bound with UM.ActiveTool.properties.getValue() calls, + // the values cannot be bound with UM.Controller.properties.getValue() calls, // so here we connect to the signal and update the those values. - if (typeof UM.ActiveTool.properties.getValue("SelectedObjectId") !== "undefined") + if (typeof UM.Controller.properties.getValue("SelectedObjectId") !== "undefined") { - const selectedObjectId = UM.ActiveTool.properties.getValue("SelectedObjectId") + const selectedObjectId = UM.Controller.properties.getValue("SelectedObjectId") if (addedSettingsModel.visibilityHandler.selectedObjectId != selectedObjectId) { addedSettingsModel.visibilityHandler.selectedObjectId = selectedObjectId } } - if (typeof UM.ActiveTool.properties.getValue("ContainerID") !== "undefined") + if (typeof UM.Controller.properties.getValue("ContainerID") !== "undefined") { - const containerId = UM.ActiveTool.properties.getValue("ContainerID") + const containerId = UM.Controller.properties.getValue("ContainerID") if (provider.containerStackId !== containerId) { provider.containerStackId = containerId diff --git a/resources/qml/Actions.qml b/resources/qml/Actions.qml index 458d7fcaae..7eac124a8f 100644 --- a/resources/qml/Actions.qml +++ b/resources/qml/Actions.qml @@ -120,8 +120,8 @@ Item text: catalog.i18nc("@action:inmenu menubar:edit", "&Undo") icon.name: "edit-undo" shortcut: StandardKey.Undo - onTriggered: UM.OperationStack.undo() - enabled: UM.OperationStack.canUndo + onTriggered: UM.CuraActions.undo() + enabled: UM.CuraActions.canUndo } Action @@ -130,8 +130,8 @@ Item text: catalog.i18nc("@action:inmenu menubar:edit", "&Redo") icon.name: "edit-redo" shortcut: StandardKey.Redo - onTriggered: UM.OperationStack.redo() - enabled: UM.OperationStack.canRedo + onTriggered: UM.CuraActions.redo() + enabled: UM.CuraActions.canRedo } Action diff --git a/resources/qml/PrintSetupSelector/Custom/CustomPrintSetup.qml b/resources/qml/PrintSetupSelector/Custom/CustomPrintSetup.qml index 41ab40eb31..4cc1e3034a 100644 --- a/resources/qml/PrintSetupSelector/Custom/CustomPrintSetup.qml +++ b/resources/qml/PrintSetupSelector/Custom/CustomPrintSetup.qml @@ -160,7 +160,7 @@ Item ProfileWarningReset { id: profileWarningReset - width: childrenRect.width + width: parent.width anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter fullWarning: false diff --git a/resources/qml/Settings/SettingTextField.qml b/resources/qml/Settings/SettingTextField.qml index d8e90e4951..f49b688c18 100644 --- a/resources/qml/Settings/SettingTextField.qml +++ b/resources/qml/Settings/SettingTextField.qml @@ -223,7 +223,7 @@ SettingItem cursorShape: Qt.IBeamCursor - onPressed: { + onPressed:(mouse)=> { if (!input.activeFocus) { base.focusGainedByClick = true diff --git a/resources/qml/Toolbar.qml b/resources/qml/Toolbar.qml index fd48ef7448..1af4e958f4 100644 --- a/resources/qml/Toolbar.qml +++ b/resources/qml/Toolbar.qml @@ -203,7 +203,7 @@ Item x: UM.Theme.getSize("default_margin").width y: UM.Theme.getSize("default_margin").height - source: UM.ActiveTool.valid ? UM.ActiveTool.activeToolPanel : "" + source: UM.Controller.valid ? UM.Controller.activeToolPanel : "" enabled: UM.Controller.toolsEnabled } } @@ -222,7 +222,7 @@ Item UM.Label { id: toolHint - text: UM.ActiveTool.properties.getValue("ToolHint") != undefined ? UM.ActiveTool.properties.getValue("ToolHint") : "" + text: UM.Controller.properties.getValue("ToolHint") != undefined ? UM.ActiveTool.properties.getValue("ToolHint") : "" color: UM.Theme.getColor("tooltip_text") anchors.horizontalCenter: parent.horizontalCenter }