-
Notifications
You must be signed in to change notification settings - Fork 1
/
filetablesend.go
155 lines (135 loc) · 4.04 KB
/
filetablesend.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
155
package main
import "github.com/therecipe/qt/core"
const (
sendFilename = int(core.Qt__UserRole) + 1<<iota
sendCode
sendFilesize
sendTransmitted
sendStatus
)
type SendFileTableItem struct {
filename string
code string
size string
transmitted string
status string
}
type SendFileTableModel struct {
core.QAbstractTableModel
_ func() `constructor:"init"`
_ func() `signal:"remove,auto"`
_ func(item []*core.QVariant) `signal:"add,auto"`
_ func(filename string, code string, size string, transmitted string, status string) `signal:"editLast,auto"`
_ func(tableIdx int, filename string, code string, size string, transmitted string, status string) `signal:"editIdx,auto"`
modelData []SendFileTableItem
}
func (m *SendFileTableModel) init() {
m.modelData = []SendFileTableItem{
// {"test1.txt", "1000", "1000", "Done"},
// {"test2.txt", "1000", "0", "Started"},
}
m.ConnectRoleNames(m.roleNames)
m.ConnectRowCount(m.rowCount)
m.ConnectColumnCount(m.columnCount)
m.ConnectData(m.data)
}
func (m *SendFileTableModel) roleNames() map[int]*core.QByteArray {
return map[int]*core.QByteArray{
sendFilename: core.NewQByteArray2("sendFilename", -1),
sendCode: core.NewQByteArray2("sendCode", -1),
sendFilesize: core.NewQByteArray2("sendFilesize", -1),
sendTransmitted: core.NewQByteArray2("sendTransmitted", -1),
sendStatus: core.NewQByteArray2("sendStatus", -1),
}
}
func (m *SendFileTableModel) rowCount(*core.QModelIndex) int {
return len(m.modelData)
}
func (m *SendFileTableModel) columnCount(*core.QModelIndex) int {
return 5
}
func (m *SendFileTableModel) data(index *core.QModelIndex, role int) *core.QVariant {
item := m.modelData[index.Row()]
switch role {
case sendFilename:
return core.NewQVariant1(item.filename)
case sendCode:
return core.NewQVariant1(item.code)
case sendFilesize:
return core.NewQVariant1(item.size)
case sendTransmitted:
return core.NewQVariant1(item.transmitted)
case sendStatus:
return core.NewQVariant1(item.status)
}
return core.NewQVariant()
}
func (m *SendFileTableModel) remove() {
if len(m.modelData) == 0 {
return
}
m.BeginRemoveRows(core.NewQModelIndex(), len(m.modelData)-1, len(m.modelData)-1)
m.modelData = m.modelData[:len(m.modelData)-1]
m.EndRemoveRows()
}
func (m *SendFileTableModel) add(item []*core.QVariant) {
m.BeginInsertRows(core.NewQModelIndex(), len(m.modelData), len(m.modelData))
m.modelData = append(
m.modelData,
SendFileTableItem{
item[0].ToString(),
item[1].ToString(),
item[2].ToString(),
item[3].ToString(),
item[4].ToString(),
})
m.EndInsertRows()
}
func (m *SendFileTableModel) addNative(
filename string, code string, size string, transmitted string, status string) int {
m.BeginInsertRows(core.NewQModelIndex(), len(m.modelData), len(m.modelData))
m.modelData = append(
m.modelData,
SendFileTableItem{
filename,
code,
size,
transmitted,
status,
})
m.EndInsertRows()
return len(m.modelData) - 1
}
func (m *SendFileTableModel) editLast(
filename string,
code string,
size string,
transmitted string,
status string) {
if len(m.modelData) == 0 {
return
}
m.modelData[len(m.modelData)-1] = SendFileTableItem{
filename, code, size, transmitted, status}
m.DataChanged(
m.Index(len(m.modelData)-1, 0, core.NewQModelIndex()),
m.Index(len(m.modelData)-1, 1, core.NewQModelIndex()),
[]int{sendFilename, sendCode, sendFilesize, sendTransmitted, sendStatus})
}
func (m *SendFileTableModel) editIdx(
tableIdx int,
filename string,
code string,
size string,
transmitted string,
status string) {
if len(m.modelData) == 0 {
return
}
m.modelData[tableIdx] = SendFileTableItem{
filename, code, size, transmitted, status}
m.DataChanged(
m.Index(tableIdx, 0, core.NewQModelIndex()),
m.Index(tableIdx, 1, core.NewQModelIndex()),
[]int{sendFilename, sendCode, sendFilesize, sendTransmitted, sendStatus})
}