QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MultiVehicleSelector.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.FactControls
7import QGroundControl.Controls
8
9RowLayout {
10 id: control
11 spacing: 0
12
13 property bool showIndicator: _multipleVehicles
14 property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
15 property bool _multipleVehicles: QGroundControl.multiVehicleManager.vehicles.count > 1
16 property var _vehicleModel: [ ]
17
18 Connections {
19 target: QGroundControl.multiVehicleManager.vehicles
20 function onCountChanged(count) { _updateVehicleModel() }
21 }
22
23 Component.onCompleted: _updateVehicleModel()
24 on_ActiveVehicleChanged: _updateVehicleModel()
25
26 RowLayout {
27 Layout.fillWidth: true
28
29 QGCColoredImage {
30 width: ScreenTools.defaultFontPixelWidth * 4
31 height: ScreenTools.defaultFontPixelHeight * 1.33
32 fillMode: Image.PreserveAspectFit
33 mipmap: true
34 color: qgcPal.text
35 source: "/InstrumentValueIcons/airplane.svg"
36 }
37
38 QGCLabel {
39 text: _activeVehicle ? qsTr("Vehicle") + " " + _activeVehicle.id : qsTr("N/A")
40 font.pointSize: ScreenTools.mediumFontPointSize
41 Layout.alignment: Qt.AlignCenter
42
43 MouseArea {
44 anchors.fill: parent
45 onClicked: mainWindow.showIndicatorDrawer(vehicleSelectorDrawer, control)
46 }
47 }
48 }
49
50 Component {
51 id: vehicleSelectorDrawer
52
53 ToolIndicatorPage {
54 showExpand: true
55
56 contentComponent: Component {
57 ColumnLayout {
58 spacing: ScreenTools.defaultFontPixelWidth / 2
59
60 Repeater {
61 model: _vehicleModel
62
63 QGCButton {
64 text: modelData
65 Layout.fillWidth: true
66
67 onClicked: {
68 var vehicleId = modelData.split(" ")[1]
69 var vehicle = QGroundControl.multiVehicleManager.getVehicleById(vehicleId)
70 QGroundControl.multiVehicleManager.activeVehicle = vehicle
71 mainWindow.closeIndicatorDrawer()
72 }
73 }
74 }
75 }
76 }
77
78 expandedComponent: Component {
79 SettingsGroupLayout {
80 Layout.fillWidth: true
81
82 FactCheckBoxSlider {
83 Layout.fillWidth: true
84 text: qsTr("Enable Multi-Vehicle Panel")
85 fact: _enableMultiVehiclePanel
86 visible: _enableMultiVehiclePanel.visible
87
88 property Fact _enableMultiVehiclePanel: QGroundControl.settingsManager.appSettings.enableMultiVehiclePanel
89 }
90 }
91 }
92 }
93 }
94
95 function _updateVehicleModel() {
96 var newModel = [ ]
97 if (_multipleVehicles) {
98 for (var i = 0; i < QGroundControl.multiVehicleManager.vehicles.count; i++) {
99 var vehicle = QGroundControl.multiVehicleManager.vehicles.get(i)
100 newModel.push(qsTr("Vehicle") + " " + vehicle.id)
101 }
102 }
103 _vehicleModel = newModel
104 }
105}