Move setMaterialName() into MaterialManager

This commit is contained in:
Lipu Fei 2018-03-02 16:22:22 +01:00
parent f7377e6321
commit c6128ef5ba
4 changed files with 22 additions and 13 deletions

View file

@ -859,6 +859,7 @@ class CuraApplication(QtApplication):
def getVariantManager(self, *args): def getVariantManager(self, *args):
return self._variant_manager return self._variant_manager
@pyqtSlot(result = QObject)
def getMaterialManager(self, *args): def getMaterialManager(self, *args):
return self._material_manager return self._material_manager

View file

@ -4,7 +4,7 @@
from collections import defaultdict, OrderedDict from collections import defaultdict, OrderedDict
from typing import Optional from typing import Optional
from PyQt5.Qt import QTimer, QObject, pyqtSignal from PyQt5.Qt import QTimer, QObject, pyqtSignal, pyqtSlot
from UM.Logger import Logger from UM.Logger import Logger
from UM.Settings import ContainerRegistry from UM.Settings import ContainerRegistry
@ -339,3 +339,20 @@ class MaterialManager(QObject):
return self.getRootMaterialIDWithoutDiameter(fallback_material["id"]) return self.getRootMaterialIDWithoutDiameter(fallback_material["id"])
else: else:
return None return None
#
# Methods for GUI
#
#
# Sets the new name for the given material.
#
@pyqtSlot("QVariant", str)
def setMaterialName(self, material_node: "MaterialNode", name: str):
root_material_id = material_node.metadata["base_file"]
if self._container_registry.isReadOnly(root_material_id):
Logger.log("w", "Cannot set name of read-only container %s.", root_material_id)
return
material_group = self.getMaterialGroup(root_material_id)
material_group.root_material_node.getContainer().setName(name)

View file

@ -160,17 +160,6 @@ class ContainerManager(QObject):
return container.getProperty(setting_key, property_name) return container.getProperty(setting_key, property_name)
## Set the name of the specified material.
@pyqtSlot("QVariant", str)
def setMaterialName(self, material_node, new_name):
root_material_id = material_node.metadata["base_file"]
if self._container_registry.isReadOnly(root_material_id):
Logger.log("w", "Cannot set name of read-only container %s.", root_material_id)
return
material_group = self._material_manager.getMaterialGroup(root_material_id)
material_group.root_material_node.getContainer().setName(new_name)
@pyqtSlot(str, result = str) @pyqtSlot(str, result = str)
def makeUniqueName(self, original_name): def makeUniqueName(self, original_name):
return self._container_registry.uniqueName(original_name) return self._container_registry.uniqueName(original_name)

View file

@ -12,6 +12,8 @@ TabView
{ {
id: base id: base
property QtObject materialManager: CuraApplication.getMaterialManager()
property QtObject properties property QtObject properties
property var currentMaterialNode: null property var currentMaterialNode: null
@ -497,7 +499,7 @@ TabView
} }
// update the values // update the values
Cura.ContainerManager.setMaterialName(base.currentMaterialNode, new_name) base.materialManager.setMaterialName(base.currentMaterialNode, new_name)
materialProperties.name = new_name materialProperties.name = new_name
} }