-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.hpp
More file actions
82 lines (62 loc) · 1.93 KB
/
node.hpp
File metadata and controls
82 lines (62 loc) · 1.93 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
#pragma once
#include <QAbstractItemModel>
#include <QIcon>
#include <filesystem>
#include <thread>
class FileSystemNodeLoader;
class FileSystemNode
{
public:
enum {
COLUMN_NAME,
COLUMN_EXT,
COLUMN_SIZE,
COLUMN_COUNT
};
FileSystemNode();
FileSystemNode(const QString &path);
~FileSystemNode();
Qt::ItemFlags flags() const;
int count() const;
int columnCount() const;
FileSystemNode* child(int row) const;
FileSystemNode* parent() const { return parentNode; }
int row() const { return parentIndex; }
QVariant data(int column, int role) const;
bool setData(int column, const QVariant &value);
bool isDirectory() const { return ftype == file_type::directory; }
bool isLoaded() const { return loaded; }
FileSystemNodeLoader* startLoad();
bool removeRows(int row, int count);
private:
using file_type = std::filesystem::file_type;
using directory_entry = std::filesystem::directory_entry;
using path = std::filesystem::path;
FileSystemNode* parentNode = nullptr;
int parentIndex = 0;
QVector<FileSystemNode*> children;
file_type ftype = file_type::none;
path fpath;
bool loaded;
QIcon icon;
FileSystemNodeLoader* loader = nullptr;
QString name;
QString ext;
FileSystemNode(const directory_entry& e, FileSystemNode* p = nullptr, int idx = 0);
QIcon makeIcon() const;
void remove();
friend class FileSystemNodeLoader;
};
class FileSystemNodeLoader
{
public:
FileSystemNodeLoader(FileSystemNode* n);
void wait();
private:
using directory_entry = std::filesystem::directory_entry;
FileSystemNode* node;
std::thread thread;
QVector<directory_entry> entries;
QVector<FileSystemNode*> children;
void run();
};