-
Notifications
You must be signed in to change notification settings - Fork 1
/
storagefavoriteinfomodel.h
76 lines (58 loc) · 1.8 KB
/
storagefavoriteinfomodel.h
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
#ifndef STORAGEFAVORITEINFOMODEL_H
#define STORAGEFAVORITEINFOMODEL_H
#include <QAbstractListModel>
#include <QFileSystemModel>
#include <QStorageInfo>
namespace Farman
{
class StorageFavoriteInfo
{
public:
enum class Type : int
{
Storage,
Favorite,
};
StorageFavoriteInfo(Type type, const QString& name, const QString& path)
{
m_type = type;
m_name = name;
m_path = path;
}
~StorageFavoriteInfo() = default;
Type getType() const { return m_type; }
QString getTypeName() const { return (m_type == Type::Storage) ? "Storage" : (m_type == Type::Favorite) ? "Favorite" : "Unknown"; }
QString getName() const { return m_name; }
QString getPath() const { return m_path; }
private:
StorageFavoriteInfo() = delete;
Type m_type;
QString m_name;
QString m_path;
};
class StorageFavoriteInfoModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Roles
{
TypeRole = Qt::UserRole + 1,
NameRole,
PathRole,
};
explicit StorageFavoriteInfoModel(QObject *parent = Q_NULLPTR);
~StorageFavoriteInfoModel() Q_DECL_OVERRIDE;
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
protected:
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
private:
int initialize();
QList<StorageFavoriteInfo> m_infos;
QFileSystemModel* m_fileSystemModel;
};
} // namespace Farman
#endif // STORAGEFAVORITEINFOMODEL_H