qsortfilterproxymodel.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QSORTFILTERPROXYMODEL_H
00043 #define QSORTFILTERPROXYMODEL_H
00044 
00045 #include <QtGui/qabstractproxymodel.h>
00046 
00047 #ifndef QT_NO_SORTFILTERPROXYMODEL
00048 
00049 #include <QtCore/qregexp.h>
00050 
00051 QT_BEGIN_HEADER
00052 
00053 QT_BEGIN_NAMESPACE
00054 
00055 QT_MODULE(Gui)
00056 
00057 class QSortFilterProxyModelPrivate;
00058 class QSortFilterProxyModelLessThan;
00059 class QSortFilterProxyModelGreaterThan;
00060 
00061 class Q_GUI_EXPORT QSortFilterProxyModel : public QAbstractProxyModel
00062 {
00063     friend class QSortFilterProxyModelLessThan;
00064     friend class QSortFilterProxyModelGreaterThan;
00065 
00066     Q_OBJECT
00067     Q_PROPERTY(QRegExp filterRegExp READ filterRegExp WRITE setFilterRegExp)
00068     Q_PROPERTY(int filterKeyColumn READ filterKeyColumn WRITE setFilterKeyColumn)
00069     Q_PROPERTY(bool dynamicSortFilter READ dynamicSortFilter WRITE setDynamicSortFilter)
00070     Q_PROPERTY(Qt::CaseSensitivity filterCaseSensitivity READ filterCaseSensitivity WRITE setFilterCaseSensitivity)
00071     Q_PROPERTY(Qt::CaseSensitivity sortCaseSensitivity READ sortCaseSensitivity WRITE setSortCaseSensitivity)
00072     Q_PROPERTY(bool isSortLocaleAware READ isSortLocaleAware WRITE setSortLocaleAware)
00073     Q_PROPERTY(int sortRole READ sortRole WRITE setSortRole)
00074     Q_PROPERTY(int filterRole READ filterRole WRITE setFilterRole)
00075 
00076 public:
00077     QSortFilterProxyModel(QObject *parent = 0);
00078     ~QSortFilterProxyModel();
00079 
00080     void setSourceModel(QAbstractItemModel *sourceModel);
00081 
00082     QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
00083     QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
00084 
00085     QItemSelection mapSelectionToSource(const QItemSelection &proxySelection) const;
00086     QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection) const;
00087 
00088     QRegExp filterRegExp() const;
00089     void setFilterRegExp(const QRegExp &regExp);
00090 
00091     int filterKeyColumn() const;
00092     void setFilterKeyColumn(int column);
00093 
00094     Qt::CaseSensitivity filterCaseSensitivity() const;
00095     void setFilterCaseSensitivity(Qt::CaseSensitivity cs);
00096 
00097     Qt::CaseSensitivity sortCaseSensitivity() const;
00098     void setSortCaseSensitivity(Qt::CaseSensitivity cs);
00099 
00100     bool isSortLocaleAware() const;
00101     void setSortLocaleAware(bool on);
00102 
00103     int sortColumn() const;
00104     Qt::SortOrder sortOrder() const;
00105 
00106     bool dynamicSortFilter() const;
00107     void setDynamicSortFilter(bool enable);
00108 
00109     int sortRole() const;
00110     void setSortRole(int role);
00111 
00112     int filterRole() const;
00113     void setFilterRole(int role);
00114 
00115 public Q_SLOTS:
00116     void setFilterRegExp(const QString &pattern);
00117     void setFilterWildcard(const QString &pattern);
00118     void setFilterFixedString(const QString &pattern);
00119     void clear();
00120     void invalidate();
00121 
00122 protected:
00123     virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
00124     virtual bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const;
00125     virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
00126 
00127     void filterChanged();
00128     void invalidateFilter();
00129 
00130 public:
00131 #ifdef Q_NO_USING_KEYWORD
00132     inline QObject *parent() const { return QObject::parent(); }
00133 #else
00134     using QObject::parent;
00135 #endif
00136 
00137     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
00138     QModelIndex parent(const QModelIndex &child) const;
00139 
00140     int rowCount(const QModelIndex &parent = QModelIndex()) const;
00141     int columnCount(const QModelIndex &parent = QModelIndex()) const;
00142     bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
00143 
00144     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00145     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
00146 
00147     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00148     bool setHeaderData(int section, Qt::Orientation orientation,
00149             const QVariant &value, int role = Qt::EditRole);
00150 
00151     QMimeData *mimeData(const QModelIndexList &indexes) const;
00152     bool dropMimeData(const QMimeData *data, Qt::DropAction action,
00153                       int row, int column, const QModelIndex &parent);
00154 
00155     bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
00156     bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex());
00157     bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
00158     bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
00159 
00160     void fetchMore(const QModelIndex &parent);
00161     bool canFetchMore(const QModelIndex &parent) const;
00162     Qt::ItemFlags flags(const QModelIndex &index) const;
00163 
00164     QModelIndex buddy(const QModelIndex &index) const;
00165     QModelIndexList match(const QModelIndex &start, int role,
00166                           const QVariant &value, int hits = 1,
00167                           Qt::MatchFlags flags =
00168                           Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const;
00169     QSize span(const QModelIndex &index) const;
00170     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
00171 
00172     QStringList mimeTypes() const;
00173     Qt::DropActions supportedDropActions() const;
00174 private:
00175     Q_DECLARE_PRIVATE(QSortFilterProxyModel)
00176     Q_DISABLE_COPY(QSortFilterProxyModel)
00177 
00178     Q_PRIVATE_SLOT(d_func(), void _q_sourceDataChanged(const QModelIndex &source_top_left, const QModelIndex &source_bottom_right))
00179     Q_PRIVATE_SLOT(d_func(), void _q_sourceHeaderDataChanged(Qt::Orientation orientation, int start, int end))
00180     Q_PRIVATE_SLOT(d_func(), void _q_sourceAboutToBeReset())
00181     Q_PRIVATE_SLOT(d_func(), void _q_sourceReset())
00182     Q_PRIVATE_SLOT(d_func(), void _q_sourceLayoutAboutToBeChanged())
00183     Q_PRIVATE_SLOT(d_func(), void _q_sourceLayoutChanged())
00184     Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeInserted(const QModelIndex &source_parent, int start, int end))
00185     Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsInserted(const QModelIndex &source_parent, int start, int end))
00186     Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeRemoved(const QModelIndex &source_parent, int start, int end))
00187     Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsRemoved(const QModelIndex &source_parent, int start, int end))
00188     Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsAboutToBeInserted(const QModelIndex &source_parent, int start, int end))
00189     Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsInserted(const QModelIndex &source_parent, int start, int end))
00190     Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsAboutToBeRemoved(const QModelIndex &source_parent, int start, int end))
00191     Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsRemoved(const QModelIndex &source_parent, int start, int end))
00192 };
00193 
00194 QT_END_NAMESPACE
00195 
00196 QT_END_HEADER
00197 
00198 #endif // QT_NO_SORTFILTERPROXYMODEL
00199 
00200 #endif // QSORTFILTERPROXYMODEL_H