Browse Source

Merge remote-tracking branch 'arkpar2/mix' into ide_m25

cl-refactor
yann300 10 years ago
parent
commit
6cd9587f0a
  1. 2
      mix/CodeEditorExtensionManager.cpp
  2. 30
      mix/TransactionListModel.cpp
  3. 11
      mix/TransactionListModel.h
  4. 3
      mix/TransactionListView.h

2
mix/CodeEditorExtensionManager.cpp

@ -73,7 +73,7 @@ void CodeEditorExtensionManager::initExtensions()
initExtension(std::make_shared<ConstantCompilationCtrl>(m_doc)); initExtension(std::make_shared<ConstantCompilationCtrl>(m_doc));
std::shared_ptr<AssemblyDebuggerCtrl> debug = std::make_shared<AssemblyDebuggerCtrl>(m_doc); std::shared_ptr<AssemblyDebuggerCtrl> debug = std::make_shared<AssemblyDebuggerCtrl>(m_doc);
std::shared_ptr<TransactionListView> tr = std::make_shared<TransactionListView>(m_doc); std::shared_ptr<TransactionListView> tr = std::make_shared<TransactionListView>(m_doc);
QObject::connect(tr->model(), &TransactionListModel::transactionRan, debug.get(), &AssemblyDebuggerCtrl::runTransaction); QObject::connect(tr->model(), &TransactionListModel::transactionStarted, debug.get(), &AssemblyDebuggerCtrl::runTransaction);
initExtension(debug); initExtension(debug);
initExtension(tr); initExtension(tr);
} }

30
mix/TransactionListModel.cpp

@ -35,11 +35,13 @@ namespace dev
namespace mix namespace mix
{ {
/// @todo Move this to QML
u256 fromQString(QString const& _s) u256 fromQString(QString const& _s)
{ {
return dev::jsToU256(_s.toStdString()); return dev::jsToU256(_s.toStdString());
} }
/// @todo Move this to QML
QString toQString(u256 _value) QString toQString(u256 _value)
{ {
std::ostringstream s; std::ostringstream s;
@ -72,10 +74,10 @@ int TransactionListModel::rowCount(QModelIndex const& _parent) const
QVariant TransactionListModel::data(QModelIndex const& _index, int _role) const QVariant TransactionListModel::data(QModelIndex const& _index, int _role) const
{ {
if(_index.row() < 0 || _index.row() >= (int)m_transactions.size()) if (_index.row() < 0 || _index.row() >= (int)m_transactions.size())
return QVariant(); return QVariant();
auto const& transaction = m_transactions.at(_index.row()); auto const& transaction = m_transactions.at(_index.row());
switch(_role) switch (_role)
{ {
case TitleRole: case TitleRole:
return QVariant(transaction.title); return QVariant(transaction.title);
@ -86,7 +88,7 @@ QVariant TransactionListModel::data(QModelIndex const& _index, int _role) const
} }
} }
//TODO: get parameters from code model ///@todo: get parameters from code model
QList<TransactionParameterItem*> buildParameters(QTextDocument* _document, TransactionSettings const& _transaction, QString const& _functionId) QList<TransactionParameterItem*> buildParameters(QTextDocument* _document, TransactionSettings const& _transaction, QString const& _functionId)
{ {
QList<TransactionParameterItem*> params; QList<TransactionParameterItem*> params;
@ -94,14 +96,14 @@ QList<TransactionParameterItem*> buildParameters(QTextDocument* _document, Trans
{ {
std::shared_ptr<QContractDefinition> contract = QContractDefinition::Contract(_document->toPlainText()); std::shared_ptr<QContractDefinition> contract = QContractDefinition::Contract(_document->toPlainText());
auto functions = contract->functions(); auto functions = contract->functions();
for(auto qf : functions) for (auto qf : functions)
{ {
QFunctionDefinition const& f = (QFunctionDefinition const&) *qf; QFunctionDefinition const& f = (QFunctionDefinition const&) *qf;
if (f.name() != _functionId) if (f.name() != _functionId)
continue; continue;
auto parameters = f.parameters(); auto parameters = f.parameters();
for(auto qp : parameters) for (auto qp : parameters)
{ {
QVariableDeclaration const& p = (QVariableDeclaration const&) *qp; QVariableDeclaration const& p = (QVariableDeclaration const&) *qp;
QString paramValue; QString paramValue;
@ -126,7 +128,7 @@ QList<TransactionParameterItem*> buildParameters(QTextDocument* _document, Trans
return params; return params;
} }
//TODO: get fnctions from code model ///@todo: get fnctions from code model
QList<QString> TransactionListModel::getFunctions() QList<QString> TransactionListModel::getFunctions()
{ {
QList<QString> functionNames; QList<QString> functionNames;
@ -135,9 +137,9 @@ QList<QString> TransactionListModel::getFunctions()
QString code = m_document->toPlainText(); QString code = m_document->toPlainText();
std::shared_ptr<QContractDefinition> contract(QContractDefinition::Contract(code)); std::shared_ptr<QContractDefinition> contract(QContractDefinition::Contract(code));
auto functions = contract->functions(); auto functions = contract->functions();
for(auto qf : functions) for (auto qf : functions)
{ {
QFunctionDefinition const& f = (QFunctionDefinition const&) *qf; QFunctionDefinition const& f = (QFunctionDefinition const&) * qf;
functionNames.append(f.name()); functionNames.append(f.name());
} }
} }
@ -149,17 +151,17 @@ QList<QString> TransactionListModel::getFunctions()
QVariantList TransactionListModel::getParameters(int _index, QString const& _functionId) QVariantList TransactionListModel::getParameters(int _index, QString const& _functionId)
{ {
TransactionSettings const& transaction = (_index >=0 && _index < (int)m_transactions.size()) ? m_transactions[_index] : TransactionSettings(); TransactionSettings const& transaction = (_index >= 0 && _index < (int)m_transactions.size()) ? m_transactions[_index] : TransactionSettings();
auto plist = buildParameters(m_document, transaction, _functionId); auto plist = buildParameters(m_document, transaction, _functionId);
QVariantList vl; QVariantList vl;
for(QObject* p : plist) for (QObject* p : plist)
vl.append(QVariant::fromValue(p)); vl.append(QVariant::fromValue(p));
return vl; return vl;
} }
QObject* TransactionListModel::getItem(int _index) QObject* TransactionListModel::getItem(int _index)
{ {
TransactionSettings const& transaction = (_index >=0 && _index < (int)m_transactions.size()) ? m_transactions[_index] : TransactionSettings(); TransactionSettings const& transaction = (_index >= 0 && _index < (int)m_transactions.size()) ? m_transactions[_index] : TransactionSettings();
TransactionListItem* item = new TransactionListItem(_index, transaction, nullptr); TransactionListItem* item = new TransactionListItem(_index, transaction, nullptr);
QQmlEngine::setObjectOwnership(item, QQmlEngine::JavaScriptOwnership); QQmlEngine::setObjectOwnership(item, QQmlEngine::JavaScriptOwnership);
return item; return item;
@ -168,6 +170,7 @@ QObject* TransactionListModel::getItem(int _index)
void TransactionListModel::edit(QObject* _data) void TransactionListModel::edit(QObject* _data)
{ {
//these properties come from TransactionDialog QML object //these properties come from TransactionDialog QML object
///@todo change the model to a qml component
int index = _data->property("transactionIndex").toInt(); int index = _data->property("transactionIndex").toInt();
QString title = _data->property("transactionTitle").toString(); QString title = _data->property("transactionTitle").toString();
QString gas = _data->property("gas").toString(); QString gas = _data->property("gas").toString();
@ -177,7 +180,7 @@ void TransactionListModel::edit(QObject* _data)
QAbstractListModel* paramsModel = qvariant_cast<QAbstractListModel*>(_data->property("transactionParams")); QAbstractListModel* paramsModel = qvariant_cast<QAbstractListModel*>(_data->property("transactionParams"));
TransactionSettings transaction(title, functionId, fromQString(value), fromQString(gas), fromQString(gasPrice)); TransactionSettings transaction(title, functionId, fromQString(value), fromQString(gas), fromQString(gasPrice));
int paramCount = paramsModel->rowCount(QModelIndex()); int paramCount = paramsModel->rowCount(QModelIndex());
for(int p = 0; p < paramCount; ++p) for (int p = 0; p < paramCount; ++p)
{ {
QString paramName = paramsModel->data(paramsModel->index(p, 0), Qt::DisplayRole).toString(); QString paramName = paramsModel->data(paramsModel->index(p, 0), Qt::DisplayRole).toString();
QString paramValue = paramsModel->data(paramsModel->index(p, 0), Qt::DisplayRole + 2).toString(); QString paramValue = paramsModel->data(paramsModel->index(p, 0), Qt::DisplayRole + 2).toString();
@ -196,7 +199,6 @@ void TransactionListModel::edit(QObject* _data)
beginInsertRows(QModelIndex(), index, index); beginInsertRows(QModelIndex(), index, index);
m_transactions.push_back(transaction); m_transactions.push_back(transaction);
emit transactionAdded();
emit countChanged(); emit countChanged();
endInsertRows(); endInsertRows();
} }
@ -209,7 +211,7 @@ int TransactionListModel::getCount() const
void TransactionListModel::runTransaction(int _index) void TransactionListModel::runTransaction(int _index)
{ {
TransactionSettings tr = m_transactions.at(_index); TransactionSettings tr = m_transactions.at(_index);
emit transactionRan(tr); emit transactionStarted(tr);
} }
} }

11
mix/TransactionListModel.h

@ -28,6 +28,7 @@
#include <QHash> #include <QHash>
#include <QByteArray> #include <QByteArray>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libethcore/CommonEth.h>
class QTextDocument; class QTextDocument;
@ -40,7 +41,7 @@ namespace mix
struct TransactionSettings struct TransactionSettings
{ {
TransactionSettings(): TransactionSettings():
value(0), gas(10000), gasPrice(10) {} value(0), gas(10000), gasPrice(10 * dev::eth::szabo) {}
TransactionSettings(QString const& _title, QString const& _functionId, u256 _value, u256 _gas, u256 _gasPrice): TransactionSettings(QString const& _title, QString const& _functionId, u256 _value, u256 _gas, u256 _gasPrice):
title(_title), functionId(_functionId), value(_value), gas(_gas), gasPrice(_gasPrice) {} title(_title), functionId(_functionId), value(_value), gas(_gas), gasPrice(_gasPrice) {}
@ -124,7 +125,7 @@ class TransactionListModel: public QAbstractListModel
Q_OBJECT Q_OBJECT
Q_PROPERTY(int count READ getCount() NOTIFY countChanged()) Q_PROPERTY(int count READ getCount() NOTIFY countChanged())
enum Roles enum Roles
{ {
TitleRole = Qt::DisplayRole, TitleRole = Qt::DisplayRole,
IdRole = Qt::UserRole + 1 IdRole = Qt::UserRole + 1
@ -147,12 +148,14 @@ public:
Q_INVOKABLE QList<QString> getFunctions(); Q_INVOKABLE QList<QString> getFunctions();
/// @returns function parameters along with parameter values if set. @see TransactionParameterItem /// @returns function parameters along with parameter values if set. @see TransactionParameterItem
Q_INVOKABLE QVariantList getParameters(int _id, QString const& _functionId); Q_INVOKABLE QVariantList getParameters(int _id, QString const& _functionId);
/// Launch transaction execution UI handler
Q_INVOKABLE void runTransaction(int _index); Q_INVOKABLE void runTransaction(int _index);
signals: signals:
void transactionAdded(); /// Transaction count has changed
void countChanged(); void countChanged();
void transactionRan(dev::mix::TransactionSettings); /// Transaction has be launched
void transactionStarted(dev::mix::TransactionSettings);
private: private:
std::vector<TransactionSettings> m_transactions; std::vector<TransactionSettings> m_transactions;

3
mix/TransactionListView.h

@ -42,13 +42,12 @@ public:
void start() const override; void start() const override;
QString title() const override; QString title() const override;
QString contentUrl() const override; QString contentUrl() const override;
/// @returns the underlying model
TransactionListModel* model() const { return m_model.get(); } TransactionListModel* model() const { return m_model.get(); }
private: private:
QTextDocument* m_editor; QTextDocument* m_editor;
std::unique_ptr<TransactionListModel> m_model; std::unique_ptr<TransactionListModel> m_model;
public slots:
}; };
} }

Loading…
Cancel
Save