QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FactComboBox.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3
4import QGroundControl
5import QGroundControl.Controls
6
7QGCComboBox {
8 property Fact fact: Fact { }
9 property bool indexModel: fact ? fact.enumValues.length === 0 : true // true: Fact values are indices, false: Fact values are FactMetadata.enumValues
10
11 model: fact ? fact.enumStrings : null
12
13 currentIndex: fact ? (indexModel ? fact.value : fact.enumIndex) : 0
14
15 function _updateCurrentIndex() {
16 Qt.callLater(function() {
17 currentIndex = Qt.binding(function() {
18 return fact ? (indexModel ? fact.value : fact.enumIndex) : 0
19 })
20 })
21 }
22
23 onModelChanged: {
24 // When the model changes, the index gets reset to 0, so re-establish
25 // the declarative currentIndex binding. callLater() avoids a binding
26 // loop since enumIndex could trigger a model change.
27 _updateCurrentIndex()
28 }
29
30 onFactChanged: {
31 // When the fact changes to a different Fact object with the same
32 // enumStrings, modelChanged does not fire, so the binding must be
33 // re-established here to point at the new Fact.
34 _updateCurrentIndex()
35 }
36
37 onActivated: (index) => {
38 if (indexModel) {
39 fact.value = index
40 } else {
41 fact.value = fact.enumValues[index]
42 }
43 }
44}