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 spacing: 0.8 * ScreenTools.defaultFontPixelWidth
12
13 property real _verticalMargin: ScreenTools.defaultFontPixelHeight / 2
14
15 Loader {
16 id: modelContainer
17 source: "qrc:/qml/QGroundControl/FlyView/DefaultChecklist.qml"
18 }
19
20 property bool allChecksPassed: false
21 property var vehicleCopy: globals.activeVehicle
22
23 onVehicleCopyChanged: {
24 if (checkListRepeater.model) {
25 checkListRepeater.model.reset()
26 }
27 }
28
29 onAllChecksPassedChanged: {
30 if (allChecksPassed) {
31 globals.activeVehicle.checkListState = Vehicle.CheckListPassed
32 } else {
33 globals.activeVehicle.checkListState = Vehicle.CheckListFailed
34 }
35 }
36
37 function _handleGroupPassedChanged(index, passed) {
38 if (passed) {
39 // Collapse current group
40 var group = checkListRepeater.itemAt(index)
41 group._checked = false
42 // Expand next group
43 if (index + 1 < checkListRepeater.count) {
44 group = checkListRepeater.itemAt(index + 1)
45 group.enabled = true
46 group._checked = true
47 }
48 }
49
50 // Walk the list and check if any group is failing
51 var allPassed = true
52 for (var i=0; i < checkListRepeater.count; i++) {
53 if (!checkListRepeater.itemAt(i).passed) {
54 allPassed = false
55 break
56 }
57 }
58 allChecksPassed = allPassed;
59 }
60
61 //-- Pick a checklist model that matches the current airframe type (if any)
62 function _updateModel() {
63 var vehicle = globals.activeVehicle
64 if (!vehicle) {
65 vehicle = QGroundControl.multiVehicleManager.offlineEditingVehicle
66 }
67
68 if(vehicle.multiRotor) {
69 modelContainer.source = "qrc:/qml/QGroundControl/FlyView/MultiRotorChecklist.qml"
70 } else if(vehicle.vtol) {
71 modelContainer.source = "qrc:/qml/QGroundControl/FlyView/VTOLChecklist.qml"
72 } else if(vehicle.rover) {
73 modelContainer.source = "qrc:/qml/QGroundControl/FlyView/RoverChecklist.qml"
74 } else if(vehicle.sub) {
75 modelContainer.source = "qrc:/qml/QGroundControl/FlyView/SubChecklist.qml"
76 } else if(vehicle.fixedWing) {
77 modelContainer.source = "qrc:/qml/QGroundControl/FlyView/FixedWingChecklist.qml"
78 } else {
79 modelContainer.source = "qrc:/qml/QGroundControl/FlyView/DefaultChecklist.qml"
80 }
81 return
82 }
83
84 Component.onCompleted: {
85 _updateModel()
86 }
87
88 onVisibleChanged: {
89 if(globals.activeVehicle) {
90 if(visible) {
91 _updateModel()
92 }
93 }
94 }
95
96 // We delay the updates when a group passes so the user can see all items green for a moment prior to hiding
97 Timer {
98 id: delayedGroupPassed
99 interval: 750
100
101 property int index
102
103 onTriggered: _handleGroupPassedChanged(index, true /* passed */)
104 }
105
106 function groupPassedChanged(index, passed) {
107 if (passed) {
108 delayedGroupPassed.index = index
109 delayedGroupPassed.restart()
110 } else {
111 _handleGroupPassedChanged(index, passed)
112 }
113 }
114
115 // Header/title of checklist
116 RowLayout {
117 Layout.fillWidth: true
118 height: 1.75 * ScreenTools.defaultFontPixelHeight
119 spacing: 0
120
121 QGCLabel {
122 Layout.fillWidth: true
123 text: allChecksPassed ? qsTr("(Passed)") : qsTr("In Progress")
124 font.pointSize: ScreenTools.mediumFontPointSize
125 }
126 QGCButton {
127 width: 1.2 * ScreenTools.defaultFontPixelHeight
128 height: 1.2 * ScreenTools.defaultFontPixelHeight
129 Layout.alignment: Qt.AlignVCenter
130 onClicked: checkListRepeater.model.reset()
131
132 QGCColoredImage {
133 source: "/qmlimages/MapSyncBlack.svg"
134 color: qgcPal.buttonText
135 anchors.fill: parent
136 }
137 }
138 }
139
140 // All check list items
141 Repeater {
142 id: checkListRepeater
143 model: modelContainer.item.model
144 }
145}