diff --git a/cura/Machines/Models/QualityManagementModel.py b/cura/Machines/Models/QualityManagementModel.py index 792159b31d..eaaf1eb058 100644 --- a/cura/Machines/Models/QualityManagementModel.py +++ b/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__)) diff --git a/cura/Machines/QualityManager.py b/cura/Machines/QualityManager.py index 75c8e89e11..94dfdd78e9 100644 --- a/cura/Machines/QualityManager.py +++ b/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 diff --git a/resources/qml/Preferences/ProfilesPage.qml b/resources/qml/Preferences/ProfilesPage.qml index da41a0f23c..6907795e1a 100644 --- a/resources/qml/Preferences/ProfilesPage.qml +++ b/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. }