forked from IENT/YUView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatslistmodel.cpp
More file actions
205 lines (163 loc) · 6.08 KB
/
statslistmodel.cpp
File metadata and controls
205 lines (163 loc) · 6.08 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/* YUView - YUV player with advanced analytics toolset
* Copyright (C) 2015 Institut für Nachrichtentechnik
* RWTH Aachen University, GERMANY
*
* YUView is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* YUView is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with YUView. If not, see <http://www.gnu.org/licenses/>.
*/
#include "statslistmodel.h"
StatsListModel::StatsListModel(QObject *parent) : QAbstractListModel(parent)
{
}
int StatsListModel::rowCount(const QModelIndex &) const {
return p_statisticsTypeList.count();
}
QVariant StatsListModel::data(const QModelIndex &index, int role) const {
if (!index.isValid())
return QVariant();
if (role == Qt::CheckStateRole)
return p_statisticsTypeList[index.row()].render?Qt::Checked:Qt::Unchecked;
else if (role == Qt::DisplayRole)
return p_statisticsTypeList[index.row()].typeName;
else if (role == Qt::UserRole)
return p_statisticsTypeList[index.row()].typeID;
else if (role == Qt::UserRole+1)
return p_statisticsTypeList[index.row()].alphaFactor;
else if (role == Qt::UserRole+2)
return p_statisticsTypeList[index.row()].renderGrid;
return QVariant();
}
Qt::ItemFlags StatsListModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::ItemIsDropEnabled;
else
return (Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable);
}
Qt::DropActions StatsListModel::supportedDropActions() const
{
return QAbstractItemModel::supportedDropActions() | Qt::MoveAction;
}
bool StatsListModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.row() >= 0 && index.row() < p_statisticsTypeList.count()) {
switch (role) {
case Qt::CheckStateRole:
p_statisticsTypeList[index.row()].render = value.toUInt()==Qt::Checked;
emit dataChanged(index, index);
emit signalStatsTypesChanged();
return true;
case Qt::UserRole+1:
p_statisticsTypeList[index.row()].alphaFactor = value.toInt();
emit dataChanged(index, index);
emit signalStatsTypesChanged();
return true;
case Qt::UserRole+2:
p_statisticsTypeList[index.row()].renderGrid = value.toBool();
emit dataChanged(index, index);
emit signalStatsTypesChanged();
return true;
}
}
return false;
}
bool StatsListModel::insertRows(int row, int count, const QModelIndex &parent)
{
if (count < 1 || row < 0 || row > rowCount(parent))
return false;
beginInsertRows(QModelIndex(), row, row + count - 1);
for (int r = 0; r < count; ++r) {
StatisticsType newStatsType;
p_statisticsTypeList.insert(row, newStatsType);
}
endInsertRows();
emit signalStatsTypesChanged();
return true;
}
bool StatsListModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (count <= 0 || row < 0 || (row + count) > rowCount(parent))
return false;
beginRemoveRows(QModelIndex(), row, row + count - 1);
for (int r = 0; r < count; ++r) {
p_statisticsTypeList.remove(row);
}
endRemoveRows();
emit signalStatsTypesChanged();
return true;
}
QStringList StatsListModel::mimeTypes() const
{
QStringList types;
types << "application/YUView-Statistics";
return types;
}
QMimeData *StatsListModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
foreach (QModelIndex index, indexes) {
if (index.isValid()) {
int ind = data(index, Qt::UserRole).toInt();
int alpha = data(index, Qt::UserRole+1).toInt();
QModelIndex checkindex = StatsListModel::createIndex(index.row(), 1, 999);
bool draw = data(checkindex, Qt::CheckStateRole).toBool();
bool drawgrid = data(index, Qt::UserRole+2).toBool();
QString name = data(index, Qt::DisplayRole).toString();
stream << ind << alpha << draw << drawgrid << name;
}
}
mimeData->setData("application/YUView-Statistics", encodedData);
return mimeData;
}
bool StatsListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &)
{
if (!data->hasFormat("application/YUView-Statistics"))
return false;
if (action == Qt::IgnoreAction)
return true;
if (column > 2)
return false;
QByteArray encodedData = data->data("application/YUView-Statistics");
QDataStream stream(&encodedData, QIODevice::ReadOnly);
while (!stream.atEnd()) {
int index;
int alpha;
bool draw;
bool drawgrid;
QString name;
stream >> index >> alpha >> draw >> drawgrid >> name;
if (row == INT_INVALID)
row = p_statisticsTypeList.count();
beginInsertRows(QModelIndex(), row, row);
StatisticsType newStatsType;
newStatsType.typeID = index;
newStatsType.typeName = name;
newStatsType.render = draw;
newStatsType.renderGrid = drawgrid;
newStatsType.alphaFactor = alpha;
p_statisticsTypeList.insert(row, newStatsType);
endInsertRows();
}
emit signalStatsTypesChanged();
return true;
}
void StatsListModel::setStatisticsTypeList(StatisticsTypeList typeList)
{
beginResetModel();
// establish connection
p_statisticsTypeList = typeList;
endResetModel();
}
StatisticsTypeList StatsListModel::getStatisticsTypeList() { return p_statisticsTypeList; }