forked from AlloyTeam/Rythem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rytablesortfilterproxymodel.cpp
119 lines (109 loc) · 3.64 KB
/
rytablesortfilterproxymodel.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
#include "rytablesortfilterproxymodel.h"
RyTableSortFilterProxyModel::RyTableSortFilterProxyModel(QObject *parent) :
QSortFilterProxyModel(parent){
_filterFlags = NoFilter;
}
void RyTableSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel){
QSortFilterProxyModel::setSourceModel(sourceModel);
_sourceModel = dynamic_cast<RyTableModel*>(sourceModel);
}
RyTableModel *RyTableSortFilterProxyModel::sourceModel()const{
return _sourceModel;
}
bool RyTableSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &) const{
//qDebug()<<"filterAcceptsRow comparing";
RyPipeData_ptr p = _sourceModel->getItem(sourceRow);
if(p.isNull()){
qDebug()<<"filterAcceptsRow got null";
return true;
}
//先处理文本过滤
if(!_filterText.isEmpty()){
QStringList hostFilterList = _filterText.split("|");
bool matchHost = false;
foreach(QString hostFilter,hostFilterList){
if(p->fullUrl.indexOf(hostFilter) != -1){
matchHost = true;
}
}
if(!matchHost){
return matchHost;
}
}
//qDebug()<<"filterAcceptsRow comparing"<<p->responseStatus;
if(_filterFlags & NoImageFilter){
if(p->getResponseHeader("Content-Type").toLower().indexOf("image")!=-1){
//if(!noImageFilterAccepted(p)){
return false;
}
}
if(_filterFlags & No304Filter){
if(p->responseStatus == "304"){
return false;
}
}
if(_filterFlags & OnlyMatchingFilter){
if(!p->isMatchingRule){
return false;
}
}
if(_filterFlags & HideTunnelFilter){
if(p->isConnectTunnel){
return false;
}
}
if(_filterFlags & CustomFilter){
//if(!_filterCallback(p)){
// return false;
//}
}
return true;
}
bool RyTableSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const{
//qDebug()<<QString("row:%1,col:%2").arg(left.row()).arg(left.column());
//qDebug()<<QString("row:%1,col:%2").arg(right.row()).arg(right.column());
//QModelIndex leftSource = mapToSource(left);
//QModelIndex rightSource = mapToSource(right);
return _sourceModel->itemLessThan(left,right);
}
RyPipeData_ptr RyTableSortFilterProxyModel::getItem(int sourceRow){
return _sourceModel->getItem(sourceRow);
}
RyPipeData_ptr RyTableSortFilterProxyModel::getItem(const QModelIndex& proxyIndex){
return getItem(mapToSource(proxyIndex).row());
}
void RyTableSortFilterProxyModel::setFilterText(QString filterText){
_filterText = filterText;
invalidateFilter();
}
void RyTableSortFilterProxyModel::setFilter(int flag){
int oldFlags = _filterFlags;
_filterFlags = flag;
qDebug()<<"setting flags";
if(oldFlags!=_filterFlags){
invalidateFilter();
}
}
int RyTableSortFilterProxyModel::filter()const{
return _filterFlags;
}
void RyTableSortFilterProxyModel::setCustomeFilter(FilterCallBack filtercb){
_filterCallback = filtercb;
}
void RyTableSortFilterProxyModel::setMaxRequestSize(int maxSize){
sourceModel()->setMaxRequestSize(maxSize);
invalidateFilter();
}
void RyTableSortFilterProxyModel::removeAllItem(){
sourceModel()->removeAllItem();
QSortFilterProxyModel::clear();
}
void RyTableSortFilterProxyModel::updateItem(RyPipeData_ptr p){
sourceModel()->updateItem(p);
//emit dataChanged(index(0,0),index(rowCount()-1,columnCount()-1));
}
void RyTableSortFilterProxyModel::addItem(RyPipeData_ptr p){
sourceModel()->addItem(p);
invalidateFilter();
//emit dataChanged(index(0,0),index(rowCount()-1,columnCount()-1));
}