-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
storemodel.cpp
82 lines (74 loc) · 2.06 KB
/
storemodel.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
#include "storemodel.h"
/**
* @brief StoreModel::StoreModel
* SubClass of QSortFilterProxyModel via
* http://www.qtcentre.org/threads/46471-QTreeView-Filter
*/
StoreModel::StoreModel() { fs = NULL; }
/**
* @brief StoreModel::filterAcceptsRow
* @param sourceRow
* @param sourceParent
* @return
*/
bool StoreModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const {
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
return ShowThis(index);
}
/**
* @brief StoreModel::ShowThis
* @param index
* @return
*/
bool StoreModel::ShowThis(const QModelIndex index) const {
bool retVal = false;
if (fs == NULL)
return retVal;
// Gives you the info for number of childs with a parent
if (sourceModel()->rowCount(index) > 0) {
for (int nChild = 0; nChild < sourceModel()->rowCount(index); ++nChild) {
QModelIndex childIndex = sourceModel()->index(nChild, 0, index);
if (!childIndex.isValid())
break;
retVal = ShowThis(childIndex);
if (retVal)
break;
}
} else {
QModelIndex useIndex = sourceModel()->index(index.row(), 0, index.parent());
QString path = fs->filePath(useIndex);
path = QDir(store).relativeFilePath(path);
path.replace(QRegExp("\\.gpg$"), "");
retVal = path.contains(filterRegExp());
}
return retVal;
}
/**
* @brief StoreModel::setModelAndStore
* @param sourceModel
* @param passStore
*/
void StoreModel::setModelAndStore(QFileSystemModel *sourceModel,
QString passStore) {
fs = sourceModel;
store = passStore;
}
/**
* @brief StoreModel::data
* @param index
* @param role
* @return
*/
QVariant StoreModel::data(const QModelIndex &index, int role) const {
if (!index.isValid())
return QVariant();
QVariant initial_value;
initial_value = QSortFilterProxyModel::data(index, role);
if (role == Qt::DisplayRole) {
QString name = initial_value.toString();
name.replace(QRegExp("\\.gpg$"), "");
initial_value.setValue(name);
}
return initial_value;
}