-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSortMultiFilterProxyModel.h
119 lines (114 loc) · 2.25 KB
/
SortMultiFilterProxyModel.h
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
#ifndef SORTMULTIFILTERPROXYMODEL_H
#define SORTMULTIFILTERPROXYMODEL_H
#include <unordered_map>
#include <QSortFilterProxyModel>
#include <QString>
#include <QTimer>
#include <QRegularExpression>
class SortMultiFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit SortMultiFilterProxyModel(QObject *parent = 0);
public slots:
void setMin(int col, double min)
{
if(min==_min[col]) {
return;
}
_min[col]=min;
correctMinMax(col);
invalidateFilter();
}
void unsetMin(int col)
{
if(_min.count(col)==0) {
return;
}
_min.erase(col);
invalidateFilter();
}
void setMax(int col, double max)
{
if(_max[col]==max) {
return;
}
_max[col]=max;
correctMinMax(col);
invalidateFilter();
}
void unsetMax(int col)
{
if(_max.count(col)==0) {
return;
}
_max.erase(col);
invalidateFilter();
}
void setMatch(int col, const QString& match )
{
if (match.isEmpty()) {
unsetMatch(col);
return;
}
if(_match[col]==match) {
return;
}
_match[col]=match;
invalidateFilter();
}
void unsetMatch(int col)
{
if(_match.count(col)==0) {
return;
}
_match.erase(col);
invalidateFilter();
}
void setNotMatch(int col, const QString& notMatch )
{
if (notMatch.isEmpty()) {
unsetNotMatch(col);
return;
}
if(_notMatch[col]==notMatch) {
return;
}
_notMatch[col]=notMatch;
invalidateFilter();
//std::cout<<"setNotMatch end"<<std::endl;
}
void unsetNotMatch(int col)
{
if(_notMatch.count(col)==0) {
return;
}
_notMatch.erase(col);
invalidateFilter();
}
void setFilters(const QMap<int,QString>& match,
const QMap<int,QString>& notMatch,
const QMap<int,double>& min,
const QMap<int,double>& max);
protected:
bool filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const;
private:
void correctMinMax(int col)
{
if (_min[col]>_max[col] /*|| _max[col]==0.0*/)
{
if(_max.count(col)==0) {
return;
}
_max.erase(col);
}
}
std::unordered_map<int, QString> _match;
std::unordered_map<int, QString> _notMatch;
std::unordered_map<int, double> _min;
std::unordered_map<int, double> _max;
QRegularExpression::PatternOption _caseSensitive=QRegularExpression::CaseInsensitiveOption;
//QTimer timer;
};
#endif // SORTMULTIFILTERPROXYMODEL_H