From 0e4d256c5bb658bdd1649291fe828cc44304f33e Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Sat, 13 Apr 2019 17:18:53 -0300 Subject: [PATCH] Handle multi vehicles --- qgroundcontrol.qrc | 9 ++- .../PX4/CameraComponentSummary.qml | 1 - src/FirmwarePlugin/FirmwarePlugin.cc | 1 + src/FlightDisplay/MultiVehicleList.qml | 6 +- src/ui/MainQmlWindow.qml | 7 +- src/ui/toolbar/MainToolBarIndicators.qml | 55 ------------- src/ui/toolbar/MultiVehicleSelector.qml | 79 +++++++++++++++++++ 7 files changed, 92 insertions(+), 66 deletions(-) create mode 100644 src/ui/toolbar/MultiVehicleSelector.qml diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index 9d65b3172..d7f24d67c 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -3,18 +3,19 @@ src/FactSystem/FactSystemTest.qml - src/ui/toolbar/MainToolBarIndicators.qml src/ui/toolbar/ArmedIndicator.qml src/ui/toolbar/BatteryIndicator.qml src/ui/toolbar/GPSIndicator.qml src/ui/toolbar/GPSRTKIndicator.qml + src/ui/toolbar/JoystickIndicator.qml + src/ui/toolbar/LinkIndicator.qml + src/ui/toolbar/MainToolBarIndicators.qml src/ui/toolbar/MessageIndicator.qml src/ui/toolbar/ModeIndicator.qml - src/ui/toolbar/VTOLModeIndicator.qml + src/ui/toolbar/MultiVehicleSelector.qml src/ui/toolbar/RCRSSIIndicator.qml src/ui/toolbar/TelemetryRSSIIndicator.qml - src/ui/toolbar/JoystickIndicator.qml - src/ui/toolbar/LinkIndicator.qml + src/ui/toolbar/VTOLModeIndicator.qml src/PlanView/CorridorScanEditor.qml diff --git a/src/AutoPilotPlugins/PX4/CameraComponentSummary.qml b/src/AutoPilotPlugins/PX4/CameraComponentSummary.qml index 8b22d0902..53bb2aecf 100644 --- a/src/AutoPilotPlugins/PX4/CameraComponentSummary.qml +++ b/src/AutoPilotPlugins/PX4/CameraComponentSummary.qml @@ -8,7 +8,6 @@ import QGroundControl.Palette 1.0 Item { anchors.fill: parent - color: qgcPal.windowShadeDark FactPanelController { id: controller; } diff --git a/src/FirmwarePlugin/FirmwarePlugin.cc b/src/FirmwarePlugin/FirmwarePlugin.cc index 1790a4a50..0ab4af0a6 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.cc +++ b/src/FirmwarePlugin/FirmwarePlugin.cc @@ -321,6 +321,7 @@ const QVariantList &FirmwarePlugin::toolBarIndicators(const Vehicle* vehicle) Q_UNUSED(vehicle); //-- Default list of indicators for all vehicles. if(_toolBarIndicatorList.size() == 0) { + _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/MultiVehicleSelector.qml"))); _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/MessageIndicator.qml"))); _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/GPSIndicator.qml"))); _toolBarIndicatorList.append(QVariant::fromValue(QUrl::fromUserInput("qrc:/toolbar/TelemetryRSSIIndicator.qml"))); diff --git a/src/FlightDisplay/MultiVehicleList.qml b/src/FlightDisplay/MultiVehicleList.qml index 2a050c61b..64ffdc12e 100644 --- a/src/FlightDisplay/MultiVehicleList.qml +++ b/src/FlightDisplay/MultiVehicleList.qml @@ -19,7 +19,7 @@ import QGroundControl.Vehicle 1.0 import QGroundControl.FlightMap 1.0 Item { - property var guidedActionsController + property var guidedActionsController property real _margin: ScreenTools.defaultFontPixelWidth / 2 property real _widgetHeight: ScreenTools.defaultFontPixelHeight * 3 @@ -111,7 +111,7 @@ Item { QGCLabel { Layout.alignment: Qt.AlignTop - text: _vehicle.id + text: _vehicle ? _vehicle.id : "" color: _textColor } @@ -128,7 +128,7 @@ Item { QGCLabel { Layout.alignment: Qt.AlignHCenter - text: _vehicle.armed ? qsTr("Armed") : qsTr("Disarmed") + text: _vehicle && _vehicle.armed ? qsTr("Armed") : qsTr("Disarmed") color: _textColor } } diff --git a/src/ui/MainQmlWindow.qml b/src/ui/MainQmlWindow.qml index 5c6a3e0c5..0da3d2518 100644 --- a/src/ui/MainQmlWindow.qml +++ b/src/ui/MainQmlWindow.qml @@ -591,7 +591,7 @@ ApplicationWindow { //-- System Messages property var _messageQueue: [] - property string _systemMessage: "" + property string _systemMessage: "" function showMessage(message) { vehicleMessageArea.close() @@ -616,7 +616,7 @@ ApplicationWindow { y: ScreenTools.defaultFontPixelHeight x: Math.round((mainWindow.width - width) * 0.5) width: mainWindow.width * 0.55 - height: ScreenTools.defaultFontPixelHeight * 4 + height: ScreenTools.defaultFontPixelHeight * 6 modal: false focus: true closePolicy: Popup.CloseOnEscape @@ -640,7 +640,8 @@ ApplicationWindow { //-- Show all messages in queue for (var i = 0; i < mainWindow._messageQueue.length; i++) { var text = mainWindow._messageQueue[i] - mainWindow._systemMessage.append(text) + if(i) mainWindow._systemMessage += "
" + mainWindow._systemMessage += text } //-- Clear it mainWindow._messageQueue = [] diff --git a/src/ui/toolbar/MainToolBarIndicators.qml b/src/ui/toolbar/MainToolBarIndicators.qml index ade60c832..55105f2d7 100644 --- a/src/ui/toolbar/MainToolBarIndicators.qml +++ b/src/ui/toolbar/MainToolBarIndicators.qml @@ -81,61 +81,6 @@ Item { anchors.leftMargin: ScreenTools.defaultFontPixelWidth * 2 spacing: ScreenTools.defaultFontPixelWidth * 1.5 visible: activeVehicle && !communicationLost - - //--------------------------------------------------------------------- - //-- Vehicle Selector - QGCButton { - id: vehicleSelectorButton - width: visible ? 0 : ScreenTools.defaultFontPixelHeight * 8 - text: "Vehicle " + (activeVehicle ? activeVehicle.id : "None") - visible: QGroundControl.multiVehicleManager.vehicles.count > 1 - Layout.alignment: Qt.AlignVCenter - - onClicked: { - vehicleMenu.popup() - } - - Menu { - id: vehicleMenu - } - - Component { - id: vehicleMenuItemComponent - MenuItem { - onTriggered: QGroundControl.multiVehicleManager.activeVehicle = vehicle - property int vehicleId: Number(text.split(" ")[1]) - property var vehicle: QGroundControl.multiVehicleManager.getVehicleById(vehicleId) - } - } - - property var vehicleMenuItems: [] - - function updateVehicleMenu() { - var i; - // Remove old menu items - for (i = 0; i < vehicleMenuItems.length; i++) { - vehicleMenu.removeItem(vehicleMenuItems[i]) - } - vehicleMenuItems.length = 0 - // Add new items - for (i = 0; i < QGroundControl.multiVehicleManager.vehicles.count; i++) { - var vehicle = QGroundControl.multiVehicleManager.vehicles.get(i) - var menuItem = vehicleMenuItemComponent.createObject(null, { "text": "Vehicle " + vehicle.id }) - vehicleMenuItems.push(menuItem) - vehicleMenu.insertItem(i, menuItem) - } - } - - Component.onCompleted: updateVehicleMenu() - - Connections { - target: QGroundControl.multiVehicleManager.vehicles - onCountChanged: vehicleSelectorButton.updateVehicleMenu() - } - } - - //--------------------------------------------------------------------- - //-- Indicators Repeater { model: activeVehicle ? activeVehicle.toolBarIndicators : [] Loader { diff --git a/src/ui/toolbar/MultiVehicleSelector.qml b/src/ui/toolbar/MultiVehicleSelector.qml new file mode 100644 index 000000000..2d5253687 --- /dev/null +++ b/src/ui/toolbar/MultiVehicleSelector.qml @@ -0,0 +1,79 @@ +/**************************************************************************** + * + * (c) 2009-2016 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + + +import QtQuick 2.3 +import QtQuick.Controls 1.2 + +import QGroundControl 1.0 +import QGroundControl.Controls 1.0 +import QGroundControl.MultiVehicleManager 1.0 +import QGroundControl.ScreenTools 1.0 +import QGroundControl.Palette 1.0 + +//------------------------------------------------------------------------- +//-- Mode Indicator +Item { + anchors.top: parent.top + anchors.bottom: parent.bottom + visible: _multiVehicles + width: _multiVehicles ? multiVehicleSelector.width : 0 + + property bool _multiVehicles: activeVehicle ? QGroundControl.multiVehicleManager.vehicles.count > 1 : false + + Connections { + target: QGroundControl.multiVehicleManager.vehicles + onCountChanged: multiVehicleSelector.updatemultiVehiclesMenu() + } + + QGCLabel { + id: multiVehicleSelector + text: "Vehicle " + (activeVehicle ? activeVehicle.id : "None") + font.pointSize: ScreenTools.mediumFontPointSize + color: qgcPal.buttonText + anchors.verticalCenter: parent.verticalCenter + Menu { + id: multiVehiclesMenu + } + Component { + id: multiVehicleMenuItemComponent + MenuItem { + onTriggered: QGroundControl.multiVehicleManager.activeVehicle = vehicle + property int vehicleId: Number(text.split(" ")[1]) + property var vehicle: QGroundControl.multiVehicleManager.getVehicleById(vehicleId) + } + } + property var multiVehiclesMenuItems: [] + function updatemultiVehiclesMenu() { + if (_multiVehicles) { + // Remove old menu items + for (var i = 0; i < multiVehiclesMenuItems.length; i++) { + multiVehiclesMenu.removeItem(multiVehiclesMenuItems[i]) + } + multiVehiclesMenuItems.length = 0 + // Add new items + for (i = 0; i < QGroundControl.multiVehicleManager.vehicles.count; i++) { + var vehicle = QGroundControl.multiVehicleManager.vehicles.get(i) + var menuItem = multiVehicleMenuItemComponent.createObject(null, { "text": "Vehicle " + vehicle.id }) + multiVehiclesMenuItems.push(menuItem) + multiVehiclesMenu.insertItem(i, menuItem) + console.log("Vehicle " + vehicle.id) + } + } + } + Component.onCompleted: { + multiVehicleSelector.updatemultiVehiclesMenu() + } + } + MouseArea { + visible: _multiVehicles + anchors.fill: parent + onClicked: multiVehiclesMenu.popup() + } +} -- 2.22.0