QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PX4FailsafesComponent.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Layouts
3
4import QGroundControl
5import QGroundControl.Controls
6import QGroundControl.FactControls
7
8import "PX4ConfigRows.js" as ConfigRows
9import "PX4FailsafeRows.js" as FailsafeRows
10
11SetupPage {
12 id: failsafesPage
13 pageComponent: pageComponent
14
15 property bool _showActiveOnly: false
16 // Parameter values when the page first showed them, so a reboot is only flagged after a change
17 property var _initialValues: Object.create(null)
18
19 readonly property var _vehicle: controller.vehicle
20 readonly property var _allRows: FailsafeRows.failsafeRows()
21 readonly property var _rows: ConfigRows.visibleRows(
22 _allRows,
23 {
24 "multiRotor": _vehicle ? _vehicle.multiRotor : false,
25 "fixedWing": _vehicle ? _vehicle.fixedWing : false,
26 "vtol": _vehicle ? _vehicle.vtol : false
27 },
28 function (name) { return controller.parameterExists(-1, name) })
29 readonly property var _groups: ConfigRows.groupRows(_rows)
30 readonly property int _shownCount: {
31 let count = 0
32 for (const row of _rows) {
33 if (_rowShown(row)) {
34 count++
35 }
36 }
37 return count
38 }
39
40 function _fact(name) {
41 return controller.getParameterFact(-1, name, false)
42 }
43
44 function _rowActive(row) {
45 return ConfigRows.isRowActive(row, function (name) {
46 const fact = _fact(name)
47 return fact ? fact.rawValue : undefined
48 })
49 }
50
51 function _rowShown(row) {
52 return !_showActiveOnly || _rowActive(row)
53 }
54
55 function _groupShown(group) {
56 return group.rows.some(row => _rowShown(row))
57 }
58
59 FactPanelController {
60 id: controller
61 // Reboot-required settings are marked on the page instead
62 suppressRebootMessage: true
63 }
64
65 QGCPalette {
66 id: qgcPal
67 }
68
69 component SeverityDot: Rectangle {
70 property string severity: "none"
71
72 implicitWidth: ScreenTools.defaultFontPixelHeight * 0.5
73 implicitHeight: implicitWidth
74 radius: ScreenTools.defaultBorderRadius / 2
75 color: {
76 switch (severity) {
77 case "warning": return dotPal.colorYellow
78 case "fallback": return dotPal.colorYellowGreen
79 case "hold": return dotPal.colorBlue
80 case "return": return dotPal.accent
81 case "land": return dotPal.colorOrange
82 case "terminate": return dotPal.colorRed
83 default: return dotPal.textSecondary
84 }
85 }
86
87 QGCPalette {
88 id: dotPal
89 }
90 }
91
92 Component {
93 id: pageComponent
94
95 ColumnLayout {
96 width: Math.max(availableWidth, implicitWidth)
97 spacing: _margins
98
99 ConfigRowsPanel {
100 ConfigRowsFilterBar {
101 objectName: "failsafes_filter"
102 filterLabels: [ qsTr("All Failsafes"), qsTr("Active") ]
103 filterIndex: _showActiveOnly ? 1 : 0
104 summary: _showActiveOnly ?
105 qsTr("Showing %1 of %2 failsafes.").arg(_shownCount).arg(_rows.length) :
106 qsTr("Showing all %1 failsafes.").arg(_rows.length)
107 onFilterActivated: (index) => { _showActiveOnly = index === 1 }
108 }
109
110 RowLayout {
111 spacing: ScreenTools.defaultFontPixelWidth * 2
112
113 Repeater {
114 model: [
115 { "severity": "warning", "text": qsTr("Warning") },
116 { "severity": "hold", "text": qsTr("Hold") },
117 { "severity": "fallback", "text": qsTr("Mode fallback") },
118 { "severity": "return", "text": qsTr("Return") },
119 { "severity": "land", "text": qsTr("Land") },
120 { "severity": "terminate", "text": qsTr("Terminate / Disarm") }
121 ]
122
123 RowLayout {
124 spacing: ScreenTools.defaultFontPixelWidth / 2
125
126 required property var modelData
127
128 SeverityDot {
129 severity: modelData.severity
130 }
131
132 QGCLabel {
133 text: modelData.text
134 font.pointSize: ScreenTools.smallFontPointSize
135 color: qgcPal.textSecondary
136 }
137 }
138 }
139 }
140
141 ConfigNote {
142 // A wrapped label reports its unwrapped width as its implicit width, which would widen the page
143 Layout.preferredWidth: 0
144 text: qsTr("Return actions use the settings on the Return & Land page.")
145 }
146
147 ConfigRowGroups {
148 model: _groups
149 groupShown: failsafesPage._groupShown
150 objectNamePrefix: "failsafes"
151
152 rowDelegate: ConfigRow {
153 id: rowLayout
154 objectName: "failsafes_row_" + row.id
155 title: row.title
156 params: row.params
157 active: _rowActive(row)
158 showSeparator: index > 0
159 visible: _rowShown(row)
160
161 required property var modelData
162 required property int index
163
164 readonly property var row: modelData
165
166 QGCChip {
167 text: qsTr("Warning only")
168 visible: rowLayout.row.warnOnly
169 }
170
171 ConfigNote {
172 text: rowLayout.row.description
173 }
174
175 cellsData: Repeater {
176 model: rowLayout.row.cells
177
178 ConfigParamCell {
179 id: paramCell
180 cell: modelData
181 factFor: failsafesPage._fact
182 initialValues: failsafesPage._initialValues
183 objectNamePrefix: "failsafes"
184 enumLeading: modelData.severity !== undefined ? severityDotComponent : null
185
186 required property var modelData
187
188 Component {
189 id: severityDotComponent
190
191 SeverityDot {
192 severity: FailsafeRows.actionSeverity(paramCell.modelData, paramCell.fact ? paramCell.fact.rawValue : undefined)
193 }
194 }
195
196 extraData: RowLayout {
197 spacing: ScreenTools.defaultFontPixelWidth
198 visible: paramCell.modelData.fixed !== undefined
199
200 SeverityDot {
201 severity: FailsafeRows.actionSeverity(paramCell.modelData)
202 visible: paramCell.modelData.severity !== undefined
203 }
204
205 QGCLabel {
206 text: paramCell.modelData.fixed !== undefined ? paramCell.modelData.fixed : ""
207 }
208 }
209 }
210 }
211 }
212 }
213 }
214 }
215 }
216}