forked from AlloyTeam/Rythem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rytablesortfilterproxymodel.cpp
96 lines (88 loc) · 2.95 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
#include "rytablesortfilterproxymodel.h"
RyTableSortFilterProxyModel::RyTableSortFilterProxyModel(QObject *parent) :
QSortFilterProxyModel(parent){
_filterFlags = NoFilter;
}
void RyTableSortFilterProxyModel::setSourceModel(RyTableModel *sourceModel){
QSortFilterProxyModel::setSourceModel(sourceModel);
_sourceModel = 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;
}
//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::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::removeAllItem(){
sourceModel()->removeAllItem();
reset();
}
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));
}