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 onModelChanged: {
16 // When the model changes, the index gets reset to 0, so make sure to
17 // restore it correctly.
18 // Since enumIndex could trigger a model change, we use callLater() to
19 // avoid an event binding loop (the 2. call will for certain not trigger
20 // another model change)
21 Qt.callLater(function() {
22 currentIndex = fact ? (indexModel ? fact.value : fact.enumIndex) : 0
23 })
24 }
25
26 onActivated: (index) => {
27 if (indexModel) {
28 fact.value = index
29 } else {
30 fact.value = fact.enumValues[index]
31 }
32 }
33}