QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
AnalyzeView.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3
4import QGroundControl
5import QGroundControl.Controls
6
7Rectangle {
8 id: _root
9 color: qgcPal.window
10 z: QGroundControl.zOrderTopMost
11
12 readonly property real _defaultTextHeight: ScreenTools.defaultFontPixelHeight
13 readonly property real _defaultTextWidth: ScreenTools.defaultFontPixelWidth
14 readonly property real _horizontalMargin: _defaultTextWidth / 2
15 readonly property real _verticalMargin: _defaultTextHeight / 2
16
17 property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
18 property var _currentPage: null
19 property var _currentItem: null
20 // Destroy the in-panel page item while panelContainer is still alive, before the
21 // loader clears the source and tears down this component.
22 Component.onDestruction: mainWindow.destroyInPanelAnalyzePage()
23
24 function _loadPage(source) {
25 // Clear reference before calling mainWindow.createAnalyzePage (which destroys the old item).
26 _currentItem = null
27 if (source !== "") {
28 // mainWindow creates and owns the item (QObject parent = mainWindow) so it
29 // survives AnalyzeView being unloaded in the popped-out case.
30 // anchors.fill: parent in AnalyzePage.qml automatically fills panelContainer.
31 _currentItem = mainWindow.createAnalyzePage(source)
32 if (_currentItem) {
33 _currentItem.parent = panelContainer
34 }
35 } else {
36 mainWindow.destroyInPanelAnalyzePage()
37 }
38 }
39
40 function _updatePanelSource() {
41 if (_currentPage) {
42 if (_currentPage.requiresVehicle && !_activeVehicle) {
43 _loadPage("")
44 } else {
45 _loadPage(_currentPage.url)
46 }
47 }
48 }
49
50 on_ActiveVehicleChanged: {
51 if (_currentPage && _currentPage.requiresVehicle) {
52 _loadPage("")
53 if (_activeVehicle) {
54 Qt.callLater(_updatePanelSource)
55 }
56 }
57 }
58
59 // This need to block click event leakage to underlying map.
60 DeadMouseArea {
61 anchors.fill: parent
62 }
63
64 QGCFlickable {
65 id: buttonScroll
66 width: buttonColumn.width
67 anchors.topMargin: _defaultTextHeight / 2
68 anchors.top: parent.top
69 anchors.bottom: parent.bottom
70 anchors.leftMargin: _horizontalMargin
71 anchors.left: parent.left
72 contentHeight: buttonColumn.height
73 flickableDirection: Flickable.VerticalFlick
74 clip: true
75
76 Column {
77 id: buttonColumn
78 width: _maxButtonWidth
79 spacing: _defaultTextHeight / 2
80
81 property real _maxButtonWidth: {
82 var maxW = 0
83 for (var i = 0; i < buttonRepeater.count; i++) {
84 var item = buttonRepeater.itemAt(i)
85 if (item) maxW = Math.max(maxW, item.implicitWidth)
86 }
87 return maxW
88 }
89
90 Repeater {
91 id: buttonRepeater
92 model: QGroundControl.corePlugin ? QGroundControl.corePlugin.analyzePages : []
93
94 Component.onCompleted: {
95 if (count > 0) {
96 _currentPage = QGroundControl.corePlugin.analyzePages[0]
97 panelContainer.title = _currentPage.title
98 _updatePanelSource()
99 }
100 }
101
102 SubMenuButton {
103 objectName: "analyzeButton_" + modelData.title
104 imageResource: modelData.icon
105 text: modelData.title
106 width: buttonColumn._maxButtonWidth
107 checked: _currentPage === modelData
108
109 onClicked: {
110 if (!mainWindow.allowViewSwitch()) {
111 return
112 }
113 _currentPage = modelData
114 panelContainer.title = modelData.title
115 _updatePanelSource()
116 }
117 }
118 }
119 }
120 }
121
122 Rectangle {
123 id: divider
124 anchors.topMargin: _verticalMargin
125 anchors.bottomMargin: _verticalMargin
126 anchors.leftMargin: _horizontalMargin
127 anchors.left: buttonScroll.right
128 anchors.top: parent.top
129 anchors.bottom: parent.bottom
130 width: 1
131 color: qgcPal.windowShade
132 }
133
134 Item {
135 id: panelContainer
136 anchors.topMargin: _verticalMargin
137 anchors.bottomMargin: _verticalMargin
138 anchors.leftMargin: _horizontalMargin
139 anchors.rightMargin: _horizontalMargin
140 anchors.left: divider.right
141 anchors.right: parent.right
142 anchors.top: parent.top
143 anchors.bottom: parent.bottom
144
145 property string title
146
147 Connections {
148 target: _currentItem
149
150 function onPopout() {
151 var existingItem = _currentItem
152 var pageTitle = panelContainer.title
153 var pageSource = _currentPage.url
154 var requiresVehicle = _currentPage ? _currentPage.requiresVehicle : false
155 // Clear references before handing item to the popup window.
156 _currentItem = null
157 // Tell mainWindow this item has moved to a popup so it is not destroyed
158 // when AnalyzeView is torn down.
159 mainWindow.analyzePageMovedToPopup()
160 existingItem.visible = false
161 // Hand the existing item to the popout window.
162 mainWindow.createWindowedAnalyzePage(pageTitle, pageSource, requiresVehicle, existingItem)
163 // Create a fresh in-panel instance.
164 _loadPage(pageSource)
165 }
166 }
167 }
168
169 QGCLabel {
170 anchors.centerIn: panelContainer
171 text: qsTr("Requires a connected vehicle")
172 visible: _currentPage && _currentPage.requiresVehicle && !_activeVehicle
173 }
174}