Qt 4.8
qsortfilterproxymodel.h
Go to the documentation of this file.
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 
52 
54 
55 QT_MODULE(Gui)
56 
60 
62 {
65 
66  Q_OBJECT
73  int sortRole;
75 
76 public:
77  QSortFilterProxyModel(QObject *parent = 0);
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 
115 public 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 
122 protected:
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 
130 public:
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;
174 private:
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 
196 
198 
199 #endif // QT_NO_SORTFILTERPROXYMODEL
200 
201 #endif // QSORTFILTERPROXYMODEL_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
Returns a list of indexes for the items in the column of the start index where data stored under the ...
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Handles the data supplied by a drag and drop operation that ended with the given action.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QRegExp filterRegExp
the QRegExp used to filter the contents of the source model
#define QT_MODULE(x)
Definition: qglobal.h:2783
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
virtual QItemSelection mapSelectionToSource(const QItemSelection &selection) const
Returns a source selection mapped from the specified proxySelection.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
virtual QItemSelection mapSelectionFromSource(const QItemSelection &selection) const
Returns a proxy selection mapped from the specified sourceSelection.
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Reimplemented Function
virtual void setSourceModel(QAbstractItemModel *sourceModel)
Sets the given sourceModel to be processed by the proxy model.
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
bool dynamicSortFilter
whether the proxy model is dynamically sorted and filtered whenever the contents of the source model ...
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
void fetchMore(const QModelIndex &parent)
Reimplemented Function
bool canFetchMore(const QModelIndex &parent) const
Reimplemented Function
#define Q_SLOTS
Definition: qobjectdefs.h:71
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const =0
Reimplement this function to return the model index in the source model that corresponds to the proxy...
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isSortLocaleAware
the local aware setting used for comparing strings when sorting
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const =0
Reimplement this function to return the model index in the proxy model that corresponds to the source...
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
Reimplemented Function
int filterRole
the item role that is used to query the source model&#39;s data when filtering items
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
SortOrder
Definition: qnamespace.h:189
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool lessThan(const QChar *a, int l, const char *c)
Definition: qurl.cpp:3253
Qt::DropActions supportedDropActions() const
Reimplemented Function
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Reimplemented Function
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
On models that support this, removes count rows starting with the given row under parent parent from ...
QStringList mimeTypes() const
Reimplemented Function
static const char * data(const QByteArray &arr)
DropAction
Definition: qnamespace.h:1597
bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
QModelIndex buddy(const QModelIndex &index) const
Reimplemented Function
QSize span(const QModelIndex &index) const
Reimplemented Function
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
Qt::CaseSensitivity filterCaseSensitivity
the case sensitivity of the QRegExp pattern used to filter the contents of the source model ...
virtual bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
On models that support this, inserts count rows into the model before the given row.
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QAbstractItemModel class provides the abstract interface for item model classes.
The QAbstractProxyModel class provides a base class for proxy item models that can do sorting...
CaseSensitivity
Definition: qnamespace.h:1451
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QItemSelection class manages information about selected items in a model.
QMimeData * mimeData(const QModelIndexList &indexes) const
Reimplemented Function
QVariant data(const QModelIndex &proxyIndex, int role=Qt::DisplayRole) const
Reimplemented Function
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
int sortRole
the item role that is used to query the source model&#39;s data when sorting items
virtual bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
On models that support this, inserts count new columns into the model before the given column...
quint16 index
Qt::ItemFlags flags(const QModelIndex &index) const
Reimplemented Function
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Reimplemented Function
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
int filterKeyColumn
the column where the key used to filter the contents of the source model is read from.
Qt::CaseSensitivity sortCaseSensitivity
the case sensitivity setting used for comparing strings when sorting
static const KeyPair *const end
Orientation
Definition: qnamespace.h:174
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define QT_END_HEADER
Definition: qglobal.h:137
virtual bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
On models that support this, removes count columns starting with the given column under parent parent...