Browse Source

Make ExtruderManager a QML context item

There were two singletons of this manager: One created by QML and managed by QML, and one created by us and managed by our own singleton pattern. That won't work! So we now manage just our own singleton type, and make it a context item for QML so it can use the manager too.

Contributes to issues CURA-340 and CURA-1278.
Ghostkeeper 8 years ago
parent
commit
dff94b4559

+ 5 - 2
cura/CuraApplication.py

@@ -353,8 +353,6 @@ class CuraApplication(QtApplication):
 
         qmlRegisterSingletonType(MachineManagerModel.MachineManagerModel, "Cura", 1, 0, "MachineManager",
                                  MachineManagerModel.createMachineManagerModel)
-        qmlRegisterSingletonType(ExtruderManager.ExtruderManager, "Cura", 1, 0, "ExtruderManager",
-                                 ExtruderManager.createExtruderManager)
 
         self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
         self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles))
@@ -386,6 +384,9 @@ class CuraApplication(QtApplication):
     def getPrintInformation(self):
         return self._print_information
 
+    ##  Registers objects for the QML engine to use.
+    #
+    #   \param engine The QML engine.
     def registerObjects(self, engine):
         engine.rootContext().setContextProperty("Printer", self)
         self._print_information = PrintInformation.PrintInformation()
@@ -399,6 +400,8 @@ class CuraApplication(QtApplication):
 
         qmlRegisterSingletonType(QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")), "Cura", 1, 0, "Actions")
 
+        engine.rootContext().setContextProperty("ExtruderManager", ExtruderManager.ExtruderManager.getInstance())
+
         for path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.QmlFiles):
             type_name = os.path.splitext(os.path.basename(path))[0]
             if type_name in ("Cura", "Actions"):

+ 1 - 5
cura/ExtruderManager.py

@@ -76,7 +76,7 @@ class ExtruderManager(QObject):
 
         #Add the extruder trains that don't exist yet.
         for position, extruder_definition_id in machine_definition.getMetaDataEntry("machine_extruder_trains", default = {}).items():
-            extruder_definition = container_registry.findDefinitionContainers(id = extruder_definition_id)
+            extruder_definition = container_registry.findDefinitionContainers(machine = machine_definition.getId())
             if extruder_definition:
                 extruder_definition = extruder_definition[0]
             else:
@@ -194,7 +194,3 @@ class ExtruderManager(QObject):
             i += 1  # Try next numbering.
             unique_name = "%s #%d" % (name, i)  # Fill name like this: "Extruder #2".
         return unique_name
-
-
-def createExtruderManager(engine, script_engine):
-    return ExtruderManager()

+ 1 - 1
resources/qml/Settings/SettingView.qml

@@ -80,7 +80,7 @@ ScrollView
             {
                 id: provider
 
-                containerStackId: Cura.ExtruderManager.activeExtruderStackId ? Cura.ExtruderManager.activeExtruderStackId : Cura.MachineManager.activeMachineId
+                containerStackId: ExtruderManager.activeExtruderStackId ? ExtruderManager.activeExtruderStackId : Cura.MachineManager.activeMachineId
                 key: model.key
                 watchedProperties: [ "value", "enabled", "state", "validationState" ]
                 storeIndex: 0

+ 1 - 1
resources/qml/SidebarHeader.qml

@@ -111,7 +111,7 @@ Item
                 onClicked:
                 {
                     base.currentExtruderIndex = index
-                    Cura.ExtruderManager.setActiveExtruderIndex(index)
+                    ExtruderManager.setActiveExtruderIndex(index)
                 }
 
                 style: ButtonStyle {