insilmaril@795: /**************************************************************************** insilmaril@795: ** insilmaril@795: ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). insilmaril@795: ** Contact: Qt Software Information (qt-info@nokia.com) insilmaril@795: ** insilmaril@795: ** This file is part of the example classes of the Qt Toolkit. insilmaril@795: ** insilmaril@795: ** Commercial Usage insilmaril@795: ** Licensees holding valid Qt Commercial licenses may use this file in insilmaril@795: ** accordance with the Qt Commercial License Agreement provided with the insilmaril@795: ** Software or, alternatively, in accordance with the terms contained in insilmaril@795: ** a written agreement between you and Nokia. insilmaril@795: ** insilmaril@795: ** insilmaril@795: ** GNU General Public License Usage insilmaril@795: ** Alternatively, this file may be used under the terms of the GNU insilmaril@795: ** General Public License versions 2.0 or 3.0 as published by the Free insilmaril@795: ** Software Foundation and appearing in the file LICENSE.GPL included in insilmaril@795: ** the packaging of this file. Please review the following information insilmaril@795: ** to ensure GNU General Public Licensing requirements will be met: insilmaril@795: ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and insilmaril@795: ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special insilmaril@795: ** exception, Nokia gives you certain additional rights. These rights insilmaril@795: ** are described in the Nokia Qt GPL Exception version 1.3, included in insilmaril@795: ** the file GPL_EXCEPTION.txt in this package. insilmaril@795: ** insilmaril@795: ** Qt for Windows(R) Licensees insilmaril@795: ** As a special exception, Nokia, as the sole copyright holder for Qt insilmaril@795: ** Designer, grants users of the Qt/Eclipse Integration plug-in the insilmaril@795: ** right for the Qt/Eclipse Integration to link to functionality insilmaril@795: ** provided by Qt Designer and its related libraries. insilmaril@795: ** insilmaril@795: ** If you are unsure which license is appropriate for your use, please insilmaril@795: ** contact the sales department at qt-sales@nokia.com. insilmaril@795: ** insilmaril@795: ****************************************************************************/ insilmaril@795: insilmaril@795: #include insilmaril@795: insilmaril@795: #include "mysortfilterproxymodel.h" insilmaril@795: insilmaril@795: MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) insilmaril@795: : QSortFilterProxyModel(parent) insilmaril@795: { insilmaril@795: } insilmaril@795: /* insilmaril@795: void MySortFilterProxyModel::setFilterMinimumDate(const QDate &date) insilmaril@795: { insilmaril@795: minDate = date; insilmaril@795: invalidateFilter(); insilmaril@795: } insilmaril@795: void MySortFilterProxyModel::setFilterMaximumDate(const QDate &date) insilmaril@795: { insilmaril@795: maxDate = date; insilmaril@795: invalidateFilter(); insilmaril@795: } insilmaril@795: */ insilmaril@795: insilmaril@795: #include insilmaril@795: using namespace std; insilmaril@795: bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, insilmaril@795: const QModelIndex &sourceParent) const insilmaril@795: { insilmaril@795: return true; insilmaril@795: cout << "MSFPM sM="<index(sourceRow, 0, sourceParent); insilmaril@795: QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent); insilmaril@795: insilmaril@795: return (sourceModel()->data(index0).toString().contains(filterRegExp()) ); insilmaril@795: } insilmaril@795: insilmaril@795: /* insilmaril@795: bool MySortFilterProxyModel::lessThan(const QModelIndex &left, insilmaril@795: const QModelIndex &right) const insilmaril@795: { insilmaril@795: QVariant leftData = sourceModel()->data(left); insilmaril@795: QVariant rightData = sourceModel()->data(right); insilmaril@795: if (leftData.type() == QVariant::DateTime) { insilmaril@795: return leftData.toDateTime() < rightData.toDateTime(); insilmaril@795: } else { insilmaril@795: QRegExp *emailPattern = new QRegExp("([\\w\\.]*@[\\w\\.]*)"); insilmaril@795: insilmaril@795: QString leftString = leftData.toString(); insilmaril@795: if(left.column() == 1 && emailPattern->indexIn(leftString) != -1) insilmaril@795: leftString = emailPattern->cap(1); insilmaril@795: insilmaril@795: QString rightString = rightData.toString(); insilmaril@795: if(right.column() == 1 && emailPattern->indexIn(rightString) != -1) insilmaril@795: rightString = emailPattern->cap(1); insilmaril@795: insilmaril@795: return QString::localeAwareCompare(leftString, rightString) < 0; insilmaril@795: } insilmaril@795: } insilmaril@795: bool MySortFilterProxyModel::dateInRange(const QDate &date) const insilmaril@795: { insilmaril@795: return (!minDate.isValid() || date > minDate) insilmaril@795: && (!maxDate.isValid() || date < maxDate); insilmaril@795: } insilmaril@795: */