From c0d77c2df7d0ee258bd4c2093ee4a12dbaac3cf4 Mon Sep 17 00:00:00 2001 From: Tasuku Suzuki Date: Wed, 12 Dec 2018 18:10:29 +0900 Subject: Improve Qt-ness of AGLApplication Let's follow Q*Application and QObjectPrivate pattern. Change-Id: I7b9193ac6e384c47807f13055ee645fc3e24278f Signed-off-by: Tasuku Suzuki --- src/aglextras/aglextras.pro | 2 +- src/aglextras/hmi/aglapplication.cpp | 67 ++++++++++++++++++------------------ src/aglextras/hmi/aglapplication.h | 6 ++-- src/aglextras/hmi/aglapplication_p.h | 15 ++++---- 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 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 + 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 -- cgit 1.2.3-korg