1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QSORTFILTERPROXYMODEL_H
43#define QSORTFILTERPROXYMODEL_H
44
45#include <QtGui/qabstractproxymodel.h>
46
47#ifndef QT_NO_SORTFILTERPROXYMODEL
48
49#include <QtCore/qregexp.h>
50
51QT_BEGIN_HEADER
52
53QT_BEGIN_NAMESPACE
54
55QT_MODULE(Gui)
56
57class QSortFilterProxyModelPrivate;
58class QSortFilterProxyModelLessThan;
59class QSortFilterProxyModelGreaterThan;
60
61class Q_GUI_EXPORT QSortFilterProxyModel : public QAbstractProxyModel
62{
63 friend class QSortFilterProxyModelLessThan;
64 friend class QSortFilterProxyModelGreaterThan;
65
66 Q_OBJECT
67 Q_PROPERTY(QRegExp filterRegExp READ filterRegExp WRITE setFilterRegExp)
68 Q_PROPERTY(int filterKeyColumn READ filterKeyColumn WRITE setFilterKeyColumn)
69 Q_PROPERTY(bool dynamicSortFilter READ dynamicSortFilter WRITE setDynamicSortFilter)
70 Q_PROPERTY(Qt::CaseSensitivity filterCaseSensitivity READ filterCaseSensitivity WRITE setFilterCaseSensitivity)
71 Q_PROPERTY(Qt::CaseSensitivity sortCaseSensitivity READ sortCaseSensitivity WRITE setSortCaseSensitivity)
72 Q_PROPERTY(bool isSortLocaleAware READ isSortLocaleAware WRITE setSortLocaleAware)
73 Q_PROPERTY(int sortRole READ sortRole WRITE setSortRole)
74 Q_PROPERTY(int filterRole READ filterRole WRITE setFilterRole)
75
76public:
77 QSortFilterProxyModel(QObject *parent = 0);
78 ~QSortFilterProxyModel();
79
80 void setSourceModel(QAbstractItemModel *sourceModel);
81
82 QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
83 QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
84
85 QItemSelection mapSelectionToSource(const QItemSelection &proxySelection) const;
86 QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection) const;
87
88 QRegExp filterRegExp() const;
89 void setFilterRegExp(const QRegExp &regExp);
90
91 int filterKeyColumn() const;
92 void setFilterKeyColumn(int column);
93
94 Qt::CaseSensitivity filterCaseSensitivity() const;
95 void setFilterCaseSensitivity(Qt::CaseSensitivity cs);
96
97 Qt::CaseSensitivity sortCaseSensitivity() const;
98 void setSortCaseSensitivity(Qt::CaseSensitivity cs);
99
100 bool isSortLocaleAware() const;
101 void setSortLocaleAware(bool on);
102
103 int sortColumn() const;
104 Qt::SortOrder sortOrder() const;
105
106 bool dynamicSortFilter() const;
107 void setDynamicSortFilter(bool enable);
108
109 int sortRole() const;
110 void setSortRole(int role);
111
112 int filterRole() const;
113 void setFilterRole(int role);
114
115public Q_SLOTS:
116 void setFilterRegExp(const QString &pattern);
117 void setFilterWildcard(const QString &pattern);
118 void setFilterFixedString(const QString &pattern);
119 void clear();
120 void invalidate();
121
122protected:
123 virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
124 virtual bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const;
125 virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
126
127 void filterChanged();
128 void invalidateFilter();
129
130public:
131#ifdef Q_NO_USING_KEYWORD
132 inline QObject *parent() const { return QObject::parent(); }
133#else
134 using QObject::parent;
135#endif
136
137 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
138 QModelIndex parent(const QModelIndex &child) const;
139
140 int rowCount(const QModelIndex &parent = QModelIndex()) const;
141 int columnCount(const QModelIndex &parent = QModelIndex()) const;
142 bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
143
144 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
145 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
146
147 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
148 bool setHeaderData(int section, Qt::Orientation orientation,
149 const QVariant &value, int role = Qt::EditRole);
150
151 QMimeData *mimeData(const QModelIndexList &indexes) const;
152 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
153 int row, int column, const QModelIndex &parent);
154
155 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
156 bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex());
157 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
158 bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
159
160 void fetchMore(const QModelIndex &parent);
161 bool canFetchMore(const QModelIndex &parent) const;
162 Qt::ItemFlags flags(const QModelIndex &index) const;
163
164 QModelIndex buddy(const QModelIndex &index) const;
165 QModelIndexList match(const QModelIndex &start, int role,
166 const QVariant &value, int hits = 1,
167 Qt::MatchFlags flags =
168 Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const;
169 QSize span(const QModelIndex &index) const;
170 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
171
172 QStringList mimeTypes() const;
173 Qt::DropActions supportedDropActions() const;
174private:
175 Q_DECLARE_PRIVATE(QSortFilterProxyModel)
176 Q_DISABLE_COPY(QSortFilterProxyModel)
177
178 Q_PRIVATE_SLOT(d_func(), void _q_sourceDataChanged(const QModelIndex &source_top_left, const QModelIndex &source_bottom_right))
179 Q_PRIVATE_SLOT(d_func(), void _q_sourceHeaderDataChanged(Qt::Orientation orientation, int start, int end))
180 Q_PRIVATE_SLOT(d_func(), void _q_sourceAboutToBeReset())
181 Q_PRIVATE_SLOT(d_func(), void _q_sourceReset())
182 Q_PRIVATE_SLOT(d_func(), void _q_sourceLayoutAboutToBeChanged())
183 Q_PRIVATE_SLOT(d_func(), void _q_sourceLayoutChanged())
184 Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeInserted(const QModelIndex &source_parent, int start, int end))
185 Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsInserted(const QModelIndex &source_parent, int start, int end))
186 Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsAboutToBeRemoved(const QModelIndex &source_parent, int start, int end))
187 Q_PRIVATE_SLOT(d_func(), void _q_sourceRowsRemoved(const QModelIndex &source_parent, int start, int end))
188 Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsAboutToBeInserted(const QModelIndex &source_parent, int start, int end))
189 Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsInserted(const QModelIndex &source_parent, int start, int end))
190 Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsAboutToBeRemoved(const QModelIndex &source_parent, int start, int end))
191 Q_PRIVATE_SLOT(d_func(), void _q_sourceColumnsRemoved(const QModelIndex &source_parent, int start, int end))
192 Q_PRIVATE_SLOT(d_func(), void _q_clearMapping())
193};
194
195QT_END_NAMESPACE
196
197QT_END_HEADER
198
199#endif // QT_NO_SORTFILTERPROXYMODEL
200
201#endif // QSORTFILTERPROXYMODEL_H
202