Browse Source

Fix nozzle selection checkmark

CURA-11299
c.lamboo 1 year ago
parent
commit
61b33691e5
2 changed files with 12 additions and 14 deletions
  1. 6 0
      cura/Settings/MachineManager.py
  2. 6 14
      resources/qml/Menus/NozzleMenu.qml

+ 6 - 0
cura/Settings/MachineManager.py

@@ -48,6 +48,8 @@ from UM.i18n import i18nCatalog
 catalog = i18nCatalog("cura")
 from cura.Settings.GlobalStack import GlobalStack
 if TYPE_CHECKING:
+    from PyQt6.QtCore import QVariantList
+
     from cura.CuraApplication import CuraApplication
     from cura.Machines.MaterialNode import MaterialNode
     from cura.Machines.QualityChangesGroup import QualityChangesGroup
@@ -581,6 +583,10 @@ class MachineManager(QObject):
     def activeMachine(self) -> Optional["GlobalStack"]:
         return self._global_container_stack
 
+    @pyqtProperty("QVariantList", notify=activeVariantChanged)
+    def activeMachineExtruders(self) -> Optional["QVariantList"]:
+        return self._global_container_stack.extruderList if self._global_container_stack else None
+
     @pyqtProperty(str, notify = activeStackChanged)
     def activeStackId(self) -> str:
         if self._active_container_stack:

+ 6 - 14
resources/qml/Menus/NozzleMenu.qml

@@ -27,24 +27,17 @@ Cura.Menu
         {
             text: model.hotend_name
             checkable: true
-            property var activeMachine: Cura.MachineManager.activeMachine
             checked:
             {
-                if (activeMachine === null)
-                {
-                    return false
-                }
-                var extruder = activeMachine.extruderList[extruderIndex]
-                return (extruder === undefined) ? false : (extruder.variant.name == model.hotend_name)
+                const extruder = Cura.MachineManager.activeMachineExtruders[extruderIndex];
+                if (!extruder) return false;
+                return extruder.variant.name == model.hotend_name;
             }
             enabled:
             {
-                if (activeMachine === null)
-                {
-                    return false
-                }
-                var extruder = activeMachine.extruderList[extruderIndex]
-                return (extruder === undefined) ? false : extruder.isEnabled
+                const extruder = Cura.MachineManager.activeMachineExtruders[extruderIndex];
+                if (!extruder) return false;
+                return extruder.isEnabled;
             }
             onTriggered: Cura.MachineManager.setVariant(nozzleMenu.extruderIndex, model.container_node)
         }
@@ -52,5 +45,4 @@ Cura.Menu
         onObjectAdded: function(index, object) { nozzleMenu.insertItem(index, object) }
         onObjectRemoved: function(index, object) {nozzleMenu.removeItem(object)}
     }
-
 }