Browse Source

Integrate solidity type with project files.

cl-refactor
yann300 10 years ago
parent
commit
afa9b4337f
  1. 1
      mix/AppContext.cpp
  2. 3
      mix/ClientModel.cpp
  3. 5
      mix/QVariableDeclaration.h
  4. 7
      mix/qml/QVariableDeclaration.qml
  5. 49
      mix/qml/StateListModel.qml
  6. 1
      mix/res.qrc

1
mix/AppContext.cpp

@ -68,6 +68,7 @@ void AppContext::load()
qmlRegisterType<QStringType>("org.ethereum.qml.QStringType", 1, 0, "QStringType");
qmlRegisterType<QHashType>("org.ethereum.qml.QHashType", 1, 0, "QHashType");
qmlRegisterType<QBoolType>("org.ethereum.qml.QBoolType", 1, 0, "QBoolType");
qmlRegisterType<QVariableDeclaration>("org.ethereum.qml.QVariableDeclaration", 1, 0, "QVariableDeclaration");
QQmlComponent projectModelComponent(m_applicationEngine, QUrl("qrc:/qml/ProjectModel.qml"));
QObject* projectModel = projectModelComponent.create();
if (projectModelComponent.isError())

3
mix/ClientModel.cpp

@ -357,7 +357,6 @@ void ClientModel::onNewTransaction()
if (creation)
returned = QString::fromStdString(toJS(tr.contractAddress));
QList<QVariableDefinition*> returnValues;
if (m_contractAddress != 0 && (tr.address == m_contractAddress || tr.contractAddress == m_contractAddress))
{
auto compilerRes = m_context->codeModel()->code();
@ -370,7 +369,7 @@ void ClientModel::onNewTransaction()
{
function = funcDef->name();
ContractCallDataEncoder encoder;
returnValues = encoder.decode(funcDef->returnParameters(), tr.returnValue);
QList<QVariableDefinition*> returnValues = encoder.decode(funcDef->returnParameters(), tr.returnValue);
for (auto const& var: returnValues)
returned += var->value() + " | ";
}

5
mix/QVariableDeclaration.h

@ -34,13 +34,14 @@ namespace mix
class QVariableDeclaration: public QBasicNodeDefinition
{
Q_OBJECT
Q_PROPERTY(QString type READ type CONSTANT)
Q_PROPERTY(QString type READ type WRITE setType)
public:
QVariableDeclaration() {}
QVariableDeclaration(solidity::VariableDeclaration const* _v): QBasicNodeDefinition(_v), m_type(QString::fromStdString(_v->getType()->toString())) {}
QVariableDeclaration(std::string const& _name, std::string const& _type): QBasicNodeDefinition(_name), m_type(QString::fromStdString(_type)) {}
QString type() const { return m_type; }
void setType(QString _type) { m_type = _type; }
private:
QString m_type;
@ -48,3 +49,5 @@ private:
}
}
Q_DECLARE_METATYPE(dev::mix::QVariableDeclaration*)

7
mix/qml/QVariableDeclaration.qml

@ -0,0 +1,7 @@
import QtQuick 2.0
import org.ethereum.qml.QVariableDeclaration 1.0
QVariableDeclaration
{
}

49
mix/qml/StateListModel.qml

@ -31,12 +31,30 @@ Item {
stdContract: t.stdContract,
parameters: {}
};
for (var key in t.parameters) {
var intComponent = Qt.createComponent("qrc:/qml/BigIntValue.qml");
var param = intComponent.createObject();
param.setValue(t.parameters[key]);
r.parameters[key] = param;
}
var qType = [];
for (var key in t.parameters)
{
r.parameters[key] = t.parameters[key].value;
var type = t.parameters[key].type;
var varComponent;
if (type.indexOf("int") !== -1)
varComponent = Qt.createComponent("qrc:/qml/QIntType.qml");
else if (type.indexOf("real") !== -1)
varComponent = Qt.createComponent("qrc:/qml/QRealType.qml");
else if (type.indexOf("string") !== -1 || type.indexOf("text") !== -1)
varComponent = Qt.createComponent("qrc:/qml/QStringType.qml");
else if (type.indexOf("hash") !== -1 || type.indexOf("address") !== -1)
varComponent = Qt.createComponent("qrc:/qml/QHashType.qml");
else if (type.indexOf("bool") !== -1)
varComponent = Qt.createComponent("qrc:/qml/QBoolType.qml");
var param = varComponent.createObject(stateListModel);
var dec = Qt.createComponent("qrc:/qml/QVariableDeclaration.qml");
param.setDeclaration(dec.createObject(stateListModel, { "type": type }));
param.setValue(r.parameters[key]);
qType.push(param);
}
r.qType = qType;
return r;
}
@ -48,6 +66,16 @@ Item {
};
}
function getParamType(param, params)
{
for (var k in params)
{
if (params[k].declaration.name === param)
return params[k].declaration.type;
}
return '';
}
function toPlainTransactionItem(t) {
var r = {
functionId: t.functionId,
@ -60,7 +88,14 @@ Item {
parameters: {}
};
for (var key in t.parameters)
r.parameters[key] = t.parameters[key];
{
var param = {
name: key,
value: t.parameters[key],
type: getParamType(key, t.qType)
}
r.parameters[key] = param;
}
return r;
}

1
mix/res.qrc

@ -63,5 +63,6 @@
<file>qml/TransactionLog.qml</file>
<file>res/mix_256x256x32.png</file>
<file>qml/CallStack.qml</file>
<file>qml/QVariableDeclaration.qml</file>
</qresource>
</RCC>

Loading…
Cancel
Save