From 9e048aa6adf20afe71ec6fd32ea158304221a539 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Wed, 9 Nov 2016 15:29:23 +0100 Subject: [PATCH] Get gcode flavor options from propertyprovider instead of hardcoding --- .../MachineSettingsAction.qml | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/plugins/MachineSettingsAction/MachineSettingsAction.qml b/plugins/MachineSettingsAction/MachineSettingsAction.qml index f6b20a648a..ea299438f0 100644 --- a/plugins/MachineSettingsAction/MachineSettingsAction.qml +++ b/plugins/MachineSettingsAction/MachineSettingsAction.qml @@ -147,19 +147,40 @@ Cura.MachineAction ComboBox { - model: ["RepRap (Marlin/Sprinter)", "UltiGCode", "Repetier"] + model: ListModel + { + id: flavorModel + Component.onCompleted: + { + // Options come in as a string-representation of an OrderedDict + var options = machineGCodeFlavorProvider.properties.options.match(/^OrderedDict\(\[\((.*)\)\]\)$/); + if(options) + { + options = options[1].split("), (") + for(var i = 0; i < options.length; i++) + { + var option = options[i].substring(1, options[i].length - 1).split("', '") + flavorModel.append({text: option[1], value: option[0]}); + } + } + } + } currentIndex: { - var index = model.indexOf(machineGCodeFlavorProvider.properties.value); - if(index == -1) + var currentValue = machineGCodeFlavorProvider.properties.value; + var index = 0; + for(var i = 0; i < flavorModel.count; i++) { - index = 0; + if(flavorModel.get(i).value == currentValue) { + index = i; + break; + } } return index } onActivated: { - machineGCodeFlavorProvider.setPropertyValue("value", model[index]); + machineGCodeFlavorProvider.setPropertyValue("value", flavorModel.get(index).value); manager.updateHasMaterialsMetadata(); } } @@ -433,7 +454,7 @@ Cura.MachineAction containerStackId: Cura.MachineManager.activeMachineId key: "machine_gcode_flavor" - watchedProperties: [ "value" ] + watchedProperties: [ "value", "options" ] storeIndex: manager.containerIndex }