3 #include "mysortfilterproxymodel.h"
5 MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent)
6 : QSortFilterProxyModel(parent)
13 void MySortFilterProxyModel::setFilterMinimumDate(const QDate &date)
21 void MySortFilterProxyModel::setFilterMaximumDate(const QDate &date)
28 bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, // FIXME-1 find a way to show _all_ rows which match, independent of parent
29 const QModelIndex &sourceParent) const
31 QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
32 QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
33 QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
35 return (sourceModel()->data(index0).toString().contains(filterRegExp())
36 || sourceModel()->data(index1).toString().contains(filterRegExp()));
37 // && dateInRange(sourceModel()->data(index2).toDate());
41 bool MySortFilterProxyModel::lessThan(const QModelIndex &left,
42 const QModelIndex &right) const
44 QVariant leftData = sourceModel()->data(left);
45 QVariant rightData = sourceModel()->data(right);
49 if (leftData.type() == QVariant::DateTime) {
50 return leftData.toDateTime() < rightData.toDateTime();
52 QRegExp *emailPattern = new QRegExp("([\\w\\.]*@[\\w\\.]*)");
54 QString leftString = leftData.toString();
55 if(left.column() == 1 && emailPattern->indexIn(leftString) != -1)
56 leftString = emailPattern->cap(1);
58 QString rightString = rightData.toString();
59 if(right.column() == 1 && emailPattern->indexIn(rightString) != -1)
60 rightString = emailPattern->cap(1);
62 return QString::localeAwareCompare(leftString, rightString) < 0;
68 bool MySortFilterProxyModel::dateInRange(const QDate &date) const
70 return (!minDate.isValid() || date > minDate)
71 && (!maxDate.isValid() || date < maxDate);