1.1 --- a/mysortfilterproxymodel.cpp Thu Sep 17 09:41:09 2009 +0000
1.2 +++ b/mysortfilterproxymodel.cpp Fri Oct 02 13:24:55 2009 +0000
1.3 @@ -1,37 +1,41 @@
1.4 /****************************************************************************
1.5 **
1.6 -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
1.7 -** Contact: Qt Software Information (qt-info@nokia.com)
1.8 +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.9 +** Contact: Nokia Corporation (qt-info@nokia.com)
1.10 **
1.11 -** This file is part of the example classes of the Qt Toolkit.
1.12 +** This file is part of the examples of the Qt Toolkit.
1.13 **
1.14 +** $QT_BEGIN_LICENSE:LGPL$
1.15 ** Commercial Usage
1.16 ** Licensees holding valid Qt Commercial licenses may use this file in
1.17 ** accordance with the Qt Commercial License Agreement provided with the
1.18 ** Software or, alternatively, in accordance with the terms contained in
1.19 ** a written agreement between you and Nokia.
1.20 **
1.21 +** GNU Lesser General Public License Usage
1.22 +** Alternatively, this file may be used under the terms of the GNU Lesser
1.23 +** General Public License version 2.1 as published by the Free Software
1.24 +** Foundation and appearing in the file LICENSE.LGPL included in the
1.25 +** packaging of this file. Please review the following information to
1.26 +** ensure the GNU Lesser General Public License version 2.1 requirements
1.27 +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
1.28 +**
1.29 +** In addition, as a special exception, Nokia gives you certain
1.30 +** additional rights. These rights are described in the Nokia Qt LGPL
1.31 +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
1.32 +** package.
1.33 **
1.34 ** GNU General Public License Usage
1.35 ** Alternatively, this file may be used under the terms of the GNU
1.36 -** General Public License versions 2.0 or 3.0 as published by the Free
1.37 -** Software Foundation and appearing in the file LICENSE.GPL included in
1.38 -** the packaging of this file. Please review the following information
1.39 -** to ensure GNU General Public Licensing requirements will be met:
1.40 -** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
1.41 -** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
1.42 -** exception, Nokia gives you certain additional rights. These rights
1.43 -** are described in the Nokia Qt GPL Exception version 1.3, included in
1.44 -** the file GPL_EXCEPTION.txt in this package.
1.45 -**
1.46 -** Qt for Windows(R) Licensees
1.47 -** As a special exception, Nokia, as the sole copyright holder for Qt
1.48 -** Designer, grants users of the Qt/Eclipse Integration plug-in the
1.49 -** right for the Qt/Eclipse Integration to link to functionality
1.50 -** provided by Qt Designer and its related libraries.
1.51 +** General Public License version 3.0 as published by the Free Software
1.52 +** Foundation and appearing in the file LICENSE.GPL included in the
1.53 +** packaging of this file. Please review the following information to
1.54 +** ensure the GNU General Public License version 3.0 requirements will be
1.55 +** met: http://www.gnu.org/copyleft/gpl.html.
1.56 **
1.57 ** If you are unsure which license is appropriate for your use, please
1.58 -** contact the sales department at qt-sales@nokia.com.
1.59 +** contact the sales department at http://www.qtsoftware.com/contact.
1.60 +** $QT_END_LICENSE$
1.61 **
1.62 ****************************************************************************/
1.63
1.64 @@ -39,42 +43,52 @@
1.65
1.66 #include "mysortfilterproxymodel.h"
1.67
1.68 +//! [0]
1.69 MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent)
1.70 : QSortFilterProxyModel(parent)
1.71 {
1.72 }
1.73 -/*
1.74 +//! [0]
1.75 +
1.76 +//! [1]
1.77 void MySortFilterProxyModel::setFilterMinimumDate(const QDate &date)
1.78 {
1.79 minDate = date;
1.80 invalidateFilter();
1.81 }
1.82 +//! [1]
1.83 +
1.84 +//! [2]
1.85 void MySortFilterProxyModel::setFilterMaximumDate(const QDate &date)
1.86 {
1.87 maxDate = date;
1.88 invalidateFilter();
1.89 }
1.90 -*/
1.91 +//! [2]
1.92
1.93 -#include <iostream>
1.94 -using namespace std;
1.95 +//! [3]
1.96 bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
1.97 const QModelIndex &sourceParent) const
1.98 {
1.99 - return true;
1.100 -cout << "MSFPM sM="<<sourceModel()<<endl;
1.101 QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
1.102 QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
1.103 + QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
1.104
1.105 - return (sourceModel()->data(index0).toString().contains(filterRegExp()) );
1.106 + return (sourceModel()->data(index0).toString().contains(filterRegExp())
1.107 + || sourceModel()->data(index1).toString().contains(filterRegExp()))
1.108 + && dateInRange(sourceModel()->data(index2).toDate());
1.109 }
1.110 +//! [3]
1.111
1.112 -/*
1.113 +//! [4] //! [5]
1.114 bool MySortFilterProxyModel::lessThan(const QModelIndex &left,
1.115 const QModelIndex &right) const
1.116 {
1.117 QVariant leftData = sourceModel()->data(left);
1.118 QVariant rightData = sourceModel()->data(right);
1.119 +//! [4]
1.120 +
1.121 +//! [6]
1.122 if (leftData.type() == QVariant::DateTime) {
1.123 return leftData.toDateTime() < rightData.toDateTime();
1.124 } else {
1.125 @@ -91,9 +105,12 @@
1.126 return QString::localeAwareCompare(leftString, rightString) < 0;
1.127 }
1.128 }
1.129 +//! [5] //! [6]
1.130 +
1.131 +//! [7]
1.132 bool MySortFilterProxyModel::dateInRange(const QDate &date) const
1.133 {
1.134 return (!minDate.isValid() || date > minDate)
1.135 && (!maxDate.isValid() || date < maxDate);
1.136 }
1.137 -*/
1.138 +//! [7]