mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Added materialspage Display Name field and made it work. CURA-1969
This commit is contained in:
parent
8df5bba6e9
commit
2ae998737f
4 changed files with 60 additions and 2 deletions
|
@ -181,7 +181,7 @@ class ContainerManager(QObject):
|
||||||
def setContainerMetaDataEntry(self, container_id, entry_name, entry_value):
|
def setContainerMetaDataEntry(self, container_id, entry_name, entry_value):
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findContainers(None, id = container_id)
|
containers = UM.Settings.ContainerRegistry.getInstance().findContainers(None, id = container_id)
|
||||||
if not containers:
|
if not containers:
|
||||||
UM.Logger.log("w", "Could set metadata of container %s because it was not found.", container_id)
|
UM.Logger.log("w", "Could not set metadata of container %s because it was not found.", container_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
container = containers[0]
|
container = containers[0]
|
||||||
|
@ -210,6 +210,24 @@ class ContainerManager(QObject):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
## Set the name of the specified container.
|
||||||
|
@pyqtSlot(str, str, result = bool)
|
||||||
|
def setContainerName(self, container_id, new_name):
|
||||||
|
containers = UM.Settings.ContainerRegistry.getInstance().findContainers(None, id = container_id)
|
||||||
|
if not containers:
|
||||||
|
UM.Logger.log("w", "Could not set name of container %s because it was not found.", container_id)
|
||||||
|
return False
|
||||||
|
|
||||||
|
container = containers[0]
|
||||||
|
|
||||||
|
if container.isReadOnly():
|
||||||
|
UM.Logger.log("w", "Cannot set name of read-only container %s.", container_id)
|
||||||
|
return False
|
||||||
|
|
||||||
|
container.setName(new_name)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
## Find instance containers matching certain criteria.
|
## Find instance containers matching certain criteria.
|
||||||
#
|
#
|
||||||
# This effectively forwards to ContainerRegistry::findInstanceContainers.
|
# This effectively forwards to ContainerRegistry::findInstanceContainers.
|
||||||
|
|
|
@ -61,6 +61,27 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
||||||
for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(GUID = self.getMetaDataEntry("GUID"), base_file = basefile):
|
for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(GUID = self.getMetaDataEntry("GUID"), base_file = basefile):
|
||||||
container.setMetaData(copy.deepcopy(self._metadata))
|
container.setMetaData(copy.deepcopy(self._metadata))
|
||||||
|
|
||||||
|
## Overridden from InstanceContainer, similar to setMetaDataEntry.
|
||||||
|
# without this function the setName would only set the name of the specific nozzle / material / machine combination container
|
||||||
|
# The function is a bit tricky. It will not set the name of all containers if it has the correct name itself.
|
||||||
|
def setName(self, new_name):
|
||||||
|
if self.isReadOnly():
|
||||||
|
return
|
||||||
|
|
||||||
|
# Not only is this faster, it also prevents a major loop that causes a stack overflow.
|
||||||
|
if self.getName() == new_name:
|
||||||
|
return
|
||||||
|
|
||||||
|
super().setName(new_name)
|
||||||
|
|
||||||
|
basefile = self.getMetaDataEntry("base_file", self._id) # if basefile is none, this is a basefile.
|
||||||
|
# Update the basefile as well, this is actually what we're trying to do
|
||||||
|
# Update all containers that share GUID and basefile
|
||||||
|
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=basefile) + UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(
|
||||||
|
GUID=self.getMetaDataEntry("GUID"), base_file=basefile)
|
||||||
|
for container in containers:
|
||||||
|
container.setName(new_name)
|
||||||
|
|
||||||
## Overridden from InstanceContainer
|
## Overridden from InstanceContainer
|
||||||
def setProperty(self, key, property_name, property_value, container = None):
|
def setProperty(self, key, property_name, property_value, container = None):
|
||||||
if self.isReadOnly():
|
if self.isReadOnly():
|
||||||
|
|
|
@ -44,6 +44,16 @@ TabView
|
||||||
|
|
||||||
property real rowHeight: textField.height;
|
property real rowHeight: textField.height;
|
||||||
|
|
||||||
|
Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Display Name") }
|
||||||
|
ReadOnlyTextField
|
||||||
|
{
|
||||||
|
id: displayNameTextField;
|
||||||
|
width: base.secondColumnWidth;
|
||||||
|
text: properties.name;
|
||||||
|
readOnly: !base.editingEnabled;
|
||||||
|
onEditingFinished: base.setName(properties.name, text)
|
||||||
|
}
|
||||||
|
|
||||||
Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Brand") }
|
Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Brand") }
|
||||||
ReadOnlyTextField
|
ReadOnlyTextField
|
||||||
{
|
{
|
||||||
|
@ -254,7 +264,15 @@ TabView
|
||||||
{
|
{
|
||||||
if(old_value != new_value)
|
if(old_value != new_value)
|
||||||
{
|
{
|
||||||
Cura.ContainerManager.setContainerMetaDataEntry(base.containerId, entry_name, new_value)
|
Cura.ContainerManager.setContainerMetaDataEntry(base.containerId, entry_name, new_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setName(old_value, new_value)
|
||||||
|
{
|
||||||
|
if(old_value != new_value)
|
||||||
|
{
|
||||||
|
Cura.ContainerManager.setContainerName(base.containerId, new_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// Copyright (c) 2016 Ultimaker B.V.
|
// Copyright (c) 2016 Ultimaker B.V.
|
||||||
// Uranium is released under the terms of the AGPLv3 or higher.
|
// Uranium is released under the terms of the AGPLv3 or higher.
|
||||||
|
// Different than the name suggests, it is not always read-only.
|
||||||
|
|
||||||
import QtQuick 2.1
|
import QtQuick 2.1
|
||||||
import QtQuick.Controls 1.1
|
import QtQuick.Controls 1.1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue