-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfileitem.cc
92 lines (83 loc) · 2.34 KB
/
fileitem.cc
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
#include "fileitem.hpp"
#include "fileinfo.hpp"
#include <QFileIconProvider>
#include <QFileInfo>
struct FileItem::FileItemPrivate
{
FileInfo fileInfo;
};
FileItem::FileItem(const QFileInfo &fileInfo, bool depth)
: d_ptr(new FileItemPrivate)
{
d_ptr->fileInfo = FileInfo(fileInfo);
if (!depth || !fileInfo.isDir()) {
return;
}
auto itemList = QDir(fileInfo.absoluteFilePath())
.entryInfoList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot,
QDir::DirsFirst);
//qDebug() << fileInfo.absoluteFilePath();
for (const auto &item : std::as_const(itemList)) {
appendChild(new FileItem(item, depth));
}
}
FileItem::~FileItem() {}
QVariant FileItem::data(int column, int role) const
{
switch (role) {
case Qt::TextAlignmentRole: return QVariant(Qt::AlignVCenter);
case Qt::CheckStateRole:
if (column == 0) {
return d_ptr->fileInfo.checked() ? Qt::Checked : Qt::Unchecked;
}
break;
case Qt::DecorationRole:
if (column == 1) {
return QIcon(d_ptr->fileInfo.icon());
}
break;
case Qt::WhatsThisRole:
case Qt::ToolTipRole:
case Qt::EditRole:
case Qt::DisplayRole: {
switch (column) {
case 1: return d_ptr->fileInfo.fileInfo().fileName();
case 2: return d_ptr->fileInfo.fileInfo().absoluteFilePath();
case 3: return d_ptr->fileInfo.modifyTime();
case 4: return d_ptr->fileInfo.type();
case 5: return d_ptr->fileInfo.size();
default: break;
}
} break;
case Qt::UserRole: return QVariant::fromValue(d_ptr->fileInfo);
default: break;
}
return QVariant();
}
bool FileItem::setData(int column, const QVariant &data, int role)
{
switch (role) {
case Qt::CheckStateRole:
switch (column) {
case 0: d_ptr->fileInfo.setChecked(data.toBool()); return true;
default: break;
}
break;
default: break;
}
return false;
}
Qt::ItemFlags FileItem::flags(int column) const
{
Qt::ItemFlags flags = TreeItem::flags(column);
if (column == 0) {
flags |= Qt::ItemIsUserCheckable;
} else if (column == 1) {
flags |= Qt::ItemIsEditable;
}
return flags;
}
FileInfo FileItem::fileInfo() const
{
return d_ptr->fileInfo;
}