From 035a6092777ca4f5333c8447c8eaec6dc9325265 Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Tue, 14 Mar 2023 19:23:11 +0100 Subject: [PATCH 1/2] Boyscouting CURA-10374 --- .../MachineSettings/ComboBoxWithOptions.qml | 76 ++++++++----------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/resources/qml/MachineSettings/ComboBoxWithOptions.qml b/resources/qml/MachineSettings/ComboBoxWithOptions.qml index 7ba7c0f701..058ac6853f 100644 --- a/resources/qml/MachineSettings/ComboBoxWithOptions.qml +++ b/resources/qml/MachineSettings/ComboBoxWithOptions.qml @@ -65,32 +65,30 @@ UM.TooltipArea { id: defaultOptionsModel - function updateModel() - { - clear() + function updateModel() { + clear(); - if(!propertyProvider.properties.options) - { - return + if (!propertyProvider.properties.options) { + return; } - if (typeof propertyProvider.properties["options"] === "string") - { - return + if (typeof propertyProvider.properties["options"] === "string") { + return; } + let currentIndex = -1; + const keys = propertyProvider.properties["options"].keys(); + for (let index = 0; index < propertyProvider.properties["options"].keys().length; index ++) { + const key = propertyProvider.properties["options"].keys()[index]; + const value = propertyProvider.properties["options"][key]; - for (var i = 0; i < propertyProvider.properties["options"].keys().length; i++) - { - var key = propertyProvider.properties["options"].keys()[i] - var value = propertyProvider.properties["options"][key] - append({ text: value, code: key }) - - if (propertyProvider.properties.value === key) - { - comboBox.currentIndex = i + if (propertyProvider.properties.value === key) { + currentIndex = index; } + defaultOptionsModel.append({ text: value, code: key }); } + + comboBox.currentIndex = currentIndex; } Component.onCompleted: updateModel() @@ -114,36 +112,28 @@ UM.TooltipArea model: defaultOptionsModel textRole: "text" - currentIndex: - { - var currentValue = propertyProvider.properties.value - var index = 0 - for (var i = 0; i < model.count; i++) - { - if (model.get(i).value == currentValue) - { - index = i - break + currentIndex: function () { + const currentValue = propertyProvider.properties.value + for (let i = 0; i < model.count; i ++) { + if (model.get(i).value === currentValue) { + return i; } } - return index + return -1; } - onActivated: - { - var newValue = model.get(index).value - if (propertyProvider.properties.value !== newValue && newValue !== undefined) - { - if (setValueFunction !== null) - { - setValueFunction(newValue) + onActivated: function (index) { + const key = propertyProvider.properties["options"].keys()[index]; + const newValue = model.get(index).value; + + if (propertyProvider.properties.value !== newValue && newValue !== undefined) { + if (setValueFunction !== null) { + setValueFunction(newValue); + } else { + propertyProvider.setPropertyValue("value", newValue); } - else - { - propertyProvider.setPropertyValue("value", newValue) - } - forceUpdateOnChangeFunction() - afterOnEditingFinishedFunction() + forceUpdateOnChangeFunction(); + afterOnEditingFinishedFunction(); } } } From 37f4271c9bfba35aa0da684157cb4f195a3f4b67 Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Tue, 14 Mar 2023 19:24:47 +0100 Subject: [PATCH 2/2] Fix comboboxes not updating the accosiated value Was introduced by this commit: https://github.com/Ultimaker/Cura/commit/788ab7da1b61d5d002ba35914f57b5cc971d2fc9 CURA-10374 --- resources/qml/MachineSettings/ComboBoxWithOptions.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/qml/MachineSettings/ComboBoxWithOptions.qml b/resources/qml/MachineSettings/ComboBoxWithOptions.qml index 058ac6853f..a25e165d2d 100644 --- a/resources/qml/MachineSettings/ComboBoxWithOptions.qml +++ b/resources/qml/MachineSettings/ComboBoxWithOptions.qml @@ -85,7 +85,7 @@ UM.TooltipArea if (propertyProvider.properties.value === key) { currentIndex = index; } - defaultOptionsModel.append({ text: value, code: key }); + defaultOptionsModel.append({ text: value, value: key }); } comboBox.currentIndex = currentIndex;