diff --git a/src/ui/preferences/SerialSettings.qml b/src/ui/preferences/SerialSettings.qml index 8438549d070b9ad7a6a3b8306bc3168c26accf53..0b9ba0f31e164ec3db0806003826c4e7720d8a20 100644 --- a/src/ui/preferences/SerialSettings.qml +++ b/src/ui/preferences/SerialSettings.qml @@ -59,26 +59,41 @@ Item { id: commPortCombo anchors.verticalCenter: parent.verticalCenter width: _secondColumn - model: QGroundControl.linkManager.serialPortStrings visible: QGroundControl.linkManager.serialPortStrings.length > 0 + onActivated: { if (index != -1) { - subEditConfig.portName = QGroundControl.linkManager.serialPorts[index] + if (index >= QGroundControl.linkManager.serialPortStrings.length) { + // This item was adding at the end, must use added text as name + subEditConfig.portName = commPortCombo.textAt(index) + } else { + subEditConfig.portName = QGroundControl.linkManager.serialPorts[index] + } } } Component.onCompleted: { - if(subEditConfig != null) { - if(subEditConfig.portDisplayName === "" && QGroundControl.linkManager.serialPorts.length > 0) + var index + var serialPorts = [ ] + + for (var i=0; i 0) { subEditConfig.portName = QGroundControl.linkManager.serialPorts[0] - var index = commPortCombo.find(subEditConfig.portDisplayName) + } + index = serialPorts.indexOf(subEditConfig.portDisplayName) if (index === -1) { - console.warn(qsTr("Serial Port not present"), subEditConfig.portName) - } else { - commPortCombo.currentIndex = index + serialPorts.push(subEditConfig.portName) + index = serialPorts.indexOf(subEditConfig.portName) } } else { - commPortCombo.currentIndex = 0 + index = 0 } + + commPortCombo.model = serialPorts + commPortCombo.currentIndex = index } } }