-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHeaderObjectsModel.cpp
More file actions
148 lines (128 loc) · 4.07 KB
/
HeaderObjectsModel.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"
int HeaderObjectsModel::rowCount(const QModelIndex &parent) const {
return (int) m_lines.size();
}
int HeaderObjectsModel::columnCount(const QModelIndex &parent) const {
return COL_MAX;
}
QVariant HeaderObjectsModel::data(const QModelIndex &index, int role) const {
if (role == Qt::DisplayRole) {
if ((index.row() >= m_lines.size()) || (index.column() >= COL_MAX))
return QVariant();
const auto &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:
return QVariant();
}
}
return QVariant();
}
QVariant HeaderObjectsModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
return QString(colNamesToString(static_cast<enColumnsNames>(section)));
} else {
return section + 1;
}
}
return QVariant();
}
Qt::ItemFlags HeaderObjectsModel::flags(const QModelIndex &index) const {
return Qt::ItemIsEditable | QAbstractTableModel::flags(index);
}
bool HeaderObjectsModel::setData(const QModelIndex &index, const QVariant &value, int role) {
if (role == Qt::EditRole) {
if (!checkIndex(index))
return false;
bool ok;
uint32_t v = value.toUInt(&ok);
if (!ok)
return false;
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())
return false;
m_lines[index.row()].type = v;
break;
case z :
if(v > std::numeric_limits<uint8_t>::max())
return false;
m_lines[index.row()].Z = v;
break;
case intensity :
if(v > std::numeric_limits<uint8_t>::max())
return false;
m_lines[index.row()].intensity = v;
break;
case R :
if(v > std::numeric_limits<uint8_t>::max())
return false;
m_lines[index.row()].R = v;
break;
case G :
if(v > std::numeric_limits<uint8_t>::max())
return false;
m_lines[index.row()].G = v;
break;
case B :
if(v > std::numeric_limits<uint8_t>::max())
return false;
m_lines[index.row()].B = v;
break;
case A :
if(v > std::numeric_limits<uint8_t>::max())
return false;
m_lines[index.row()].palette_id = v;
break;
default:
return false;
}
return true;
}
return false;
}
void HeaderObjectsModel::importLines(const vector<ImageSection::HeaderRecord> &data) {
m_lines = data;
beginResetModel();
endResetModel();
}
const vector<ImageSection::HeaderRecord> &HeaderObjectsModel::exportLines() const {
return m_lines;
}