From 7e44c34491a62cba5ecef5253404e0a25241a74b Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 8 Dec 2014 15:41:22 +0100 Subject: [PATCH] - manage Debugger states calculation in a separate thread (avoid blocking the UI) --- mix/AssemblyDebuggerCtrl.cpp | 25 +++++++++++++++++++------ mix/AssemblyDebuggerCtrl.h | 8 ++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/mix/AssemblyDebuggerCtrl.cpp b/mix/AssemblyDebuggerCtrl.cpp index 6e2b11e70..4d293cd8d 100644 --- a/mix/AssemblyDebuggerCtrl.cpp +++ b/mix/AssemblyDebuggerCtrl.cpp @@ -17,6 +17,7 @@ * display opcode debugging. */ +#include #include #include #include @@ -31,6 +32,9 @@ using namespace dev::mix; AssemblyDebuggerCtrl::AssemblyDebuggerCtrl(QTextDocument* _doc): Extension(ExtensionDisplayBehavior::ModalDialog) { + qRegisterMetaType(); + connect(this, SIGNAL(dataAvailable(QList, AssemblyDebuggerData)), + this, SLOT(updateGUI(QList, AssemblyDebuggerData)), Qt::QueuedConnection); m_modelDebugger = std::unique_ptr(new AssemblyDebuggerModel); m_doc = _doc; } @@ -56,6 +60,9 @@ void AssemblyDebuggerCtrl::keyPressed(int _key) if (_key == Qt::Key_F5) { + QString code = m_doc->toPlainText(); + QtConcurrent::run([this, code](){ + if (!m_modelDebugger->compile(m_doc->toPlainText())) { AppContext::getInstance()->displayMessageDialog("debugger","compilation failed"); @@ -76,10 +83,16 @@ void AssemblyDebuggerCtrl::keyPressed(int _key) s->setState(debuggingContent.states.at(i)); wStates.append(s); } - std::tuple, QQMLMap*> code = DebuggingStateWrapper::getHumanReadableCode(debuggingContent.executionCode, this); - AppContext::getInstance()->appEngine()->rootContext()->setContextProperty("debugStates", QVariant::fromValue(wStates)); - AppContext::getInstance()->appEngine()->rootContext()->setContextProperty("humanReadableExecutionCode", QVariant::fromValue(std::get<0>(code))); - AppContext::getInstance()->appEngine()->rootContext()->setContextProperty("bytesCodeMapping", QVariant::fromValue(std::get<1>(code))); - this->addContentOn(this); - }; + AssemblyDebuggerData code = DebuggingStateWrapper::getHumanReadableCode(debuggingContent.executionCode, this); + emit dataAvailable(wStates, code); + }); + } +} + +void AssemblyDebuggerCtrl::updateGUI(QList _wStates, AssemblyDebuggerData _code) +{ + AppContext::getInstance()->appEngine()->rootContext()->setContextProperty("debugStates", QVariant::fromValue(_wStates)); + AppContext::getInstance()->appEngine()->rootContext()->setContextProperty("humanReadableExecutionCode", QVariant::fromValue(std::get<0>(_code))); + AppContext::getInstance()->appEngine()->rootContext()->setContextProperty("bytesCodeMapping", QVariant::fromValue(std::get<1>(_code))); + this->addContentOn(this); } diff --git a/mix/AssemblyDebuggerCtrl.h b/mix/AssemblyDebuggerCtrl.h index a1642cc14..66256e472 100644 --- a/mix/AssemblyDebuggerCtrl.h +++ b/mix/AssemblyDebuggerCtrl.h @@ -25,6 +25,9 @@ #include "ConstantCompilationModel.h" #include "AssemblyDebuggerModel.h" +using AssemblyDebuggerData = std::tuple, dev::mix::QQMLMap*>; +Q_DECLARE_METATYPE(AssemblyDebuggerData) + namespace dev { @@ -48,6 +51,11 @@ private: public Q_SLOTS: void keyPressed(int); + void updateGUI(QList _wStates, AssemblyDebuggerData _code); + +signals: + void dataAvailable(QList _wStates, AssemblyDebuggerData _code); + }; }