Browse Source
ide_m25 Conflicts: libdevcore/CommonJS.cpp libdevcore/CommonJS.h mix/AssemblyDebuggerCtrl.cpp mix/AssemblyDebuggerCtrl.h mix/AssemblyDebuggerModel.cpp mix/DebuggingStateWrapper.cpp mix/QBasicNodeDefinition.h mix/QFunctionDefinition.h mix/QVariableDeclaration.h mix/TransactionBuilder.cpp mix/TransactionBuilder.hcl-refactor
yann300
10 years ago
45 changed files with 1215 additions and 329 deletions
@ -0,0 +1,217 @@ |
|||||
|
/*
|
||||
|
This file is part of cpp-ethereum. |
||||
|
|
||||
|
cpp-ethereum is free software: you can redistribute it and/or modify |
||||
|
it under the terms of the GNU General Public License as published by |
||||
|
the Free Software Foundation, either version 3 of the License, or |
||||
|
(at your option) any later version. |
||||
|
|
||||
|
cpp-ethereum is distributed in the hope that it will be useful, |
||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
GNU General Public License for more details. |
||||
|
|
||||
|
You should have received a copy of the GNU General Public License |
||||
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
/** @file TransactionListModel.cpp
|
||||
|
* @author Arkadiy Paronyan arkadiy@ethdev.com |
||||
|
* @date 2014 |
||||
|
* Ethereum IDE client. |
||||
|
*/ |
||||
|
|
||||
|
#include <QObject> |
||||
|
#include <QQmlEngine> |
||||
|
#include <QTextDocument> |
||||
|
#include <QAbstractListModel> |
||||
|
#include "TransactionListModel.h" |
||||
|
#include "QContractDefinition.h" |
||||
|
#include "QFunctionDefinition.h" |
||||
|
#include "QVariableDeclaration.h" |
||||
|
#include "libdevcore/CommonJS.h" |
||||
|
|
||||
|
namespace dev |
||||
|
{ |
||||
|
namespace mix |
||||
|
{ |
||||
|
|
||||
|
u256 fromQString(QString const& _s) |
||||
|
{ |
||||
|
return dev::jsToU256(_s.toStdString()); |
||||
|
} |
||||
|
|
||||
|
QString toQString(u256 _value) |
||||
|
{ |
||||
|
std::ostringstream s; |
||||
|
s << _value; |
||||
|
return QString::fromStdString(s.str()); |
||||
|
} |
||||
|
|
||||
|
TransactionListItem::TransactionListItem(int _index, TransactionSettings const& _t, QObject* _parent): |
||||
|
QObject(_parent), m_index(_index), m_title(_t.title), m_functionId(_t.functionId), m_value(toQString(_t.value)), |
||||
|
m_gas(toQString(_t.gas)), m_gasPrice(toQString(_t.gasPrice)) |
||||
|
{} |
||||
|
|
||||
|
TransactionListModel::TransactionListModel(QObject* _parent, QTextDocument* _document): |
||||
|
QAbstractListModel(_parent), m_document(_document) |
||||
|
{} |
||||
|
|
||||
|
QHash<int, QByteArray> TransactionListModel::roleNames() const |
||||
|
{ |
||||
|
QHash<int, QByteArray> roles; |
||||
|
roles[TitleRole] = "title"; |
||||
|
roles[IdRole] = "transactionIndex"; |
||||
|
return roles; |
||||
|
} |
||||
|
|
||||
|
int TransactionListModel::rowCount(QModelIndex const& _parent) const |
||||
|
{ |
||||
|
Q_UNUSED(_parent); |
||||
|
return m_transactions.size(); |
||||
|
} |
||||
|
|
||||
|
QVariant TransactionListModel::data(QModelIndex const& _index, int _role) const |
||||
|
{ |
||||
|
if(_index.row() < 0 || _index.row() >= (int)m_transactions.size()) |
||||
|
return QVariant(); |
||||
|
auto const& transaction = m_transactions.at(_index.row()); |
||||
|
switch(_role) |
||||
|
{ |
||||
|
case TitleRole: |
||||
|
return QVariant(transaction.title); |
||||
|
case IdRole: |
||||
|
return QVariant(_index.row()); |
||||
|
default: |
||||
|
return QVariant(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//TODO: get parameters from code model
|
||||
|
QList<TransactionParameterItem*> buildParameters(QTextDocument* _document, TransactionSettings const& _transaction, QString const& _functionId) |
||||
|
{ |
||||
|
QList<TransactionParameterItem*> params; |
||||
|
try |
||||
|
{ |
||||
|
QString code = _document->toPlainText().replace("\n", ""); //TODO: is this required?
|
||||
|
std::shared_ptr<QContractDefinition> contract = QContractDefinition::Contract(code); |
||||
|
auto functions = contract->functions(); |
||||
|
for(auto qf : functions) |
||||
|
{ |
||||
|
QFunctionDefinition const& f = (QFunctionDefinition const&) *qf; |
||||
|
if (f.name() != _functionId) |
||||
|
continue; |
||||
|
|
||||
|
auto parameters = f.parameters(); |
||||
|
for(auto qp : parameters) |
||||
|
{ |
||||
|
QVariableDeclaration const& p = (QVariableDeclaration const&) *qp; |
||||
|
QString paramValue; |
||||
|
if (f.name() == _transaction.functionId) |
||||
|
{ |
||||
|
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); |
||||
|
QQmlEngine::setObjectOwnership(item, QQmlEngine::JavaScriptOwnership); |
||||
|
params.append(item); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
catch (boost::exception const&) |
||||
|
{ |
||||
|
//TODO:
|
||||
|
} |
||||
|
|
||||
|
return params; |
||||
|
} |
||||
|
|
||||
|
//TODO: get fnctions from code model
|
||||
|
QList<QString> TransactionListModel::getFunctions() |
||||
|
{ |
||||
|
QList<QString> functionNames; |
||||
|
try |
||||
|
{ |
||||
|
QString code = m_document->toPlainText().replace("\n", ""); //TODO: is this required?
|
||||
|
std::shared_ptr<QContractDefinition> contract(QContractDefinition::Contract(code)); |
||||
|
auto functions = contract->functions(); |
||||
|
for(auto qf : functions) |
||||
|
{ |
||||
|
QFunctionDefinition const& f = (QFunctionDefinition const&) *qf; |
||||
|
functionNames.append(f.name()); |
||||
|
} |
||||
|
} |
||||
|
catch (boost::exception const&) |
||||
|
{ |
||||
|
} |
||||
|
return functionNames; |
||||
|
} |
||||
|
|
||||
|
QVariantList TransactionListModel::getParameters(int _index, QString const& _functionId) |
||||
|
{ |
||||
|
TransactionSettings const& transaction = (_index >=0 && _index < (int)m_transactions.size()) ? m_transactions[_index] : TransactionSettings(); |
||||
|
auto plist = buildParameters(m_document, transaction, _functionId); |
||||
|
QVariantList vl; |
||||
|
for(QObject* p : plist) |
||||
|
vl.append(QVariant::fromValue(p)); |
||||
|
return vl; |
||||
|
} |
||||
|
|
||||
|
QObject* 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); |
||||
|
QQmlEngine::setObjectOwnership(item, QQmlEngine::JavaScriptOwnership); |
||||
|
return item; |
||||
|
} |
||||
|
|
||||
|
void TransactionListModel::edit(QObject* _data) |
||||
|
{ |
||||
|
//these properties come from TransactionDialog QML object
|
||||
|
int index = _data->property("transactionIndex").toInt(); |
||||
|
QString title = _data->property("transactionTitle").toString(); |
||||
|
QString gas = _data->property("gas").toString(); |
||||
|
QString gasPrice = _data->property("gasPrice").toString(); |
||||
|
QString value = _data->property("transactionValue").toString(); |
||||
|
QString functionId = _data->property("functionId").toString(); |
||||
|
QAbstractListModel* paramsModel = qvariant_cast<QAbstractListModel*>(_data->property("transactionParams")); |
||||
|
TransactionSettings transaction(title, functionId, fromQString(value), fromQString(gas), fromQString(gasPrice)); |
||||
|
int paramCount = paramsModel->rowCount(QModelIndex()); |
||||
|
for(int p = 0; p < paramCount; ++p) |
||||
|
{ |
||||
|
QString paramName = paramsModel->data(paramsModel->index(p, 0), Qt::DisplayRole).toString(); |
||||
|
QString paramValue = paramsModel->data(paramsModel->index(p, 0), Qt::DisplayRole + 2).toString(); |
||||
|
if (!paramValue.isEmpty() && !paramName.isEmpty()) |
||||
|
transaction.parameterValues[paramName] = fromQString(paramValue); |
||||
|
} |
||||
|
|
||||
|
if (index >= 0 && index < (int)m_transactions.size()) |
||||
|
{ |
||||
|
beginRemoveRows(QModelIndex(), index, index); |
||||
|
m_transactions.erase(m_transactions.begin() + index); |
||||
|
endRemoveRows(); |
||||
|
} |
||||
|
else |
||||
|
index = rowCount(QModelIndex()); |
||||
|
|
||||
|
beginInsertRows(QModelIndex(), index, index); |
||||
|
m_transactions.push_back(transaction); |
||||
|
emit transactionAdded(); |
||||
|
emit countChanged(); |
||||
|
endInsertRows(); |
||||
|
} |
||||
|
|
||||
|
int TransactionListModel::getCount() const |
||||
|
{ |
||||
|
return rowCount(QModelIndex()); |
||||
|
} |
||||
|
|
||||
|
void TransactionListModel::runTransaction(int _index) |
||||
|
{ |
||||
|
TransactionSettings tr = m_transactions.at(_index); |
||||
|
emit transactionRan(tr); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,165 @@ |
|||||
|
/*
|
||||
|
This file is part of cpp-ethereum. |
||||
|
|
||||
|
cpp-ethereum is free software: you can redistribute it and/or modify |
||||
|
it under the terms of the GNU General Public License as published by |
||||
|
the Free Software Foundation, either version 3 of the License, or |
||||
|
(at your option) any later version. |
||||
|
|
||||
|
cpp-ethereum is distributed in the hope that it will be useful, |
||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
GNU General Public License for more details. |
||||
|
|
||||
|
You should have received a copy of the GNU General Public License |
||||
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
/** @file TransactionListView.h
|
||||
|
* @author Arkadiy Paronyan arkadiy@ethdev.com |
||||
|
* @date 2014 |
||||
|
* Ethereum IDE client. |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <QObject> |
||||
|
#include <QVariant> |
||||
|
#include <QAbstractListModel> |
||||
|
#include <QHash> |
||||
|
#include <QByteArray> |
||||
|
#include <libdevcore/Common.h> |
||||
|
|
||||
|
class QTextDocument; |
||||
|
|
||||
|
namespace dev |
||||
|
{ |
||||
|
namespace mix |
||||
|
{ |
||||
|
|
||||
|
/// Backend transaction config class
|
||||
|
struct TransactionSettings |
||||
|
{ |
||||
|
TransactionSettings(): |
||||
|
value(0), gas(10000), gasPrice(10) {} |
||||
|
|
||||
|
TransactionSettings(QString const& _title, QString const& _functionId, u256 _value, u256 _gas, u256 _gasPrice): |
||||
|
title(_title), functionId(_functionId), value(_value), gas(_gas), gasPrice(_gasPrice) {} |
||||
|
|
||||
|
/// User specified transaction title
|
||||
|
QString title; |
||||
|
/// Contract function name
|
||||
|
QString functionId; |
||||
|
/// Transaction value
|
||||
|
u256 value; |
||||
|
/// Gas
|
||||
|
u256 gas; |
||||
|
/// Gas price
|
||||
|
u256 gasPrice; |
||||
|
/// Mapping from contract function parameter name to value
|
||||
|
std::map<QString, u256> parameterValues; |
||||
|
}; |
||||
|
|
||||
|
/// QML transaction parameter class
|
||||
|
class TransactionParameterItem: public QObject |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
Q_PROPERTY(QString name READ name CONSTANT) |
||||
|
Q_PROPERTY(QString type READ type CONSTANT) |
||||
|
Q_PROPERTY(QString value READ value CONSTANT) |
||||
|
public: |
||||
|
TransactionParameterItem(QString const& _name, QString const& _type, QString const& _value): |
||||
|
m_name(_name), m_type(_type), m_value(_value) {} |
||||
|
|
||||
|
/// Parameter name, set by contract definition
|
||||
|
QString name() { return m_name; } |
||||
|
/// Parameter type, set by contract definition
|
||||
|
QString type() { return m_type; } |
||||
|
/// Parameter value, set by user
|
||||
|
QString value() { return m_value; } |
||||
|
|
||||
|
private: |
||||
|
QString m_name; |
||||
|
QString m_type; |
||||
|
QString m_value; |
||||
|
}; |
||||
|
|
||||
|
class TransactionListItem: public QObject |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
Q_PROPERTY(int index READ index CONSTANT) |
||||
|
Q_PROPERTY(QString title READ title CONSTANT) |
||||
|
Q_PROPERTY(QString functionId READ functionId CONSTANT) |
||||
|
Q_PROPERTY(QString gas READ gas CONSTANT) |
||||
|
Q_PROPERTY(QString gasPrice READ gasPrice CONSTANT) |
||||
|
Q_PROPERTY(QString value READ value CONSTANT) |
||||
|
|
||||
|
public: |
||||
|
TransactionListItem(int _index, TransactionSettings const& _t, QObject* _parent); |
||||
|
|
||||
|
/// User specified transaction title
|
||||
|
QString title() { return m_title; } |
||||
|
/// Gas
|
||||
|
QString gas() { return m_gas; } |
||||
|
/// Gas cost
|
||||
|
QString gasPrice() { return m_gasPrice; } |
||||
|
/// Transaction value
|
||||
|
QString value() { return m_value; } |
||||
|
/// Contract function name
|
||||
|
QString functionId() { return m_functionId; } |
||||
|
/// Index of this transaction in the transactions list
|
||||
|
int index() { return m_index; } |
||||
|
|
||||
|
private: |
||||
|
int m_index; |
||||
|
QString m_title; |
||||
|
QString m_functionId; |
||||
|
QString m_value; |
||||
|
QString m_gas; |
||||
|
QString m_gasPrice; |
||||
|
}; |
||||
|
|
||||
|
/// QML model for a list of transactions
|
||||
|
class TransactionListModel: public QAbstractListModel |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
Q_PROPERTY(int count READ getCount() NOTIFY countChanged()) |
||||
|
|
||||
|
enum Roles |
||||
|
{ |
||||
|
TitleRole = Qt::DisplayRole, |
||||
|
IdRole = Qt::UserRole + 1 |
||||
|
}; |
||||
|
|
||||
|
public: |
||||
|
TransactionListModel(QObject* _parent, QTextDocument* _document); |
||||
|
~TransactionListModel() {} |
||||
|
|
||||
|
QHash<int, QByteArray> roleNames() const override; |
||||
|
int rowCount(QModelIndex const& _parent) const override; |
||||
|
QVariant data(QModelIndex const& _index, int _role) const override; |
||||
|
int getCount() const; |
||||
|
/// Apply changes from transaction dialog. Argument is a dialog model as defined in TransactionDialog.qml
|
||||
|
/// @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); |
||||
|
/// @returns a list of functions for current contract
|
||||
|
Q_INVOKABLE QList<QString> getFunctions(); |
||||
|
/// @returns function parameters along with parameter values if set. @see TransactionParameterItem
|
||||
|
Q_INVOKABLE QVariantList getParameters(int _id, QString const& _functionId); |
||||
|
Q_INVOKABLE void runTransaction(int _index); |
||||
|
|
||||
|
signals: |
||||
|
void transactionAdded(); |
||||
|
void countChanged(); |
||||
|
void transactionRan(dev::mix::TransactionSettings); |
||||
|
|
||||
|
private: |
||||
|
std::vector<TransactionSettings> m_transactions; |
||||
|
QTextDocument* m_document; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,56 @@ |
|||||
|
/*
|
||||
|
This file is part of cpp-ethereum. |
||||
|
|
||||
|
cpp-ethereum is free software: you can redistribute it and/or modify |
||||
|
it under the terms of the GNU General Public License as published by |
||||
|
the Free Software Foundation, either version 3 of the License, or |
||||
|
(at your option) any later version. |
||||
|
|
||||
|
cpp-ethereum is distributed in the hope that it will be useful, |
||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
GNU General Public License for more details. |
||||
|
|
||||
|
You should have received a copy of the GNU General Public License |
||||
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
/** @file TransactionListView.cpp
|
||||
|
* @author Arkadiy Paronyan arkadiy@ethdev.com |
||||
|
* @date 2014 |
||||
|
* Ethereum IDE client. |
||||
|
*/ |
||||
|
|
||||
|
#include <QQuickItem> |
||||
|
#include <QApplication> |
||||
|
#include <QQmlApplicationEngine> |
||||
|
#include <QQmlContext> |
||||
|
#include <QDebug> |
||||
|
#include "TransactionListView.h" |
||||
|
#include "TransactionListModel.h" |
||||
|
using namespace dev::mix; |
||||
|
|
||||
|
TransactionListView::TransactionListView(QTextDocument* _doc): Extension(ExtensionDisplayBehavior::RightTab) |
||||
|
{ |
||||
|
m_editor = _doc; |
||||
|
m_model.reset(new TransactionListModel(this, _doc)); |
||||
|
m_appEngine->rootContext()->setContextProperty("transactionListModel", m_model.get()); |
||||
|
} |
||||
|
|
||||
|
TransactionListView::~TransactionListView() |
||||
|
{ |
||||
|
//implementation is in cpp file so that all types deleted are complete
|
||||
|
} |
||||
|
|
||||
|
QString TransactionListView::contentUrl() const |
||||
|
{ |
||||
|
return QStringLiteral("qrc:/qml/TransactionList.qml"); |
||||
|
} |
||||
|
|
||||
|
QString TransactionListView::title() const |
||||
|
{ |
||||
|
return QApplication::tr("Transactions"); |
||||
|
} |
||||
|
|
||||
|
void TransactionListView::start() const |
||||
|
{ |
||||
|
} |
@ -0,0 +1,56 @@ |
|||||
|
/*
|
||||
|
This file is part of cpp-ethereum. |
||||
|
cpp-ethereum is free software: you can redistribute it and/or modify |
||||
|
it under the terms of the GNU General Public License as published by |
||||
|
the Free Software Foundation, either version 3 of the License, or |
||||
|
(at your option) any later version. |
||||
|
cpp-ethereum is distributed in the hope that it will be useful, |
||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
GNU General Public License for more details. |
||||
|
You should have received a copy of the GNU General Public License |
||||
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
/** @file TransactionListView.h
|
||||
|
* @author Arkadiy Paronyan arkadiy@ethdev.com |
||||
|
* @date 2014 |
||||
|
* Ethereum IDE client. |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <QTextDocument> |
||||
|
#include "TransactionListView.h" |
||||
|
#include "Extension.h" |
||||
|
|
||||
|
namespace dev |
||||
|
{ |
||||
|
namespace mix |
||||
|
{ |
||||
|
|
||||
|
class TransactionListModel; |
||||
|
|
||||
|
/// Transactions list control
|
||||
|
/// @todo This should be moved into state as a sequence
|
||||
|
class TransactionListView: public Extension |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
|
||||
|
public: |
||||
|
TransactionListView(QTextDocument*); |
||||
|
~TransactionListView(); |
||||
|
void start() const override; |
||||
|
QString title() const override; |
||||
|
QString contentUrl() const override; |
||||
|
TransactionListModel* model() const { return m_model.get(); } |
||||
|
|
||||
|
private: |
||||
|
QTextDocument* m_editor; |
||||
|
std::unique_ptr<TransactionListModel> m_model; |
||||
|
|
||||
|
public slots: |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,187 @@ |
|||||
|
import QtQuick 2.3 |
||||
|
import QtQuick.Controls 1.2 |
||||
|
import QtQuick.Dialogs 1.2 |
||||
|
import QtQuick.Layouts 1.1 |
||||
|
import QtQuick.Window 2.0 |
||||
|
|
||||
|
Dialog { |
||||
|
modality: Qt.WindowModal |
||||
|
standardButtons: StandardButton.Ok | StandardButton.Cancel |
||||
|
|
||||
|
width:640 |
||||
|
height:480 |
||||
|
|
||||
|
property alias focus : titleField.focus |
||||
|
property alias transactionTitle : titleField.text |
||||
|
property int transactionIndex |
||||
|
property alias transactionParams : paramsModel; |
||||
|
property alias gas : gasField.text; |
||||
|
property alias gasPrice : gasPriceField.text; |
||||
|
property alias transactionValue : valueField.text; |
||||
|
property alias functionId : functionComboBox.currentText; |
||||
|
property var model; |
||||
|
|
||||
|
function reset(index, m) { |
||||
|
model = m; |
||||
|
var item = model.getItem(index); |
||||
|
transactionIndex = index; |
||||
|
transactionTitle = item.title; |
||||
|
gas = item.gas; |
||||
|
gasPrice = item.gasPrice; |
||||
|
transactionValue = item.value; |
||||
|
var functionId = item.functionId; |
||||
|
functionsModel.clear(); |
||||
|
var functionIndex = -1; |
||||
|
var functions = model.getFunctions(); |
||||
|
for (var f = 0; f < functions.length; f++) { |
||||
|
functionsModel.append({ text: functions[f] }); |
||||
|
if (functions[f] === item.functionId) |
||||
|
functionIndex = f; |
||||
|
} |
||||
|
functionComboBox.currentIndex = functionIndex; |
||||
|
} |
||||
|
|
||||
|
function loadParameters() { |
||||
|
if (!paramsModel) |
||||
|
return; |
||||
|
paramsModel.clear(); |
||||
|
if (functionComboBox.currentIndex >= 0 && functionComboBox.currentIndex < functionsModel.count) { |
||||
|
var parameters = model.getParameters(transactionIndex, functionsModel.get(functionComboBox.currentIndex).text); |
||||
|
for (var p = 0; p < parameters.length; p++) { |
||||
|
paramsModel.append({ name: parameters[p].name, type: parameters[p].type, value: parameters[p].value }); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
GridLayout { |
||||
|
columns: 2 |
||||
|
anchors.fill: parent |
||||
|
anchors.margins: 10 |
||||
|
rowSpacing: 10 |
||||
|
columnSpacing: 10 |
||||
|
|
||||
|
Label { |
||||
|
text: qsTr("Title") |
||||
|
} |
||||
|
TextField { |
||||
|
id: titleField |
||||
|
focus: true |
||||
|
Layout.fillWidth: true |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
text: qsTr("Function") |
||||
|
} |
||||
|
|
||||
|
ComboBox { |
||||
|
id: functionComboBox |
||||
|
Layout.fillWidth: true |
||||
|
currentIndex: -1 |
||||
|
textRole: "text" |
||||
|
editable: false |
||||
|
model: ListModel { |
||||
|
id: functionsModel |
||||
|
} |
||||
|
onCurrentIndexChanged: { |
||||
|
loadParameters(); |
||||
|
} |
||||
|
} |
||||
|
Label { |
||||
|
text: qsTr("Value") |
||||
|
} |
||||
|
TextField { |
||||
|
id: valueField |
||||
|
Layout.fillWidth: true |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
text: qsTr("Gas") |
||||
|
} |
||||
|
TextField { |
||||
|
id: gasField |
||||
|
Layout.fillWidth: true |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
text: qsTr("Gas price") |
||||
|
} |
||||
|
TextField { |
||||
|
id: gasPriceField |
||||
|
Layout.fillWidth: true |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
text: qsTr("Parameters") |
||||
|
} |
||||
|
TableView { |
||||
|
model: paramsModel |
||||
|
Layout.fillWidth: true |
||||
|
|
||||
|
TableViewColumn { |
||||
|
role: "name" |
||||
|
title: "Name" |
||||
|
width: 120 |
||||
|
} |
||||
|
TableViewColumn { |
||||
|
role: "type" |
||||
|
title: "Type" |
||||
|
width: 120 |
||||
|
} |
||||
|
TableViewColumn { |
||||
|
role: "value" |
||||
|
title: "Value" |
||||
|
width: 120 |
||||
|
} |
||||
|
|
||||
|
itemDelegate: { |
||||
|
return editableDelegate; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
ListModel { |
||||
|
id: paramsModel |
||||
|
} |
||||
|
|
||||
|
Component { |
||||
|
id: editableDelegate |
||||
|
Item { |
||||
|
|
||||
|
Text { |
||||
|
width: parent.width |
||||
|
anchors.margins: 4 |
||||
|
anchors.left: parent.left |
||||
|
anchors.verticalCenter: parent.verticalCenter |
||||
|
elide: styleData.elideMode |
||||
|
text: styleData.value !== undefined ? styleData.value : "" |
||||
|
color: styleData.textColor |
||||
|
visible: !styleData.selected |
||||
|
} |
||||
|
Loader { |
||||
|
id: loaderEditor |
||||
|
anchors.fill: parent |
||||
|
anchors.margins: 4 |
||||
|
Connections { |
||||
|
target: loaderEditor.item |
||||
|
onTextChanged: { |
||||
|
paramsModel.setProperty(styleData.row, styleData.role, loaderEditor.item.text); |
||||
|
} |
||||
|
} |
||||
|
sourceComponent: (styleData.selected /*&& styleData.role === "value"*/) ? editor : null |
||||
|
Component { |
||||
|
id: editor |
||||
|
TextInput { |
||||
|
id: textinput |
||||
|
color: styleData.textColor |
||||
|
text: styleData.value |
||||
|
MouseArea { |
||||
|
id: mouseArea |
||||
|
anchors.fill: parent |
||||
|
hoverEnabled: true |
||||
|
onClicked: textinput.forceActiveFocus() |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,89 @@ |
|||||
|
import QtQuick 2.2 |
||||
|
import QtQuick.Controls.Styles 1.2 |
||||
|
import QtQuick.Controls 1.2 |
||||
|
import QtQuick.Dialogs 1.2 |
||||
|
import QtQuick.Layouts 1.1 |
||||
|
|
||||
|
|
||||
|
Rectangle { |
||||
|
color: "transparent" |
||||
|
id: transactionListContainer |
||||
|
focus: true |
||||
|
anchors.topMargin: 10 |
||||
|
anchors.left: parent.left |
||||
|
height: parent.height |
||||
|
width: parent.width |
||||
|
|
||||
|
ListView { |
||||
|
anchors.top: parent.top |
||||
|
height: parent.height |
||||
|
width: parent.width |
||||
|
id: transactionList |
||||
|
model: transactionListModel |
||||
|
delegate: renderDelegate |
||||
|
} |
||||
|
|
||||
|
Button { |
||||
|
anchors.bottom: parent.bottom |
||||
|
text: qsTr("Add") |
||||
|
onClicked: |
||||
|
{ |
||||
|
// Set next id here to work around Qt bug |
||||
|
// https://bugreports.qt-project.org/browse/QTBUG-41327 |
||||
|
// Second call to signal handle would just edit the item that was just created, no harm done |
||||
|
transactionDialog.reset(transactionListModel.count, transactionListModel); |
||||
|
transactionDialog.open(); |
||||
|
transactionDialog.focus = true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
TransactionDialog { |
||||
|
id: transactionDialog |
||||
|
onAccepted: { |
||||
|
transactionListModel.edit(transactionDialog); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Component { |
||||
|
id: renderDelegate |
||||
|
Item { |
||||
|
id: wrapperItem |
||||
|
height: 20 |
||||
|
width: parent.width |
||||
|
RowLayout |
||||
|
{ |
||||
|
anchors.fill: parent |
||||
|
Text { |
||||
|
//anchors.fill: parent |
||||
|
Layout.fillWidth: true |
||||
|
Layout.fillHeight: true |
||||
|
text: title |
||||
|
font.pointSize: 12 |
||||
|
verticalAlignment: Text.AlignBottom |
||||
|
} |
||||
|
ToolButton { |
||||
|
text: qsTr("Edit"); |
||||
|
Layout.fillHeight: true |
||||
|
onClicked: { |
||||
|
transactionDialog.reset(index, transactionListModel); |
||||
|
transactionDialog.open(); |
||||
|
transactionDialog.focus = true; |
||||
|
} |
||||
|
} |
||||
|
ToolButton { |
||||
|
text: qsTr("Delete"); |
||||
|
Layout.fillHeight: true |
||||
|
onClicked: { |
||||
|
} |
||||
|
} |
||||
|
ToolButton { |
||||
|
text: qsTr("Run"); |
||||
|
Layout.fillHeight: true |
||||
|
onClicked: { |
||||
|
transactionListModel.runTransaction(index); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue