insilmaril@795
|
1 |
/****************************************************************************
|
insilmaril@795
|
2 |
**
|
insilmaril@795
|
3 |
** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
insilmaril@795
|
4 |
** Contact: Qt Software Information (qt-info@nokia.com)
|
insilmaril@795
|
5 |
**
|
insilmaril@795
|
6 |
** This file is part of the example classes of the Qt Toolkit.
|
insilmaril@795
|
7 |
**
|
insilmaril@795
|
8 |
** Commercial Usage
|
insilmaril@795
|
9 |
** Licensees holding valid Qt Commercial licenses may use this file in
|
insilmaril@795
|
10 |
** accordance with the Qt Commercial License Agreement provided with the
|
insilmaril@795
|
11 |
** Software or, alternatively, in accordance with the terms contained in
|
insilmaril@795
|
12 |
** a written agreement between you and Nokia.
|
insilmaril@795
|
13 |
**
|
insilmaril@795
|
14 |
**
|
insilmaril@795
|
15 |
** GNU General Public License Usage
|
insilmaril@795
|
16 |
** Alternatively, this file may be used under the terms of the GNU
|
insilmaril@795
|
17 |
** General Public License versions 2.0 or 3.0 as published by the Free
|
insilmaril@795
|
18 |
** Software Foundation and appearing in the file LICENSE.GPL included in
|
insilmaril@795
|
19 |
** the packaging of this file. Please review the following information
|
insilmaril@795
|
20 |
** to ensure GNU General Public Licensing requirements will be met:
|
insilmaril@795
|
21 |
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
insilmaril@795
|
22 |
** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
|
insilmaril@795
|
23 |
** exception, Nokia gives you certain additional rights. These rights
|
insilmaril@795
|
24 |
** are described in the Nokia Qt GPL Exception version 1.3, included in
|
insilmaril@795
|
25 |
** the file GPL_EXCEPTION.txt in this package.
|
insilmaril@795
|
26 |
**
|
insilmaril@795
|
27 |
** Qt for Windows(R) Licensees
|
insilmaril@795
|
28 |
** As a special exception, Nokia, as the sole copyright holder for Qt
|
insilmaril@795
|
29 |
** Designer, grants users of the Qt/Eclipse Integration plug-in the
|
insilmaril@795
|
30 |
** right for the Qt/Eclipse Integration to link to functionality
|
insilmaril@795
|
31 |
** provided by Qt Designer and its related libraries.
|
insilmaril@795
|
32 |
**
|
insilmaril@795
|
33 |
** If you are unsure which license is appropriate for your use, please
|
insilmaril@795
|
34 |
** contact the sales department at qt-sales@nokia.com.
|
insilmaril@795
|
35 |
**
|
insilmaril@795
|
36 |
****************************************************************************/
|
insilmaril@795
|
37 |
|
insilmaril@795
|
38 |
#include <QtGui>
|
insilmaril@795
|
39 |
|
insilmaril@795
|
40 |
#include "mysortfilterproxymodel.h"
|
insilmaril@795
|
41 |
|
insilmaril@795
|
42 |
MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent)
|
insilmaril@795
|
43 |
: QSortFilterProxyModel(parent)
|
insilmaril@795
|
44 |
{
|
insilmaril@795
|
45 |
}
|
insilmaril@795
|
46 |
/*
|
insilmaril@795
|
47 |
void MySortFilterProxyModel::setFilterMinimumDate(const QDate &date)
|
insilmaril@795
|
48 |
{
|
insilmaril@795
|
49 |
minDate = date;
|
insilmaril@795
|
50 |
invalidateFilter();
|
insilmaril@795
|
51 |
}
|
insilmaril@795
|
52 |
void MySortFilterProxyModel::setFilterMaximumDate(const QDate &date)
|
insilmaril@795
|
53 |
{
|
insilmaril@795
|
54 |
maxDate = date;
|
insilmaril@795
|
55 |
invalidateFilter();
|
insilmaril@795
|
56 |
}
|
insilmaril@795
|
57 |
*/
|
insilmaril@795
|
58 |
|
insilmaril@795
|
59 |
#include <iostream>
|
insilmaril@795
|
60 |
using namespace std;
|
insilmaril@795
|
61 |
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
|
insilmaril@795
|
62 |
const QModelIndex &sourceParent) const
|
insilmaril@795
|
63 |
{
|
insilmaril@795
|
64 |
return true;
|
insilmaril@795
|
65 |
cout << "MSFPM sM="<<sourceModel()<<endl;
|
insilmaril@795
|
66 |
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
|
insilmaril@795
|
67 |
QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
|
insilmaril@795
|
68 |
|
insilmaril@795
|
69 |
return (sourceModel()->data(index0).toString().contains(filterRegExp()) );
|
insilmaril@795
|
70 |
}
|
insilmaril@795
|
71 |
|
insilmaril@795
|
72 |
/*
|
insilmaril@795
|
73 |
bool MySortFilterProxyModel::lessThan(const QModelIndex &left,
|
insilmaril@795
|
74 |
const QModelIndex &right) const
|
insilmaril@795
|
75 |
{
|
insilmaril@795
|
76 |
QVariant leftData = sourceModel()->data(left);
|
insilmaril@795
|
77 |
QVariant rightData = sourceModel()->data(right);
|
insilmaril@795
|
78 |
if (leftData.type() == QVariant::DateTime) {
|
insilmaril@795
|
79 |
return leftData.toDateTime() < rightData.toDateTime();
|
insilmaril@795
|
80 |
} else {
|
insilmaril@795
|
81 |
QRegExp *emailPattern = new QRegExp("([\\w\\.]*@[\\w\\.]*)");
|
insilmaril@795
|
82 |
|
insilmaril@795
|
83 |
QString leftString = leftData.toString();
|
insilmaril@795
|
84 |
if(left.column() == 1 && emailPattern->indexIn(leftString) != -1)
|
insilmaril@795
|
85 |
leftString = emailPattern->cap(1);
|
insilmaril@795
|
86 |
|
insilmaril@795
|
87 |
QString rightString = rightData.toString();
|
insilmaril@795
|
88 |
if(right.column() == 1 && emailPattern->indexIn(rightString) != -1)
|
insilmaril@795
|
89 |
rightString = emailPattern->cap(1);
|
insilmaril@795
|
90 |
|
insilmaril@795
|
91 |
return QString::localeAwareCompare(leftString, rightString) < 0;
|
insilmaril@795
|
92 |
}
|
insilmaril@795
|
93 |
}
|
insilmaril@795
|
94 |
bool MySortFilterProxyModel::dateInRange(const QDate &date) const
|
insilmaril@795
|
95 |
{
|
insilmaril@795
|
96 |
return (!minDate.isValid() || date > minDate)
|
insilmaril@795
|
97 |
&& (!maxDate.isValid() || date < maxDate);
|
insilmaril@795
|
98 |
}
|
insilmaril@795
|
99 |
*/
|