QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ConfigChoiceComboBox.qml
Go to the documentation of this file.
1import QtQuick
2
3import QGroundControl
4import QGroundControl.Controls
5
6/// Combo box over a chosen subset of a Fact's values. Each choice is { label, value }; selecting one sets the Fact's
7/// raw value. Use FactComboBox when every metadata choice is shown.
8QGCComboBox {
9 property var fact: null
10 property var choices: []
11
12 model: choices.map(choice => choice.label)
13 currentIndex: _indexOf(fact ? fact.rawValue : undefined)
14 sizeToContents: true
15
16 function _indexOf(value) {
17 for (let i = 0; i < choices.length; i++) {
18 if (Number(choices[i].value) === Number(value)) {
19 return i
20 }
21 }
22 return -1
23 }
24
25 function _restoreBinding() {
26 currentIndex = Qt.binding(() => _indexOf(fact ? fact.rawValue : undefined))
27 }
28
29 // A model change resets the index, so restore the binding once the model has settled
30 onModelChanged: Qt.callLater(_restoreBinding)
31
32 onActivated: (index) => {
33 if (fact && index >= 0 && index < choices.length) {
34 fact.rawValue = choices[index].value
35 }
36 _restoreBinding()
37 }
38}