Move setMaterialName to MaterialManagementModel

No longer use the material manager which is deprecated.

Contributes to issue CURA-6600.
This commit is contained in:
Ghostkeeper 2019-08-27 14:26:06 +02:00
parent 5b8ed91b04
commit 99ccddefa4
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276
2 changed files with 17 additions and 2 deletions

View file

@ -4,6 +4,8 @@
from PyQt5.QtCore import QObject, pyqtSlot # To allow the preference page proxy to be used from the actual preferences page.
from typing import TYPE_CHECKING
from UM.Logger import Logger
from cura.Settings.CuraContainerRegistry import CuraContainerRegistry # To find the sets of materials belonging to each other, and currently loaded extruder stacks.
if TYPE_CHECKING:
@ -22,6 +24,7 @@ class MaterialManagementModel(QObject):
# future we might enable this functionality again (deleting the material
# from those stacks) but for now it is easier to prevent the user from
# doing this.
# \param material_node The ContainerTree node of the material to check.
# \return Whether or not the material can be removed.
@pyqtSlot("QVariant", result = bool)
def canMaterialBeRemoved(self, material_node: "MaterialNode"):
@ -30,4 +33,16 @@ class MaterialManagementModel(QObject):
for extruder_stack in container_registry.findContainerStacks(type = "extruder_train"):
if extruder_stack.material.getId() in ids_to_remove:
return False
return True
return True
## Change the user-visible name of a material.
# \param material_node The ContainerTree node of the material to rename.
# \param name The new name for the material.
@pyqtSlot("QVariant", str)
def setMaterialName(self, material_node: "MaterialNode", name: str) -> None:
container_registry = CuraContainerRegistry.getInstance()
root_material_id = material_node.base_file
if container_registry.isReadOnly(root_material_id):
Logger.log("w", "Cannot set name of read-only container %s.", root_material_id)
return
return container_registry.findContainers(id = root_material_id)[0].setName(name)