From 81b0e0e910388cafa1815ec42be42e7ed611b1f7 Mon Sep 17 00:00:00 2001 From: arkpar Date: Fri, 19 Dec 2014 17:13:31 +0100 Subject: [PATCH 1/2] fixed typo --- mix/TransactionListModel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix/TransactionListModel.h b/mix/TransactionListModel.h index 28800a4ff..fdf420683 100644 --- a/mix/TransactionListModel.h +++ b/mix/TransactionListModel.h @@ -154,7 +154,7 @@ public: signals: /// Transaction count has changed void countChanged(); - /// Transaction has be launched + /// Transaction has been launched void transactionStarted(dev::mix::TransactionSettings); private: From ab57c7a5ffca5543fc4cbfccca9471b5bbc51064 Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 22 Dec 2014 12:16:57 +0100 Subject: [PATCH 2/2] removed unnessary casts, fixed geteItem return type --- mix/TransactionListModel.cpp | 33 ++++++++++++++++++--------------- mix/TransactionListModel.h | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/mix/TransactionListModel.cpp b/mix/TransactionListModel.cpp index 5c2cc186d..64964b898 100644 --- a/mix/TransactionListModel.cpp +++ b/mix/TransactionListModel.cpp @@ -24,11 +24,12 @@ #include #include #include +#include #include "TransactionListModel.h" #include "QContractDefinition.h" #include "QFunctionDefinition.h" #include "QVariableDeclaration.h" -#include "libdevcore/CommonJS.h" + namespace dev { @@ -56,7 +57,9 @@ TransactionListItem::TransactionListItem(int _index, TransactionSettings const& TransactionListModel::TransactionListModel(QObject* _parent, QTextDocument* _document): QAbstractListModel(_parent), m_document(_document) -{} +{ + qRegisterMetaType("TransactionListItem*"); +} QHash TransactionListModel::roleNames() const { @@ -96,25 +99,24 @@ QList buildParameters(QTextDocument* _document, Trans { std::shared_ptr contract = QContractDefinition::Contract(_document->toPlainText()); auto functions = contract->functions(); - for (auto qf : functions) + for (auto f : functions) { - QFunctionDefinition const& f = (QFunctionDefinition const&) *qf; - if (f.name() != _functionId) + if (f->name() != _functionId) continue; - auto parameters = f.parameters(); - for (auto qp : parameters) + auto parameters = f->parameters(); + //build a list of parameters for a function. If the function is selected as current, add parameter values as well + for (auto p : parameters) { - QVariableDeclaration const& p = (QVariableDeclaration const&) *qp; QString paramValue; - if (f.name() == _transaction.functionId) + if (f->name() == _transaction.functionId) { - auto paramValueIter = _transaction.parameterValues.find(p.name()); + auto paramValueIter = _transaction.parameterValues.find(p->name()); if (paramValueIter != _transaction.parameterValues.cend()) paramValue = toQString(paramValueIter->second); } - TransactionParameterItem* item = new TransactionParameterItem(p.name(), p.type(), paramValue); + TransactionParameterItem* item = new TransactionParameterItem(p->name(), p->type(), paramValue); QQmlEngine::setObjectOwnership(item, QQmlEngine::JavaScriptOwnership); params.append(item); } @@ -137,10 +139,9 @@ QList TransactionListModel::getFunctions() QString code = m_document->toPlainText(); std::shared_ptr contract(QContractDefinition::Contract(code)); auto functions = contract->functions(); - for (auto qf : functions) + for (auto f : functions) { - QFunctionDefinition const& f = (QFunctionDefinition const&) * qf; - functionNames.append(f.name()); + functionNames.append(f->name()); } } catch (boost::exception const&) @@ -159,7 +160,7 @@ QVariantList TransactionListModel::getParameters(int _index, QString const& _fun return vl; } -QObject* TransactionListModel::getItem(int _index) +TransactionListItem* TransactionListModel::getItem(int _index) { TransactionSettings const& transaction = (_index >= 0 && _index < (int)m_transactions.size()) ? m_transactions[_index] : TransactionSettings(); TransactionListItem* item = new TransactionListItem(_index, transaction, nullptr); @@ -214,5 +215,7 @@ void TransactionListModel::runTransaction(int _index) emit transactionStarted(tr); } + } } + diff --git a/mix/TransactionListModel.h b/mix/TransactionListModel.h index fdf420683..d321fc91c 100644 --- a/mix/TransactionListModel.h +++ b/mix/TransactionListModel.h @@ -143,7 +143,7 @@ public: /// @todo Change that to transaction item Q_INVOKABLE void edit(QObject* _data); /// @returns transaction item for a give index - Q_INVOKABLE QObject* getItem(int _index); + Q_INVOKABLE TransactionListItem* getItem(int _index); /// @returns a list of functions for current contract Q_INVOKABLE QList getFunctions(); /// @returns function parameters along with parameter values if set. @see TransactionParameterItem