mysortfilterproxymodel.cpp
changeset 795 6b0a5f4923d3
child 802 f076fdec767d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mysortfilterproxymodel.cpp	Thu Sep 17 09:41:09 2009 +0000
     1.3 @@ -0,0 +1,99 @@
     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 +**
     1.9 +** This file is part of the example classes of the Qt Toolkit.
    1.10 +**
    1.11 +** Commercial Usage
    1.12 +** Licensees holding valid Qt Commercial licenses may use this file in
    1.13 +** accordance with the Qt Commercial License Agreement provided with the
    1.14 +** Software or, alternatively, in accordance with the terms contained in
    1.15 +** a written agreement between you and Nokia.
    1.16 +**
    1.17 +**
    1.18 +** GNU General Public License Usage
    1.19 +** Alternatively, this file may be used under the terms of the GNU
    1.20 +** General Public License versions 2.0 or 3.0 as published by the Free
    1.21 +** Software Foundation and appearing in the file LICENSE.GPL included in
    1.22 +** the packaging of this file.  Please review the following information
    1.23 +** to ensure GNU General Public Licensing requirements will be met:
    1.24 +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
    1.25 +** http://www.gnu.org/copyleft/gpl.html.  In addition, as a special
    1.26 +** exception, Nokia gives you certain additional rights. These rights
    1.27 +** are described in the Nokia Qt GPL Exception version 1.3, included in
    1.28 +** the file GPL_EXCEPTION.txt in this package.
    1.29 +**
    1.30 +** Qt for Windows(R) Licensees
    1.31 +** As a special exception, Nokia, as the sole copyright holder for Qt
    1.32 +** Designer, grants users of the Qt/Eclipse Integration plug-in the
    1.33 +** right for the Qt/Eclipse Integration to link to functionality
    1.34 +** provided by Qt Designer and its related libraries.
    1.35 +**
    1.36 +** If you are unsure which license is appropriate for your use, please
    1.37 +** contact the sales department at qt-sales@nokia.com.
    1.38 +**
    1.39 +****************************************************************************/
    1.40 +
    1.41 +#include <QtGui>
    1.42 +
    1.43 +#include "mysortfilterproxymodel.h"
    1.44 +
    1.45 +MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent)
    1.46 +    : QSortFilterProxyModel(parent)
    1.47 +{
    1.48 +}
    1.49 +/*
    1.50 +void MySortFilterProxyModel::setFilterMinimumDate(const QDate &date)
    1.51 +{
    1.52 +    minDate = date;
    1.53 +    invalidateFilter();
    1.54 +}
    1.55 +void MySortFilterProxyModel::setFilterMaximumDate(const QDate &date)
    1.56 +{
    1.57 +    maxDate = date;
    1.58 +    invalidateFilter();
    1.59 +}
    1.60 +*/
    1.61 +
    1.62 +#include <iostream>
    1.63 +using namespace std;
    1.64 +bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
    1.65 +        const QModelIndex &sourceParent) const
    1.66 +{
    1.67 +	return true;
    1.68 +cout << "MSFPM  sM="<<sourceModel()<<endl;
    1.69 +    QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
    1.70 +    QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
    1.71 +
    1.72 +    return (sourceModel()->data(index0).toString().contains(filterRegExp()) );
    1.73 +}
    1.74 +
    1.75 +/*
    1.76 +bool MySortFilterProxyModel::lessThan(const QModelIndex &left,
    1.77 +                                      const QModelIndex &right) const
    1.78 +{
    1.79 +    QVariant leftData = sourceModel()->data(left);
    1.80 +    QVariant rightData = sourceModel()->data(right);
    1.81 +    if (leftData.type() == QVariant::DateTime) {
    1.82 +        return leftData.toDateTime() < rightData.toDateTime();
    1.83 +    } else {
    1.84 +        QRegExp *emailPattern = new QRegExp("([\\w\\.]*@[\\w\\.]*)");
    1.85 +
    1.86 +        QString leftString = leftData.toString();
    1.87 +        if(left.column() == 1 && emailPattern->indexIn(leftString) != -1)
    1.88 +            leftString = emailPattern->cap(1);
    1.89 +
    1.90 +        QString rightString = rightData.toString();
    1.91 +        if(right.column() == 1 && emailPattern->indexIn(rightString) != -1)
    1.92 +            rightString = emailPattern->cap(1);
    1.93 +
    1.94 +        return QString::localeAwareCompare(leftString, rightString) < 0;
    1.95 +    }
    1.96 +}
    1.97 +bool MySortFilterProxyModel::dateInRange(const QDate &date) const
    1.98 +{
    1.99 +    return (!minDate.isValid() || date > minDate)
   1.100 +           && (!maxDate.isValid() || date < maxDate);
   1.101 +}
   1.102 +*/