QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FactSlider.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7
8ValueSlider {
9 id: control
10 value: _fact.value
11 from: _fact.min
12 to: _fact.max
13 unitsString: _fact.units
14 decimalPlaces: _fact.decimalPlaces
15
16 required property Fact fact
17
18 property Fact _nullFact: Fact { }
19 property Fact _fact: fact ? fact : _nullFact
20
21 property bool _loadComplete: false
22
23 Component.onCompleted: {
24 _loadComplete = true
25 if (fact && fact.minIsDefaultForType && fact.min == from) {
26 console.error("FactSlider: Fact is minIsDefaultForType", _fact.name)
27 }
28 if (fact && fact.maxIsDefaultForType && fact.max == to) {
29 console.error("FactSlider: Fact is maxIsDefaultForType", _fact.name)
30 }
31 }
32
33 Component.onDestruction: {
34 if (updateTimer.running) {
35 updateTimer.stop()
36 _fact.value = control.value
37 }
38 }
39
40 Timer {
41 id: updateTimer
42 interval: 500
43 repeat: false
44 running: false
45 onTriggered: _fact.value = control.value
46 }
47
48 onValueChanged: {
49 // We don't want to spam the vehicle with parameter updates so we coalesce multiple updated with a timer
50 // We also don't want to update the fact value until we know the control has finished initialization. During
51 // initialization the fact value can go through slight changes due to cooked value floating point inprecision.
52 if (_loadComplete) {
53 updateTimer.start()
54 }
55 }
56}