Removed singleton UM.OperationStack, merged with CuraActions

Removed ActiveTool singleton added to controller singleton

CURA-7812
This commit is contained in:
saumya.jain 2024-01-09 10:29:45 +01:00
parent d01b5c1767
commit 676099ccf6
7 changed files with 45 additions and 21 deletions

View file

@ -3,10 +3,11 @@
from typing import List, cast 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.QtGui import QDesktopServices
from PyQt6.QtWidgets import QApplication from PyQt6.QtWidgets import QApplication
from UM.Application import Application
from UM.Event import CallFunctionEvent from UM.Event import CallFunctionEvent
from UM.FlameProfiler import pyqtSlot from UM.FlameProfiler import pyqtSlot
from UM.Math.Vector import Vector from UM.Math.Vector import Vector
@ -37,6 +38,10 @@ class CuraActions(QObject):
def __init__(self, parent: QObject = None) -> None: def __init__(self, parent: QObject = None) -> None:
super().__init__(parent) super().__init__(parent)
self._operation_stack = Application.getInstance().getOperationStack()
self._operation_stack.changed.connect(self._onUndoStackChanged)
undoStackChanged = pyqtSignal()
@pyqtSlot() @pyqtSlot()
def openDocumentation(self) -> None: def openDocumentation(self) -> None:
# Starting a web browser from a signal handler connected to a menu will crash on windows. # 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")], {}) 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) 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() @pyqtSlot()
def openBugReportPage(self) -> None: def openBugReportPage(self) -> None:
event = CallFunctionEvent(self._openUrl, [QUrl("https://github.com/Ultimaker/Cura/issues/new/choose")], {}) event = CallFunctionEvent(self._openUrl, [QUrl("https://github.com/Ultimaker/Cura/issues/new/choose")], {})

View file

@ -25,7 +25,7 @@ UM.TooltipArea
onClicked: onClicked:
{ {
addedSettingsModel.setVisible(model.key, checked); addedSettingsModel.setVisible(model.key, checked);
UM.ActiveTool.forceUpdate(); UM.Controller.forceUpdate();
} }
} }

View file

@ -23,7 +23,7 @@ Item
readonly property string infillMeshType: "infill_mesh" readonly property string infillMeshType: "infill_mesh"
readonly property string antiOverhangMeshType: "anti_overhang_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 // Update the view every time the currentMeshType changes
onCurrentMeshTypeChanged: onCurrentMeshTypeChanged:
@ -56,7 +56,7 @@ Item
function setMeshType(type) function setMeshType(type)
{ {
UM.ActiveTool.setProperty("MeshType", type) UM.Controller.setProperty("MeshType", type)
updateMeshTypeCheckedState(type) updateMeshTypeCheckedState(type)
} }
@ -224,7 +224,7 @@ Item
visibilityHandler: Cura.PerObjectSettingVisibilityHandler visibilityHandler: Cura.PerObjectSettingVisibilityHandler
{ {
id: visibility_handler 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 // For some reason the model object is updated after removing him from the memory and
@ -320,7 +320,7 @@ Item
{ {
id: provider id: provider
containerStackId: UM.ActiveTool.properties.getValue("ContainerID") containerStackId: UM.Controller.properties.getValue("ContainerID")
key: model.key key: model.key
watchedProperties: [ "value", "enabled", "validationState" ] watchedProperties: [ "value", "enabled", "validationState" ]
storeIndex: 0 storeIndex: 0
@ -330,7 +330,7 @@ Item
UM.SettingPropertyProvider UM.SettingPropertyProvider
{ {
id: inheritStackProvider id: inheritStackProvider
containerStackId: UM.ActiveTool.properties.getValue("ContainerID") containerStackId: UM.Controller.properties.getValue("ContainerID")
key: model.key key: model.key
watchedProperties: [ "limit_to_extruder" ] watchedProperties: [ "limit_to_extruder" ]
} }
@ -381,22 +381,22 @@ Item
Connections Connections
{ {
target: UM.ActiveTool target: UM.Controller
function onPropertiesChanged() 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. // 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) if (addedSettingsModel.visibilityHandler.selectedObjectId != selectedObjectId)
{ {
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) if (provider.containerStackId !== containerId)
{ {
provider.containerStackId = containerId provider.containerStackId = containerId

View file

@ -120,8 +120,8 @@ Item
text: catalog.i18nc("@action:inmenu menubar:edit", "&Undo") text: catalog.i18nc("@action:inmenu menubar:edit", "&Undo")
icon.name: "edit-undo" icon.name: "edit-undo"
shortcut: StandardKey.Undo shortcut: StandardKey.Undo
onTriggered: UM.OperationStack.undo() onTriggered: UM.CuraActions.undo()
enabled: UM.OperationStack.canUndo enabled: UM.CuraActions.canUndo
} }
Action Action
@ -130,8 +130,8 @@ Item
text: catalog.i18nc("@action:inmenu menubar:edit", "&Redo") text: catalog.i18nc("@action:inmenu menubar:edit", "&Redo")
icon.name: "edit-redo" icon.name: "edit-redo"
shortcut: StandardKey.Redo shortcut: StandardKey.Redo
onTriggered: UM.OperationStack.redo() onTriggered: UM.CuraActions.redo()
enabled: UM.OperationStack.canRedo enabled: UM.CuraActions.canRedo
} }
Action Action

View file

@ -160,7 +160,7 @@ Item
ProfileWarningReset ProfileWarningReset
{ {
id: profileWarningReset id: profileWarningReset
width: childrenRect.width width: parent.width
anchors.right: parent.right anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
fullWarning: false fullWarning: false

View file

@ -223,7 +223,7 @@ SettingItem
cursorShape: Qt.IBeamCursor cursorShape: Qt.IBeamCursor
onPressed: { onPressed:(mouse)=> {
if (!input.activeFocus) if (!input.activeFocus)
{ {
base.focusGainedByClick = true base.focusGainedByClick = true

View file

@ -203,7 +203,7 @@ Item
x: UM.Theme.getSize("default_margin").width x: UM.Theme.getSize("default_margin").width
y: UM.Theme.getSize("default_margin").height 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 enabled: UM.Controller.toolsEnabled
} }
} }
@ -222,7 +222,7 @@ Item
UM.Label UM.Label
{ {
id: toolHint 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") color: UM.Theme.getColor("tooltip_text")
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }