-
Notifications
You must be signed in to change notification settings - Fork 10
/
model.go
104 lines (86 loc) · 2.23 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package ladder
import (
"github.com/therecipe/qt/core"
)
// Model Roles.
const (
Rank = int(core.Qt__UserRole) + 1<<iota
Name
Class
Level
Title
Status
)
// TopLadderModel represents the in game ladder model.
type TopLadderModel struct {
core.QAbstractListModel
_ func() `constructor:"init"`
_ map[int]*core.QByteArray `property:"roles"`
_ []*Character `property:"characters"`
_ func(*Character) `slot:"addCharacter"`
_ func() `slot:"clear"`
}
func (m *TopLadderModel) init() {
m.SetRoles(map[int]*core.QByteArray{
Rank: core.NewQByteArray2("rank", -1),
Name: core.NewQByteArray2("name", -1),
Class: core.NewQByteArray2("class", -1),
Level: core.NewQByteArray2("level", -1),
Title: core.NewQByteArray2("title", -1),
Status: core.NewQByteArray2("status", -1),
})
m.ConnectData(m.data)
m.ConnectRowCount(m.rowCount)
m.ConnectColumnCount(m.columnCount)
m.ConnectRoleNames(m.roleNames)
m.ConnectAddCharacter(m.addCharacter)
m.ConnectClear(m.clear)
}
func (m *TopLadderModel) rowCount(*core.QModelIndex) int {
return len(m.Characters())
}
func (m *TopLadderModel) columnCount(*core.QModelIndex) int {
return 1
}
func (m *TopLadderModel) roleNames() map[int]*core.QByteArray {
return m.Roles()
}
func (m *TopLadderModel) data(index *core.QModelIndex, role int) *core.QVariant {
if !index.IsValid() {
return core.NewQVariant()
}
if index.Row() >= len(m.Characters()) {
return core.NewQVariant()
}
item := m.Characters()[index.Row()]
switch role {
case Rank:
return core.NewQVariant1(item.Rank)
case Name:
return core.NewQVariant1(item.Name)
case Class:
return core.NewQVariant1(item.Class)
case Level:
return core.NewQVariant1(item.Level)
case Title:
return core.NewQVariant1(item.Title)
case Status:
return core.NewQVariant1(item.Status)
default:
return core.NewQVariant()
}
}
func (m *TopLadderModel) addCharacter(c *Character) {
m.BeginInsertRows(core.NewQModelIndex(), len(m.Characters()), len(m.Characters()))
m.SetCharacters(append(m.Characters(), c))
m.EndInsertRows()
}
func (m *TopLadderModel) clear() {
m.BeginResetModel()
m.SetCharacters([]*Character{})
m.EndResetModel()
}
func init() {
TopLadderModel_QRegisterMetaType()
Character_QRegisterMetaType()
}