QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SensorsCalibrationRow.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7
8import "PX4SensorsRows.js" as SensorsRows
9
10/// A calibration row of the Sensors page: its status, the button which starts it and, for calibrations which run in the
11/// row, their progress, hint and result. It does not start anything itself, the page handles the signals.
12ConfigRow {
13 id: control
14
15 /// A row from PX4SensorsRows.js calibrationRows()
16 required property var row
17
18 /// "ok", "needs" or "optional", from SensorsRows.calibrationState()
19 property string calibrationState: "optional"
20 /// For a calibration which runs in the row: "idle", "running", "done" or "failed"
21 property string inlineState: "idle"
22 property string inlineMessage: ""
23 /// 0 to 1
24 property real progress: 0
25 /// From SensorsRows.gpsReadiness(), used by rows which show the GPS
26 property var gps: SensorsRows.gpsReadiness(0, 0, NaN)
27 /// False while something else prevents this calibration from starting, such as another calibration running
28 property bool calibrateEnabled: true
29 /// False until the vehicle has started a calibration which runs in the row, and while it is cancelling
30 property bool cancelEnabled: false
31 /// False while a calibration is running, so the parameters it changes cannot be edited
32 property bool paramsEnabled: true
33 property var factFor
34 property var initialValues
35
36 signal calibrateClicked
37 signal cancelClicked
38 signal alternateClicked
39
40 readonly property bool _inline: row.inline === true
41 readonly property bool _busy: inlineState === "running"
42 readonly property bool _failed: inlineState === "failed"
43 readonly property bool _done: inlineState === "done"
44 readonly property string _buttonName: "sensorsSetup_calibrate" + row.id.charAt(0).toUpperCase() + row.id.slice(1)
45 readonly property string _hint: {
46 if (!_inline) {
47 return ""
48 }
49 if (_failed) {
50 return inlineMessage
51 }
52 if (_busy) {
53 return qsTr("Keep the vehicle still.")
54 }
55 if (row.gps) {
56 return calibrationState !== "ok" || gps.level !== "good" ? gps.message : ""
57 }
58 return _done ? "" : row.hint
59 }
60 readonly property color _hintColor: {
61 if (_failed || (row.gps && gps.level === "none")) {
62 return qgcPal.errorText
63 }
64 return row.gps && gps.level === "poor" ? qgcPal.warningText : qgcPal.textSecondary
65 }
66
67 objectName: "sensors_row_" + row.id
68 title: row.title
69 params: row.params
70 active: calibrationState !== "optional"
71 activeColor: calibrationState === "needs" ? qgcPal.colorRed : qgcPal.colorGreen
72
73 QGCPalette { id: qgcPal }
74
75 ConfigNote {
76 text: control.row.description
77 }
78
79 cellsData: [
80 QGCCaptionCell {
81 caption: qsTr("Calibration")
82
83 RowLayout {
84 spacing: ScreenTools.defaultFontPixelWidth * 2
85
86 QGCLabel {
87 id: statusLabel
88 objectName: "sensors_status_" + control.row.id
89 Layout.fillWidth: true
90 // Calibrated and Calibrating are the same width
91 Layout.minimumWidth: Math.ceil(calibratingMetrics.advanceWidth)
92 text: control._busy ? qsTr("Calibrating…") :
93 control._failed ? qsTr("Calibration failed") :
94 control._done ? qsTr("Calibrated") :
95 SensorsRows.calibrationStatusText(control.row, control.calibrationState)
96 font.bold: true
97 color: control._failed || control.calibrationState === "needs" ? qgcPal.errorText :
98 control._busy ? qgcPal.textPrimary :
99 control._done || control.calibrationState === "ok" ? qgcPal.successText : qgcPal.textSecondary
100
101 TextMetrics {
102 id: calibratingMetrics
103 font: statusLabel.font
104 text: qsTr("Calibrating…")
105 }
106 }
107
108 QGCButton {
109 objectName: control._buttonName
110 text: control._busy ? qsTr("Cancel") : control._failed ? qsTr("Retry") : qsTr("Calibrate")
111 primary: control._failed || control.calibrationState === "needs" ||
112 (control.row.gps === true && control.calibrationState !== "ok" && control.gps.ready)
113 enabled: control._busy ? control.cancelEnabled :
114 control.calibrateEnabled && (control.row.gps !== true || control.gps.ready)
115 onClicked: control._busy ? control.cancelClicked() : control.calibrateClicked()
116 }
117 }
118
119 // The width comes from the status line, so these fill it
120 ProgressBar {
121 objectName: "sensors_progress_" + control.row.id
122 Layout.fillWidth: true
123 Layout.preferredWidth: 0
124 visible: control._busy
125 value: control.progress
126 indeterminate: control.row.progress !== true
127 }
128
129 ConfigNote {
130 objectName: "sensors_hint_" + control.row.id
131 Layout.preferredWidth: 0
132 text: control._hint
133 color: control._hintColor
134 }
135
136 QGCButton {
137 objectName: control._buttonName + "Alternate"
138 text: control.row.alternate ? control.row.alternate.label : ""
139 visible: control.row.alternate !== undefined
140 enabled: control.calibrateEnabled
141 onClicked: control.alternateClicked()
142 }
143
144 ConfigNote {
145 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 28
146 text: control.row.alternate ? control.row.alternate.note : ""
147 }
148 },
149
150 QGCCaptionCell {
151 objectName: "sensors_gpsCell"
152 caption: qsTr("GPS")
153 visible: control.row.gps === true
154
155 SensorsGpsStatus {
156 gps: control.gps
157 }
158 },
159
160 Repeater {
161 model: control.row.cells
162
163 ConfigParamCell {
164 cell: modelData
165 factFor: control.factFor
166 initialValues: control.initialValues
167 objectNamePrefix: "sensors"
168 enabled: control.paramsEnabled
169
170 required property var modelData
171 }
172 }
173 ]
174}