insilmaril@804
|
1 |
//#include <QtGui>
|
insilmaril@795
|
2 |
|
insilmaril@795
|
3 |
#include "mysortfilterproxymodel.h"
|
insilmaril@795
|
4 |
|
insilmaril@795
|
5 |
MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent)
|
insilmaril@795
|
6 |
: QSortFilterProxyModel(parent)
|
insilmaril@795
|
7 |
{
|
insilmaril@795
|
8 |
}
|
insilmaril@802
|
9 |
//! [0]
|
insilmaril@802
|
10 |
|
insilmaril@804
|
11 |
/*
|
insilmaril@802
|
12 |
//! [1]
|
insilmaril@795
|
13 |
void MySortFilterProxyModel::setFilterMinimumDate(const QDate &date)
|
insilmaril@795
|
14 |
{
|
insilmaril@795
|
15 |
minDate = date;
|
insilmaril@795
|
16 |
invalidateFilter();
|
insilmaril@795
|
17 |
}
|
insilmaril@802
|
18 |
//! [1]
|
insilmaril@802
|
19 |
|
insilmaril@802
|
20 |
//! [2]
|
insilmaril@795
|
21 |
void MySortFilterProxyModel::setFilterMaximumDate(const QDate &date)
|
insilmaril@795
|
22 |
{
|
insilmaril@795
|
23 |
maxDate = date;
|
insilmaril@795
|
24 |
invalidateFilter();
|
insilmaril@795
|
25 |
}
|
insilmaril@804
|
26 |
*/
|
insilmaril@795
|
27 |
|
insilmaril@822
|
28 |
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, // FIXME-3 find a way to show _all_ rows which match, independent of parent
|
insilmaril@795
|
29 |
const QModelIndex &sourceParent) const
|
insilmaril@795
|
30 |
{
|
insilmaril@795
|
31 |
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
|
insilmaril@795
|
32 |
QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
|
insilmaril@802
|
33 |
QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
|
insilmaril@795
|
34 |
|
insilmaril@802
|
35 |
return (sourceModel()->data(index0).toString().contains(filterRegExp())
|
insilmaril@804
|
36 |
|| sourceModel()->data(index1).toString().contains(filterRegExp()));
|
insilmaril@804
|
37 |
// && dateInRange(sourceModel()->data(index2).toDate());
|
insilmaril@795
|
38 |
}
|
insilmaril@795
|
39 |
|
insilmaril@804
|
40 |
/*
|
insilmaril@795
|
41 |
bool MySortFilterProxyModel::lessThan(const QModelIndex &left,
|
insilmaril@795
|
42 |
const QModelIndex &right) const
|
insilmaril@795
|
43 |
{
|
insilmaril@795
|
44 |
QVariant leftData = sourceModel()->data(left);
|
insilmaril@795
|
45 |
QVariant rightData = sourceModel()->data(right);
|
insilmaril@802
|
46 |
//! [4]
|
insilmaril@802
|
47 |
|
insilmaril@802
|
48 |
//! [6]
|
insilmaril@795
|
49 |
if (leftData.type() == QVariant::DateTime) {
|
insilmaril@795
|
50 |
return leftData.toDateTime() < rightData.toDateTime();
|
insilmaril@795
|
51 |
} else {
|
insilmaril@795
|
52 |
QRegExp *emailPattern = new QRegExp("([\\w\\.]*@[\\w\\.]*)");
|
insilmaril@795
|
53 |
|
insilmaril@795
|
54 |
QString leftString = leftData.toString();
|
insilmaril@795
|
55 |
if(left.column() == 1 && emailPattern->indexIn(leftString) != -1)
|
insilmaril@795
|
56 |
leftString = emailPattern->cap(1);
|
insilmaril@795
|
57 |
|
insilmaril@795
|
58 |
QString rightString = rightData.toString();
|
insilmaril@795
|
59 |
if(right.column() == 1 && emailPattern->indexIn(rightString) != -1)
|
insilmaril@795
|
60 |
rightString = emailPattern->cap(1);
|
insilmaril@795
|
61 |
|
insilmaril@795
|
62 |
return QString::localeAwareCompare(leftString, rightString) < 0;
|
insilmaril@795
|
63 |
}
|
insilmaril@795
|
64 |
}
|
insilmaril@802
|
65 |
//! [5] //! [6]
|
insilmaril@802
|
66 |
|
insilmaril@802
|
67 |
//! [7]
|
insilmaril@795
|
68 |
bool MySortFilterProxyModel::dateInRange(const QDate &date) const
|
insilmaril@795
|
69 |
{
|
insilmaril@795
|
70 |
return (!minDate.isValid() || date > minDate)
|
insilmaril@795
|
71 |
&& (!maxDate.isValid() || date < maxDate);
|
insilmaril@795
|
72 |
}
|
insilmaril@802
|
73 |
//! [7]
|
insilmaril@804
|
74 |
*/
|