-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilesListModel.cpp
executable file
·189 lines (140 loc) · 4.49 KB
/
FilesListModel.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include "FilesListModel.h"
FilesListModel::FilesListModel(QObject *poParent) : QAbstractListModel (poParent)
{
qDebug() << __FUNCTION__;
this->oCurrentPath = QDir(QDir::homePath());
//this->oFileInfoList = this->oCurrentPath.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Type | QDir::Name);
this->fnUpdate();
}
FilesListModel::~FilesListModel()
{
}
QHash<int, QByteArray> FilesListModel::roleNames() const
{
qDebug() << __FUNCTION__;
return {
{ FileNameRole, "fileName" },
{ IsDir, "isDir" }
};
}
QVariant FilesListModel::data(const QModelIndex &oIndex, int iRole) const
{
qDebug() << __FUNCTION__;
if (!oIndex.isValid())
return QVariant();
if (oIndex.row() >= this->oFileInfoList.size())
return QVariant();
if (iRole == FileNameRole) {
return this->oFileInfoList[oIndex.row()].fileName();
} if (iRole == IsDir) {
return this->oFileInfoList[oIndex.row()].isDir();
} else
return QVariant();
}
bool FilesListModel::setData(const QModelIndex &oIndex, const QVariant &oValue, int iRole)
{
qDebug() << __FUNCTION__;
return false;
}
QVariant FilesListModel::headerData(int iSection, Qt::Orientation oOrientation, int iRole) const
{
qDebug() << __FUNCTION__;
if (iRole != Qt::DisplayRole)
return QVariant();
if (oOrientation == Qt::Horizontal)
return QString("Column %1").arg(iSection);
else
return QString("Row %1").arg(iSection);
}
Qt::ItemFlags FilesListModel::flags(const QModelIndex &oIndex) const
{
qDebug() << __FUNCTION__;
if (!oIndex.isValid())
return Qt::ItemIsEnabled;
return QAbstractItemModel::flags(oIndex) | Qt::ItemIsEditable;
}
bool FilesListModel::insertRows(int iPosition, int iRows, const QModelIndex &oParent)
{
qDebug() << __FUNCTION__;
return false;
}
bool FilesListModel::removeRows(int iPosition, int iRows, const QModelIndex &oParent)
{
qDebug() << __FUNCTION__;
if (iRows==0) {
return true;
}
beginRemoveRows(QModelIndex(), iPosition, iPosition+iRows-1);
endRemoveRows();
return true;
}
QModelIndex FilesListModel::index(int iRow, int iColumn, const QModelIndex &oParent) const
{
qDebug() << __FUNCTION__;
return createIndex(iRow, iColumn);
}
QModelIndex FilesListModel::parent(const QModelIndex &oChild) const
{
qDebug() << __FUNCTION__;
return QModelIndex();
}
int FilesListModel::rowCount(const QModelIndex &oParent) const
{
int iRows = this->oFileInfoList.size();
qDebug() << __FUNCTION__ << iRows;
return iRows;
}
int FilesListModel::columnCount(const QModelIndex &oParent) const
{
qDebug() << __FUNCTION__;
Q_UNUSED(oParent);
return 1;
}
bool FilesListModel::hasChildren(const QModelIndex &oParent) const
{
qDebug() << __FUNCTION__;
return false;
}
void FilesListModel::fnOpenDir(int iIndex)
{
qDebug() << __FUNCTION__;
//this->oFileInfoList = this->oCurrentPath.entryInfoList();
if (iIndex<0 || iIndex>=this->oFileInfoList.size()) {
qDebug() << "iIndex " << iIndex << " out of bounds";
return;
}
this->oCurrentPath.cd(this->oFileInfoList[iIndex].fileName());
//this->oFileInfoList = this->oCurrentPath.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Type | QDir::Name);
//this->fnSetPath(this->fnGetCurrentPath()+"/"+this->oFileInfoList[iIndex].fileName());
/*
for (int i = 0; i < list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
std::cout << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10)
.arg(fileInfo.fileName()));
std::cout << std::endl;
}
*/
}
void FilesListModel::fnSetPath(QString sPath)
{
qDebug() << __FUNCTION__ << sPath;
this->oCurrentPath.setPath(sPath);
//this->oFileInfoList = this->oCurrentPath.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Type | QDir::Name);
}
QString FilesListModel::fnGetCurrentPath()
{
qDebug() << __FUNCTION__;
return this->oCurrentPath.path();
}
void FilesListModel::fnUp()
{
qDebug() << __FUNCTION__;
this->oCurrentPath.cdUp();
//this->oFileInfoList = this->oCurrentPath.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Type | QDir::Name);
}
void FilesListModel::fnUpdate()
{
this->oFileInfoList = this->oCurrentPath.entryInfoList(QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot, QDir::DirsFirst | QDir::Name);
beginResetModel();
endResetModel();
}