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/cura/CuraApplication.py b/cura/CuraApplication.py index 1ef2f63a9e..67c420028b 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -15,13 +15,13 @@ import numpy from PyQt6.QtCore import QObject, QTimer, QUrl, QUrlQuery, pyqtSignal, pyqtProperty, QEvent, pyqtEnum, QCoreApplication, \ QByteArray from PyQt6.QtGui import QColor, QIcon -from PyQt6.QtQml import qmlRegisterUncreatableType, qmlRegisterUncreatableMetaObject, qmlRegisterSingletonType, qmlRegisterType +from PyQt6.QtQml import qmlRegisterUncreatableMetaObject, qmlRegisterSingletonType, qmlRegisterType from PyQt6.QtWidgets import QMessageBox import UM.Util import cura.Settings.cura_empty_instance_containers from UM.Application import Application -from UM.Decorators import override +from UM.Decorators import override, deprecated from UM.FlameProfiler import pyqtSlot from UM.Logger import Logger from UM.Math.AxisAlignedBox import AxisAlignedBox @@ -191,7 +191,7 @@ class CuraApplication(QtApplication): self.empty_container = None # type: EmptyInstanceContainer self.empty_definition_changes_container = None # type: EmptyInstanceContainer self.empty_variant_container = None # type: EmptyInstanceContainer - self.empty_intent_container = None # type: EmptyInstanceContainer + self.empty_intent_container = None # type: EmptyInstanceContainer self.empty_material_container = None # type: EmptyInstanceContainer self.empty_quality_container = None # type: EmptyInstanceContainer self.empty_quality_changes_container = None # type: EmptyInstanceContainer @@ -1138,6 +1138,10 @@ class CuraApplication(QtApplication): return cast(MachineActionManager.MachineActionManager, self._machine_action_manager) + @pyqtSlot(result = QObject) + def getMachineActionManagerQml(self)-> MachineActionManager.MachineActionManager: + return cast(QObject, self._machine_action_manager) + @pyqtSlot(result = QObject) def getMaterialManagementModel(self) -> MaterialManagementModel: if not self._material_management_model: @@ -1150,7 +1154,8 @@ class CuraApplication(QtApplication): self._quality_management_model = QualityManagementModel(parent = self) return self._quality_management_model - def getSimpleModeSettingsManager(self, *args): + @pyqtSlot(result=QObject) + def getSimpleModeSettingsManager(self)-> SimpleModeSettingsManager: if self._simple_mode_settings_manager is None: self._simple_mode_settings_manager = SimpleModeSettingsManager() return self._simple_mode_settings_manager @@ -1193,16 +1198,43 @@ class CuraApplication(QtApplication): return self._print_information - def getQualityProfilesDropDownMenuModel(self, *args, **kwargs): + @pyqtSlot(result=QObject) + def getQualityProfilesDropDownMenuModel(self, *args, **kwargs)-> QualityProfilesDropDownMenuModel: if self._quality_profile_drop_down_menu_model is None: self._quality_profile_drop_down_menu_model = QualityProfilesDropDownMenuModel(self) return self._quality_profile_drop_down_menu_model - def getCustomQualityProfilesDropDownMenuModel(self, *args, **kwargs): + @pyqtSlot(result=QObject) + def getCustomQualityProfilesDropDownMenuModel(self, *args, **kwargs)->CustomQualityProfilesDropDownMenuModel: if self._custom_quality_profile_drop_down_menu_model is None: self._custom_quality_profile_drop_down_menu_model = CustomQualityProfilesDropDownMenuModel(self) return self._custom_quality_profile_drop_down_menu_model + @deprecated("SimpleModeSettingsManager is deprecated and will be removed in major SDK release, Use getSimpleModeSettingsManager() instead", since = "5.7.0") + def getSimpleModeSettingsManagerWrapper(self, *args, **kwargs): + return self.getSimpleModeSettingsManager() + + @deprecated("MachineActionManager is deprecated and will be removed in major SDK release, Use getMachineActionManager() instead", since="5.7.0") + def getMachineActionManagerWrapper(self, *args, **kwargs): + return self.getMachineActionManager() + + @deprecated("QualityManagementModel is deprecated and will be removed in major SDK release, Use getQualityManagementModel() instead", since="5.7.0") + def getQualityManagementModelWrapper(self, *args, **kwargs): + return self.getQualityManagementModel() + + @deprecated("MaterialManagementModel is deprecated and will be removed in major SDK release, Use getMaterialManagementModel() instead", since = "5.7.0") + def getMaterialManagementModelWrapper(self, *args, **kwargs): + return self.getMaterialManagementModel() + + @deprecated("QualityProfilesDropDownMenuModel is deprecated and will be removed in major SDK release, Use getQualityProfilesDropDownMenuModel() instead", since = "5.7.0") + def getQualityProfilesDropDownMenuModelWrapper(self, *args, **kwargs): + return self.getQualityProfilesDropDownMenuModel() + + @deprecated("CustomQualityProfilesDropDownMenuModel is deprecated and will be removed in major SDK release, Use getCustomQualityProfilesDropDownMenuModel() instead", since = "5.7.0") + def getCustomQualityProfilesDropDownMenuModelWrapper(self, *args, **kwargs): + return self.getCustomQualityProfilesDropDownMenuModel() + + def getCuraAPI(self, *args, **kwargs) -> "CuraAPI": return self._cura_API @@ -1231,8 +1263,8 @@ class CuraApplication(QtApplication): qmlRegisterSingletonType(MachineManager, "Cura", 1, 0, self.getMachineManager, "MachineManager") qmlRegisterSingletonType(IntentManager, "Cura", 1, 6, self.getIntentManager, "IntentManager") qmlRegisterSingletonType(SettingInheritanceManager, "Cura", 1, 0, self.getSettingInheritanceManager, "SettingInheritanceManager") - qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 0, self.getSimpleModeSettingsManager, "SimpleModeSettingsManager") - qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, self.getMachineActionManager, "MachineActionManager") + qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 0, self.getSimpleModeSettingsManagerWrapper, "SimpleModeSettingsManager") + qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, self.getMachineActionManagerWrapper, "MachineActionManager") self.processEvents() qmlRegisterType(NetworkingUtil, "Cura", 1, 5, "NetworkingUtil") @@ -1257,16 +1289,14 @@ class CuraApplication(QtApplication): qmlRegisterType(FavoriteMaterialsModel, "Cura", 1, 0, "FavoriteMaterialsModel") qmlRegisterType(GenericMaterialsModel, "Cura", 1, 0, "GenericMaterialsModel") qmlRegisterType(MaterialBrandsModel, "Cura", 1, 0, "MaterialBrandsModel") - qmlRegisterSingletonType(QualityManagementModel, "Cura", 1, 0, self.getQualityManagementModel, "QualityManagementModel") - qmlRegisterSingletonType(MaterialManagementModel, "Cura", 1, 5, self.getMaterialManagementModel, "MaterialManagementModel") + qmlRegisterSingletonType(QualityManagementModel, "Cura", 1, 0, self.getQualityManagementModelWrapper,"QualityManagementModel") + qmlRegisterSingletonType(MaterialManagementModel, "Cura", 1, 5, self.getMaterialManagementModelWrapper,"MaterialManagementModel") self.processEvents() qmlRegisterType(DiscoveredPrintersModel, "Cura", 1, 0, "DiscoveredPrintersModel") qmlRegisterType(DiscoveredCloudPrintersModel, "Cura", 1, 7, "DiscoveredCloudPrintersModel") - qmlRegisterSingletonType(QualityProfilesDropDownMenuModel, "Cura", 1, 0, - self.getQualityProfilesDropDownMenuModel, "QualityProfilesDropDownMenuModel") - qmlRegisterSingletonType(CustomQualityProfilesDropDownMenuModel, "Cura", 1, 0, - self.getCustomQualityProfilesDropDownMenuModel, "CustomQualityProfilesDropDownMenuModel") + qmlRegisterSingletonType(QualityProfilesDropDownMenuModel, "Cura", 1, 0, self.getQualityProfilesDropDownMenuModelWrapper, "QualityProfilesDropDownMenuModel") + qmlRegisterSingletonType(CustomQualityProfilesDropDownMenuModel, "Cura", 1, 0, self.getCustomQualityProfilesDropDownMenuModelWrapper, "CustomQualityProfilesDropDownMenuModel") qmlRegisterType(NozzleModel, "Cura", 1, 0, "NozzleModel") qmlRegisterType(IntentModel, "Cura", 1, 6, "IntentModel") qmlRegisterType(IntentCategoryModel, "Cura", 1, 6, "IntentCategoryModel") 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..3717e778d3 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: CuraActions.undo() + enabled: 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: CuraActions.redo() + enabled: CuraActions.canRedo } Action diff --git a/resources/qml/Dialogs/AboutDialog.qml b/resources/qml/Dialogs/AboutDialog.qml index 947b46269a..5c80964e38 100644 --- a/resources/qml/Dialogs/AboutDialog.qml +++ b/resources/qml/Dialogs/AboutDialog.qml @@ -58,7 +58,7 @@ UM.Dialog UM.Label { id: version - text: catalog.i18nc("@label","version: %1").arg(UM.Application.version) + text: catalog.i18nc("@label","version: %1").arg(CuraApplication.version()) font: UM.Theme.getFont("large_bold") color: UM.Theme.getColor("button_text") anchors.right : logo.right diff --git a/resources/qml/Preferences/MachinesPage.qml b/resources/qml/Preferences/MachinesPage.qml index fb98cb59c5..971de03696 100644 --- a/resources/qml/Preferences/MachinesPage.qml +++ b/resources/qml/Preferences/MachinesPage.qml @@ -12,6 +12,7 @@ import Cura 1.0 as Cura UM.ManagementPage { id: base + property var machineActionManager: CuraApplication.getMachineActionManagerQml() Item { enabled: false; UM.I18nCatalog { id: catalog; name: "cura"} } title: catalog.i18nc("@title:tab", "Printers") @@ -58,10 +59,11 @@ UM.ManagementPage anchors.fill: parent spacing: UM.Theme.getSize("default_margin").height + Repeater { id: machineActionRepeater - model: base.currentItem ? Cura.MachineActionManager.getSupportedActions(Cura.MachineManager.getDefinitionByMachineId(base.currentItem.id)) : null + model: base.currentItem ? machineActionManager.getSupportedActions(Cura.MachineManager.getDefinitionByMachineId(base.currentItem.id)) : null Item { 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/PrintSetupSelector/Custom/QualitiesWithIntentMenu.qml b/resources/qml/PrintSetupSelector/Custom/QualitiesWithIntentMenu.qml index 646e835cb2..9facc5095e 100644 --- a/resources/qml/PrintSetupSelector/Custom/QualitiesWithIntentMenu.qml +++ b/resources/qml/PrintSetupSelector/Custom/QualitiesWithIntentMenu.qml @@ -187,7 +187,7 @@ Popup //Add all the custom profiles. Repeater { - model: Cura.CustomQualityProfilesDropDownMenuModel + model: CuraApplication.getCustomQualityProfilesDropDownMenuModel() MenuButton { onClicked: Cura.MachineManager.setQualityChangesGroup(model.quality_changes_group) diff --git a/resources/qml/PrintSetupSelector/ProfileWarningReset.qml b/resources/qml/PrintSetupSelector/ProfileWarningReset.qml index c44fcc8cc2..bf4385446d 100644 --- a/resources/qml/PrintSetupSelector/ProfileWarningReset.qml +++ b/resources/qml/PrintSetupSelector/ProfileWarningReset.qml @@ -11,7 +11,7 @@ import "../Dialogs" Item { property bool fullWarning: true // <- Can you see the warning icon and the text, or is it just the buttons? - + property var simpleModeSettingsManager :CuraApplication.getSimpleModeSettingsManager() height: visible ? UM.Theme.getSize("action_button_icon").height : 0 width: visible ? childrenRect.width: 0 visible: Cura.MachineManager.hasUserSettings || (fullWarning && Cura.MachineManager.hasCustomQuality) @@ -96,7 +96,7 @@ Item State { name: "custom settings changed" - when: Cura.SimpleModeSettingsManager.isProfileCustomized + when: simpleModeSettingsManager.isProfileCustomized PropertyChanges { target: warning 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 }