/
queuemodel.go
154 lines (121 loc) · 3.11 KB
/
queuemodel.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
import (
"github.com/therecipe/qt/core"
)
const (
Size = int(core.Qt__UserRole) + 1<<iota
Name
Remaining
ItemStatus
Storage
)
type QueueModel struct {
core.QAbstractListModel
_ func() `constructor:"init"`
_ map[int]*core.QByteArray `property:"roles"`
_ []*Queue `property:"items"`
_ func(*Queue) `slot:"addQueue"`
_ func(row int, size, name, remaining, itemStatus, storage string) `slot:"editQueue"`
_ func(row int) `slot:"removeQueue"`
}
type Queue struct {
core.QObject
_ string `property:"name"`
_ string `property:"size"`
_ string `property:"remaining"`
_ string `property:"itemStatus"`
_ string `property:"storage"`
}
func init() {
Queue_QRegisterMetaType()
}
func (m *QueueModel) init() {
m.SetRoles(map[int]*core.QByteArray{
Name: core.NewQByteArray2("name", len("name")),
Size: core.NewQByteArray2("size", len("size")),
Remaining: core.NewQByteArray2("remaining", len("remaining")),
ItemStatus: core.NewQByteArray2("itemStatus", len("itemStatus")),
Storage: core.NewQByteArray2("storage", len("storage")),
})
m.ConnectData(m.data)
m.ConnectRowCount(m.rowCount)
m.ConnectColumnCount(m.columnCount)
m.ConnectRoleNames(m.roleNames)
m.ConnectAddQueue(m.addQueue)
m.ConnectEditQueue(m.editQueue)
m.ConnectRemoveQueue(m.removeQueue)
}
func (m *QueueModel) data(index *core.QModelIndex, role int) *core.QVariant {
if !index.IsValid() {
return core.NewQVariant()
}
if index.Row() >= len(m.Items()) {
return core.NewQVariant()
}
var p = m.Items()[index.Row()]
switch role {
case Name:
{
return core.NewQVariant14(p.Name())
}
case Size:
{
return core.NewQVariant14(p.Size())
}
case Remaining:
{
return core.NewQVariant14(p.Remaining())
}
case ItemStatus:
{
return core.NewQVariant14(p.ItemStatus())
}
case Storage:
{
return core.NewQVariant14(p.Storage())
}
default:
{
return core.NewQVariant()
}
}
}
func (m *QueueModel) rowCount(parent *core.QModelIndex) int {
return len(m.Items())
}
func (m *QueueModel) columnCount(parent *core.QModelIndex) int {
return 4
}
func (m *QueueModel) roleNames() map[int]*core.QByteArray {
return m.Roles()
}
func (m *QueueModel) addQueue(p *Queue) {
m.BeginInsertRows(core.NewQModelIndex(), len(m.Items()), len(m.Items()))
m.SetItems(append(m.Items(), p))
m.EndInsertRows()
}
func (m *QueueModel) editQueue(row int, size string, name string, remaining string, itemStatus string, storage string) {
var p = m.Items()[row]
if size != "" {
p.SetSize(size)
}
if name != "" {
p.SetName(name)
}
if remaining != "" {
p.SetRemaining(remaining)
}
if itemStatus != "" {
p.SetItemStatus(itemStatus)
}
if storage != "" {
p.SetStorage(storage)
}
var pIndex = m.Index(row, 0, core.NewQModelIndex())
m.DataChanged(pIndex, pIndex, []int{Name, Size, Remaining, ItemStatus, Storage})
}
func (m *QueueModel) removeQueue(row int) {
m.BeginRemoveRows(core.NewQModelIndex(), row, row)
m.SetItems(append(m.Items()[:row], m.Items()[row+1:]...))
m.EndRemoveRows()
}