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 signal popout()
13
14 readonly property real _defaultTextHeight: ScreenTools.defaultFontPixelHeight
15 readonly property real _defaultTextWidth: ScreenTools.defaultFontPixelWidth
16 readonly property real _horizontalMargin: _defaultTextWidth / 2
17 readonly property real _verticalMargin: _defaultTextHeight / 2
18
19 property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
20 property var _currentPage: null
21 property var _currentItem: null
22
23 function _loadPage(source) {
24 if (_currentItem) {
25 _currentItem.destroy()
26 _currentItem = null
27 }
28 if (source !== "") {
29 var component = Qt.createComponent(source)
30 if (component.status === Component.Ready) {
31 _currentItem = component.createObject(panelContainer)
32 }
33 }
34 }
35
36 function _updatePanelSource() {
37 if (_currentPage) {
38 if (_currentPage.requiresVehicle && !_activeVehicle) {
39 _loadPage("")
40 } else {
41 _loadPage(_currentPage.url)
42 }
43 }
44 }
45
46 on_ActiveVehicleChanged: {
47 if (_currentPage && _currentPage.requiresVehicle) {
48 _loadPage("")
49 if (_activeVehicle) {
50 Qt.callLater(_updatePanelSource)
51 }
52 }
53 }
54
55 // This need to block click event leakage to underlying map.
56 DeadMouseArea {
57 anchors.fill: parent
58 }
59
60 QGCFlickable {
61 id: buttonScroll
62 width: buttonColumn.width
63 anchors.topMargin: _defaultTextHeight / 2
64 anchors.top: parent.top
65 anchors.bottom: parent.bottom
66 anchors.leftMargin: _horizontalMargin
67 anchors.left: parent.left
68 contentHeight: buttonColumn.height
69 flickableDirection: Flickable.VerticalFlick
70 clip: true
71
72 Column {
73 id: buttonColumn
74 width: _maxButtonWidth
75 spacing: _defaultTextHeight / 2
76
77 property real _maxButtonWidth: {
78 var maxW = 0
79 for (var i = 0; i < buttonRepeater.count; i++) {
80 var item = buttonRepeater.itemAt(i)
81 if (item) maxW = Math.max(maxW, item.implicitWidth)
82 }
83 return maxW
84 }
85
86 Repeater {
87 id: buttonRepeater
88 model: QGroundControl.corePlugin ? QGroundControl.corePlugin.analyzePages : []
89
90 Component.onCompleted: {
91 if (count > 0) {
92 itemAt(0).checked = true
93 _currentPage = QGroundControl.corePlugin.analyzePages[0]
94 panelContainer.title = _currentPage.title
95 _updatePanelSource()
96 }
97 }
98
99 SubMenuButton {
100 imageResource: modelData.icon
101 autoExclusive: true
102 text: modelData.title
103 width: buttonColumn._maxButtonWidth
104
105 onClicked: {
106 _currentPage = modelData
107 panelContainer.title = modelData.title
108 checked = true
109 _updatePanelSource()
110 }
111 }
112 }
113 }
114 }
115
116 Rectangle {
117 id: divider
118 anchors.topMargin: _verticalMargin
119 anchors.bottomMargin: _verticalMargin
120 anchors.leftMargin: _horizontalMargin
121 anchors.left: buttonScroll.right
122 anchors.top: parent.top
123 anchors.bottom: parent.bottom
124 width: 1
125 color: qgcPal.windowShade
126 }
127
128 Item {
129 id: panelContainer
130 anchors.topMargin: _verticalMargin
131 anchors.bottomMargin: _verticalMargin
132 anchors.leftMargin: _horizontalMargin
133 anchors.rightMargin: _horizontalMargin
134 anchors.left: divider.right
135 anchors.right: parent.right
136 anchors.top: parent.top
137 anchors.bottom: parent.bottom
138
139 property string title
140
141 Connections {
142 target: _currentItem
143 function onPopout() {
144 var existingItem = _currentItem
145 var pageTitle = panelContainer.title
146 var pageSource = _currentPage.url
147 var requiresVehicle = _currentPage ? _currentPage.requiresVehicle : false
148 // Release ownership without destroying
149 _currentItem = null
150 existingItem.visible = false
151 // Hand the existing item to the popout window
152 mainWindow.createWindowedAnalyzePage(pageTitle, pageSource, requiresVehicle, existingItem)
153 // Create a fresh instance in-place
154 _loadPage(pageSource)
155 }
156 }
157 }
158
159 QGCLabel {
160 anchors.centerIn: panelContainer
161 text: qsTr("Requires a connected vehicle")
162 visible: _currentPage && _currentPage.requiresVehicle && !_activeVehicle
163 }
164}