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.
This commit is contained in:
Ghostkeeper 2019-08-28 15:21:33 +02:00
parent ba608c5987
commit b3fd310d37
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276
3 changed files with 37 additions and 9 deletions

View file

@ -1,12 +1,18 @@
# Copyright (c) 2019 Ultimaker B.V. # Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # 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.Logger import Logger
from UM.Qt.ListModel import ListModel from UM.Qt.ListModel import ListModel
import cura.CuraApplication # Imported this way to prevent circular imports. import cura.CuraApplication # Imported this way to prevent circular imports.
from cura.Machines.ContainerTree import ContainerTree 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. # This the QML model for the quality management page.
@ -34,6 +40,27 @@ class QualityManagementModel(ListModel):
self._update() 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): def _update(self):
Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__)) Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__))

View file

@ -146,18 +146,19 @@ class QualityManager(QObject):
# #
@pyqtSlot(QObject) @pyqtSlot(QObject)
def removeQualityChangesGroup(self, quality_changes_group: "QualityChangesGroup") -> None: 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() removed_quality_changes_ids = set()
for node in quality_changes_group.getAllNodes(): container_registry = cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry()
container_id = node.container_id for metadata in [quality_changes_group.metadata_for_global] + list(quality_changes_group.metadata_per_extruder.values()):
self._container_registry.removeContainer(container_id) container_id = metadata["id"]
container_registry.removeContainer(container_id)
removed_quality_changes_ids.add(container_id) removed_quality_changes_ids.add(container_id)
# Reset all machines that have activated this quality changes to empty. # Reset all machines that have activated this custom profile.
for global_stack in self._container_registry.findContainerStacks(type = "machine"): for global_stack in container_registry.findContainerStacks(type = "machine"):
if global_stack.qualityChanges.getId() in removed_quality_changes_ids: if global_stack.qualityChanges.getId() in removed_quality_changes_ids:
global_stack.qualityChanges = self._empty_quality_changes_container 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: if extruder_stack.qualityChanges.getId() in removed_quality_changes_ids:
extruder_stack.qualityChanges = self._empty_quality_changes_container extruder_stack.qualityChanges = self._empty_quality_changes_container

View file

@ -254,7 +254,7 @@ Item
onYes: 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 // reset current item to the first if available
qualityListView.currentIndex = -1; // Reset selection. qualityListView.currentIndex = -1; // Reset selection.
} }