From dbc5201e98c1fdc1e09f1fe3108a6c10f6b20fc1 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 5 Dec 2014 12:57:09 +0100 Subject: [PATCH] - coding standards. - set 'parent' on QObject custom class to ensure object deletion. --- mix/ApplicationCtx.cpp | 6 ++---- mix/AssemblyDebuggerCtrl.cpp | 2 +- mix/AssemblyDebuggerModel.cpp | 1 - mix/AssemblyDebuggerModel.h | 1 + mix/CodeEditorExtensionManager.cpp | 12 ++++++------ mix/ConstantCompilationModel.h | 2 +- mix/DebuggingStateWrapper.cpp | 6 +++--- mix/DebuggingStateWrapper.h | 6 +++--- mix/qml/Debugger.qml | 2 +- 9 files changed, 18 insertions(+), 20 deletions(-) diff --git a/mix/ApplicationCtx.cpp b/mix/ApplicationCtx.cpp index 52e66dab7..99d9bee4c 100644 --- a/mix/ApplicationCtx.cpp +++ b/mix/ApplicationCtx.cpp @@ -38,10 +38,8 @@ ApplicationCtx* ApplicationCtx::Instance = nullptr; ApplicationCtx::ApplicationCtx(QQmlApplicationEngine* _engine) { m_applicationEngine = _engine; - m_keyEventManager = std::unique_ptr(); - m_webThree = std::unique_ptr(); - m_webThree.reset(new WebThreeDirect(std::string("Mix/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir() + "/Mix", false, {"eth", "shh"})); - m_keyEventManager.reset(new KeyEventManager()); + m_keyEventManager = std::unique_ptr(new KeyEventManager()); + m_webThree = std::unique_ptr(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() diff --git a/mix/AssemblyDebuggerCtrl.cpp b/mix/AssemblyDebuggerCtrl.cpp index e8b0391d8..94d8bf6cb 100644 --- a/mix/AssemblyDebuggerCtrl.cpp +++ b/mix/AssemblyDebuggerCtrl.cpp @@ -75,7 +75,7 @@ void AssemblyDebuggerCtrl::keyPressed(int _key) s->setState(debuggingContent.states.at(i)); wStates.append(s); } - std::tuple, QQMLMap*> code = DebuggingStateWrapper::getHumanReadableCode(debuggingContent.executionCode); + std::tuple, QQMLMap*> code = DebuggingStateWrapper::getHumanReadableCode(debuggingContent.executionCode, this); ApplicationCtx::getInstance()->appEngine()->rootContext()->setContextProperty("debugStates", QVariant::fromValue(wStates)); ApplicationCtx::getInstance()->appEngine()->rootContext()->setContextProperty("humanReadableExecutionCode", QVariant::fromValue(std::get<0>(code))); ApplicationCtx::getInstance()->appEngine()->rootContext()->setContextProperty("bytesCodeMapping", QVariant::fromValue(std::get<1>(code))); diff --git a/mix/AssemblyDebuggerModel.cpp b/mix/AssemblyDebuggerModel.cpp index c65beac7d..df027acf7 100644 --- a/mix/AssemblyDebuggerModel.cpp +++ b/mix/AssemblyDebuggerModel.cpp @@ -78,7 +78,6 @@ DebuggingContent AssemblyDebuggerModel::getContractInitiationDebugStates(dev::by return d; } - DebuggingContent AssemblyDebuggerModel::getContractInitiationDebugStates(dev::u256 _value, dev::u256 _gasPrice, dev::u256 _gas, diff --git a/mix/AssemblyDebuggerModel.h b/mix/AssemblyDebuggerModel.h index 3cac98db0..378f238e6 100644 --- a/mix/AssemblyDebuggerModel.h +++ b/mix/AssemblyDebuggerModel.h @@ -25,6 +25,7 @@ #include "libethereum/Executive.h" #include "libdevcore/Common.h" #include "DebuggingStateWrapper.h" + namespace dev { diff --git a/mix/CodeEditorExtensionManager.cpp b/mix/CodeEditorExtensionManager.cpp index c85292f2b..503e07447 100644 --- a/mix/CodeEditorExtensionManager.cpp +++ b/mix/CodeEditorExtensionManager.cpp @@ -64,15 +64,15 @@ void CodeEditorExtensionManager::initExtensions() initExtension(std::make_shared(m_doc)); } -void CodeEditorExtensionManager::initExtension(std::shared_ptr ext) +void CodeEditorExtensionManager::initExtension(std::shared_ptr _ext) { - if (!ext.get()->contentUrl().isEmpty()) + if (!_ext.get()->contentUrl().isEmpty()) { try { - if (ext.get()->getDisplayBehavior() == ExtensionDisplayBehavior::Tab) + if (_ext.get()->getDisplayBehavior() == ExtensionDisplayBehavior::Tab) { - ext.get()->addTabOn(m_tabView); + _ext.get()->addTabOn(m_tabView); } } catch (...) @@ -81,8 +81,8 @@ void CodeEditorExtensionManager::initExtension(std::shared_ptr ext) return; } } - ext.get()->start(); - m_features.append(ext); + _ext.get()->start(); + m_features.append(_ext); } void CodeEditorExtensionManager::setEditor(QQuickItem* _editor) diff --git a/mix/ConstantCompilationModel.h b/mix/ConstantCompilationModel.h index 01ad32224..713c9e950 100644 --- a/mix/ConstantCompilationModel.h +++ b/mix/ConstantCompilationModel.h @@ -45,7 +45,7 @@ class ConstantCompilationModel public: ConstantCompilationModel() {} ~ConstantCompilationModel() {} - CompilerResult compile(QString code); + CompilerResult compile(QString); }; } diff --git a/mix/DebuggingStateWrapper.cpp b/mix/DebuggingStateWrapper.cpp index 877598ca5..3bce8658b 100644 --- a/mix/DebuggingStateWrapper.cpp +++ b/mix/DebuggingStateWrapper.cpp @@ -31,7 +31,7 @@ using namespace dev; using namespace dev::eth; using namespace dev::mix; -std::tuple, QQMLMap*> DebuggingStateWrapper::getHumanReadableCode(const bytes& code) +std::tuple, QQMLMap*> DebuggingStateWrapper::getHumanReadableCode(const bytes& code, QObject* _objUsedAsParent) { QList codeStr; QMap codeMapping; @@ -51,7 +51,7 @@ std::tuple, QQMLMap*> DebuggingStateWrapper::getHumanReadableCod s = "PUSH 0x" + QString::fromStdString(toHex(bytesConstRef(&code[i + 1], bc))); i += bc; } - HumanReadableCode* humanCode = new HumanReadableCode(QString::fromStdString(out.str()) + " " + s, line); + HumanReadableCode* humanCode = new HumanReadableCode(QString::fromStdString(out.str()) + " " + s, line, _objUsedAsParent); codeStr.append(humanCode); } catch (...) @@ -61,7 +61,7 @@ std::tuple, QQMLMap*> DebuggingStateWrapper::getHumanReadableCod break; // probably hit data segment } } - return std::make_tuple(codeStr, new QQMLMap(codeMapping)); + return std::make_tuple(codeStr, new QQMLMap(codeMapping, _objUsedAsParent)); } QString DebuggingStateWrapper::debugStack() diff --git a/mix/DebuggingStateWrapper.h b/mix/DebuggingStateWrapper.h index 07716e9ad..0285a4693 100644 --- a/mix/DebuggingStateWrapper.h +++ b/mix/DebuggingStateWrapper.h @@ -65,7 +65,7 @@ class HumanReadableCode: public QObject Q_PROPERTY(int processIndex READ processIndex) public: - HumanReadableCode(QString _line, int _processIndex) : m_line(_line), m_processIndex(_processIndex) {} + HumanReadableCode(QString _line, int _processIndex, QObject* _parent) : m_line(_line), m_processIndex(_processIndex), QObject(_parent) {} QString line() { return m_line; } int processIndex() { return m_processIndex; } @@ -80,7 +80,7 @@ class QQMLMap : public QObject Q_OBJECT public: - QQMLMap(QMap _map) : m_map(_map) { } + QQMLMap(QMap _map, QObject* _parent) : m_map(_map), QObject(_parent) { } Q_INVOKABLE int getValue(int _key) { return m_map.value(_key); } private: @@ -118,7 +118,7 @@ public: QStringList levels(); DebuggingState state() { return m_state; } void setState(DebuggingState _state) { m_state = _state; } - static std::tuple, QQMLMap*> getHumanReadableCode(bytes const& code); + static std::tuple, QQMLMap*> getHumanReadableCode(bytes const& code, QObject* _objUsedAsParent); private: DebuggingState m_state; diff --git a/mix/qml/Debugger.qml b/mix/qml/Debugger.qml index 490f49f61..6802f57df 100644 --- a/mix/qml/Debugger.qml +++ b/mix/qml/Debugger.qml @@ -84,7 +84,7 @@ Rectangle { anchors.top: statesList.bottom height: parent.height * 0.35 width: parent.width - anchors.topMargin: 13 + anchors.topMargin: 15 color: "transparent" Label { id: callStackLabel