Browse Source

ScenarioLoader.qml ui changes

cl-refactor
yann300 10 years ago
parent
commit
870e58e1fb
  1. 1
      mix/ClientModel.cpp
  2. 5
      mix/CodeModel.h
  3. 2
      mix/qml/Application.qml
  4. 111
      mix/qml/BlockChain.qml
  5. 8
      mix/qml/ScenarioButton.qml
  6. 276
      mix/qml/ScenarioLoader.qml
  7. 5
      mix/qml/StateListModel.qml
  8. 4
      mix/qml/Watchers.qml

1
mix/ClientModel.cpp

@ -351,7 +351,6 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence)
if (!transaction.isFunctionCall) if (!transaction.isFunctionCall)
{ {
callAddress(Address(address.toStdString()), bytes(), transaction); callAddress(Address(address.toStdString()), bytes(), transaction);
onNewTransaction(); onNewTransaction();
continue; continue;
} }

5
mix/CodeModel.h

@ -33,6 +33,7 @@
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
#include <libevmcore/Params.h> #include <libevmcore/Params.h>
#include <libevmasm/Assembly.h> #include <libevmasm/Assembly.h>
#include <libdevcore/SHA3.h>
#include "SolidityType.h" #include "SolidityType.h"
#include "QBigInt.h" #include "QBigInt.h"
@ -246,8 +247,12 @@ public:
void gasEstimation(solidity::CompilerStack const& _cs); void gasEstimation(solidity::CompilerStack const& _cs);
/// Gas cost by doc id /// Gas cost by doc id
Q_INVOKABLE QVariantList gasCostByDocumentId(QString const& _documentId) const; Q_INVOKABLE QVariantList gasCostByDocumentId(QString const& _documentId) const;
/// Gas cost by @arg contractName @arg functionName
Q_INVOKABLE QVariantList gasCostBy(QString const& _contractName, QString const& _functionName) const; Q_INVOKABLE QVariantList gasCostBy(QString const& _contractName, QString const& _functionName) const;
/// Set optimize code
Q_INVOKABLE void setOptimizeCode(bool _value); Q_INVOKABLE void setOptimizeCode(bool _value);
/// sha3
Q_INVOKABLE QString sha3(QString _source) { return QString::fromStdString(dev::sha3(_source.toStdString()).hex()); }
int txGas() { return static_cast<int>(dev::eth::c_txGas); } int txGas() { return static_cast<int>(dev::eth::c_txGas); }
int callStipend() { return static_cast<int>(dev::eth::c_callStipend); } int callStipend() { return static_cast<int>(dev::eth::c_callStipend); }

2
mix/qml/Application.qml

@ -202,7 +202,7 @@ ApplicationWindow {
text: qsTr("Deploy") text: qsTr("Deploy")
shortcut: "F5" shortcut: "F5"
onTriggered: mainContent.startQuickDebugging() onTriggered: mainContent.startQuickDebugging()
enabled: codeModel.hasContract && !clientModel.running enabled: codeModel.hasContract && !clientModel.running && projectModel.stateListModel.defaultStateName() !== ""
} }
Action { Action {

111
mix/qml/BlockChain.qml

@ -20,7 +20,7 @@ ColumnLayout {
spacing: 0 spacing: 0
property int previousWidth property int previousWidth
property variant debugTrRequested: [] property variant debugTrRequested: []
signal chainChanged signal chainChanged(var blockIndex, var txIndex, var item)
signal chainReloaded signal chainReloaded
signal txSelected(var blockIndex, var txIndex) signal txSelected(var blockIndex, var txIndex)
signal rebuilding signal rebuilding
@ -30,15 +30,46 @@ ColumnLayout {
{ {
target: codeModel target: codeModel
onContractRenamed: { onContractRenamed: {
rebuild.startBlinking() rebuild.needRebuild("ContractRenamed")
} }
onNewContractCompiled: { onNewContractCompiled: {
rebuild.startBlinking() rebuild.needRebuild("NewContractCompiled")
}
onCompilationComplete: {
for (var c in rebuild.contractsHex)
{
if (codeModel.contracts[c] === undefined || codeModel.contracts[c].codeHex !== rebuild.contractsHex[c])
{
if (!rebuild.containsRebuildCause("CodeChanged"))
{
rebuild.needRebuild("CodeChanged")
}
return
}
}
rebuild.notNeedRebuild("CodeChanged")
} }
} }
onChainChanged: { onChainChanged: {
rebuild.startBlinking() if (rebuild.txSha3[blockIndex][txIndex] !== codeModel.sha3(JSON.stringify(model.blocks[blockIndex].transactions[txIndex])))
{
rebuild.txChanged.push(rebuild.txSha3[blockIndex][txIndex])
rebuild.needRebuild("txChanged")
}
else {
for (var k in rebuild.txChanged)
{
if (rebuild.txChanged[k] === rebuild.txSha3[blockIndex][txIndex])
{
rebuild.txChanged.splice(k, 1)
break
}
}
if (rebuild.txChanged.length === 0)
rebuild.notNeedRebuild("txChanged")
}
} }
onWidthChanged: onWidthChanged:
@ -174,7 +205,8 @@ ColumnLayout {
Connections Connections
{ {
target: block target: block
onTxSelected: { onTxSelected:
{
blockChainPanel.txSelected(index, txIndex) blockChainPanel.txSelected(index, txIndex)
} }
} }
@ -274,8 +306,7 @@ ColumnLayout {
Rectangle { Rectangle {
Layout.preferredWidth: 100 Layout.preferredWidth: 100
Layout.preferredHeight: 30 Layout.preferredHeight: 30
ScenarioButton { ScenarioButton {
id: rebuild id: rebuild
text: qsTr("Rebuild") text: qsTr("Rebuild")
@ -283,6 +314,43 @@ ColumnLayout {
height: 30 height: 30
roundLeft: true roundLeft: true
roundRight: true roundRight: true
property variant contractsHex: ({})
property variant txSha3: ({})
property variant txChanged: []
property var blinkReasons: []
function needRebuild(reason)
{
rebuild.startBlinking()
blinkReasons.push(reason)
}
function containsRebuildCause(reason)
{
for (var c in blinkReasons)
{
if (blinkReasons[c] === reason)
{
return true
}
}
}
function notNeedRebuild(reason)
{
for (var c in blinkReasons)
{
if (blinkReasons[c] === reason)
{
blinkReasons.splice(c, 1)
break
}
}
if (blinkReasons.length === 0)
rebuild.stopBlinking()
}
onClicked: onClicked:
{ {
if (ensureNotFuturetime.running) if (ensureNotFuturetime.running)
@ -335,8 +403,34 @@ ColumnLayout {
blockModel.append(model.blocks[j]) blockModel.append(model.blocks[j])
ensureNotFuturetime.start() ensureNotFuturetime.start()
takeCodeSnapshot()
takeTxSnaphot()
blinkReasons = []
clientModel.setupScenario(model); clientModel.setupScenario(model);
} }
function takeCodeSnapshot()
{
contractsHex = {}
for (var c in codeModel.contracts)
contractsHex[c] = codeModel.contracts[c].codeHex
}
function takeTxSnaphot()
{
txSha3 = {}
txChanged = []
for (var j = 0; j < model.blocks.length; j++)
{
for (var k = 0; k < model.blocks[j].transactions.length; k++)
{
if (txSha3[j] === undefined)
txSha3[j] = {}
txSha3[j][k] = codeModel.sha3(JSON.stringify(model.blocks[j].transactions[k]))
}
}
}
buttonShortcut: "" buttonShortcut: ""
sourceImg: "qrc:/qml/img/recycleicon@2x.png" sourceImg: "qrc:/qml/img/recycleicon@2x.png"
} }
@ -548,9 +642,8 @@ ColumnLayout {
else { else {
model.blocks[blockIndex].transactions[transactionIndex] = item model.blocks[blockIndex].transactions[transactionIndex] = item
blockModel.setTransaction(blockIndex, transactionIndex, item) blockModel.setTransaction(blockIndex, transactionIndex, item)
chainChanged() chainChanged(blockIndex, transactionIndex, item)
} }
} }
} }
} }

8
mix/qml/ScenarioButton.qml

@ -30,8 +30,8 @@ Rectangle {
id: left id: left
width: 10 width: 10
height: parent.height height: parent.height
anchors.left: parent.left anchors.left: contentRectangle.left
anchors.leftMargin: -8 anchors.leftMargin: -4
radius: 15 radius: 15
} }
@ -111,8 +111,8 @@ Rectangle {
id: right id: right
width: 10 width: 10
height: parent.height height: parent.height
anchors.left: contentRectangle.right anchors.right: contentRectangle.right
anchors.leftMargin: -8 anchors.rightMargin: -4
radius: 15 radius: 15
} }

276
mix/qml/ScenarioLoader.qml

@ -6,6 +6,7 @@ import QtQuick.Dialogs 1.2
import QtQuick.Window 2.0 import QtQuick.Window 2.0
import QtQuick.Dialogs 1.1 import QtQuick.Dialogs 1.1
import Qt.labs.settings 1.0 import Qt.labs.settings 1.0
import org.ethereum.qml.InverseMouseArea 1.0
import "js/Debugger.js" as Debugger import "js/Debugger.js" as Debugger
import "js/ErrorLocationFormater.js" as ErrorLocationFormater import "js/ErrorLocationFormater.js" as ErrorLocationFormater
import "." import "."
@ -18,6 +19,7 @@ ColumnLayout
signal duplicated(variant scenario) signal duplicated(variant scenario)
signal loaded(variant scenario) signal loaded(variant scenario)
signal renamed(variant scenario) signal renamed(variant scenario)
signal deleted()
spacing: 0 spacing: 0
function init() function init()
{ {
@ -29,146 +31,92 @@ ColumnLayout
editStatus.visible = true editStatus.visible = true
} }
Rectangle RowLayout
{ {
Layout.fillWidth: true Layout.preferredWidth: 560
Layout.preferredHeight: 30 anchors.horizontalCenter: parent.horizontalCenter
color: "transparent" Layout.preferredHeight: 60
Rectangle spacing: 0
anchors.top: parent.top
anchors.topMargin: 10
Row
{ {
anchors.verticalCenter: parent.verticalCenter Layout.preferredWidth: 100 * 5 + 30
anchors.horizontalCenter: parent.horizontalCenter Layout.preferredHeight: 50
color: "transparent" spacing: 25
Label
{
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
id: scenarioName
font.bold: true
}
TextInput Rectangle
{ {
id: scenarioNameEdit color: "white"
visible: false width: 251 + 30
anchors.verticalCenter: parent.verticalCenter height: 30
anchors.horizontalCenter: parent.horizontalCenter
Keys.onEnterPressed:
{
save()
}
function edit()
{
editIconRect.anchors.left = scenarioNameEdit.right
editStatus.parent.anchors.left = scenarioNameEdit.right
scenarioNameEdit.forceActiveFocus()
}
function save()
{
editIconRect.anchors.left = scenarioName.right
editStatus.parent.anchors.left = scenarioName.right
scenarioName.text = scenarioNameEdit.text
scenarioName.visible = true
scenarioNameEdit.visible = false
projectModel.stateListModel.getState(scenarioList.currentIndex).title = scenarioName.text
projectModel.saveProjectFile()
saved(state)
scenarioList.model.get(scenarioList.currentIndex).title = scenarioName.text
scenarioList.currentIndex = scenarioList.currentIndex
renamed(projectModel.stateListModel.getState(scenarioList.currentIndex))
}
}
Connections Rectangle
{
target: blockChainSelector
onLoaded:
{ {
scenarioName.text = scenario.title id: left
scenarioNameEdit.text = scenario.title width: 10
} height: parent.height
} anchors.left: parent.left
anchors.leftMargin: -5
Rectangle radius: 15
{
anchors.left: scenarioName.right
anchors.top: scenarioName.top
anchors.leftMargin: 2
Layout.preferredWidth: 20
Text {
id: editStatus
text: "*"
visible: false
} }
}
Rectangle
{
id: editIconRect
anchors.top: scenarioName.top
anchors.topMargin: 6
anchors.left: scenarioName.right
anchors.leftMargin: 20
Image { Image {
source: "qrc:/qml/img/edittransaction.png" source: "qrc:/qml/img/edittransaction.png"
width: 30 height: parent.height - 10
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left
anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top
anchors.topMargin: 4
id: editImg
MouseArea MouseArea
{ {
anchors.fill: parent anchors.fill: parent
onClicked: onClicked:
{ {
scenarioName.visible = !scenarioName.visible scenarioNameEdit.toggleEdit()
scenarioNameEdit.visible = !scenarioNameEdit.visible
if (!scenarioNameEdit.visible)
scenarioNameEdit.save()
else
scenarioNameEdit.edit()
} }
} }
} }
}
}
}
RowLayout Label
{
Layout.preferredWidth: 560
anchors.horizontalCenter: parent.horizontalCenter
Layout.preferredHeight: 50
spacing: 0
Row
{
Layout.preferredWidth: 100 * 5
Layout.preferredHeight: 50
spacing: 15
Rectangle
{
color: "transparent"
width: 251
height: 30
Rectangle
{ {
width: 10 anchors.left: editImg.right
text: "X"
height: parent.height height: parent.height
anchors.right: scenarioList.left color: "#cccccc"
anchors.rightMargin: -8 id: deleteImg
radius: 15 anchors.top: parent.top
anchors.topMargin: 6
visible: projectModel.stateListModel.count > 1
MouseArea
{
anchors.fill: parent
onClicked:
{
if (projectModel.stateListModel.count > 1)
{
projectModel.stateListModel.deleteState(scenarioList.currentIndex)
scenarioList.currentIndex = 0
deleted()
}
}
}
} }
ComboBox ComboBox
{ {
id: scenarioList id: scenarioList
anchors.left: deleteImg.right
anchors.leftMargin: 2
model: projectModel.stateListModel model: projectModel.stateListModel
anchors.top: parent.top
textRole: "title" textRole: "title"
height: parent.height height: parent.height
width: 150 width: 150
signal updateView()
onCurrentIndexChanged: onCurrentIndexChanged:
{ {
restoreScenario.restore() restoreScenario.restore()
@ -177,15 +125,18 @@ ColumnLayout
function load() function load()
{ {
var state = projectModel.stateListModel.getState(currentIndex) var state = projectModel.stateListModel.getState(currentIndex)
loaded(state) if (state)
loaded(state)
} }
style: ComboBoxStyle { style: ComboBoxStyle {
id: style
background: Rectangle { background: Rectangle {
color: "white" color: "white"
anchors.fill: parent anchors.fill: parent
} }
label: Rectangle { label: Rectangle {
property alias label: comboLabel
anchors.fill: parent anchors.fill: parent
color: "white" color: "white"
Label { Label {
@ -194,20 +145,33 @@ ColumnLayout
elide: Text.ElideRight elide: Text.ElideRight
width: parent.width width: parent.width
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter anchors.left: parent.left
text: { Component.onCompleted:
if (projectModel.stateListModel.getState(scenarioList.currentIndex)) {
return projectModel.stateListModel.getState(scenarioList.currentIndex).title comboLabel.updateLabel()
else }
return ""
function updateLabel()
{
comboLabel.text = ""
if (scenarioList.currentIndex < projectModel.stateListModel.count)
comboLabel.text = projectModel.stateListModel.getState(scenarioList.currentIndex).title
} }
Connections { Connections {
target: blockChainSelector target: blockChainSelector
onLoaded: { onLoaded: {
comboLabel.text = projectModel.stateListModel.getState(scenarioList.currentIndex).title if (projectModel.stateListModel.count > 0)
comboLabel.text = projectModel.stateListModel.getState(scenarioList.currentIndex).title
else
return ""
} }
onRenamed: { onRenamed: {
comboLabel.text = scenario.title comboLabel.text = scenario.title
scenarioNameEdit.text = scenario.title
}
onDeleted: {
comboLabel.updateLabel()
} }
} }
} }
@ -215,9 +179,74 @@ ColumnLayout
} }
} }
TextField
{
id: scenarioNameEdit
anchors.left: deleteImg.right
anchors.leftMargin: 2
height: parent.height
z: 5
visible: false
width: 150
Keys.onEnterPressed:
{
toggleEdit()
}
Keys.onReturnPressed:
{
toggleEdit()
}
function toggleEdit()
{
scenarioList.visible = !scenarioList.visible
scenarioNameEdit.visible = !scenarioNameEdit.visible
if (!scenarioNameEdit.visible)
scenarioNameEdit.save()
else
{
scenarioNameEdit.text = projectModel.stateListModel.getState(scenarioList.currentIndex).title
scenarioNameEdit.forceActiveFocus()
outsideClick.active = true
}
}
function save()
{
outsideClick.active = false
projectModel.stateListModel.getState(scenarioList.currentIndex).title = scenarioNameEdit.text
projectModel.saveProjectFile()
saved(state)
scenarioList.model.get(scenarioList.currentIndex).title = scenarioNameEdit.text
scenarioList.currentIndex = scenarioList.currentIndex
renamed(projectModel.stateListModel.getState(scenarioList.currentIndex))
}
style: TextFieldStyle {
background: Rectangle {
radius: 2
implicitWidth: 100
implicitHeight: 30
color: "white"
border.color: "#cccccc"
border.width: 1
}
}
InverseMouseArea {
id: outsideClick
anchors.fill: parent
active: false
onClickedOutside: {
scenarioNameEdit.toggleEdit()
}
}
}
Rectangle Rectangle
{ {
width: 1 width: 1
height: parent.height height: parent.height
anchors.right: addScenario.left anchors.right: addScenario.left
color: "#ededed" color: "#ededed"
@ -236,7 +265,6 @@ ColumnLayout
projectModel.stateListModel.appendState(item) projectModel.stateListModel.appendState(item)
projectModel.stateListModel.save() projectModel.stateListModel.save()
scenarioList.currentIndex = projectModel.stateListModel.count - 1 scenarioList.currentIndex = projectModel.stateListModel.count - 1
scenarioNameEdit.edit()
} }
text: qsTr("New..") text: qsTr("New..")
roundRight: true roundRight: true
@ -251,15 +279,6 @@ ColumnLayout
height: 30 height: 30
color: "transparent" color: "transparent"
Rectangle
{
width: 10
height: parent.height
anchors.right: restoreScenario.left
anchors.rightMargin: -4
radius: 15
}
ScenarioButton { ScenarioButton {
id: restoreScenario id: restoreScenario
width: 100 width: 100
@ -275,7 +294,6 @@ ColumnLayout
var state = projectModel.stateListModel.reloadStateFromFromProject(scenarioList.currentIndex) var state = projectModel.stateListModel.reloadStateFromFromProject(scenarioList.currentIndex)
if (state) if (state)
{ {
editStatus.visible = false
restored(state) restored(state)
loaded(state) loaded(state)
} }

5
mix/qml/StateListModel.qml

@ -403,7 +403,10 @@ Item {
function defaultStateName() function defaultStateName()
{ {
return stateList[defaultStateIndex].title; if (stateList.length > 0)
return stateList[defaultStateIndex].title;
else
return ""
} }
function reloadStateFromFromProject(index) function reloadStateFromFromProject(index)

4
mix/qml/Watchers.qml

@ -83,7 +83,7 @@ Rectangle {
Label { Label {
id: fromLabel id: fromLabel
text: qsTr("from") text: qsTr("from")
visible: from.text !== "" visible: false
color: "#EAB920" color: "#EAB920"
} }
Label { Label {
@ -97,7 +97,7 @@ Rectangle {
Label { Label {
id: toLabel id: toLabel
text: qsTr("to") text: qsTr("to")
visible: from.text !== "" visible: false
color: "#EAB920" color: "#EAB920"
} }
Label { Label {

Loading…
Cancel
Save