4import QGroundControl.Controls
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.
9 property var fact: null
10 property var choices: []
12 model: choices.map(choice => choice.label)
13 currentIndex: _indexOf(fact ? fact.rawValue : undefined)
16 function _indexOf(value) {
17 for (let i = 0; i < choices.length; i++) {
18 if (Number(choices[i].value) === Number(value)) {
25 function _restoreBinding() {
26 currentIndex = Qt.binding(() => _indexOf(fact ? fact.rawValue : undefined))
29 // A model change resets the index, so restore the binding once the model has settled
30 onModelChanged: Qt.callLater(_restoreBinding)
32 onActivated: (index) => {
33 if (fact && index >= 0 && index < choices.length) {
34 fact.rawValue = choices[index].value