-
Notifications
You must be signed in to change notification settings - Fork 1
/
filetablerecv.go
134 lines (114 loc) · 3.56 KB
/
filetablerecv.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
package main
import "github.com/therecipe/qt/core"
const (
Filename = int(core.Qt__UserRole) + 1<<iota
Filesize
Transmitted
Status
)
type TableItem struct {
filename string
filesize string
transmitted string
status string
}
type RecvFileTableModel struct {
core.QAbstractTableModel
_ func() `constructor:"init"`
_ func() `signal:"remove,auto"`
_ func(item []*core.QVariant) `signal:"add,auto"`
_ func(filename string, filesize string, transmitted string, status string) `signal:"editLast,auto"`
_ func(tableIdx int, filename string, filesize string, transmitted string, status string) `signal:"editIdx,auto"`
modelData []TableItem
}
func (m *RecvFileTableModel) init() {
m.modelData = []TableItem{
// {"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 *RecvFileTableModel) roleNames() map[int]*core.QByteArray {
return map[int]*core.QByteArray{
Filename: core.NewQByteArray2("Filename", -1),
Filesize: core.NewQByteArray2("Filesize", -1),
Transmitted: core.NewQByteArray2("Transmitted", -1),
Status: core.NewQByteArray2("Status", -1),
}
}
func (m *RecvFileTableModel) rowCount(*core.QModelIndex) int {
return len(m.modelData)
}
func (m *RecvFileTableModel) columnCount(*core.QModelIndex) int {
return 4
}
func (m *RecvFileTableModel) data(index *core.QModelIndex, role int) *core.QVariant {
item := m.modelData[index.Row()]
switch role {
case Filename:
return core.NewQVariant1(item.filename)
case Filesize:
return core.NewQVariant1(item.filesize)
case Transmitted:
return core.NewQVariant1(item.transmitted)
case Status:
return core.NewQVariant1(item.status)
}
return core.NewQVariant()
}
func (m *RecvFileTableModel) 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 *RecvFileTableModel) add(item []*core.QVariant) {
m.BeginInsertRows(core.NewQModelIndex(), len(m.modelData), len(m.modelData))
m.modelData = append(
m.modelData,
TableItem{
item[0].ToString(),
item[1].ToString(),
item[2].ToString(),
item[3].ToString(),
})
m.EndInsertRows()
}
func (m *RecvFileTableModel) addNative(a string, b string, c string, d string) int {
m.BeginInsertRows(core.NewQModelIndex(), len(m.modelData), len(m.modelData))
m.modelData = append(
m.modelData,
TableItem{
a,
b,
c,
d,
})
m.EndInsertRows()
return len(m.modelData) - 1
}
func (m *RecvFileTableModel) editLast(filename string, filesize string, transmitted string, status string) {
if len(m.modelData) == 0 {
return
}
m.modelData[len(m.modelData)-1] = TableItem{filename, filesize, transmitted, status}
m.DataChanged(
m.Index(len(m.modelData)-1, 0, core.NewQModelIndex()),
m.Index(len(m.modelData)-1, 1, core.NewQModelIndex()),
[]int{Filename, Filesize, Transmitted, Status})
}
func (m *RecvFileTableModel) editIdx(tableIdx int, filename string, filesize string, transmitted string, status string) {
if len(m.modelData) == 0 {
return
}
m.modelData[tableIdx] = TableItem{filename, filesize, transmitted, status}
m.DataChanged(
m.Index(tableIdx, 0, core.NewQModelIndex()),
m.Index(tableIdx, 1, core.NewQModelIndex()),
[]int{Filename, Filesize, Transmitted, Status})
}