QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PreFlightCheckList.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQml.Models
4import QtQuick.Layouts
5
6import QGroundControl
7import QGroundControl.Controls
8import QGroundControl.FlyView
9
10ColumnLayout {
11 objectName: "preFlightCheckList"
12 spacing: 0.8 * ScreenTools.defaultFontPixelWidth
13
14 property real _verticalMargin: ScreenTools.defaultFontPixelHeight / 2
15 property Item _firstHeader: null ///< SectionHeader of the first group
16 readonly property real _headerLineGap: 2
17
18 Loader {
19 id: modelContainer
20 source: "qrc:/qml/QGroundControl/FlyView/DefaultChecklist.qml"
21 }
22
23 property bool allChecksPassed: false
24 property bool prerequisitesPassed: true ///< Checks which must pass before this list's, such as the pre-vehicle checks
25 property var vehicleCopy: globals.activeVehicle
26
27 readonly property bool checklistPassed: allChecksPassed && prerequisitesPassed
28
29 onVehicleCopyChanged: {
30 if (checkListRepeater.model) {
31 checkListRepeater.model.reset()
32 }
33 }
34
35 onChecklistPassedChanged: {
36 if (checklistPassed) {
37 globals.activeVehicle.checkListState = Vehicle.CheckListPassed
38 } else {
39 globals.activeVehicle.checkListState = Vehicle.CheckListFailed
40 }
41 }
42
43 Binding {
44 target: checkListRepeater.model
45 property: "prerequisitesPassed"
46 value: prerequisitesPassed
47 when: !!checkListRepeater.model
48 }
49
50 function reset() {
51 if (checkListRepeater.model) {
52 checkListRepeater.model.reset()
53 }
54 }
55
56 function groupPassedChanged() {
57 const model = checkListRepeater.model
58 if (!model) {
59 return
60 }
61 model.updateGroupLocks()
62 allChecksPassed = model.isPassed()
63 }
64
65 //-- Pick a checklist model that matches the current airframe type (if any)
66 function _updateModel() {
67 var vehicle = globals.activeVehicle
68 if (!vehicle) {
69 vehicle = QGroundControl.multiVehicleManager.offlineEditingVehicle
70 }
71
72 if(vehicle.multiRotor) {
73 modelContainer.source = "qrc:/qml/QGroundControl/FlyView/MultiRotorChecklist.qml"
74 } else if(vehicle.vtol) {
75 modelContainer.source = "qrc:/qml/QGroundControl/FlyView/VTOLChecklist.qml"
76 } else if(vehicle.rover) {
77 modelContainer.source = "qrc:/qml/QGroundControl/FlyView/RoverChecklist.qml"
78 } else if(vehicle.sub) {
79 modelContainer.source = "qrc:/qml/QGroundControl/FlyView/SubChecklist.qml"
80 } else if(vehicle.fixedWing) {
81 modelContainer.source = "qrc:/qml/QGroundControl/FlyView/FixedWingChecklist.qml"
82 } else {
83 modelContainer.source = "qrc:/qml/QGroundControl/FlyView/DefaultChecklist.qml"
84 }
85 return
86 }
87
88 Component.onCompleted: {
89 _updateModel()
90 }
91
92 onVisibleChanged: {
93 if(globals.activeVehicle) {
94 if(visible) {
95 _updateModel()
96 }
97 }
98 }
99
100 // Zero-height row so the Reset button floats over the first group header's empty right side
101 Item {
102 Layout.fillWidth: true
103 Layout.preferredHeight: 0
104 Layout.bottomMargin: -parent.spacing
105 z: 1
106
107 QGCButton {
108 objectName: "preFlightCheckListResetButton"
109 small: true
110 anchors.right: parent.right
111 y: _firstHeader ? Math.max(0, _firstHeader.height - _firstHeader.bottomPadding - height - _headerLineGap) : 0
112 text: qsTr("Reset")
113 onClicked: reset()
114 }
115 }
116
117 // All check list items
118 Repeater {
119 id: checkListRepeater
120 model: modelContainer.item.model
121
122 onItemAdded: (index, item) => {
123 if (index === 0 && item.headerItem) {
124 _firstHeader = item.headerItem
125 // Nothing precedes the first group, so drop the header's separation from the tab bar
126 _firstHeader.showSpacer = false
127 _firstHeader.topPadding = 0
128 }
129 }
130 }
131}