-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsandboxitemmodel.h
75 lines (57 loc) · 2.03 KB
/
sandboxitemmodel.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
#ifndef SANDBOXITEMMODEL_H
#define SANDBOXITEMMODEL_H
#include <QStandardItemModel>
#include <QStandardItem>
#include <QDebug>
class CustomStandardItem : public QStandardItem
{
public:
CustomStandardItem();
CustomStandardItem(int rows, int columns = 1) : QStandardItem(rows, columns) {};
CustomStandardItem(const QIcon &icon, const QString &text) : QStandardItem(icon, text) {};
CustomStandardItem(const QString &text) : QStandardItem(text) {};
~CustomStandardItem(){};
void setType(QString type_) {type = type_;}
decltype (auto) getType() {return type;}
private:
QString type;
};
class SandBoxItemModel : public QStandardItemModel
{
Q_OBJECT
public:
SandBoxItemModel(QObject* parent = 0);
~SandBoxItemModel();
enum ItemRoles {
NAME = Qt::DisplayRole
};
QHash<int, QByteArray> roleNames() const override;
void setSandBoxDetails(QString names);
void populateSandBoxes(const QStringList &names);
void createDirectoryItem(QString dirName, QStandardItem *parentItem = NULL, bool forMainDirectory=false);
Q_INVOKABLE QStandardItem* datax(const QModelIndex &index) const{
return QStandardItemModel::itemFromIndex(index);
}
Q_INVOKABLE QString getIconType(const QModelIndex &index) const
{
return dynamic_cast<CustomStandardItem*>(QStandardItemModel::itemFromIndex(index))->getType();
}
void setUseMainDirectory(bool flag){mainDirectory=flag;}
/*Q_INVOKABLE QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
{
switch (role) {
//case NAME:
// return QFileSystemModel::data(this->index(index.row(), 1, index.parent()),
// Qt::DisplayRole);
default:
return QStandardItemModel::data(index, role);
}
}*/
private:
QHash<int, QByteArray> m_roleNameMapping;
QStandardItem *rootItem;
QIcon dirIcon;
QIcon fileIcon;
bool mainDirectory = false;
};
#endif // SANDBOXITEMMODEL_H