Browse Source

Move removeMaterial() to MaterialManager

Lipu Fei 7 years ago
parent
commit
5f0bb3a283

+ 15 - 0
cura/Machines/MaterialManager.py

@@ -360,6 +360,21 @@ class MaterialManager(QObject):
         material_group = self.getMaterialGroup(root_material_id)
         material_group.root_material_node.getContainer().setName(name)
 
+    #
+    # Removes the given material.
+    #
+    @pyqtSlot("QVariant")
+    def removeMaterial(self, material_node: "MaterialNode"):
+        root_material_id = material_node.metadata["base_file"]
+        material_group = self.getMaterialGroup(root_material_id)
+        if not material_group:
+            Logger.log("d", "Unable to remove the material with id %s, because it doesn't exist.", root_material_id)
+            return
+
+        nodes_to_remove = [material_group.root_material_node] + material_group.derived_material_node_list
+        for node in nodes_to_remove:
+            self._container_registry.removeContainer(node.metadata["id"])
+
     #
     # Creates a duplicate of a material, which has the same GUID and base_file metadata.
     # Returns the root material ID of the duplicated material if successful.

+ 0 - 14
cura/Settings/ContainerManager.py

@@ -382,20 +382,6 @@ class ContainerManager(QObject):
 
             self._container_registry.addContainer(new_changes)
 
-    @pyqtSlot("QVariant")
-    def removeMaterial(self, material_node):
-        root_material_id = material_node.metadata["base_file"]
-        material_group = self._material_manager.getMaterialGroup(root_material_id)
-        if not material_group:
-            Logger.log("d", "Unable to remove the material with id %s, because it doesn't exist.", root_material_id)
-            return
-
-        nodes_to_remove = [material_group.root_material_node] + material_group.derived_material_node_list
-        for node in nodes_to_remove:
-            self._container_registry.removeContainer(node.metadata["id"])
-
-
-
     ##  Create a new material by cloning Generic PLA for the current material diameter and setting the GUID to something unqiue
     #
     #   \return \type{str} the id of the newly created container.

+ 1 - 1
resources/qml/Preferences/MaterialsPage.qml

@@ -183,7 +183,7 @@ Item
 
         onYes:
         {
-            Cura.ContainerManager.removeMaterial(base.currentItem.container_node);
+            base.materialManager.removeMaterial(base.currentItem.container_node);
         }
     }