Skip to content
Snippets Groups Projects
Commit 573b6e18 authored by Alexandr Mruchok's avatar Alexandr Mruchok
Browse files

[+] DapApplication

parent b238f526
No related branches found
No related tags found
1 merge request!11Cellframe clone
......@@ -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)
......
#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()));
}
#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
......@@ -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();
}
Subproject commit e553fb10954bf6b8ec1ccc3dd0a8249e838f607f
Subproject commit 8d533dad6022bd413aab9bf99cbbd8e95aaf27f0
Subproject commit 54556afb3e929b5c132e882c911b94965eb836cb
Subproject commit 9db15afc70f9382737614d07f89b3f3e2a8e9707
Subproject commit 1d5bea3124da07a7d83c3387515486c35dbdfdeb
Subproject commit 2c62121ae0a291c1023059337c77b5dc2d572c59
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment