Skip to content

Commit

Permalink
Mobile runs Native QML
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer committed Dec 8, 2015
1 parent 5259467 commit 4f080b9
Show file tree
Hide file tree
Showing 23 changed files with 373 additions and 166 deletions.
1 change: 0 additions & 1 deletion QGCCommon.pri
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ linux {
DEFINES += __android__
DEFINES += __STDC_LIMIT_MACROS
target.path = $$DESTDIR
warning("Android build is experimental and not fully functional")
} else {
error("Unsuported Linux toolchain, only GCC 32- or 64-bit is supported")
}
Expand Down
4 changes: 2 additions & 2 deletions qgroundcontrol.pro
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ HEADERS += \
src/uas/UAS.h \
src/uas/UASInterface.h \
src/uas/UASMessageHandler.h \
src/ui/MainWindow.h \
src/ui/toolbar/MainToolBarController.h \
src/AutoPilotPlugins/PX4/PX4AirframeLoader.h \
src/QmlControls/QGCImageProvider.h \
Expand Down Expand Up @@ -327,6 +326,7 @@ HEADERS += \
src/ui/linechart/Scrollbar.h \
src/ui/linechart/ScrollZoomer.h \
src/ui/LogReplayLinkConfigurationWidget.h \
src/ui/MainWindow.h \
src/ui/MAVLinkDecoder.h \
src/ui/MAVLinkSettingsWidget.h \
src/ui/MultiVehicleDockWidget.h \
Expand Down Expand Up @@ -400,7 +400,6 @@ SOURCES += \
src/QmlControls/QmlObjectListModel.cc \
src/uas/UAS.cc \
src/uas/UASMessageHandler.cc \
src/ui/MainWindow.cc \
src/ui/toolbar/MainToolBarController.cc \
src/AutoPilotPlugins/PX4/PX4AirframeLoader.cc \
src/QmlControls/QGCImageProvider.cc \
Expand Down Expand Up @@ -453,6 +452,7 @@ SOURCES += \
src/ui/linechart/LinechartWidget.cc \
src/ui/linechart/Scrollbar.cc \
src/ui/linechart/ScrollZoomer.cc \
src/ui/MainWindow.cc \
src/ui/MultiVehicleDockWidget.cc \
src/ui/QGCDataPlot2D.cc \
src/ui/QGCHilConfiguration.cc \
Expand Down
4 changes: 3 additions & 1 deletion qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

<file alias="JoystickConfig.qml">src/VehicleSetup/JoystickConfig.qml</file>
<file alias="MainToolBar.qml">src/ui/toolbar/MainToolBar.qml</file>
<file alias="MainWindow.qml">src/ui/MainWindow.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>
<file alias="MainWindowLeftPanel.qml">src/ui/MainWindowLeftPanel.qml</file>
<file alias="MissionEditor.qml">src/MissionEditor/MissionEditor.qml</file>
<file alias="MissionEditorHelp.qml">src/MissionEditor/MissionEditorHelp.qml</file>
Expand Down
3 changes: 1 addition & 2 deletions src/AutoPilotPlugins/AutoPilotPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "AutoPilotPlugin.h"
#include "QGCApplication.h"
#include "MainWindow.h"
#include "ParameterLoader.h"
#include "UAS.h"
#include "FirmwarePlugin.h"
Expand Down Expand Up @@ -65,7 +64,7 @@ void AutoPilotPlugin::_parametersReadyChanged(bool parametersReady)
qgcApp()->showMessage("One or more vehicle components require setup prior to flight.");

// Take the user to Vehicle Summary
MainWindow::instance()->showSetupView();
qgcApp()->showSetupView();
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
}
}
Expand Down
91 changes: 75 additions & 16 deletions src/QGCApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@

#include "QGC.h"
#include "QGCApplication.h"
#include "MainWindow.h"
#include "GAudioOutput.h"
#include "CmdLineOptParser.h"
#include "MainWindow.h"
#include "UDPLink.h"
#include "LinkManager.h"
#include "HomePositionManager.h"
Expand Down Expand Up @@ -101,6 +99,7 @@
#include "QGCMessageBox.h"
#include "FirmwareUpgradeController.h"
#include "JoystickConfigController.h"
#include "MainWindow.h"
#endif

#ifdef QGC_RTLAB_ENABLED
Expand Down Expand Up @@ -154,7 +153,12 @@ static QObject* qgroundcontrolQmlGlobalSingletonFactory(QQmlEngine*, QJSEngine*)
**/

QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
#ifdef __mobile__
: QGuiApplication(argc, argv)
, _qmlAppEngine(NULL)
#else
: QApplication(argc, argv)
#endif
, _runningUnitTests(unitTesting)
#if defined (__mobile__)
, _styleIsDark(false)
Expand Down Expand Up @@ -323,10 +327,12 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)

QGCApplication::~QGCApplication()
{
#ifndef __mobile__
MainWindow* mainWindow = MainWindow::instance();
if (mainWindow) {
delete mainWindow;
}
#endif
shutdownVideoStreaming();
delete _toolbox;
}
Expand Down Expand Up @@ -446,18 +452,23 @@ bool QGCApplication::_initForNormalAppBoot(void)
// Exit main application when last window is closed
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit()));

#ifdef __mobile__
_qmlAppEngine = new QQmlApplicationEngine(this);
_qmlAppEngine->addImportPath("qrc:/qml");
_qmlAppEngine->rootContext()->setContextProperty("multiVehicleManager", toolbox()->multiVehicleManager());
_qmlAppEngine->rootContext()->setContextProperty("joystickManager", toolbox()->joystickManager());
_qmlAppEngine->load(QUrl(QStringLiteral("qrc:/qml/MainWindowNative.qml")));
#else
// Start the user interface
MainWindow* mainWindow = MainWindow::_create();
Q_CHECK_PTR(mainWindow);

#ifndef __mobile__
// If we made it this far and we still don't have a location. Either the specfied location was invalid
// or we coudn't create a default location. Either way, we need to let the user know and prompt for a new
/// settings.
QString savedFilesLocation = settings.value(_savedFilesLocationKey).toString();
if (savedFilesLocation.isEmpty()) {
showMessage("The location to save files to is invalid, or cannot be written to. Please provide a new one.");
mainWindow->showSettings();
}

// Now that main window is up check for lost log files
Expand Down Expand Up @@ -653,12 +664,10 @@ void QGCApplication::setStyle(bool styleIsDark)

void QGCApplication::_loadCurrentStyle(void)
{
#ifndef __mobile__
bool success = true;
QString styles;

// Signal to the user that the app will pause to apply a new stylesheet
setOverrideCursor(Qt::WaitCursor);

// The dark style sheet is the master. Any other selected style sheet just overrides
// the colors of the master sheet.
QFile masterStyleSheet(_darkStyleFile);
Expand Down Expand Up @@ -687,11 +696,9 @@ void QGCApplication::_loadCurrentStyle(void)
// Fall back to plastique if we can't load our own
setStyle("plastique");
}
#endif

QGCPalette::setGlobalTheme(_styleIsDark ? QGCPalette::Dark : QGCPalette::Light);

// Finally restore the cursor before returning.
restoreOverrideCursor();
}

void QGCApplication::reportMissingParameter(int componentId, const QString& name)
Expand All @@ -718,12 +725,64 @@ void QGCApplication::_missingParamsDisplay(void)
showMessage(QString("Parameters missing from firmware: %1.\n\nYou should quit QGroundControl immediately and update your firmware.").arg(params));
}

QObject* QGCApplication::_rootQmlObject(void)
{
#ifdef __mobile__
return _qmlAppEngine->rootObjects()[0];
#else
return MainWindow::instance()->rootQmlObject();
#endif
}


void QGCApplication::showMessage(const QString& message)
{
MainWindow* mainWindow = MainWindow::instance();
if (mainWindow) {
mainWindow->showMessage(message);
} else {
qWarning() << "showMessage with no mainWindow" << message;
}
QVariant varReturn;
QVariant varMessage = QVariant::fromValue(message);

QMetaObject::invokeMethod(_rootQmlObject(), "showMessage", Q_RETURN_ARG(QVariant, varReturn), Q_ARG(QVariant, varMessage));
}

void QGCApplication::showFlyView(void)
{
QMetaObject::invokeMethod(_rootQmlObject(), "showFlyView");
}

void QGCApplication::showPlanView(void)
{
QMetaObject::invokeMethod(_rootQmlObject(), "showPlanView");
}

void QGCApplication::showSetupView(void)
{
QMetaObject::invokeMethod(_rootQmlObject(), "showSetupView");
}

void QGCApplication::showWindowCloseMessage(void)
{
QMetaObject::invokeMethod(_rootQmlObject(), "showWindowCloseMessage");
}


void QGCApplication::_showSetupFirmware(void)
{
QMetaObject::invokeMethod(_rootQmlObject(), "showSetupFirmware");
}

void QGCApplication::_showSetupParameters(void)
{
QMetaObject::invokeMethod(_rootQmlObject(), "showSetupParameters");
}

void QGCApplication::_showSetupSummary(void)
{
QMetaObject::invokeMethod(_rootQmlObject(), "showSetupSummary");
}

void QGCApplication::_showSetupVehicleComponent(VehicleComponent* vehicleComponent)
{
QVariant varReturn;
QVariant varComponent = QVariant::fromValue(vehicleComponent);

QMetaObject::invokeMethod(_rootQmlObject(), "showSetupVehicleComponent", Q_RETURN_ARG(QVariant, varReturn), Q_ARG(QVariant, varComponent));
}
23 changes: 22 additions & 1 deletion src/QGCApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ class QGCToolbox;
* the central management unit of the groundstation application.
*
**/
class QGCApplication : public QApplication
class QGCApplication : public
#ifdef __mobile__
QGuiApplication // Native Qml based application
#else
QApplication // QtWidget based application
#endif
{
Q_OBJECT

Expand Down Expand Up @@ -138,6 +143,12 @@ public slots:
/// You can connect to this slot to show a critical message box from a different thread.
void criticalMessageBoxOnMainThread(const QString& title, const QString& msg);

void showFlyView(void);
void showPlanView(void);
void showSetupView(void);

void showWindowCloseMessage(void);

#ifndef __mobile__
/// Save the specified Flight Data Log
void saveTempFlightDataLogOnMainThread(QString tempLogfile);
Expand Down Expand Up @@ -166,6 +177,11 @@ public slots:
/// @brief Intialize the application for normal application boot. Or in other words we are not going to run
/// unit tests. Although public should only be called by main.
bool _initForUnitTests(void);

void _showSetupFirmware(void);
void _showSetupParameters(void);
void _showSetupSummary(void);
void _showSetupVehicleComponent(VehicleComponent* vehicleComponent);

static QGCApplication* _app; ///< Our own singleton. Should be reference directly by qgcApp

Expand All @@ -174,6 +190,11 @@ private slots:

private:
void _loadCurrentStyle(void);
QObject* _rootQmlObject(void);

#ifdef __mobile__
QQmlApplicationEngine* _qmlAppEngine;
#endif

static const char* _settingsVersionKey; ///< Settings key which hold settings version
static const char* _deleteAllSettingsKey; ///< If this settings key is set on boot, all settings will be deleted
Expand Down
2 changes: 1 addition & 1 deletion src/QmlControls/ParameterEditorController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

#include "ParameterEditorController.h"
#include "AutoPilotPluginManager.h"
#include "MainWindow.h"
#include "QGCApplication.h"

#ifndef __mobile__
#include "QGCFileDialog.h"
#include "QGCMapRCToParamDialog.h"
#include "MainWindow.h"
#endif

/// @Brief Constructs a new ParameterEditorController Widget. This widget is used within the PX4VehicleConfig set of screens.
Expand Down
6 changes: 0 additions & 6 deletions src/QmlControls/QGroundControlQmlGlobal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,6 @@ void QGroundControlQmlGlobal::setIsAudioMuted(bool muted)
emit isAudioMutedChanged(muted);
}

void QGroundControlQmlGlobal::setIsLowPowerMode(bool low)
{
MainWindow::instance()->enableLowPowerMode(low);
emit isLowPowerModeChanged(low);
}

void QGroundControlQmlGlobal::setIsSaveLogPrompt(bool prompt)
{
qgcApp()->setPromptFlightDataSave(prompt);
Expand Down
5 changes: 0 additions & 5 deletions src/QmlControls/QGroundControlQmlGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <QObject>

#include "QGCApplication.h"
#include "MainWindow.h"
#include "LinkManager.h"
#include "HomePositionManager.h"
#include "FlightMapSettings.h"
Expand Down Expand Up @@ -63,7 +62,6 @@ class QGroundControlQmlGlobal : public QObject
Q_PROPERTY(bool isAdvancedMode READ isAdvancedMode CONSTANT) ///< Global "Advance Mode" preference. Certain UI elements and features are different based on this.
Q_PROPERTY(bool isDarkStyle READ isDarkStyle WRITE setIsDarkStyle NOTIFY isDarkStyleChanged) // TODO: Should be in ScreenTools?
Q_PROPERTY(bool isAudioMuted READ isAudioMuted WRITE setIsAudioMuted NOTIFY isAudioMutedChanged)
Q_PROPERTY(bool isLowPowerMode READ isLowPowerMode WRITE setIsLowPowerMode NOTIFY isLowPowerModeChanged)
Q_PROPERTY(bool isSaveLogPrompt READ isSaveLogPrompt WRITE setIsSaveLogPrompt NOTIFY isSaveLogPromptChanged)
Q_PROPERTY(bool isSaveLogPromptNotArmed READ isSaveLogPromptNotArmed WRITE setIsSaveLogPromptNotArmed NOTIFY isSaveLogPromptNotArmedChanged)
Q_PROPERTY(bool isHeartBeatEnabled READ isHeartBeatEnabled WRITE setIsHeartBeatEnabled NOTIFY isHeartBeatEnabledChanged)
Expand Down Expand Up @@ -99,7 +97,6 @@ class QGroundControlQmlGlobal : public QObject

bool isDarkStyle () { return qgcApp()->styleIsDark(); }
bool isAudioMuted () { return qgcApp()->toolbox()->audioOutput()->isMuted(); }
bool isLowPowerMode () { return MainWindow::instance()->lowPowerModeEnabled(); }
bool isSaveLogPrompt () { return qgcApp()->promptFlightDataSave(); }
bool isSaveLogPromptNotArmed () { return qgcApp()->promptFlightDataSaveNotArmed(); }
bool isHeartBeatEnabled () { return qgcApp()->toolbox()->mavlinkProtocol()->heartbeatsEnabled(); }
Expand All @@ -112,7 +109,6 @@ class QGroundControlQmlGlobal : public QObject

void setIsDarkStyle (bool dark);
void setIsAudioMuted (bool muted);
void setIsLowPowerMode (bool low);
void setIsSaveLogPrompt (bool prompt);
void setIsSaveLogPromptNotArmed (bool prompt);
void setIsHeartBeatEnabled (bool enable);
Expand All @@ -123,7 +119,6 @@ class QGroundControlQmlGlobal : public QObject
signals:
void isDarkStyleChanged (bool dark);
void isAudioMutedChanged (bool muted);
void isLowPowerModeChanged (bool lowPower);
void isSaveLogPromptChanged (bool prompt);
void isSaveLogPromptNotArmedChanged (bool prompt);
void isHeartBeatEnabledChanged (bool enabled);
Expand Down
1 change: 0 additions & 1 deletion src/QmlControls/ScreenToolsController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
/// @author Gus Grubba <[email protected]>

#include "ScreenToolsController.h"
#include "MainWindow.h"

#ifdef Q_OS_WIN
const double ScreenToolsController::_defaultFontPixelSizeRatio = 1.0;
Expand Down
10 changes: 5 additions & 5 deletions src/VehicleSetup/SetupViewTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,25 @@ void SetupViewTest::_clickThrough_test(void)
_createMainWindow();

// Switch to the Setup view
_mainWindow->showSetupView();
qgcApp()->showSetupView();
QTest::qWait(1000);

// Click through fixed buttons
qDebug() << "Showing firmware";
_mainWindow->showSetupFirmware();
qgcApp()->_showSetupFirmware();
QTest::qWait(1000);
qDebug() << "Showing parameters";
_mainWindow->showSetupParameters();
qgcApp()->_showSetupParameters();
QTest::qWait(1000);
qDebug() << "Showing summary";
_mainWindow->showSetupSummary();
qgcApp()->_showSetupSummary();
QTest::qWait(1000);

const QVariantList& components = autopilot->vehicleComponents();
foreach(QVariant varComponent, components) {
VehicleComponent* component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(varComponent));
qDebug() << "Showing" << component->name();
_mainWindow->showSetupVehicleComponent(component);
qgcApp()->_showSetupVehicleComponent(component);
QTest::qWait(1000);
}

Expand Down
Loading

0 comments on commit 4f080b9

Please sign in to comment.