Browse Source

Move removeQualityChangesGroup to QualityManagementModel

This is an operation specific to the quality management page, so it should be located there.

Contributes to issue CURA-6600.
Ghostkeeper 5 years ago
parent
commit
b3fd310d37

+ 28 - 1
cura/Machines/Models/QualityManagementModel.py

@@ -1,12 +1,18 @@
 # Copyright (c) 2019 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
 
-from PyQt5.QtCore import Qt, pyqtSlot
+from typing import TYPE_CHECKING
+from PyQt5.QtCore import pyqtSlot, QObject, Qt
 
 from UM.Logger import Logger
 from UM.Qt.ListModel import ListModel
+
 import cura.CuraApplication  # Imported this way to prevent circular imports.
 from cura.Machines.ContainerTree import ContainerTree
+from cura.Settings.cura_empty_instance_containers import empty_quality_changes_container
+
+if TYPE_CHECKING:
+    from cura.Machines.QualityChangesGroup import QualityChangesGroup
 
 #
 # This the QML model for the quality management page.
@@ -34,6 +40,27 @@ class QualityManagementModel(ListModel):
 
         self._update()
 
+    ##  Deletes a custom profile. It will be gone forever.
+    #   \param quality_changes_group The quality changes group representing the
+    #   profile to delete.
+    @pyqtSlot(QObject)
+    def removeQualityChangesGroup(self, quality_changes_group: "QualityChangesGroup") -> None:
+        Logger.log("i", "Removing quality changes group {group_name}".format(group_name = quality_changes_group.name))
+        removed_quality_changes_ids = set()
+        container_registry = cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry()
+        for metadata in [quality_changes_group.metadata_for_global] + list(quality_changes_group.metadata_per_extruder.values()):
+            container_id = metadata["id"]
+            container_registry.removeContainer(container_id)
+            removed_quality_changes_ids.add(container_id)
+
+        # Reset all machines that have activated this custom profile.
+        for global_stack in container_registry.findContainerStacks(type = "machine"):
+            if global_stack.qualityChanges.getId() in removed_quality_changes_ids:
+                global_stack.qualityChanges = empty_quality_changes_container
+        for extruder_stack in container_registry.findContainerStacks(type = "extruder_train"):
+            if extruder_stack.qualityChanges.getId() in removed_quality_changes_ids:
+                extruder_stack.qualityChanges = empty_quality_changes_container
+
     def _update(self):
         Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__))
 

+ 8 - 7
cura/Machines/QualityManager.py

@@ -146,18 +146,19 @@ class QualityManager(QObject):
     #
     @pyqtSlot(QObject)
     def removeQualityChangesGroup(self, quality_changes_group: "QualityChangesGroup") -> None:
-        Logger.log("i", "Removing quality changes group [%s]", quality_changes_group.name)
+        Logger.log("i", "Removing quality changes group {group_name}".format(group_name = quality_changes_group.name))
         removed_quality_changes_ids = set()
-        for node in quality_changes_group.getAllNodes():
-            container_id = node.container_id
-            self._container_registry.removeContainer(container_id)
+        container_registry = cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry()
+        for metadata in [quality_changes_group.metadata_for_global] + list(quality_changes_group.metadata_per_extruder.values()):
+            container_id = metadata["id"]
+            container_registry.removeContainer(container_id)
             removed_quality_changes_ids.add(container_id)
 
-        # Reset all machines that have activated this quality changes to empty.
-        for global_stack in self._container_registry.findContainerStacks(type = "machine"):
+        # Reset all machines that have activated this custom profile.
+        for global_stack in container_registry.findContainerStacks(type = "machine"):
             if global_stack.qualityChanges.getId() in removed_quality_changes_ids:
                 global_stack.qualityChanges = self._empty_quality_changes_container
-        for extruder_stack in self._container_registry.findContainerStacks(type = "extruder_train"):
+        for extruder_stack in container_registry.findContainerStacks(type = "extruder_train"):
             if extruder_stack.qualityChanges.getId() in removed_quality_changes_ids:
                 extruder_stack.qualityChanges = self._empty_quality_changes_container
 

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

@@ -254,7 +254,7 @@ Item
 
         onYes:
         {
-            base.qualityManager.removeQualityChangesGroup(base.currentItem.quality_changes_group);
+            base.qualityManagementModel.removeQualityChangesGroup(base.currentItem.quality_changes_group);
             // reset current item to the first if available
             qualityListView.currentIndex = -1;  // Reset selection.
         }