Browse Source

Update material_diameter when editing the material in MaterialView.qml

fieldOfView 7 years ago
parent
commit
1f49a87acb
2 changed files with 30 additions and 1 deletions
  1. 25 0
      cura/Settings/ContainerManager.py
  2. 5 1
      resources/qml/Preferences/MaterialView.qml

+ 25 - 0
cura/Settings/ContainerManager.py

@@ -235,6 +235,31 @@ class ContainerManager(QObject):
 
         return True
 
+    ##  Set a metadata entry of the specified container.
+    #
+    #   \param container_id \type{str} The ID of the container to change.
+    #   \param setting_key \type{str} The key of the setting.
+    #   \param property_name \type{str} The name of the property, eg "value".
+    #   \param property_value \type{str} The new value of the property.
+    #
+    #   \return True if successful, False if not.
+    @pyqtSlot(str, str, str, str, result = bool)
+    def setContainerProperty(self, container_id, setting_key, property_name, value_value):
+        containers = self._container_registry.findContainers(None, id = container_id)
+        if not containers:
+            Logger.log("w", "Could not set properties of container %s because it was not found.", container_id)
+            return False
+
+        container = containers[0]
+
+        if container.isReadOnly():
+            Logger.log("w", "Cannot set properties of read-only container %s.", container_id)
+            return False
+
+        container.setProperty(setting_key, property_name, value_value)
+
+        return True
+
     ##  Set the name of the specified container.
     @pyqtSlot(str, str, result = bool)
     def setContainerName(self, container_id, new_name):

+ 5 - 1
resources/qml/Preferences/MaterialView.qml

@@ -164,7 +164,11 @@ TabView
                     stepSize: 0.01
                     readOnly: !base.editingEnabled
 
-                    onEditingFinished: base.setMetaDataEntry("properties/diameter", properties.diameter, value)
+                    onEditingFinished:
+                    {
+                        Cura.ContainerManager.setContainerProperty(base.containerId, "material_diameter", "value", value)
+                        base.setMetaDataEntry("properties/diameter", properties.diameter, value)
+                    }
                     onValueChanged: updateCostPerMeter()
                 }