Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 2fa8fc1aae829c6ddc50e25832dfe8f5b02a2484 Mon Sep 17 00:00:00 2001
- From: astrid hvalman <astrid.hvalman@gmail.com>
- Date: Mon, 9 Mar 2020 18:42:48 -0700
- Subject: [PATCH] QGC :: moved map to separate widget
- ---
- .gitignore | 1 +
- px4-firmware/qgroundcontrol/qgroundcontrol.pro | 1 +
- px4-firmware/qgroundcontrol/qgroundcontrol.qrc | 1 +
- px4-firmware/qgroundcontrol/src/QGCApplication.cc | 16 ++++
- px4-firmware/qgroundcontrol/src/ui/CMakeLists.txt | 1 +
- px4-firmware/qgroundcontrol/src/ui/MainWindow.cc | 5 ++
- px4-firmware/qgroundcontrol/src/ui/MainWindow.h | 1 +
- .../qgroundcontrol/src/ui/MainWindowInner.qml | 36 +++------
- px4-firmware/qgroundcontrol/src/ui/QGCFlightMap.cc | 90 ++++++++++++++++++++++
- px4-firmware/qgroundcontrol/src/ui/QGCFlightMap.h | 63 +++++++++++++++
- .../qgroundcontrol/src/ui/QGCFlightMapWidget.qml | 49 ++++++++++++
- .../src/ui/QGCFlightMapWidgetHolder.ui | 41 ++++++++++
- .../qgroundcontrol/src/ui/toolbar/MainToolBar.qml | 16 +---
- 13 files changed, 280 insertions(+), 41 deletions(-)
- create mode 100644 px4-firmware/qgroundcontrol/src/ui/QGCFlightMap.cc
- create mode 100644 px4-firmware/qgroundcontrol/src/ui/QGCFlightMap.h
- create mode 100644 px4-firmware/qgroundcontrol/src/ui/QGCFlightMapWidget.qml
- create mode 100644 px4-firmware/qgroundcontrol/src/ui/QGCFlightMapWidgetHolder.ui
- diff --git a/.gitignore b/.gitignore
- index c64df98..166bd19 100644
- --- a/.gitignore
- +++ b/.gitignore
- @@ -3,5 +3,6 @@
- /machine.bazelrc
- /working_dir
- +px4-firmware/qgroundcontrol/.ycm_extra_conf.py
- scripts/automated_testing/mission_dataman
- *.swp
- diff --git a/px4-firmware/qgroundcontrol/qgroundcontrol.pro b/px4-firmware/qgroundcontrol/qgroundcontrol.pro
- index 139e42d..ccf94e9 100644
- --- a/px4-firmware/qgroundcontrol/qgroundcontrol.pro
- +++ b/px4-firmware/qgroundcontrol/qgroundcontrol.pro
- @@ -380,6 +380,7 @@ FORMS += \
- src/ui/MainWindow.ui \
- src/QGCQmlWidgetHolder.ui \
- src/ui/QGCStatus.ui \
- + src/ui/QGCFlightMapWidgetHolder.ui \
- !MobileBuild {
- FORMS += \
- diff --git a/px4-firmware/qgroundcontrol/qgroundcontrol.qrc b/px4-firmware/qgroundcontrol/qgroundcontrol.qrc
- index 8ccf8cf..13cea6f 100644
- --- a/px4-firmware/qgroundcontrol/qgroundcontrol.qrc
- +++ b/px4-firmware/qgroundcontrol/qgroundcontrol.qrc
- @@ -44,6 +44,7 @@
- <file alias="LinkSettings.qml">src/ui/preferences/LinkSettings.qml</file>
- <file alias="LogDownloadPage.qml">src/AnalyzeView/LogDownloadPage.qml</file>
- <file alias="LogReplaySettings.qml">src/ui/preferences/LogReplaySettings.qml</file>
- + <file alias="QGCFlightMapWidget.qml">src/ui/QGCFlightMapWidget.qml</file>
- <file alias="MainWindowHybrid.qml">src/ui/MainWindowHybrid.qml</file>
- <file alias="MainWindowInner.qml">src/ui/MainWindowInner.qml</file>
- <file alias="MainWindowNative.qml">src/ui/MainWindowNative.qml</file>
- diff --git a/px4-firmware/qgroundcontrol/src/QGCApplication.cc b/px4-firmware/qgroundcontrol/src/QGCApplication.cc
- index 0d7e404..f115887 100644
- --- a/px4-firmware/qgroundcontrol/src/QGCApplication.cc
- +++ b/px4-firmware/qgroundcontrol/src/QGCApplication.cc
- @@ -16,6 +16,8 @@
- *
- */
- +// #include <iostream>
- +
- #include <QFile>
- #include <QFlags>
- #include <QPixmap>
- @@ -151,6 +153,18 @@ static QObject* shapeFileHelperSingletonFactory(QQmlEngine*, QJSEngine*)
- return new ShapeFileHelper;
- }
- +// TEST PURPOSES ONLY - collect all events for this object and it's siblings
- +// class FilterObject : public QObject {
- +//
- +// bool eventFilter(QObject *object, QEvent *event) {
- +// std::string first =(object->objectName()).toStdString() ;
- +// if (first.size())
- +// std::cout << first << ", " << std::endl;
- +// return false;
- +// }
- +//
- +// };
- +
- QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
- #ifdef __mobile__
- : QGuiApplication (argc, argv)
- @@ -389,6 +403,8 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
- #endif /* __mobile__ */
- _checkForNewVersion();
- + // FilterObject* f_o = new FilterObject;
- + // installEventFilter(f_o);
- }
- void QGCApplication::_shutdown(void)
- diff --git a/px4-firmware/qgroundcontrol/src/ui/CMakeLists.txt b/px4-firmware/qgroundcontrol/src/ui/CMakeLists.txt
- index bcf1e0c..0e39d2d 100644
- --- a/px4-firmware/qgroundcontrol/src/ui/CMakeLists.txt
- +++ b/px4-firmware/qgroundcontrol/src/ui/CMakeLists.txt
- @@ -43,6 +43,7 @@ add_library(ui
- QGCMAVLinkLogPlayer.ui
- QGCPluginHost.ui
- QGCStatus.cc
- + QGCFlightMap.cc
- QGCUASFileView.ui
- QGCUASFileViewMulti.ui
- QMap3D.ui
- diff --git a/px4-firmware/qgroundcontrol/src/ui/MainWindow.cc b/px4-firmware/qgroundcontrol/src/ui/MainWindow.cc
- index cba09c0..3088ec7 100644
- --- a/px4-firmware/qgroundcontrol/src/ui/MainWindow.cc
- +++ b/px4-firmware/qgroundcontrol/src/ui/MainWindow.cc
- @@ -69,6 +69,7 @@ enum DockWidgetTypes {
- ONBOARD_FILES,
- HIL_CONFIG,
- STATUS,
- + FLIGHT_MAP,
- ANALYZE1,
- ANALYZE2,
- ANALYZE3,
- @@ -85,6 +86,7 @@ static const char *rgDockWidgetNames[] = {
- "Onboard Files",
- "HIL Config",
- "Status",
- + "Flight Map",
- "Analyze: Servos",
- "Analyze: Attitude",
- @@ -369,6 +371,9 @@ bool MainWindow::_createInnerDockWidget(const QString& widgetName)
- case STATUS:
- widget = new QGCStatus(widgetName, action, qgcApp()->toolbox()->mavlinkProtocol(), this);
- break;
- + case FLIGHT_MAP:
- + widget = new QGCFlightMap(widgetName, action, this);
- + break;
- }
- if(widget) {
- _mapName2DockWidget[widgetName] = widget;
- diff --git a/px4-firmware/qgroundcontrol/src/ui/MainWindow.h b/px4-firmware/qgroundcontrol/src/ui/MainWindow.h
- index b45126c..167052c 100644
- --- a/px4-firmware/qgroundcontrol/src/ui/MainWindow.h
- +++ b/px4-firmware/qgroundcontrol/src/ui/MainWindow.h
- @@ -34,6 +34,7 @@
- #include "QGCMAVLinkInspector.h"
- #include "QGCMAVLinkLogPlayer.h"
- #include "QGCStatus.h"
- +#include "QGCFlightMap.h"
- #include "MAVLinkDecoder.h"
- #include "Vehicle.h"
- #include "QGCDockWidget.h"
- diff --git a/px4-firmware/qgroundcontrol/src/ui/MainWindowInner.qml b/px4-firmware/qgroundcontrol/src/ui/MainWindowInner.qml
- index 2c9e581..99d2409 100644
- --- a/px4-firmware/qgroundcontrol/src/ui/MainWindowInner.qml
- +++ b/px4-firmware/qgroundcontrol/src/ui/MainWindowInner.qml
- @@ -33,7 +33,7 @@ Item {
- property var activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
- property string formatedMessage: activeVehicle ? activeVehicle.formatedMessage : ""
- - property var _viewList: [ settingsViewLoader, setupViewLoader, planViewLoader, flightView, analyzeViewLoader ]
- + property var _viewList: [ settingsViewLoader, setupViewLoader, planViewLoader, analyzeViewLoader ]
- readonly property string _settingsViewSource: "AppSettings.qml"
- readonly property string _setupViewSource: "SetupView.qml"
- @@ -109,18 +109,6 @@ Item {
- planToolBar.visible = true
- }
- - function showFlyView() {
- - mainWindow.enableToolbar()
- - rootLoader.sourceComponent = null
- - if(currentPopUp) {
- - currentPopUp.close()
- - }
- - ScreenTools.availableHeight = parent.height - toolBar.height
- - hideAllViews()
- - flightView.visible = true
- - toolBar.checkFlyButton()
- - }
- -
- function showAnalyzeView() {
- mainWindow.enableToolbar()
- rootLoader.sourceComponent = null
- @@ -278,11 +266,10 @@ Item {
- opacity: planToolBar.visible ? 0 : 1
- z: QGroundControl.zOrderTopMost
- - Component.onCompleted: ScreenTools.availableHeight = parent.height - toolBar.height
- + Component.onCompleted: on_completed()
- onShowSettingsView: mainWindow.showSettingsView()
- onShowSetupView: mainWindow.showSetupView()
- onShowPlanView: mainWindow.showPlanView()
- - onShowFlyView: mainWindow.showFlyView()
- onShowAnalyzeView: mainWindow.showAnalyzeView()
- onArmVehicle: flightView.guidedController.confirmAction(flightView.guidedController.actionArm)
- onDisarmVehicle: {
- @@ -301,6 +288,12 @@ Item {
- enabled: false
- anchors.fill: parent
- }
- +
- + function on_completed (){
- + // this is done to minimize changes to QGC qml files
- + ScreenTools.availableHeight = parent.height - toolBar.height
- + mainWindow.showPlanView()
- + }
- }
- PlanToolBar {
- @@ -313,7 +306,6 @@ Item {
- onShowFlyView: {
- planToolBar.visible = false
- - mainWindow.showFlyView()
- }
- }
- @@ -347,24 +339,16 @@ Item {
- Loader {
- id: planViewLoader
- anchors.fill: parent
- - visible: false
- + visible: true
- property var toolbar: planToolBar
- - }
- -
- - FlightDisplayView {
- - id: flightView
- - anchors.fill: parent
- - visible: true
- - //-------------------------------------------------------------------------
- - //-- Loader helper for any child, no matter how deep can display an element
- - // on top of the video window.
- Loader {
- id: rootVideoLoader
- anchors.centerIn: parent
- }
- }
- +
- Loader {
- id: analyzeViewLoader
- anchors.left: parent.left
- diff --git a/px4-firmware/qgroundcontrol/src/ui/QGCFlightMap.cc b/px4-firmware/qgroundcontrol/src/ui/QGCFlightMap.cc
- new file mode 100644
- index 0000000..9644b08
- --- /dev/null
- +++ b/px4-firmware/qgroundcontrol/src/ui/QGCFlightMap.cc
- @@ -0,0 +1,90 @@
- +#include <QScreen>
- +#include "QGCFlightMap.h"
- +#include "AppMessages.h"
- +#include "QGCApplication.h"
- +
- +#include "ui_QGCFlightMapWidgetHolder.h"
- +
- +
- +QGCFlightMapWidgetHolder::QGCFlightMapWidgetHolder(const QString& title, QAction* action, QWidget *parent) :
- + QGCDockWidget(title, action, parent),
- + _ui(new Ui::QGCFlightMapWidgetHolder)
- +{
- + _ui->setupUi(this);
- +
- + layout()->setContentsMargins(0,0,0,0);
- +
- + if (action) {
- + setWindowTitle(title);
- + }
- + setResizeMode(QQuickWidget::SizeRootObjectToView);
- +}
- +
- +QGCFlightMapWidgetHolder::~QGCFlightMapWidgetHolder()
- +{
- +
- +}
- +
- +bool QGCFlightMapWidgetHolder::setSource(const QUrl& qmlUrl)
- +{
- + return _ui->QGCFlightMapWidget->setSource(qmlUrl);
- +}
- +
- +// void QGCFlightMapWidgetHolder::setContextPropertyObject(const QString& name, QObject* object)
- +// {
- +// _ui->QGCFlightMapWidget->rootContext()->setContextProperty(name, object);
- +// }
- +
- +// QQmlContext* QGCFlightMapWidgetHolder::getRootContext(void)
- +// {
- +// return _ui->QGCFlightMapWidget->rootContext();
- +// }
- +//
- +// QQuickItem* QGCFlightMapWidgetHolder::getRootObject(void)
- +// {
- +// return _ui->QGCFlightMapWidget->rootObject();
- +// }
- +
- +// QQmlEngine* QGCFlightMapWidgetHolder::getEngine()
- +// {
- +// return _ui->QGCFlightMapWidget->engine();
- +// }
- +
- +void QGCFlightMapWidgetHolder::setResizeMode(QQuickWidget::ResizeMode resizeMode)
- +{
- + _ui->QGCFlightMapWidget->setResizeMode(resizeMode);
- +}
- +
- +QGCFlightMapWidgetHolder* createMapQmlWidgetHolder(QLayout *mainLayout, QWidget* parent)
- +{
- + QGCFlightMapWidgetHolder* pMainQmlWidgetHolder = new QGCFlightMapWidgetHolder(QString(), nullptr, parent);
- + mainLayout->addWidget(pMainQmlWidgetHolder);
- + pMainQmlWidgetHolder->setVisible(true);
- + QQmlEngine::setObjectOwnership(parent, QQmlEngine::CppOwnership);
- + pMainQmlWidgetHolder->setSource(QUrl::fromUserInput("qrc:qml/QGCFlightMapWidget.qml"));
- + return pMainQmlWidgetHolder;
- +}
- +
- +
- +QGCFlightMap::QGCFlightMap(const QString& title, QAction* action, QWidget *parent) :
- + QGCDockWidget(title, action, parent)
- +{
- + _centralLayout = new QVBoxLayout();
- + _centralLayout->setContentsMargins(0, 0, 0, 0);
- +
- + // FilterObject* f_o = new FilterObject;
- + // parent->installEventFilter(f_o);
- +
- + setLayout(_centralLayout);
- + _mainQmlWidgetHolder = createMapQmlWidgetHolder(_centralLayout, this);
- + QScreen* scr = QApplication::primaryScreen();
- + QSize scrSize = scr->availableSize();
- + if (scrSize.width() <= 1280) {
- + resize(scrSize.width(), scrSize.height());
- + } else {
- + int w = scrSize.width();
- + int h = scrSize.height();
- + resize(w, h);
- + move((scrSize.width() - w) / 2, (scrSize.height() - h) / 2);
- + }
- +};
- diff --git a/px4-firmware/qgroundcontrol/src/ui/QGCFlightMap.h b/px4-firmware/qgroundcontrol/src/ui/QGCFlightMap.h
- new file mode 100644
- index 0000000..4d0ec9b
- --- /dev/null
- +++ b/px4-firmware/qgroundcontrol/src/ui/QGCFlightMap.h
- @@ -0,0 +1,63 @@
- +#ifndef QGC_FLIGHT_MAP_WIDGET_H
- +#define QGC_FLIGHT_MAP_WIDGET_H
- +
- +#include <QVBoxLayout>
- +#include "QGCDockWidget.h"
- +#include <QQmlContext>
- +#include <QQuickItem>
- +#include <QQuickWidget>
- +
- +namespace Ui {
- + class QGCFlightMapWidgetHolder;
- +}
- +
- +/// This is used to create widgets which are implemented in QML.
- +
- +class QGCFlightMapWidgetHolder : public QGCDockWidget
- +{
- + Q_OBJECT
- +
- +public:
- + // This has a title and action since the base class is QGCDockWidget. In order to use this
- + // control as a normal QWidget, not a doc widget just pass in:
- + // title = QString()
- + // action = NULL
- + explicit QGCFlightMapWidgetHolder(const QString& title, QAction* action, QWidget *parent = 0);
- + ~QGCFlightMapWidgetHolder();
- +
- + /// Get Root Context
- + // QQmlContext* getRootContext(void);
- +
- + // /// Get Root Object
- + // QQuickItem* getRootObject(void);
- +
- + /// Get QML Engine
- + // QQmlEngine* getEngine();
- +
- + /// Sets the QML into the control. Will display errors message box if error occurs loading source.
- + /// @return true: source loaded, false: source not loaded, errors occurred
- + bool setSource(const QUrl& qmlUrl);
- +
- + // void setContextPropertyObject(const QString& name, QObject* object);
- +
- + /// Sets the resize mode for the QQuickWidget container
- + void setResizeMode(QQuickWidget::ResizeMode resizeMode);
- +
- +
- +private:
- + Ui::QGCFlightMapWidgetHolder *_ui;
- +};
- +
- +
- +class QGCFlightMap : public QGCDockWidget {
- +
- + Q_OBJECT
- +
- + public:
- + explicit QGCFlightMap(const QString& title, QAction* action, QWidget *parent);
- + QVBoxLayout* _centralLayout;
- + QGCFlightMapWidgetHolder* _mainQmlWidgetHolder;
- +
- +};
- +
- +#endif // QGC_FLIGHT_MAP_WIDGET_H
- diff --git a/px4-firmware/qgroundcontrol/src/ui/QGCFlightMapWidget.qml b/px4-firmware/qgroundcontrol/src/ui/QGCFlightMapWidget.qml
- new file mode 100644
- index 0000000..73d8e2a
- --- /dev/null
- +++ b/px4-firmware/qgroundcontrol/src/ui/QGCFlightMapWidget.qml
- @@ -0,0 +1,49 @@
- +/****************************************************************************
- + *
- + * (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
- + *
- + * 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 QtQuick.Dialogs 1.2
- +import QtPositioning 5.3
- +
- +import QGroundControl 1.0
- +import QGroundControl.Palette 1.0
- +import QGroundControl.Controls 1.0
- +import QGroundControl.FlightDisplay 1.0
- +import QGroundControl.ScreenTools 1.0
- +import QGroundControl.MultiVehicleManager 1.0
- +
- +/// Inner common QML for mainWindow
- +Item {
- +
- + id: mainWindow
- + QGCPalette { id: qgcPal; colorGroupEnabled: true }
- + onHeightChanged: {
- + ScreenTools.availableHeight = parent.height
- + }
- +
- +
- + function enableToolbar() {}
- +
- + FlightDisplayView {
- + id: flightView
- + anchors.fill: parent
- + visible: true
- + Loader {
- + id: rootVideoLoader
- + anchors.centerIn: parent
- + }
- + }
- +
- + Loader {
- + id: rootLoader
- + anchors.centerIn: parent
- + }
- +}
- diff --git a/px4-firmware/qgroundcontrol/src/ui/QGCFlightMapWidgetHolder.ui b/px4-firmware/qgroundcontrol/src/ui/QGCFlightMapWidgetHolder.ui
- new file mode 100644
- index 0000000..6f7a0a7
- --- /dev/null
- +++ b/px4-firmware/qgroundcontrol/src/ui/QGCFlightMapWidgetHolder.ui
- @@ -0,0 +1,41 @@
- +<?xml version="1.0" encoding="UTF-8"?>
- +<ui version="4.0">
- + <class>QGCFlightMapWidgetHolder</class>
- + <widget class="QWidget" name="QGCFlightMapWidgetHolder">
- + <property name="geometry">
- + <rect>
- + <x>0</x>
- + <y>0</y>
- + <width>1400</width>
- + <height>700</height>
- + </rect>
- + </property>
- + <property name="windowTitle">
- + <string>Form</string>
- + </property>
- + <layout class="QVBoxLayout" name="verticalLayout">
- + <item>
- + <widget class="QGCQuickWidget" name="QGCFlightMapWidget">
- + <property name="acceptDrops">
- + <bool>true</bool>
- + </property>
- + </widget>
- + </item>
- + </layout>
- + </widget>
- + <customwidgets>
- + <customwidget>
- + <class>QQuickWidget</class>
- + <extends>QWidget</extends>
- + <header>QQuickWidget</header>
- + </customwidget>
- + <customwidget>
- + <class>QGCQuickWidget</class>
- + <extends>QQuickWidget</extends>
- + <header>QGCQuickWidget.h</header>
- + <container>1</container>
- + </customwidget>
- + </customwidgets>
- + <resources/>
- + <connections/>
- +</ui>
- diff --git a/px4-firmware/qgroundcontrol/src/ui/toolbar/MainToolBar.qml b/px4-firmware/qgroundcontrol/src/ui/toolbar/MainToolBar.qml
- index 4424569..a7c5854 100644
- --- a/px4-firmware/qgroundcontrol/src/ui/toolbar/MainToolBar.qml
- +++ b/px4-firmware/qgroundcontrol/src/ui/toolbar/MainToolBar.qml
- @@ -30,7 +30,6 @@ Rectangle {
- signal showSettingsView
- signal showSetupView
- signal showPlanView
- - signal showFlyView
- signal showAnalyzeView
- signal armVehicle
- signal disarmVehicle
- @@ -49,17 +48,13 @@ Rectangle {
- planButton.checked = true
- }
- - function checkFlyButton() {
- - flyButton.checked = true
- - }
- -
- function checkAnalyzeButton() {
- analyzeButton.checked = true
- }
- Component.onCompleted: {
- //-- TODO: Get this from the actual state
- - flyButton.checked = true
- + // flyButton.checked = true
- }
- // Prevent all clicks from going through to lower layers
- @@ -122,15 +117,6 @@ Rectangle {
- }
- QGCToolBarButton {
- - id: flyButton
- - anchors.top: parent.top
- - anchors.bottom: parent.bottom
- - exclusiveGroup: mainActionGroup
- - source: "/qmlimages/PaperPlane.svg"
- - onClicked: toolBar.showFlyView()
- - }
- -
- - QGCToolBarButton {
- id: analyzeButton
- anchors.top: parent.top
- anchors.bottom: parent.bottom
- --
- 2.7.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement