-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsandboxitemmodel.cpp
91 lines (76 loc) · 2.58 KB
/
sandboxitemmodel.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
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
#include "sandboxitemmodel.h"
#include <QApplication>
#include <QStyle>
#include <QDir>
#include <QDebug>
#include <QDirIterator>
SandBoxItemModel::SandBoxItemModel(QObject *parent)
:QStandardItemModel(parent)
{
rootItem = this->invisibleRootItem();
dirIcon = QIcon("qrc:/images/object_menu_folder");
fileIcon = QIcon("qrc:/images/object_menu_folder");
m_roleNameMapping[NAME] = "name";
}
SandBoxItemModel::~SandBoxItemModel()
{
}
QHash<int, QByteArray> SandBoxItemModel::roleNames() const
{
return m_roleNameMapping;
}
void SandBoxItemModel::setSandBoxDetails(QString names)
{
populateSandBoxes(names.split("\n"));
}
void SandBoxItemModel::populateSandBoxes(const QStringList &names)
{
QString name;
CustomStandardItem* parent;
unsigned int fileIndex = 0;
foreach (name, names) {
if (mainDirectory && (++fileIndex > 1)) return; // nur erster Folder wird Main.
if(!name.isEmpty())
{
name.remove("\r");
parent = new CustomStandardItem(dirIcon, name); //create the parent directory item
parent->setAccessibleDescription(name); //set actual path to item
parent->setType("dir");
if (!mainDirectory){
rootItem->appendRow(parent); //add the parent item to root item
createDirectoryItem(name, parent); //Iterate and populate the contents
}else{
createDirectoryItem(name, rootItem, true); //Iterate and populate the contents
}
}
}
}
void SandBoxItemModel::createDirectoryItem(QString dirName, QStandardItem *parentItem, bool forMainDirectory)
{
QDir dir(dirName);
QFileInfoList subFolders;
QFileInfo folderName;
CustomStandardItem* child;
if (!forMainDirectory)
subFolders = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
else
subFolders = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
foreach (folderName, subFolders)
{
if(folderName.isFile())
{
child = new CustomStandardItem(fileIcon, folderName.fileName());
child->setAccessibleDescription(folderName.filePath());
child->setType("file");
child->setEnabled(false);
}
else
{
child = new CustomStandardItem(dirIcon, folderName.fileName());
child->setAccessibleDescription(folderName.filePath());
child->setType("dir");
}
parentItem->appendRow(child);
createDirectoryItem(folderName.filePath(), child);
}
}