-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProxyModel.cpp
47 lines (38 loc) · 1.21 KB
/
ProxyModel.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
#include "ProxyModel.h"
ProxyModel::ProxyModel(QObject *parent) : QSortFilterProxyModel(parent),
searchName("")
{
}
void ProxyModel::setSearchName(QString name) {
if (searchName != name)
searchName = name;
invalidateFilter();
}
void ProxyModel::setSearchType(QString name) {
if (searchType != name)
searchType = name;
invalidateFilter();
}
bool ProxyModel::filterAcceptsRow(int source_row,
const QModelIndex &source_parent) const {
QModelIndex iItemName = sourceModel()->index(source_row, 0, source_parent);
QModelIndex iItemType = sourceModel()->index(source_row, 1, source_parent);
if (searchType.length() < 1) {
if (searchName.length() < 1) return true;
if (sourceModel()->data(iItemName).toString().toLower().contains(searchName.toLower()))
return true;
return false;
}
if (sourceModel()->data(iItemType).toString().toLower().contains(searchType.toLower())) {
if (searchName.length() < 1) return true;
if (sourceModel()->data(iItemName).toString().toLower().contains(searchName.toLower()))
return true;
return false;
}
return false;
}
QVariant ProxyModel::headerData(int section, Qt::Orientation orientation,
int role) const {
return sourceModel()->headerData(section, orientation,
role);
}