-
Notifications
You must be signed in to change notification settings - Fork 0
/
formats.cpp
167 lines (145 loc) · 3.32 KB
/
formats.cpp
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
#include "formats.h"
#include <qnamespace.h>
FormatData::FormatData(const QString &id, const QString &name, const QString &resolution, const QString &vcodec,
const QString &acodec, fps_t fps, filesize_t filesize, bool filesizeEstimate, double tbr)
: m_id(id), m_name(name), m_resolution(resolution), m_vcodec(vcodec), m_acodec(acodec), m_fps(fps),
m_filesize(filesize), m_filesizeEstimate(filesizeEstimate), m_tbr(tbr)
{
}
bool
FormatData::selected() const
{
return m_selected;
}
void
FormatData::selected(bool newValue)
{
m_selected = newValue;
}
QString
FormatData::id() const
{
return m_id;
}
QString
FormatData::name() const
{
return m_name;
}
QString
FormatData::resolution() const
{
return m_resolution;
}
QString
FormatData::vcodec() const
{
return m_vcodec;
}
QString
FormatData::acodec() const
{
return m_acodec;
}
fps_t
FormatData::fps() const
{
return m_fps;
}
filesize_t
FormatData::filesize() const
{
return m_filesize;
}
bool
FormatData::filesizeEstimate() const
{
return m_filesizeEstimate;
}
double
FormatData::tbr() const
{
return m_tbr;
}
FormatDataModel::FormatDataModel(QObject *parent): QAbstractListModel(parent)
{
}
int
FormatDataModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_formats.count();
}
QVariant
FormatDataModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= m_formats.count())
return QVariant();
const FormatData &format = m_formats[index.row()];
switch (role) {
case SelectedRole:
return QVariant::fromValue(format.selected());
case NameRole:
return format.name();
case ResolutionRole:
return format.resolution();
case VcodecRole:
return format.vcodec();
case AcodecRole:
return format.acodec();
case FpsRole:
return QVariant::fromValue(format.fps());
case FilesizeRole:
return QVariant::fromValue(format.filesize());
case FilesizeEstimateRole:
return QVariant::fromValue(format.filesizeEstimate());
case TbrRole:
return QVariant::fromValue(format.tbr());
default:
return QVariant();
}
}
bool
FormatDataModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (role != SelectedRole || index.row() < 0 || index.row() >= m_formats.count()) {
return false;
}
FormatData &format = m_formats[index.row()];
format.selected(value.toBool());
emit dataChanged(index, index);
return true;
}
QHash<int, QByteArray>
FormatDataModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[SelectedRole] = "selected";
roles[NameRole] = "name";
roles[ResolutionRole] = "resolution";
roles[VcodecRole] = "vcodec";
roles[AcodecRole] = "acodec";
roles[FpsRole] = "fps";
roles[FilesizeRole] = "filesize";
roles[FilesizeEstimateRole] = "filesize_estimate";
roles[TbrRole] = "tbr";
return roles;
}
void
FormatDataModel::setFormatList(const QString &searchUrl, const QList<FormatData> &list)
{
beginResetModel();
m_searchUrl = searchUrl;
m_formats = list;
endResetModel();
}
const FormatData &
FormatDataModel::operator[](qsizetype idx) const
{
return m_formats[idx];
}
const QString &
FormatDataModel::searchUrl() const
{
return m_searchUrl;
}