You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
3.6 KiB

10 years ago
import QtQuick 2.0
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import org.ethereum.qml.QSolidityType 1.0
Column
10 years ago
{
id: root
property alias members: repeater.model //js array
property variant accounts
property var value: ({})
10 years ago
property int blockIndex
property int transactionIndex
property string context
property bool readOnly
Layout.fillWidth: true
spacing: 0
property int colHeight
10 years ago
function clear()
{
10 years ago
value = {}
members = []
colHeight = 0
}
Repeater
10 years ago
{
id: repeater
visible: members.length > 0
RowLayout
10 years ago
{
id: row
Layout.fillWidth: true
Component.onCompleted:
{
if (QSolidityType.Address === members[index].type.category && members[index].type.array && context === "parameter")
height = 60
else
height = 30 + (members[index].type.category === QSolidityType.Struct ? (30 * members[index].type.members.length) : 0)
root.colHeight += height
}
Rectangle
{
Layout.preferredWidth: 150
Row
{
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
Label
{
id: nameLabel
text: modelData.name
}
10 years ago
Label
{
id: typeLabel
text: " (" + modelData.type.name + ")"
font.italic: true
font.weight: Font.Light
}
}
}
Loader
{
id: typeLoader
sourceComponent:
{
var t = modelData.type.category;
if (t === QSolidityType.SignedInteger || t === QSolidityType.UnsignedInteger)
return Qt.createComponent("qrc:/qml/QIntTypeView.qml");
else if (t === QSolidityType.Bool)
return Qt.createComponent("qrc:/qml/QBoolTypeView.qml");
else if (t === QSolidityType.Bytes || t === QSolidityType.String)
return Qt.createComponent("qrc:/qml/QStringTypeView.qml");
else if (t === QSolidityType.Hash)
return Qt.createComponent("qrc:/qml/QHashTypeView.qml");
else if (t === QSolidityType.Struct)
return Qt.createComponent("qrc:/qml/StructView.qml");
else if (t === QSolidityType.Enum)
10 years ago
return Qt.createComponent("qrc:/qml/QIntTypeView.qml");
else if (t === QSolidityType.Address)
return Qt.createComponent("qrc:/qml/QAddressView.qml");
else
return undefined;
10 years ago
}
onLoaded:
10 years ago
{
var ptype = members[index].type;
var pname = members[index].name;
var vals = value;
item.readOnly = context === "variable";
if (ptype.category === QSolidityType.Address)
{
item.accounts = accounts
item.value = getValue();
if (context === "parameter")
{
var dec = modelData.type.name.split(" ");
item.subType = dec[0];
item.load();
}
item.init();
}
else if (ptype.category === QSolidityType.Struct && !item.members)
{
item.value = getValue();
item.members = ptype.members;
10 years ago
}
else
item.value = getValue();
10 years ago
10 years ago
if (ptype.category === QSolidityType.Bool)
{
item.subType = modelData.type.name
10 years ago
item.init();
}
10 years ago
item.onValueChanged.connect(function() {
10 years ago
syncValue(vals, pname)
10 years ago
});
var newWidth = nameLabel.width + typeLabel.width + item.width + 108;
if (root.width < newWidth)
root.width = newWidth;
10 years ago
10 years ago
syncValue(vals, pname)
}
10 years ago
10 years ago
function syncValue(vals, pname)
{
vals[pname] = item.value;
valueChanged();
}
function getValue()
{
var r = "";
if (value && value[modelData.name] !== undefined)
r = value[modelData.name];
else if (modelData.type.category === QSolidityType.Struct)
r = {};
if (Array.isArray(r))
r = r.join(", ");
return r;
10 years ago
}
}
}
}
}