Browse Source

Merge branch 'main' into CURA-11468-qtflickable-bug

c.lamboo 1 year ago
parent
commit
bcf50e2ac1

+ 25 - 1
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")], {})

+ 44 - 14
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")

+ 1 - 1
plugins/PerObjectSettingsTool/PerObjectItem.qml

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

+ 11 - 11
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

+ 4 - 4
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

+ 1 - 1
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

+ 3 - 1
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
             {

+ 1 - 1
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

+ 1 - 1
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)

+ 2 - 2
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

Some files were not shown because too many files changed in this diff