Browse Source

use unique_ptr for QQMLApplicationEngine

cl-refactor
yann300 10 years ago
parent
commit
eb3e005dee
  1. 11
      mix/ApplicationCtx.cpp
  2. 4
      mix/ApplicationCtx.h

11
mix/ApplicationCtx.cpp

@ -37,19 +37,14 @@ ApplicationCtx* ApplicationCtx::Instance = nullptr;
ApplicationCtx::ApplicationCtx(QQmlApplicationEngine* _engine) ApplicationCtx::ApplicationCtx(QQmlApplicationEngine* _engine)
{ {
m_applicationEngine = _engine; m_applicationEngine = std::unique_ptr<QQmlApplicationEngine>(_engine);
m_keyEventManager = std::unique_ptr<KeyEventManager>(new KeyEventManager()); m_keyEventManager = std::unique_ptr<KeyEventManager>(new KeyEventManager());
m_webThree = std::unique_ptr<dev::WebThreeDirect>(new WebThreeDirect(std::string("Mix/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir() + "/Mix", false, {"eth", "shh"})); m_webThree = std::unique_ptr<dev::WebThreeDirect>(new WebThreeDirect(std::string("Mix/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir() + "/Mix", false, {"eth", "shh"}));
} }
ApplicationCtx::~ApplicationCtx()
{
delete m_applicationEngine;
}
QQmlApplicationEngine* ApplicationCtx::appEngine() QQmlApplicationEngine* ApplicationCtx::appEngine()
{ {
return m_applicationEngine; return m_applicationEngine.get();
} }
dev::eth::Client* ApplicationCtx::getEthereumClient() dev::eth::Client* ApplicationCtx::getEthereumClient()
@ -81,7 +76,7 @@ void ApplicationCtx::setApplicationContext(QQmlApplicationEngine* _engine)
void ApplicationCtx::displayMessageDialog(QString _title, QString _message) void ApplicationCtx::displayMessageDialog(QString _title, QString _message)
{ {
QQmlComponent component(m_applicationEngine, QUrl("qrc:/qml/BasicMessage.qml")); QQmlComponent component(m_applicationEngine.get(), QUrl("qrc:/qml/BasicMessage.qml"));
QObject* dialog = component.create(); QObject* dialog = component.create();
dialog->findChild<QObject*>("messageContent", Qt::FindChildrenRecursively)->setProperty("text", _message); dialog->findChild<QObject*>("messageContent", Qt::FindChildrenRecursively)->setProperty("text", _message);
QObject* dialogWin = ApplicationCtx::getInstance()->appEngine()->rootObjects().at(0)->findChild<QObject*>("messageDialog", Qt::FindChildrenRecursively); QObject* dialogWin = ApplicationCtx::getInstance()->appEngine()->rootObjects().at(0)->findChild<QObject*>("messageDialog", Qt::FindChildrenRecursively);

4
mix/ApplicationCtx.h

@ -42,7 +42,7 @@ class ApplicationCtx: public QObject
public: public:
ApplicationCtx(QQmlApplicationEngine* _engine); ApplicationCtx(QQmlApplicationEngine* _engine);
~ApplicationCtx(); ~ApplicationCtx() {}
static ApplicationCtx* getInstance() { return Instance; } static ApplicationCtx* getInstance() { return Instance; }
static void setApplicationContext(QQmlApplicationEngine* _engine); static void setApplicationContext(QQmlApplicationEngine* _engine);
QQmlApplicationEngine* appEngine(); QQmlApplicationEngine* appEngine();
@ -53,7 +53,7 @@ public:
private: private:
static ApplicationCtx* Instance; static ApplicationCtx* Instance;
QQmlApplicationEngine* m_applicationEngine; std::unique_ptr<QQmlApplicationEngine> m_applicationEngine;
std::unique_ptr<dev::WebThreeDirect> m_webThree; std::unique_ptr<dev::WebThreeDirect> m_webThree;
std::unique_ptr<KeyEventManager> m_keyEventManager; std::unique_ptr<KeyEventManager> m_keyEventManager;

Loading…
Cancel
Save