Merge pull request #14885 from Ultimaker/CURA-10374_fix_combobobobobox

Cura 10374 fix combobobobobox
This commit is contained in:
Jelle Spijker 2023-03-15 12:44:55 +01:00 committed by GitHub
commit dc22a4980c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,32 +65,30 @@ UM.TooltipArea
{ {
id: defaultOptionsModel id: defaultOptionsModel
function updateModel() function updateModel() {
{ clear();
clear()
if(!propertyProvider.properties.options) if (!propertyProvider.properties.options) {
{ return;
return
} }
if (typeof propertyProvider.properties["options"] === "string") if (typeof propertyProvider.properties["options"] === "string") {
{ return;
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++) if (propertyProvider.properties.value === key) {
{ currentIndex = index;
var key = propertyProvider.properties["options"].keys()[i] }
var value = propertyProvider.properties["options"][key] defaultOptionsModel.append({ text: value, value: key });
append({ text: value, code: key }) }
if (propertyProvider.properties.value === key) comboBox.currentIndex = currentIndex;
{
comboBox.currentIndex = i
}
}
} }
Component.onCompleted: updateModel() Component.onCompleted: updateModel()
@ -114,36 +112,28 @@ UM.TooltipArea
model: defaultOptionsModel model: defaultOptionsModel
textRole: "text" textRole: "text"
currentIndex: currentIndex: function () {
{ const currentValue = propertyProvider.properties.value
var currentValue = propertyProvider.properties.value for (let i = 0; i < model.count; i ++) {
var index = 0 if (model.get(i).value === currentValue) {
for (var i = 0; i < model.count; i++) return i;
{
if (model.get(i).value == currentValue)
{
index = i
break
} }
} }
return index return -1;
} }
onActivated: onActivated: function (index) {
{ const key = propertyProvider.properties["options"].keys()[index];
var newValue = model.get(index).value const newValue = model.get(index).value;
if (propertyProvider.properties.value !== newValue && newValue !== undefined)
{ if (propertyProvider.properties.value !== newValue && newValue !== undefined) {
if (setValueFunction !== null) if (setValueFunction !== null) {
{ setValueFunction(newValue);
setValueFunction(newValue) } else {
propertyProvider.setPropertyValue("value", newValue);
} }
else forceUpdateOnChangeFunction();
{ afterOnEditingFinishedFunction();
propertyProvider.setPropertyValue("value", newValue)
}
forceUpdateOnChangeFunction()
afterOnEditingFinishedFunction()
} }
} }
} }