-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowserproxymodel.cpp
49 lines (41 loc) · 1.68 KB
/
browserproxymodel.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
#include "browserproxymodel.h"
BrowserProxyModel::BrowserProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
void BrowserProxyModel::setFilteringColumns(int filterColumn)
{
filter = filterColumn;
}
bool BrowserProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex index0 = sourceModel()->index(sourceRow, BrowserColProject, sourceParent);//ProjectName
QModelIndex index1 = sourceModel()->index(sourceRow, BrowserColCustomer, sourceParent);//Customer
QModelIndex index2 = sourceModel()->index(sourceRow, BrowserColProjectFolder, sourceParent);//ProjectFolder
//Filter List: "All" << "Project" << "Customer" << "Project Folder"
bool filterResult = false;
switch(filter)
{
case 0:
filterResult = sourceModel()->data(index0).toString().contains(filterRegExp())
|| sourceModel()->data(index1).toString().contains(filterRegExp())
|| sourceModel()->data(index2).toString().contains(filterRegExp());
break;
case 1:
filterResult = sourceModel()->data(index0).toString().contains(filterRegExp());
break;
case 2:
filterResult = sourceModel()->data(index1).toString().contains(filterRegExp());
break;
case 3:
filterResult = sourceModel()->data(index2).toString().contains(filterRegExp());
break;
}
return filterResult;
}
bool BrowserProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
QString leftData = sourceModel()->data(left).toString();
QString rightData = sourceModel()->data(right).toString();
return QString::localeAwareCompare(leftData, rightData) < 0;
}