From 71a0044bf828cc117730edfa26f769c4964251ab Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Wed, 15 Mar 2023 18:18:31 +0100 Subject: [PATCH] Fix extruder number most important change was changing ``` currentIndex: function () { ... } ``` to currentIndex: { ... } ``` This changed the behavior so that the variables inside the code blocked are watched so that `currentIndex` is automatically updated. No longer needed to set the `currentIndex` from any where else anymore. CURA-10374 --- .../MachineSettingsPrinterTab.qml | 15 ++++++++------- .../qml/MachineSettings/ComboBoxWithOptions.qml | 12 ++---------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml b/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml index c1c54954f1..740e248828 100644 --- a/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml +++ b/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml @@ -303,18 +303,17 @@ Item Component.onCompleted: { - update() + updateModel(); } - function update() + function updateModel() { - clear() - for (var i = 1; i <= Cura.MachineManager.activeMachine.maxExtruderCount; i++) - { + clear(); + for (var i = 1; i <= Cura.MachineManager.activeMachine.maxExtruderCount; i ++) { // Use String as value. JavaScript only has Number. PropertyProvider.setPropertyValue() // takes a QVariant as value, and Number gets translated into a float. This will cause problem // for integer settings such as "Number of Extruders". - append({ text: String(i), value: String(i) }) + append({ text: String(i), value: String(i) }); } } } @@ -322,7 +321,9 @@ Item Connections { target: Cura.MachineManager - function onGlobalContainerChanged() { extruderCountModel.update() } + function onGlobalContainerChanged() { + extruderCountModel.updateModel(); + } } } diff --git a/resources/qml/MachineSettings/ComboBoxWithOptions.qml b/resources/qml/MachineSettings/ComboBoxWithOptions.qml index a25e165d2d..5046859d14 100644 --- a/resources/qml/MachineSettings/ComboBoxWithOptions.qml +++ b/resources/qml/MachineSettings/ComboBoxWithOptions.qml @@ -72,23 +72,16 @@ UM.TooltipArea return; } - if (typeof propertyProvider.properties["options"] === "string") { + 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]; - - if (propertyProvider.properties.value === key) { - currentIndex = index; - } defaultOptionsModel.append({ text: value, value: key }); } - - comboBox.currentIndex = currentIndex; } Component.onCompleted: updateModel() @@ -112,7 +105,7 @@ UM.TooltipArea model: defaultOptionsModel textRole: "text" - currentIndex: function () { + currentIndex: { const currentValue = propertyProvider.properties.value for (let i = 0; i < model.count; i ++) { if (model.get(i).value === currentValue) { @@ -123,7 +116,6 @@ UM.TooltipArea } onActivated: function (index) { - const key = propertyProvider.properties["options"].keys()[index]; const newValue = model.get(index).value; if (propertyProvider.properties.value !== newValue && newValue !== undefined) {