-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharcmodel.cpp
54 lines (47 loc) · 1.17 KB
/
arcmodel.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
#include "arcmodel.h"
ArcModel::ArcModel(QObject *parent):QAbstractListModel(parent)
{
m_pFilenameList = 0;
m_size = 0;
}
void ArcModel::init(QByteArray &data, quint32 count)
{
beginResetModel();
m_data = data;
m_size = count;
m_pFilenameList = (FilenameList*)m_data.data();
endResetModel();
}
int ArcModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_size;
}
QVariant ArcModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant();
if(index.row()>=m_size)
return QVariant();
auto i = index.row();
if(role == Qt::DisplayRole || role == NameRole)
{
QString n = QString(m_pFilenameList[i].filename);
n.truncate(12);
return n;
}
else if(role == OffsetRole)
return m_pFilenameList[i].offset;
else if(role == SizeRole)
return m_pFilenameList[i].size;
else
return QVariant();
}
QHash<int, QByteArray> ArcModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[SizeRole] = "size";
roles[OffsetRole] = "offset";
return roles;
}