-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
82 lines (63 loc) · 2.94 KB
/
main.cpp
File metadata and controls
82 lines (63 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QProcess>
#include <QtQuickControls2/QQuickStyle>
#include "MapController.h"
#include "FileHandler.h"
#include "backend/dbmanager.h"
#include "DroneController.h"
#include "SettingsManager.h"
#include "missionmanager.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
// Force a non-native style so customization is supported
QQuickStyle::setStyle("Basic");
/*
* We want to use QQmlApplicationEngine as it provides more resources for our use case
* https://doc.qt.io/qt-6/qqmlapplicationengine.html
*/
// If the database doesn't exist, it will create the database. The following code intializes the drones Table.
DBManager gcs_db_manager;
gcs_db_manager.initDB();
qDebug() << "[main.cpp] Database started successfully.";
// TODO: Intialize and make UI button click reach database
QQmlApplicationEngine engine;
// Create and register SettingsManager for persistent per-user settings
SettingsManager settingsManager;
engine.rootContext()->setContextProperty("settingsManager", &settingsManager);
// Create and register MapController as an object that the cpp can use
MapController mapController;
engine.rootContext()->setContextProperty("mapController", &mapController);
// Register the FileHandler class so that it can be used in QML
qmlRegisterType<FileHandler>("com.gcs.filehandler", 1, 0, "FileHandler");
// Register droneclass to QML
qmlRegisterUncreatableType<DroneClass>(
"com.gcs.dronecontroller", 1, 0, "DroneClass",
"DroneClass cannot be created from QML");
// Expose dronecontroller to QML
qmlRegisterType<DroneController>("com.gcs.dronecontroller", 1, 0, "DroneController");
DroneController droneController(gcs_db_manager);
// Populate the QML property cache
droneController.rebuildVariant();
// Expose to QML
engine.rootContext()->setContextProperty("droneController", &droneController);
MissionManager missionManager;
engine.rootContext()->setContextProperty("missionManager", &missionManager);
QObject::connect(&missionManager, &MissionManager::navigateToNext,
&droneController, &DroneController::sendToCoordByUavID);
const QUrl url(QStringLiteral("qrc:/main.qml"));
/*
* main.qml is our entry point for all of our UI/GUI resources.
* It calls all of our QML files needed to create and display our GUI
* As such, it allows for us to create very modular UI displays
*/
// Creates the root object, which is the engine that runs the program
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl)
{
if (!obj && url == objUrl)
QCoreApplication::exit(-1); }, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}