Skip to content

Commit

Permalink
[explorer] refs fibercrypto#248 - Install models for explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
AntiD2ta committed Dec 27, 2019
1 parent bce016f commit 5a11ce7
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 52 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
_ "github.com/fibercrypto/fibercryptowallet/src/models"
_ "github.com/fibercrypto/fibercryptowallet/src/models/history"
_ "github.com/fibercrypto/fibercryptowallet/src/models/pending"
_ "github.com/fibercrypto/fibercryptowallet/src/models/explorer"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/qml"
Expand Down
56 changes: 31 additions & 25 deletions src/models/explorer/blocksModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,41 +51,42 @@ const (
type BlocksModel struct {
qtcore.QAbstractListModel

_ func() `constructor:"init"`
_ func() `constructor:"init"`

_ int `property:"currentPage"`
_ map[int]*core.QByteArray `property:"roles"`
_ []*QBlock `property:"blocks"`
_ int `property:"currentPage"`
_ map[int]*qtcore.QByteArray `property:"roles"`
_ []*QBlock `property:"blocks"`

_ func(pageNum int) `signal:"loadPage"`
_ func() `signal:"update,auto"`
_ func(pageNum int) `signal:"loadPage"`
_ func() `signal:"update,auto"`

_ func([]*QBlock) `slot:"addBlocks"`
_ func([]*QBlock) `slot:"loadModel"`
_ func([]*QBlock) `slot:"addBlocks"`
_ func() `slot:"loadModel"`
}

// QBlock Contains info about the block to be show.
type QBlock struct {
core.QObject
qtcore.QObject

_ string `property:"time"`
_ string `property:"blockNumber"`
_ string `property:"Transactions"`
_ string `property:"Blockhash"`
}

func (blocksM *BlocksModel) init() {
m.SetRoles(map[int]*core.QByteArray{
QBlocks: core.NewQByteArray2("qblocks", -1),
func (m *BlocksModel) init() {
m.SetRoles(map[int]*qtcore.QByteArray{
Time: qtcore.NewQByteArray2("time", -1),
BlockNumber: qtcore.NewQByteArray2("blockNumber", -1),
Transactions: qtcore.NewQByteArray2("transactions", -1),
Blockhash: qtcore.NewQByteArray2("blockhash", -1),
})

m.ConnectRowCount(m.rowCount)
m.ConnectRoleNames(m.roleNames)
m.ConnectData(m.data)
m.ConnectAddBlocks(m.addBlocks)
m.ConnectInsertBlocks(m.insertBlocks)
m.ConnectLoadModel(m.loadModel)
m.ConnectCleanModel(m.cleanModel)

m.loadModel()
}
Expand All @@ -108,45 +109,51 @@ func (blocksM *BlocksModel) loadPage(pageNum int) {

}

func (m *BlocksModel) rowCount(*core.QModelIndex) int {
return len(m.Outputs())
func (m *BlocksModel) rowCount(*qtcore.QModelIndex) int {
return len(m.Blocks())
}

func (m *BlocksModel) roleNames() map[int]*core.QByteArray {
func (m *BlocksModel) roleNames() map[int]*qtcore.QByteArray {
return m.Roles()
}

func (m *BlocksModel) data(index *core.QModelIndex, role int) *core.QVariant {
func (m *BlocksModel) data(index *qtcore.QModelIndex, role int) *qtcore.QVariant {
if !index.IsValid() || index.Row() >= len(m.Blocks()) {
return core.NewQVariant()
return qtcore.NewQVariant()
}

qb := m.Blocks()[index.Row()]

switch role {
case Time:
{
return core.NewQVariant1(qb.Time())
return qtcore.NewQVariant1(qb.Time())
}
case BlockNumber:
{
return core.NewQVariant1(qb.BlockNumber())
return qtcore.NewQVariant1(qb.BlockNumber())
}
case Transactions:
{
return core.NewQVariant1(qb.Transactions())
return qtcore.NewQVariant1(qb.Transactions())
}
case Blockhash:
{
return core.NewQVariant1(qb.Blockhash())
return qtcore.NewQVariant1(qb.Blockhash())
}
default:
{
return core.NewQVariant()
return qtcore.NewQVariant()
}
}
}

func (m *BlocksModel) insertRows(row int, count int) bool {
m.BeginInsertRows(qtcore.NewQModelIndex(), row, row+count)
m.EndInsertRows()
return true
}

func (m *BlocksModel) addBlocks(qb []*QBlock) {
m.SetBlocks(qb)
m.insertRows(len(m.Blocks()), len(qb))
Expand All @@ -155,4 +162,3 @@ func (m *BlocksModel) addBlocks(qb []*QBlock) {
func (m *BlocksModel) loadModel() {
//m.SetOutputs(mo)
}

4 changes: 4 additions & 0 deletions src/models/explorer/explorerManager.go
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
package explorer

func init() {
BlocksModel_QmlRegisterType2("ExplorerModels", 1, 0, "QBlocks")
}
1 change: 0 additions & 1 deletion src/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ func init() {
ModelOutputs_QmlRegisterType2("OutputsModels", 1, 0, "QOutputs")
QTransaction_QmlRegisterType2("Transactions", 1, 0, "QTransaction")
QBridge_QmlRegisterType2("Utils", 1, 0, "QBridge")

}
58 changes: 32 additions & 26 deletions src/ui/ExplorerPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.Material 2.12
import QtQuick.Layouts 1.12
import ExplorerModels 1.0

import "Delegates/" // For quick UI development, switch back to resources when making a release

Expand Down Expand Up @@ -70,33 +71,38 @@ ScrollView {
delegate: BlockListDelegate{}
}
}
ListModel{
id:blockModel
ListElement{
date:"01/02/1990"
blockNumber:10000898
txNumber:2
hash:"9516639399ab2b02f6f0bc873f03f2f2ac1c94853dd031685de1021be78c71d7"
}
ListElement{
date:"01/02/1990"
blockNumber:1
txNumber:2
hash:"9516639399ab2b02f6f0bc873f03f2f2ac1c94853dd031685de1021be78c71d7"

QBlocks{
id:blockModel
}
ListElement{
date:"01/02/1990"
blockNumber:2
txNumber:1
hash:"5ac7b5f4d170e606cc75e08c20b3ec216703e9ca77df178ea0130255bf20d5e5"
}
ListElement{
date:"01/02/1990"
blockNumber:3
txNumber:1
hash:"5ac7b5f4d170e606cc75e08c20b3ec216703e9ca77df178ea0130255bf20d5e5"
}
}//listModel

// ListModel{
// id:blockModeld
// ListElement{
// date:"01/02/1990"
// blockNumber:10000898
// txNumber:2
// hash:"9516639399ab2b02f6f0bc873f03f2f2ac1c94853dd031685de1021be78c71d7"
// }
// ListElement{
// date:"01/02/1990"
// blockNumber:1
// txNumber:2
// hash:"9516639399ab2b02f6f0bc873f03f2f2ac1c94853dd031685de1021be78c71d7"

// }
// ListElement{
// date:"01/02/1990"
// blockNumber:2
// txNumber:1
// hash:"5ac7b5f4d170e606cc75e08c20b3ec216703e9ca77df178ea0130255bf20d5e5"
// }
// ListElement{
// date:"01/02/1990"
// blockNumber:3
// txNumber:1
// hash:"5ac7b5f4d170e606cc75e08c20b3ec216703e9ca77df178ea0130255bf20d5e5"
// }
//}//listModel

}

0 comments on commit 5a11ce7

Please sign in to comment.