summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTasuku Suzuki <tasuku.suzuki@qbc.io>2018-12-12 18:10:29 +0900
committerTasuku Suzuki <tasuku.suzuki@qbc.io>2018-12-12 18:10:29 +0900
commitc0d77c2df7d0ee258bd4c2093ee4a12dbaac3cf4 (patch)
tree707bcf44a894776d778216f9c63f23845a3c6f94
parent02ce71247f30d0499e3d34f335f53a923646e710 (diff)
Improve Qt-ness of AGLApplication
Let's follow Q*Application and QObjectPrivate pattern. Change-Id: I7b9193ac6e384c47807f13055ee645fc3e24278f Signed-off-by: Tasuku Suzuki <tasuku.suzuki@qbc.io>
-rw-r--r--src/aglextras/aglextras.pro2
-rw-r--r--src/aglextras/hmi/aglapplication.cpp67
-rw-r--r--src/aglextras/hmi/aglapplication.h6
-rw-r--r--src/aglextras/hmi/aglapplication_p.h15
4 files changed, 47 insertions, 43 deletions
diff --git a/src/aglextras/aglextras.pro b/src/aglextras/aglextras.pro
index 24028a9..8811e2a 100644
--- a/src/aglextras/aglextras.pro
+++ b/src/aglextras/aglextras.pro
@@ -1,7 +1,7 @@
TARGET = QtAGLExtras
QT += quick
-QT += core-private
+QT += gui-private
include(hmi/hmi.pri)
diff --git a/src/aglextras/hmi/aglapplication.cpp b/src/aglextras/hmi/aglapplication.cpp
index 320aa17..cd7eb38 100644
--- a/src/aglextras/hmi/aglapplication.cpp
+++ b/src/aglextras/hmi/aglapplication.cpp
@@ -28,9 +28,9 @@
QT_BEGIN_NAMESPACE
-AGLApplicationPrivate::AGLApplicationPrivate (AGLApplication *app)
- : binding_address(new QUrl)
- , engine(new QQmlApplicationEngine(app))
+AGLApplicationPrivate::AGLApplicationPrivate (int &argc, char **argv, int flags)
+ : QGuiApplicationPrivate (argc, argv, flags)
+ , engine(nullptr)
{
;
}
@@ -40,14 +40,18 @@ AGLApplicationPrivate::~AGLApplicationPrivate (void)
;
}
-AGLApplication::AGLApplication (int& argc, char** argv)
- : QGuiApplication(argc, argv),
- d_ptr(new AGLApplicationPrivate(this))
+AGLApplication::AGLApplication (int& argc, char** argv, int _internal)
+ : QGuiApplication(*new AGLApplicationPrivate(argc, argv, _internal))
{
+ Q_D(AGLApplication);
+ d->init();
+
setApplicationVersion(QStringLiteral("4.99.5"));
setOrganizationDomain(QStringLiteral("automotivelinux.org"));
setOrganizationName(QStringLiteral("AutomotiveGradeLinux"));
+ d->engine = new QQmlApplicationEngine(this);
+
QCommandLineParser parser;
parser.addPositionalArgument(QLatin1String("port"),
translate("main", "port for binding"));
@@ -58,58 +62,55 @@ AGLApplication::AGLApplication (int& argc, char** argv)
parser.process(*this);
QStringList positionalArguments = parser.positionalArguments();
- if (positionalArguments.length() < 2) {
- return;
- }
-
- d_ptr->port = positionalArguments.takeFirst().toInt();
- d_ptr->secret = positionalArguments.takeFirst();
-
- d_ptr->binding_address->setScheme(QStringLiteral("ws"));
- d_ptr->binding_address->setHost(QStringLiteral("localhost"));
- d_ptr->binding_address->setPort(d_ptr->port);
- d_ptr->binding_address->setPath(QStringLiteral("/api"));
+ if (positionalArguments.length() == 2) {
+ d->port = positionalArguments.takeFirst().toInt();
+ d->secret = positionalArguments.takeFirst();
- QUrlQuery query;
- query.addQueryItem(QStringLiteral("token"), d_ptr->secret);
- d_ptr->binding_address->setQuery(query);
+ d->binding_address.setScheme(QStringLiteral("ws"));
+ d->binding_address.setHost(QStringLiteral("localhost"));
+ d->binding_address.setPort(d->port);
+ d->binding_address.setPath(QStringLiteral("/api"));
- if (!d_ptr->engine) {
- qDebug("Cannot initialize QML Engine");
- exit(EXIT_FAILURE);
+ QUrlQuery query;
+ query.addQueryItem(QStringLiteral("token"), d->secret);
+ d->binding_address.setQuery(query);
}
- d_ptr->engine->rootContext()->setContextProperty(QStringLiteral("bindingAddress"),
- *d_ptr->binding_address);
+ d->engine->rootContext()->setContextProperty(QStringLiteral("bindingAddress"),
+ d->binding_address);
}
void
AGLApplication::load (const QUrl &url)
{
- d_ptr->engine->load(url);
+ Q_D(AGLApplication);
+ d->engine->load(url);
}
void
AGLApplication::load (const QString &filePath)
{
- d_ptr->engine->load(filePath);
+ Q_D(AGLApplication);
+ d->engine->load(filePath);
}
int
AGLApplication::exec (void)
{
- if (d_ptr->wmclient) {
- d_ptr->wmclient->attach(d_ptr->engine);
+ Q_D(AGLApplication);
+ if (d->wmclient) {
+ d->wmclient->attach(d->engine);
}
return QGuiApplication::exec();
}
void AGLApplication::setupApplicationRole (const QString &role)
{
- d_ptr->wmclient = new AGLWmClient(role, d_ptr->port, d_ptr->secret);
- d_ptr->screen_info = new AGLScreenInfo(this, d_ptr->wmclient->get_scale_factor());
- d_ptr->engine->rootContext()->setContextProperty(QStringLiteral("screenInfo"),
- d_ptr->screen_info);
+ Q_D(AGLApplication);
+ d->wmclient = new AGLWmClient(role, d->port, d->secret);
+ d->screen_info = new AGLScreenInfo(this, d->wmclient->get_scale_factor());
+ d->engine->rootContext()->setContextProperty(QStringLiteral("screenInfo"),
+ d->screen_info);
}
QT_END_NAMESPACE
diff --git a/src/aglextras/hmi/aglapplication.h b/src/aglextras/hmi/aglapplication.h
index f9d17a0..babf4de 100644
--- a/src/aglextras/hmi/aglapplication.h
+++ b/src/aglextras/hmi/aglapplication.h
@@ -30,7 +30,7 @@ class AGLEXTRAS_EXPORT AGLApplication : public QGuiApplication
Q_OBJECT
public:
- AGLApplication (int& argc, char** argv);
+ AGLApplication (int& argc, char** argv, int = ApplicationFlags);
void setupApplicationRole(const QString& role);
@@ -40,8 +40,8 @@ public:
int exec (void);
private:
- friend class AGLApplicationPrivate;
- QSharedPointer<AGLApplicationPrivate> d_ptr;
+ Q_DISABLE_COPY(AGLApplication)
+ Q_DECLARE_PRIVATE(AGLApplication)
};
class AGLScreenInfo : public QObject
diff --git a/src/aglextras/hmi/aglapplication_p.h b/src/aglextras/hmi/aglapplication_p.h
index 6cc1880..84859bd 100644
--- a/src/aglextras/hmi/aglapplication_p.h
+++ b/src/aglextras/hmi/aglapplication_p.h
@@ -18,26 +18,29 @@
#ifndef AGLAPPLICATION_P_H
#define AGLAPPLICATION_P_H
+#include "private/qguiapplication_p.h"
+#include "aglapplication.h"
+#include <QtCore/QUrl>
+
QT_BEGIN_NAMESPACE
-class QUrl;
+
class QQmlApplicationEngine;
class AGLWmClient;
-class AGLApplication;
class AGLScreenInfo;
-class AGLApplicationPrivate
+class AGLApplicationPrivate : public QGuiApplicationPrivate
{
+ Q_DECLARE_PUBLIC(AGLApplication)
public:
- explicit AGLApplicationPrivate (AGLApplication *app);
+ explicit AGLApplicationPrivate (int &argc, char **argv, int flags);
~AGLApplicationPrivate (void);
private:
int port = -1;
QString secret;
- QUrl* binding_address;
+ QUrl binding_address;
QQmlApplicationEngine *engine;
AGLWmClient* wmclient;
AGLScreenInfo* screen_info;
- friend class AGLApplication;
};
QT_END_NAMESPACE