QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PreFlightCheckButton.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3
4import QGroundControl
5import QGroundControl.Controls
6
7/// The PreFlightCheckButton supports creating a button which the user then has to verify/click to confirm a check.
8/// It also supports failing the check based on values from within the system: telemetry or QGC app values. These
9/// controls are normally placed within a PreFlightCheckGroup.
10///
11/// Two types of checks may be included on the button:
12/// Manual - This is simply a check which the user must verify and confirm. It is not based on any system state.
13/// Telemetry - This type of check can fail due to some state within the system. A telemetry check failure can be
14/// a hard stop in that there is no way to pass the checklist until the system state resolves itself.
15/// Or it can also optionally be override by the user.
16/// If a button uses both manual and telemetry checks, the telemetry check takes precendence and must be passed first.
17QGCButton {
18 property string name: ""
19 property string manualText: "" ///< text to show for a manual check, "" signals no manual check
20 property string telemetryTextFailure ///< text to show if telemetry check failed (override not allowed)
21 property bool telemetryFailure: false ///< true: telemetry check failing, false: telemetry check passing
22 property bool allowTelemetryFailureOverride: false ///< true: user can click past telemetry failure
23 property bool passed: _manualState === _statePassed && _telemetryState === _statePassed
24 property bool failed: _manualState === _stateFailed || _telemetryState === _stateFailed
25
26 property int _manualState: manualText === "" ? _statePassed : _statePending
27 property int _telemetryState: _statePassed
28 property int _horizontalPadding: ScreenTools.defaultFontPixelWidth
29 property int _verticalPadding: Math.round(ScreenTools.defaultFontPixelHeight / 2)
30 property real _stateFlagWidth: ScreenTools.defaultFontPixelWidth * 4
31
32 readonly property int _statePending: 0 ///< Telemetry check is failing or manual check not yet verified, user can click to make it pass
33 readonly property int _stateFailed: 1 ///< Telemetry check is failing, user cannot click to make it pass
34 readonly property int _statePassed: 2 ///< Check has passed
35
36 readonly property color _passedColor: "#86cc6a"
37 readonly property color _pendingColor: "#f7a81f"
38 readonly property color _failedColor: "#c31818"
39
40 property string _text: "<b>" + name +"</b>: " +
41 ((_telemetryState !== _statePassed) ?
42 telemetryTextFailure :
43 (_manualState !== _statePassed ? manualText : qsTr("Passed")))
44 property color _color: _telemetryState === _statePassed && _manualState === _statePassed ?
45 _passedColor :
46 (_telemetryState == _stateFailed ?
47 _failedColor :
48 (_telemetryState === _statePending || _manualState === _statePending ?
49 _pendingColor :
50 _failedColor))
51
52 width: 40 * ScreenTools.defaultFontPixelWidth
53 topPadding: _verticalPadding
54 bottomPadding: _verticalPadding
55 leftPadding: (_horizontalPadding * 2) + _stateFlagWidth
56 rightPadding: _horizontalPadding
57
58 background: Rectangle {
59 color: qgcPal.button
60 border.color: qgcPal.button;
61
62 Rectangle {
63 color: _color
64 anchors.left: parent.left
65 anchors.top: parent.top
66 anchors.bottom: parent.bottom
67 width: _stateFlagWidth
68 }
69 }
70
71 contentItem: QGCLabel {
72 wrapMode: Text.WordWrap
73 horizontalAlignment: Text.AlignHCenter
74 color: qgcPal.buttonText
75 text: _text
76 }
77
78 function _updateTelemetryState() {
79 if (telemetryFailure) {
80 // We have a new telemetry failure, reset user pass
81 _telemetryState = allowTelemetryFailureOverride ? _statePending : _stateFailed
82 } else {
83 _telemetryState = _statePassed
84 }
85 }
86
87 onTelemetryFailureChanged: _updateTelemetryState()
88 onAllowTelemetryFailureOverrideChanged: _updateTelemetryState()
89
90 onClicked: {
91 if (telemetryFailure && !allowTelemetryFailureOverride) {
92 // No way to proceed past this failure
93 return
94 }
95 if (telemetryFailure && allowTelemetryFailureOverride && _telemetryState !== _statePassed) {
96 // User is allowed to proceed past this failure
97 _telemetryState = _statePassed
98 return
99 }
100 if (manualText !== "") {
101 // User is confirming a manual check
102 _manualState = (_manualState === _statePassed) ? _statePending : _statePassed
103 }
104 }
105
106 onPassedChanged: callButtonPassedChanged()
107 onParentChanged: callButtonPassedChanged()
108
109 function callButtonPassedChanged() {
110 if (typeof parent.buttonPassedChanged === "function") {
111 parent.buttonPassedChanged()
112 }
113 }
114
115 function reset() {
116 _manualState = manualText === "" ? _statePassed : _statePending
117 if (telemetryFailure) {
118 _telemetryState = allowTelemetryFailureOverride ? _statePending : _stateFailed
119 } else {
120 _telemetryState = _statePassed
121 }
122 }
123
124}