- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHeaderObjectsModel.cpp
More file actions
Latest commit
148 lines (128 loc) · 4.07 KB
/
Copy pathHeaderObjectsModel.cpp
File metadata and controls
148 lines (128 loc) · 4.07 KB
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
//
// Created by user on 14.06.2021.
//
#include"HeaderObjectsModel.h"
intHeaderObjectsModel::rowCount(const QModelIndex &parent) const {
return (int) m_lines.size();
}
intHeaderObjectsModel::columnCount(const QModelIndex &parent) const {
returnCOL_MAX;
}
QVariant HeaderObjectsModel::data(const QModelIndex &index, int role) const {
if (role == Qt::DisplayRole) {
if ((index.row() >= m_lines.size()) || (index.column() >= COL_MAX))
returnQVariant();
constauto &line = m_lines[index.row()];
switch (index.column()) {
case width :
return line.width;
case height :
return line.height;
case X :
return line.X;
case Y :
return line.Y;
case type :
return line.type;
case z :
return line.Z;
case intensity :
return line.intensity;
case R :
return line.R;
case G :
return line.G;
case B :
return line.B;
case A :
return line.palette_id;
default:
returnQVariant();
}
}
returnQVariant();
}
QVariant HeaderObjectsModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
returnQString(colNamesToString(static_cast<enColumnsNames>(section)));
} else {
return section + 1;
}
}
returnQVariant();
}
Qt::ItemFlags HeaderObjectsModel::flags(const QModelIndex &index) const {
return Qt::ItemIsEditable | QAbstractTableModel::flags(index);
}
boolHeaderObjectsModel::setData(const QModelIndex &index, const QVariant &value, int role) {
if (role == Qt::EditRole) {
if (!checkIndex(index))
returnfalse;
bool ok;
uint32_t v = value.toUInt(&ok);
if (!ok)
returnfalse;
switch (index.column()) {
case width :
m_lines[index.row()].width = v;
break;
case height :
m_lines[index.row()].height = v;
break;
case X :
m_lines[index.row()].X = v;
break;
case Y :
m_lines[index.row()].Y = v;
break;
case type :
if(v > std::numeric_limits<uint8_t>::max())
returnfalse;
m_lines[index.row()].type = v;
break;
case z :
if(v > std::numeric_limits<uint8_t>::max())
returnfalse;
m_lines[index.row()].Z = v;
break;
case intensity :
if(v > std::numeric_limits<uint8_t>::max())
returnfalse;
m_lines[index.row()].intensity = v;
break;
case R :
if(v > std::numeric_limits<uint8_t>::max())
returnfalse;
m_lines[index.row()].R = v;
break;
case G :
if(v > std::numeric_limits<uint8_t>::max())
returnfalse;
m_lines[index.row()].G = v;
break;
case B :
if(v > std::numeric_limits<uint8_t>::max())
returnfalse;
m_lines[index.row()].B = v;
break;
case A :
if(v > std::numeric_limits<uint8_t>::max())
returnfalse;
m_lines[index.row()].palette_id = v;
break;
default:
returnfalse;
}
returntrue;
}
returnfalse;
}
voidHeaderObjectsModel::importLines(const vector<ImageSection::HeaderRecord> &data) {
m_lines = data;
beginResetModel();
endResetModel();
}
const vector<ImageSection::HeaderRecord> &HeaderObjectsModel::exportLines() const {
return m_lines;
}