From 5eb2230d82b96edf0ef09732b34bd97347fd6070 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 10 Jul 2018 15:40:13 +0200 Subject: [PATCH] Fix default value for getMaterialPreferenceValue other than spool_weight, added cleanup code for saving default values. CURA-5408 --- resources/qml/Preferences/MaterialView.qml | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/resources/qml/Preferences/MaterialView.qml b/resources/qml/Preferences/MaterialView.qml index 528ea448cc..2f705a8b5e 100644 --- a/resources/qml/Preferences/MaterialView.qml +++ b/resources/qml/Preferences/MaterialView.qml @@ -515,7 +515,21 @@ TabView // value has not changed return; } - materialPreferenceValues[material_guid][entry_name] = new_value; + if (entry_name in materialPreferenceValues[material_guid] && new_value.toString() == 0) + { + // no need to store a 0, that's the default, so remove it + materialPreferenceValues[material_guid].delete(entry_name); + if (!(materialPreferenceValues[material_guid])) + { + // remove empty map + materialPreferenceValues.delete(material_guid); + } + } + if (new_value.toString() != 0) + { + // store new value + materialPreferenceValues[material_guid][entry_name] = new_value; + } // store preference UM.Preferences.setValue("cura/material_settings", JSON.stringify(materialPreferenceValues)); @@ -527,9 +541,12 @@ TabView { return materialPreferenceValues[material_guid][entry_name]; } - - var material_weight = Cura.ContainerManager.getContainerMetaDataEntry(base.containerId, "properties/weight"); - return material_weight || 0; + if (entry_name === "spool_weight") { + // get the default value from the metadata + var material_weight = Cura.ContainerManager.getContainerMetaDataEntry(base.containerId, "properties/weight"); + return material_weight || 0; + } + return 0; } // update the display name of the material