mobile-widgets/qml: remove use of eval()

eval() cannot be used in combination with the Qt5 qml compiler,

replace eval() with switch statements.

Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
jan Iversen 2019-12-22 18:43:47 +01:00 committed by Dirk Hohndel
parent 636b26ff4b
commit 9d74b4dc82

View file

@ -162,21 +162,47 @@ Kirigami.Page {
elide: Text.ElideRight elide: Text.ElideRight
} }
onCurrentTextChanged: { onCurrentTextChanged: {
var curVendor
var curProduct
var curDevice
dc1.enabled = dc2.enabled = dc3.enabled = dc4.enabled = true dc1.enabled = dc2.enabled = dc3.enabled = dc4.enabled = true
for (var i = 1; i < 5; i++) { for (var i = 1; i < 5; i++) {
switch (i) {
case 1:
curVendor = PrefDiveComputer.vendor1
curProduct = PrefDiveComputer.product1
curDevice = PrefDiveComputer.device1
break
case 2:
curVendor = PrefDiveComputer.vendor2
curProduct = PrefDiveComputer.product2
curDevice = PrefDiveComputer.device2
break
case 3:
curVendor = PrefDiveComputer.vendor3
curProduct = PrefDiveComputer.product3
curDevice = PrefDiveComputer.device3
break
case 4:
curVendor = PrefDiveComputer.vendor4
curProduct = PrefDiveComputer.product4
curDevice = PrefDiveComputer.device4
break
}
if (comboProduct.currentIndex === -1 && currentText === "FTDI"){ if (comboProduct.currentIndex === -1 && currentText === "FTDI"){
if ( eval("PrefDiveComputer.vendor" + i) === comboVendor.currentText && eval("PrefDiveComputer.device" + i).toUpperCase() === currentText) if ( curVendor === comboVendor.currentText && curDevice.toUpperCase() === currentText)
rememberedDCsGrid.setDC(eval("PrefDiveComputer.vendor" + i), eval("PrefDiveComputer.product" + i), ("PrefDiveComputer.device" + i)) rememberedDCsGrid.setDC(curVendor, curProduct, curDevice)
}else if (comboProduct.currentIndex !== -1 && currentText === "FTDI") { }else if (comboProduct.currentIndex !== -1 && currentText === "FTDI") {
if ( eval("PrefDiveComputer.vendor" + i) === comboVendor.currentText && eval("PrefDiveComputer.product" + i) === comboProduct.currentText && eval("PrefDiveComputer.device" + i).toUpperCase() === currentText) { if ( curVendor === comboVendor.currentText && cyrProduct === comboProduct.currentText && curDevice.toUpperCase() === currentText) {
eval("dc"+ i + ".enabled = false") disableDC(i)
break break
} }
}else if ( eval("PrefDiveComputer.vendor" + i) === comboVendor.currentText && eval("PrefDiveComputer.product" + i) === comboProduct.currentText && eval("PrefDiveComputer.product" + i) +" " + eval("PrefDiveComputer.device" + i) === currentText) { }else if ( curVendor === comboVendor.currentText && curProduct === comboProduct.currentText && curProduct +" " + curDevice === currentText) {
eval("dc"+ i + ".enabled = false") disableDC(i)
break break
}else if ( eval("PrefDiveComputer.vendor" + i) === comboVendor.currentText && eval("PrefDiveComputer.product" + i) === comboProduct.currentText && eval("PrefDiveComputer.device" + i) === currentText) { }else if ( curVendor === comboVendor.currentText && curProduct === comboProduct.currentText && curDevice === currentText) {
eval("dc"+ i + ".enabled = false") disableDC(i)
break break
} }
} }
@ -202,6 +228,23 @@ Kirigami.Page {
comboProduct.currentIndex = comboProduct.find(product); comboProduct.currentIndex = comboProduct.find(product);
comboConnection.currentIndex = manager.getConnectionIndex(device); comboConnection.currentIndex = manager.getConnectionIndex(device);
} }
function disableDC(inx) {
switch (inx) {
case 1:
dc1.enabled = false
break;
case 2:
dc2.enabled = false
break;
case 3:
dc3.enabled = false
break;
case 4:
dc4.enabled = false
break;
}
}
SsrfButton { SsrfButton {
id: dc1 id: dc1
visible: PrefDiveComputer.vendor1 !== "" visible: PrefDiveComputer.vendor1 !== ""