-
Notifications
You must be signed in to change notification settings - Fork 0
/
silofilter.cpp
66 lines (60 loc) · 1.74 KB
/
silofilter.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
/*
* silofilter.cpp
*
* Created on: Dec 10, 2008
* Author: Vincent
*/
#include "silofilter.h"
#include "common.h"
using namespace Silo;
SiloFilter::SiloFilter(QObject *parent) :
QSortFilterProxyModel(parent) {
filterType = FILTER_INVALID;
filterSize = 0;
}
void SiloFilter::setFilterDateTime(const QDateTime &dateTime,
FilterType filterType) {
this->filterType = filterType;
filterDate = dateTime;
}
void SiloFilter::setFilterSize(qint64 filterSize, FilterType filterType) {
this->filterType = filterType;
this->filterSize = filterSize;
}
void SiloFilter::setFilterType(FilterType filterType) {
this->filterType = filterType;
}
bool SiloFilter::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const {
int keyColumn = filterKeyColumn();
if (keyColumn == ID_DATE) {
if (filterType == FILTER_INVALID) {
return true;
}
QModelIndex index = sourceModel()->index(sourceRow, keyColumn,
sourceParent);
switch (filterType) {
case FILTER_LESS:
return index.data(Qt::DisplayRole).toDateTime() < filterDate;
case FILTER_MORE:
return index.data(Qt::DisplayRole).toDateTime() > filterDate;
case FILTER_MATCH:
return index.data(Qt::DisplayRole).toDateTime() == filterDate;
}
} else if (keyColumn == ID_SIZE) {
if (filterType == FILTER_INVALID) {
return true;
}
QModelIndex index = sourceModel()->index(sourceRow, keyColumn,
sourceParent);
switch (filterType) {
case FILTER_LESS:
return index.data(Qt::DisplayRole).toLongLong() < filterSize;
case FILTER_MORE:
return index.data(Qt::DisplayRole).toLongLong() > filterSize;
case FILTER_MATCH:
return index.data(Qt::DisplayRole).toLongLong() == filterSize;
}
}
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}