From 573b6e18aa52c76e6c79dfa44588d807f036a0cd Mon Sep 17 00:00:00 2001 From: alexandr <alexandrmruchok@gmail.com> Date: Tue, 13 Oct 2020 09:37:51 +0300 Subject: [PATCH] [+] DapApplication --- .../CellFrameDashboardGUI.pro | 6 +- CellFrameDashboardGUI/DapApplication.cpp | 62 +++++++++++++++++++ CellFrameDashboardGUI/DapApplication.h | 25 ++++++++ CellFrameDashboardGUI/main.cpp | 37 ++--------- cellframe-sdk | 2 +- cellframe-ui-sdk | 2 +- dap-ui-sdk | 2 +- 7 files changed, 98 insertions(+), 38 deletions(-) create mode 100644 CellFrameDashboardGUI/DapApplication.cpp create mode 100644 CellFrameDashboardGUI/DapApplication.h diff --git a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro index 7a5da7ad1..26c986feb 100755 --- a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro +++ b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro @@ -68,7 +68,8 @@ OTHER_FILES += libdap-qt-ui-qml \ SOURCES += \ $$PWD/main.cpp \ - $$PWD/DapServiceController.cpp + $$PWD/DapServiceController.cpp \ + DapApplication.cpp RESOURCES += $$PWD/qml.qrc @@ -78,7 +79,8 @@ else: unix:!android: target.path = /opt/cellframe-dashboard/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ - $$PWD/DapServiceController.h + $$PWD/DapServiceController.h \ + DapApplication.h include (../dap-ui-sdk/qml/libdap-qt-ui-qml.pri) include (../dap-ui-sdk/core/libdap-qt.pri) diff --git a/CellFrameDashboardGUI/DapApplication.cpp b/CellFrameDashboardGUI/DapApplication.cpp new file mode 100644 index 000000000..7722edc09 --- /dev/null +++ b/CellFrameDashboardGUI/DapApplication.cpp @@ -0,0 +1,62 @@ +#include "DapApplication.h" +#include <QQmlContext> +#include <DapLogMessage.h> +#include <QIcon> + +DapApplication::DapApplication(int &argc, char **argv) + :QApplication(argc, argv) +{ + this->setOrganizationName("DEMLABS"); + this->setOrganizationDomain("demlabs.net"); + this->setApplicationName("CellFrame Dashboard"); + this->setWindowIcon(QIcon(":/resources/icons/icon.ico")); + + this->registerQmlTypes(); + this->setContextProperties(); + + qRegisterMetaType<DapNetwork::State>("DapNetwork::State"); +} + +DapNetworksList *DapApplication::networks() +{ + return &m_networks; +} + +QQmlApplicationEngine *DapApplication::qmlEngine() +{ + return &m_engine; +} + +void DapApplication::registerQmlTypes() +{ + //register only enums + qmlRegisterUncreatableType<DapCertificateType>("DapCertificateManager.Commands", 1, 0, "DapCertificateType" + , "Error create DapCertificateType"); + + //register enums and constant property as singletone + qmlRegisterSingletonType<DapCertificateCommands>("DapCertificateManager.Commands", 1, 0, "DapCertificateCommands" + , [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + + //qInfo() << "DapCertificateCommands initialize in Qml"; + QQmlEngine::setObjectOwnership(DapCertificateCommands::instance() + , QQmlEngine::ObjectOwnership::CppOwnership); + return DapCertificateCommands::instance(); + }); + + + qmlRegisterType<DapLogMessage>("Demlabs", 1, 0, "DapLogMessage"); + qmlRegisterType<DapWallet>("Demlabs", 1, 0, "DapWallet"); + qmlRegisterType<DapWalletToken>("Demlabs", 1, 0, "DapWalletToken"); + qRegisterMetaType<DapWallet>(); + qRegisterMetaType<DapWalletToken>(); +} + +void DapApplication::setContextProperties() +{ + m_engine.rootContext()->setContextProperty("dapServiceController", &DapServiceController::getInstance()); + m_engine.rootContext()->setContextProperty("pt", 1); + + m_engine.rootContext()->setContextProperty("networksModel", QVariant::fromValue(this->networks()->model())); +} diff --git a/CellFrameDashboardGUI/DapApplication.h b/CellFrameDashboardGUI/DapApplication.h new file mode 100644 index 000000000..72ecceb38 --- /dev/null +++ b/CellFrameDashboardGUI/DapApplication.h @@ -0,0 +1,25 @@ +#ifndef DAPAPPLICATION_H +#define DAPAPPLICATION_H + +#include <QApplication> +#include "DapNetworksList.h" +#include "QQmlApplicationEngine" +#include "DapServiceController.h" + +class DapApplication : public QApplication +{ +public: + DapApplication(int &argc, char **argv); + + DapNetworksList *networks(); + QQmlApplicationEngine *qmlEngine(); + +private: + void setContextProperties(); + void registerQmlTypes(); + + DapNetworksList m_networks; + QQmlApplicationEngine m_engine; +}; + +#endif // DAPAPPLICATION_H diff --git a/CellFrameDashboardGUI/main.cpp b/CellFrameDashboardGUI/main.cpp index 8aec28479..9e5b24353 100644 --- a/CellFrameDashboardGUI/main.cpp +++ b/CellFrameDashboardGUI/main.cpp @@ -14,6 +14,7 @@ #include "DapLogger.h" #include "DapLogMessage.h" #include "DapWallet.h" +#include "DapApplication.h" #ifdef Q_OS_WIN #include "registry.h" @@ -25,11 +26,7 @@ int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QApplication app(argc, argv); - app.setOrganizationName("DEMLABS"); - app.setOrganizationDomain("demlabs.net"); - app.setApplicationName("CellFrame Dashboard"); - app.setWindowIcon(QIcon(":/resources/icons/icon.ico")); + DapApplication app(argc, argv); DapLogger dapLogger; /// TODO: The code is commented out at the time of developing the logging strategy in the project @@ -55,36 +52,10 @@ int main(int argc, char *argv[]) dapServiceClient.init(); - //register only enums - qmlRegisterUncreatableType<DapCertificateType>("DapCertificateManager.Commands", 1, 0, "DapCertificateType" - , "Error create DapCertificateType"); + app.qmlEngine()->load(QUrl("qrc:/main.qml")); - //register enums and constant property as singletone - qmlRegisterSingletonType<DapCertificateCommands>("DapCertificateManager.Commands", 1, 0, "DapCertificateCommands" - , [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { - Q_UNUSED(engine) - Q_UNUSED(scriptEngine) + Q_ASSERT(!app.qmlEngine()->rootObjects().isEmpty()); - //qInfo() << "DapCertificateCommands initialize in Qml"; - QQmlEngine::setObjectOwnership(DapCertificateCommands::instance() - , QQmlEngine::ObjectOwnership::CppOwnership); - return DapCertificateCommands::instance(); - }); - - qmlRegisterType<DapLogMessage>("Demlabs", 1, 0, "DapLogMessage"); - qmlRegisterType<DapWallet>("Demlabs", 1, 0, "DapWallet"); - qmlRegisterType<DapWalletToken>("Demlabs", 1, 0, "DapWalletToken"); - qRegisterMetaType<DapWallet>(); - qRegisterMetaType<DapWalletToken>(); - - QQmlApplicationEngine engine; - engine.rootContext()->setContextProperty("dapServiceController", &DapServiceController::getInstance()); - engine.rootContext()->setContextProperty("pt", 1); - engine.load(QUrl("qrc:/main.qml")); - - if (engine.rootObjects().isEmpty()) - return -1; - return app.exec(); } diff --git a/cellframe-sdk b/cellframe-sdk index e553fb109..8d533dad6 160000 --- a/cellframe-sdk +++ b/cellframe-sdk @@ -1 +1 @@ -Subproject commit e553fb10954bf6b8ec1ccc3dd0a8249e838f607f +Subproject commit 8d533dad6022bd413aab9bf99cbbd8e95aaf27f0 diff --git a/cellframe-ui-sdk b/cellframe-ui-sdk index 54556afb3..9db15afc7 160000 --- a/cellframe-ui-sdk +++ b/cellframe-ui-sdk @@ -1 +1 @@ -Subproject commit 54556afb3e929b5c132e882c911b94965eb836cb +Subproject commit 9db15afc70f9382737614d07f89b3f3e2a8e9707 diff --git a/dap-ui-sdk b/dap-ui-sdk index 1d5bea312..2c62121ae 160000 --- a/dap-ui-sdk +++ b/dap-ui-sdk @@ -1 +1 @@ -Subproject commit 1d5bea3124da07a7d83c3387515486c35dbdfdeb +Subproject commit 2c62121ae0a291c1023059337c77b5dc2d572c59 -- GitLab