6import QGroundControl.Controls
8import "PX4SensorsRows.js" as SensorsRows
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.
15 /// A row from PX4SensorsRows.js calibrationRows()
16 required property var row
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: ""
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
34 property var initialValues
36 signal calibrateClicked
38 signal alternateClicked
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: {
53 return qsTr("Keep the vehicle still.")
56 return calibrationState !== "ok" || gps.level !== "good" ? gps.message : ""
58 return _done ? "" : row.hint
60 readonly property color _hintColor: {
61 if (_failed || (row.gps && gps.level === "none")) {
62 return qgcPal.errorText
64 return row.gps && gps.level === "poor" ? qgcPal.warningText : qgcPal.textSecondary
67 objectName: "sensors_row_" + row.id
70 active: calibrationState !== "optional"
71 activeColor: calibrationState === "needs" ? qgcPal.colorRed : qgcPal.colorGreen
73 QGCPalette { id: qgcPal }
76 text: control.row.description
81 caption: qsTr("Calibration")
84 spacing: ScreenTools.defaultFontPixelWidth * 2
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)
97 color: control._failed || control.calibrationState === "needs" ? qgcPal.errorText :
98 control._busy ? qgcPal.textPrimary :
99 control._done || control.calibrationState === "ok" ? qgcPal.successText : qgcPal.textSecondary
102 id: calibratingMetrics
103 font: statusLabel.font
104 text: qsTr("Calibrating…")
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()
119 // The width comes from the status line, so these fill it
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
130 objectName: "sensors_hint_" + control.row.id
131 Layout.preferredWidth: 0
133 color: control._hintColor
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()
145 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 28
146 text: control.row.alternate ? control.row.alternate.note : ""
151 objectName: "sensors_gpsCell"
153 visible: control.row.gps === true
161 model: control.row.cells
165 factFor: control.factFor
166 initialValues: control.initialValues
167 objectNamePrefix: "sensors"
168 enabled: control.paramsEnabled
170 required property var modelData