Browse Source

changes on QBoolTypeView.qml QAddressView.qml

cl-refactor
yann300 10 years ago
parent
commit
5319baa978
  1. 25
      mix/ClientModel.cpp
  2. 43
      mix/ContractCallDataEncoder.cpp
  3. 2
      mix/QVariableDeclaration.h
  4. 152
      mix/qml/QAddressView.qml
  5. 63
      mix/qml/QBoolTypeView.qml
  6. 4
      mix/qml/QIntTypeView.qml
  7. 3
      mix/qml/QStringTypeView.qml
  8. 1
      mix/qml/ScenarioLoader.qml
  9. 41
      mix/qml/StructView.qml
  10. 9
      mix/qml/TransactionDialog.qml
  11. 2
      mix/qml/VariablesView.qml
  12. 9
      mix/qml/js/InputValidator.js

25
mix/ClientModel.cpp

@ -388,10 +388,29 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence)
{
QSolidityType const* type = p->type();
QVariant value = transaction.parameterValues.value(p->name());
if (type->type().type == SolidityType::Type::Address && value.toString().startsWith("<"))
if (type->type().type == SolidityType::Type::Address)
{
std::pair<QString, int> ctrParamInstance = resolvePair(value.toString());
value = QVariant(resolveToken(ctrParamInstance));
if (type->array())
{
QJsonArray jsonDoc = QJsonDocument::fromJson(value.toString().toUtf8()).array();
int k = 0;
for (QJsonValue const& item: jsonDoc)
{
if (item.toString().startsWith("<"))
{
std::pair<QString, int> ctrParamInstance = resolvePair(item.toString());
jsonDoc.replace(k, resolveToken(ctrParamInstance));
}
k++;
}
QJsonDocument doc(jsonDoc);
value = QVariant(doc.toJson(QJsonDocument::Compact));
}
else if (value.toString().startsWith("<"))
{
std::pair<QString, int> ctrParamInstance = resolvePair(value.toString());
value = QVariant(resolveToken(ctrParamInstance));
}
}
encoder.encode(value, type->type());
}

43
mix/ContractCallDataEncoder.cpp

@ -101,9 +101,9 @@ void ContractCallDataEncoder::encode(QVariant const& _data, SolidityType const&
bytes empty(32);
size_t sizePos = m_dynamicData.size();
m_dynamicData += empty; //reserve space for count
u256 count = encodeSingleItem(_data.toString(), _type, m_dynamicData);
encodeSingleItem(_data.toString(), _type, m_dynamicData);
vector_ref<byte> sizeRef(m_dynamicData.data() + sizePos, 32);
toBigEndian(count, sizeRef);
toBigEndian(_data.toString().size(), sizeRef);
m_staticOffsetMap.push_back(std::make_pair(m_encodedData.size(), sizePos));
m_encodedData += empty; //reserve space for offset
}
@ -262,6 +262,8 @@ QJsonArray ContractCallDataEncoder::decodeArray(SolidityType const& _type, bytes
QJsonArray array;
bytesConstRef value(&_value);
int count = 0;
bigint offset = pos;
int valuePosition = pos;
if (!_type.dynamicSize)
count = _type.count;
else
@ -269,14 +271,33 @@ QJsonArray ContractCallDataEncoder::decodeArray(SolidityType const& _type, bytes
bytesConstRef value(_value.data() + pos, 32); // offset
bytes rawParam(32);
value.populate(&rawParam);
bigint offset = decodeInt(rawParam);
pos = static_cast<int>(offset) + 32;
value = bytesConstRef(_value.data() + static_cast<int>(offset), 32); // offset
offset = decodeInt(rawParam);
valuePosition = static_cast<int>(offset) + 32;
pos += 32;
value = bytesConstRef(_value.data() + static_cast<int>(offset), 32); // count
value.populate(&rawParam);
count = static_cast<int>(decodeInt(rawParam));
}
for (int k = 0; k < count; ++k)
array.append(decodeArrayContent(_type, _value, pos));
if (_type.type == QSolidityType::Type::Bytes || _type.type == QSolidityType::Type::String)
{
bytesConstRef value(_value.data() + (static_cast<int>(offset) + 32), 32);
bytes rawParam(count);
value.populate(&rawParam);
if (_type.type == QSolidityType::Type::Bytes)
array.append(toString(decodeBytes(rawParam)));
else
array.append(toChar(decodeBytes(rawParam)));
}
else
{
for (int k = 0; k < count; ++k)
{
if (_type.dynamicSize)
array.append(decodeArrayContent(_type, _value, valuePosition));
else
array.append(decodeArrayContent(_type, _value, pos));
}
}
return array;
}
@ -329,18 +350,14 @@ QStringList ContractCallDataEncoder::decode(QList<QVariableDeclaration*> const&
QJsonArray array = decodeArray(type, _v, readPosition);
QJsonDocument jsonDoc = QJsonDocument::fromVariant(array.toVariantList());
r.append(jsonDoc.toJson(QJsonDocument::Compact));
if (type.dynamicSize)
readPosition++;
else
readPosition = type.count;
}
else
{
bytesConstRef value(_value.data() + (readPosition * 32), 32);
bytesConstRef value(_value.data() + readPosition, 32);
bytes rawParam(32);
value.populate(&rawParam);
r.append(decode(type, rawParam).toString());
readPosition++;
readPosition += 32;
}
}
return r;

2
mix/QVariableDeclaration.h

@ -47,6 +47,7 @@ class QSolidityType: public QObject
Q_PROPERTY(int size READ size CONSTANT)
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QVariantList members READ members CONSTANT)
Q_PROPERTY(bool array READ array CONSTANT)
public:
QSolidityType() {}
@ -71,6 +72,7 @@ public:
int size() const { return m_type.size; }
QString name() const { return m_type.name; }
QVariantList members() const;
bool array() const { return m_type.array; }
private:
SolidityType m_type;

152
mix/qml/QAddressView.qml

@ -1,8 +1,10 @@
import QtQuick 2.0
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.3
import QtQuick.Layouts 1.1
import "js/InputValidator.js" as InputValidator
Row
ColumnLayout
{
property alias value: textinput.text
property alias accountRef: ctrModel
@ -12,8 +14,16 @@ Row
property alias displayInput: textInputRect.visible
property variant accounts
signal indexChanged()
spacing: 0
id: editRoot
height: 20
height:
{
if (isArray() && !readOnly)
return 60
else
return 30
}
width: 320
SourceSansProBold
@ -21,6 +31,12 @@ Row
id: boldFont
}
function isArray()
{
InputValidator.init()
return InputValidator.isArray(subType)
}
function currentValue() {
return value;
}
@ -38,7 +54,7 @@ Row
function load()
{
accountRef.clear();
if (subType === "contract" || subType === "address")
if (subType.indexOf("contract") !== -1 || subType.indexOf("address") !== -1)
{
var trCr = 0;
if (blockChainPanel)
@ -59,7 +75,7 @@ Row
}
}
}
if (subType === "address")
if (subType.indexOf("address") !== -1)
{
for (k = 0; k < accounts.length; k++)
{
@ -72,8 +88,24 @@ Row
function init()
{
trCombobox.visible = !readOnly
textinput.readOnly = readOnly
if (isArray() || readOnly)
displayInput = true
else
displayInput = false
if (isArray() || !readOnly)
trCombobox.visible = true
else
trCombobox.visible = false
if (!trCombobox.visible)
{
trCombobox.height = 0
textinput.anchors.top = textinput.parent.top
}
if (!readOnly)
{
for (var k = 0; k < ctrModel.count; k++)
@ -86,7 +118,8 @@ Row
}
trCombobox.currentIndex = 0;
}
trCombobox.update()
if (!isArray())
trCombobox.update()
}
function select(address)
@ -101,17 +134,73 @@ Row
}
}
ListModel
{
id: ctrModel
}
Row
{
anchors.top: parent.top
height: 30
id: rowCombobox
ComboBox
{
property bool selected: false
id: trCombobox
model: ctrModel
width: 265
textRole: "itemid"
function update()
{
trCombobox.selected = false;
if (currentText === "")
return;
else if (currentText !== " - ")
{
if (model.get(currentIndex).type === "contract")
textinput.text = "<" + currentText + ">";
else
textinput.text = model.get(currentIndex).value; //address
trCombobox.selected = true;
}
else if (textinput.text.indexOf("<") === 0)
{
textinput.text = "";
}
indexChanged();
}
onCurrentIndexChanged: {
if (!isArray())
update()
}
}
Button
{
id: btnAdd
text: qsTr("Add")
visible: false
onClicked:
{
var ar = JSON.parse(textinput.text)
ar.push(trCombobox.model.get(currentIndex).value)
textinput.text = JSON.stringify(ar)
}
}
}
Rectangle {
radius: 4
anchors.verticalCenter: parent.verticalCenter
height: 20
width: 350
height: 30
id: textInputRect
TextInput {
TextField {
id: textinput
text: value
width: parent.width
height: parent.width
wrapMode: Text.WordWrap
anchors.fill: parent
clip: true
font.family: boldFont.name
MouseArea {
@ -130,43 +219,4 @@ Row
}
}
}
ListModel
{
id: ctrModel
}
ComboBox
{
property bool selected: false
id: trCombobox
model: ctrModel
width: 350
textRole: "itemid"
anchors.verticalCenter: parent.verticalCenter
function update()
{
trCombobox.selected = false;
if (currentText === "")
return;
else if (currentText !== " - ")
{
if (model.get(currentIndex).type === "contract")
textinput.text = "<" + currentText + ">";
else
textinput.text = model.get(currentIndex).value; //address
trCombobox.selected = true;
}
else if (textinput.text.indexOf("<") === 0)
{
textinput.text = "";
}
indexChanged();
}
onCurrentIndexChanged: {
update()
}
}
}

63
mix/qml/QBoolTypeView.qml

@ -1,5 +1,6 @@
import QtQuick 2.0
import QtQuick.Controls 1.3
import "js/InputValidator.js" as InputValidator
Item
{
@ -7,6 +8,7 @@ Item
property string value
property string defaultValue
property bool readOnly: !boolCombo.enabled
property string subType
height: 20
width: 150
@ -14,20 +16,56 @@ Item
boolCombo.enabled = !readOnly;
}
function isArray()
{
InputValidator.init()
return InputValidator.isArray(subType)
}
function init()
{
if (!isArray())
{
boolArray.visible = false
boolCombo.visible = true
value = format(value)
var setValue = "1"
if (value === "")
setValue = parseInt(defaultValue);
else
setValue = parseInt(value);
boolCombo.checked = setValue === "1" ? true: false
boolCombo.enabled = !readOnly;
}
else
{
boolArray.visible = true
boolCombo.visible = false
if (value === "")
boolArray.text = "[]"
else
boolArray.text = value
var formattedparam = []
var param = JSON.parse(boolArray.text)
for (var k in JSON.parse(boolArray.text))
formattedparam.push(parseInt(format(param[k])))
boolArray.text = JSON.stringify(formattedparam)
value = ""
value = boolArray.text
console.log("gfdg " + value)
}
}
function format(value)
{
value = value === true ? "1" : value
value = value === false ? "0" : value;
value = value === "true" ? "1" : value
value = value === "false" ? "0" : value;
var setValue = "1"
if (value === "")
setValue = parseInt(defaultValue);
else
setValue = parseInt(value);
boolCombo.checked = setValue === "1" ? true: false
boolCombo.enabled = !readOnly;
return value
}
Rectangle {
@ -52,6 +90,15 @@ Item
}
text: qsTr("True")
}
TextField
{
id: boolArray
onTextChanged:
{
value = text
}
}
}
}

4
mix/qml/QIntTypeView.qml

@ -5,7 +5,7 @@ Item
property alias value: textinput.text
property alias readOnly: textinput.readOnly
id: editRoot
width: 200
width: 350
DebuggerPaneStyle {
id: dbgStyle
}
@ -15,7 +15,7 @@ Item
id: textinput
selectByMouse: true
text: value
implicitWidth: 200
implicitWidth: 350
MouseArea {
id: mouseArea
anchors.fill: parent

3
mix/qml/QStringTypeView.qml

@ -6,7 +6,7 @@ Item
property alias value: textinput.text
property alias readOnly: textinput.readOnly
id: editRoot
width: readOnly ? textinput.implicitWidth : 150
width: 350
DebuggerPaneStyle {
id: dbgStyle
@ -17,6 +17,7 @@ Item
id: textinput
selectByMouse: true
text: value
width: 350
MouseArea {
id: mouseArea
anchors.fill: parent

1
mix/qml/ScenarioLoader.qml

@ -28,7 +28,6 @@ ColumnLayout
function needSaveOrReload()
{
editStatus.visible = true
}
RowLayout

41
mix/qml/StructView.qml

@ -13,7 +13,14 @@ Column
property int transactionIndex
property string context
Layout.fillWidth: true
spacing: 5
spacing: 0
property int colHeight
onValueChanged:
{
colHeight = 0
}
Repeater
{
id: repeater
@ -21,8 +28,17 @@ Column
RowLayout
{
id: row
height: 30 + (members[index].type.category === QSolidityType.Struct ? (30 * members[index].type.members.length) : 0)
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
@ -30,12 +46,14 @@ Column
{
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
Label {
Label
{
id: nameLabel
text: modelData.name
}
Label {
Label
{
id: typeLabel
text: " (" + modelData.type.name + ")"
font.italic: true
@ -72,6 +90,12 @@ Column
var ptype = members[index].type;
var pname = members[index].name;
var vals = value;
item.onValueChanged.connect(function() {
vals[pname] = item.value;
valueChanged();
});
item.readOnly = context === "variable";
if (ptype.category === QSolidityType.Address)
{
@ -83,6 +107,7 @@ Column
item.subType = dec[0];
item.load();
}
console.log("jj" + pname)
item.init();
}
else if (ptype.category === QSolidityType.Struct && !item.members)
@ -94,12 +119,10 @@ Column
item.value = getValue();
if (ptype.category === QSolidityType.Bool)
{
item.subType = modelData.type.name
item.init();
item.onValueChanged.connect(function() {
vals[pname] = item.value;
valueChanged();
});
}
var newWidth = nameLabel.width + typeLabel.width + item.width + 108;
if (root.width < newWidth)

9
mix/qml/TransactionDialog.qml

@ -120,6 +120,7 @@ Dialog {
var type = parameter.type;
var pname = parameter.name;
paramsModel.push({ name: pname, type: type });
console.log(JSON.stringify(paramsModel))
}
function loadParameters() {
@ -237,13 +238,15 @@ Dialog {
recipientsAccount.select(contractId);
if (functionId)
selectFunction(functionId);
else
functionComboBox.currentIndex = 0
if (isFunctionCall)
{
labelRecipient.text = qsTr("Recipient Contract")
functionRect.show()
loadFunctions(TransactionHelper.contractFromToken(recipientsAccount.currentValue()))
loadParameters();
paramScroll.updateView()
//paramScroll.updateView()
}
else
{
@ -496,11 +499,9 @@ Dialog {
function updateView()
{
paramScroll.visible = paramsModel.length > 0
paramScroll.Layout.preferredHeight = paramsModel.length < 6 ? paramsModel.length * 30 : 205
paramScroll.Layout.preferredHeight = paramScroll.colHeight
if (paramsModel.length === 0)
{
paramScroll.height = 0
}
}
}

2
mix/qml/VariablesView.qml

@ -25,7 +25,7 @@ DebugInfoList
members: []
value: {}
context: "variable"
width:parent.width
width: parent.width
}
}
}

9
mix/qml/js/InputValidator.js

@ -32,10 +32,11 @@ function init()
function check(type, value)
{
var res = { valid: true, message : "" }
if (isContractType(type))
res = validateAddress(type, value);
else if (isArray(type))
if (isArray(type))
res = validateArray(type, value);
else if (isContractType(type))
res = validateAddress(type, value);
else if (type.indexOf("int") !== -1)
res = validateInt(type, value);
else if (type.indexOf("enum") !== -1)
@ -196,7 +197,7 @@ function validateBytes(_type, _value)
function validateBool(_type, _value)
{
var ret = { valid: true, message: "" }
if (_value !== "1" && _value !== "0")
if (!(_value === "1" || _value === "0" || _value === 1 || _value === 0))
{
ret.valid = false;
ret.message = _value + " is not in the correct bool format";

Loading…
Cancel
Save