Qt 4.8
|
The QSortFilterProxyModel class provides support for sorting and filtering data passed between another model and a view. More...
#include <qsortfilterproxymodel.h>
Public Slots | |
void | clear () |
This function is obsolete. More... | |
void | invalidate () |
Invalidates the current sorting and filtering. More... | |
void | setFilterFixedString (const QString &pattern) |
Sets the fixed string used to filter the contents of the source model to the given pattern. More... | |
void | setFilterRegExp (const QString &pattern) |
Sets the regular expression used to filter the contents of the source model to pattern. More... | |
void | setFilterWildcard (const QString &pattern) |
Sets the wildcard expression used to filter the contents of the source model to the given pattern. More... | |
Public Slots inherited from QAbstractItemModel | |
Public Slots inherited from QObject | |
void | deleteLater () |
Schedules this object for deletion. More... | |
Public Functions | |
QModelIndex | buddy (const QModelIndex &index) const |
Reimplemented Function More... | |
bool | canFetchMore (const QModelIndex &parent) const |
Reimplemented Function More... | |
int | columnCount (const QModelIndex &parent=QModelIndex()) const |
Reimplemented Function More... | |
QVariant | data (const QModelIndex &index, int role=Qt::DisplayRole) const |
Reimplemented Function More... | |
bool | dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) |
Reimplemented Function More... | |
bool | dynamicSortFilter () const |
void | fetchMore (const QModelIndex &parent) |
Reimplemented Function More... | |
Qt::CaseSensitivity | filterCaseSensitivity () const |
int | filterKeyColumn () const |
QRegExp | filterRegExp () const |
int | filterRole () const |
Qt::ItemFlags | flags (const QModelIndex &index) const |
Reimplemented Function More... | |
bool | hasChildren (const QModelIndex &parent=QModelIndex()) const |
Reimplemented Function More... | |
QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const |
Reimplemented Function More... | |
QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const |
Reimplemented Function More... | |
bool | insertColumns (int column, int count, const QModelIndex &parent=QModelIndex()) |
Reimplemented Function More... | |
bool | insertRows (int row, int count, const QModelIndex &parent=QModelIndex()) |
Reimplemented Function More... | |
bool | isSortLocaleAware () const |
QModelIndex | mapFromSource (const QModelIndex &sourceIndex) const |
Returns the model index in the QSortFilterProxyModel given the sourceIndex from the source model. More... | |
QItemSelection | mapSelectionFromSource (const QItemSelection &sourceSelection) const |
Reimplemented Function More... | |
QItemSelection | mapSelectionToSource (const QItemSelection &proxySelection) const |
Reimplemented Function More... | |
QModelIndex | mapToSource (const QModelIndex &proxyIndex) const |
Returns the source model index corresponding to the given proxyIndex from the sorting filter model. More... | |
QModelIndexList | match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const |
Reimplemented Function More... | |
QMimeData * | mimeData (const QModelIndexList &indexes) const |
Reimplemented Function More... | |
QStringList | mimeTypes () const |
Reimplemented Function More... | |
QModelIndex | parent (const QModelIndex &child) const |
Reimplemented Function More... | |
QSortFilterProxyModel (QObject *parent=0) | |
Constructs a sorting filter model with the given parent. More... | |
bool | removeColumns (int column, int count, const QModelIndex &parent=QModelIndex()) |
Reimplemented Function More... | |
bool | removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) |
Reimplemented Function More... | |
int | rowCount (const QModelIndex &parent=QModelIndex()) const |
Reimplemented Function More... | |
bool | setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) |
Reimplemented Function More... | |
void | setDynamicSortFilter (bool enable) |
void | setFilterCaseSensitivity (Qt::CaseSensitivity cs) |
void | setFilterKeyColumn (int column) |
void | setFilterRegExp (const QRegExp ®Exp) |
void | setFilterRole (int role) |
bool | setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) |
Reimplemented Function More... | |
void | setSortCaseSensitivity (Qt::CaseSensitivity cs) |
void | setSortLocaleAware (bool on) |
void | setSortRole (int role) |
void | setSourceModel (QAbstractItemModel *sourceModel) |
Reimplemented Function More... | |
void | sort (int column, Qt::SortOrder order=Qt::AscendingOrder) |
Reimplemented Function More... | |
Qt::CaseSensitivity | sortCaseSensitivity () const |
int | sortColumn () const |
the column currently used for sorting More... | |
Qt::SortOrder | sortOrder () const |
the order currently used for sorting More... | |
int | sortRole () const |
QSize | span (const QModelIndex &index) const |
Reimplemented Function More... | |
Qt::DropActions | supportedDropActions () const |
Reimplemented Function More... | |
~QSortFilterProxyModel () | |
Destroys this sorting filter model. More... | |
Public Functions inherited from QAbstractProxyModel | |
QMap< int, QVariant > | itemData (const QModelIndex &index) const |
Reimplemented Function More... | |
QAbstractProxyModel (QObject *parent=0) | |
Constructs a proxy model with the given parent. More... | |
void | revert () |
Reimplemented Function More... | |
bool | setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles) |
Reimplemented Function More... | |
QAbstractItemModel * | sourceModel () const |
Returns the model that contains the data that is available through the proxy model. More... | |
bool | submit () |
Reimplemented Function More... | |
~QAbstractProxyModel () | |
Destroys the proxy model. More... | |
Public Functions inherited from QAbstractItemModel | |
bool | hasIndex (int row, int column, const QModelIndex &parent=QModelIndex()) const |
Returns true if the model returns a valid QModelIndex for row and column with parent, otherwise returns false. More... | |
bool | insertColumn (int column, const QModelIndex &parent=QModelIndex()) |
Inserts a single column before the given column in the child items of the parent specified. More... | |
bool | insertRow (int row, const QModelIndex &parent=QModelIndex()) |
Inserts a single row before the given row in the child items of the parent specified. More... | |
QAbstractItemModel (QObject *parent=0) | |
Constructs an abstract item model with the given parent. More... | |
bool | removeColumn (int column, const QModelIndex &parent=QModelIndex()) |
Removes the given column from the child items of the parent specified. More... | |
bool | removeRow (int row, const QModelIndex &parent=QModelIndex()) |
Removes the given row from the child items of the parent specified. More... | |
const QHash< int, QByteArray > & | roleNames () const |
Returns the model's role names. More... | |
void | setSupportedDragActions (Qt::DropActions) |
Sets the supported drag actions for the items in the model. More... | |
QModelIndex | sibling (int row, int column, const QModelIndex &idx) const |
Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location. More... | |
Qt::DropActions | supportedDragActions () const |
Returns the actions supported by the data in this model. More... | |
virtual | ~QAbstractItemModel () |
Destroys the abstract item model. More... | |
Public Functions inherited from QObject | |
bool | blockSignals (bool b) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More... | |
const QObjectList & | children () const |
Returns a list of child objects. More... | |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectInfo () |
Dumps information about signal connections, etc. More... | |
void | dumpObjectTree () |
Dumps a tree of children to the debug output. More... | |
QList< QByteArray > | dynamicPropertyNames () const |
Returns the names of all properties that were dynamically added to the object using setProperty(). More... | |
virtual bool | event (QEvent *) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. More... | |
virtual bool | eventFilter (QObject *, QEvent *) |
Filters events if this object has been installed as an event filter for the watched object. More... | |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More... | |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More... | |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More... | |
void | installEventFilter (QObject *) |
Installs an event filter filterObj on this object. More... | |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false. More... | |
void | killTimer (int id) |
Kills the timer with timer identifier, id. More... | |
virtual const QMetaObject * | metaObject () const |
Returns a pointer to the meta-object of this object. More... | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. More... | |
QString | objectName () const |
QObject * | parent () const |
Returns a pointer to the parent object. More... | |
QVariant | property (const char *name) const |
Returns the value of the object's name property. More... | |
Q_INVOKABLE | QObject (QObject *parent=0) |
Constructs an object with parent object parent. More... | |
void | removeEventFilter (QObject *) |
Removes an event filter object obj from this object. More... | |
void | setObjectName (const QString &name) |
void | setParent (QObject *) |
Makes the object a child of parent. More... | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. More... | |
void | setUserData (uint id, QObjectUserData *data) |
bool | signalsBlocked () const |
Returns true if signals are blocked; otherwise returns false. More... | |
int | startTimer (int interval) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (uint id) const |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. More... | |
Protected Functions | |
virtual bool | filterAcceptsColumn (int source_column, const QModelIndex &source_parent) const |
Returns true if the item in the column indicated by the given source_column and source_parent should be included in the model; otherwise returns false. More... | |
virtual bool | filterAcceptsRow (int source_row, const QModelIndex &source_parent) const |
Returns true if the item in the row indicated by the given source_row and source_parent should be included in the model; otherwise returns false. More... | |
void | filterChanged () |
This function is obsolete. More... | |
void | invalidateFilter () |
Invalidates the current filtering. More... | |
virtual bool | lessThan (const QModelIndex &left, const QModelIndex &right) const |
Returns true if the value of the item referred to by the given index left is less than the value of the item referred to by the given index right, otherwise returns false. More... | |
Protected Functions inherited from QAbstractProxyModel | |
QAbstractProxyModel (QAbstractProxyModelPrivate &, QObject *parent) | |
Protected Functions inherited from QAbstractItemModel | |
void | beginInsertColumns (const QModelIndex &parent, int first, int last) |
Begins a column insertion operation. More... | |
void | beginInsertRows (const QModelIndex &parent, int first, int last) |
Begins a row insertion operation. More... | |
bool | beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn) |
Begins a column move operation. More... | |
bool | beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow) |
Begins a row move operation. More... | |
void | beginRemoveColumns (const QModelIndex &parent, int first, int last) |
Begins a column removal operation. More... | |
void | beginRemoveRows (const QModelIndex &parent, int first, int last) |
Begins a row removal operation. More... | |
void | beginResetModel () |
Begins a model reset operation. More... | |
void | changePersistentIndex (const QModelIndex &from, const QModelIndex &to) |
Changes the QPersistentModelIndex that is equal to the given from model index to the given to model index. More... | |
void | changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to) |
Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list to the given to model index list. More... | |
QModelIndex | createIndex (int row, int column, void *data=0) const |
Creates a model index for the given row and column with the internal pointer ptr. More... | |
QModelIndex | createIndex (int row, int column, int id) const |
Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead. More... | |
QModelIndex | createIndex (int row, int column, quint32 id) const |
Creates a model index for the given row and column with the internal identifier, id. More... | |
bool | decodeData (int row, int column, const QModelIndex &parent, QDataStream &stream) |
void | encodeData (const QModelIndexList &indexes, QDataStream &stream) const |
void | endInsertColumns () |
Ends a column insertion operation. More... | |
void | endInsertRows () |
Ends a row insertion operation. More... | |
void | endMoveColumns () |
Ends a column move operation. More... | |
void | endMoveRows () |
Ends a row move operation. More... | |
void | endRemoveColumns () |
Ends a column removal operation. More... | |
void | endRemoveRows () |
Ends a row removal operation. More... | |
void | endResetModel () |
Completes a model reset operation. More... | |
QModelIndexList | persistentIndexList () const |
Returns the list of indexes stored as persistent indexes in the model. More... | |
QAbstractItemModel (QAbstractItemModelPrivate &dd, QObject *parent=0) | |
void | reset () |
Resets the model to its original state in any attached views. More... | |
void | setRoleNames (const QHash< int, QByteArray > &roleNames) |
Sets the model's role names to roleNames. More... | |
Protected Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *) |
This event handler can be reimplemented in a subclass to receive child events. More... | |
virtual void | connectNotify (const char *signal) |
This virtual function is called when something has been connected to signal in this object. More... | |
virtual void | customEvent (QEvent *) |
This event handler can be reimplemented in a subclass to receive custom events. More... | |
virtual void | disconnectNotify (const char *signal) |
This virtual function is called when something has been disconnected from signal in this object. More... | |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. More... | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More... | |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *) |
This event handler can be reimplemented in a subclass to receive timer events for the object. More... | |
Properties | |
bool | dynamicSortFilter |
whether the proxy model is dynamically sorted and filtered whenever the contents of the source model change More... | |
Qt::CaseSensitivity | filterCaseSensitivity |
the case sensitivity of the QRegExp pattern used to filter the contents of the source model More... | |
int | filterKeyColumn |
the column where the key used to filter the contents of the source model is read from. More... | |
QRegExp | filterRegExp |
the QRegExp used to filter the contents of the source model More... | |
int | filterRole |
the item role that is used to query the source model's data when filtering items More... | |
bool | isSortLocaleAware |
the local aware setting used for comparing strings when sorting More... | |
Qt::CaseSensitivity | sortCaseSensitivity |
the case sensitivity setting used for comparing strings when sorting More... | |
int | sortRole |
the item role that is used to query the source model's data when sorting items More... | |
Friends | |
class | QSortFilterProxyModelGreaterThan |
class | QSortFilterProxyModelLessThan |
Additional Inherited Members | |
Signals inherited from QAbstractItemModel | |
void | columnsAboutToBeInserted (const QModelIndex &parent, int first, int last) |
This signal is emitted just before columns are inserted into the model. More... | |
void | columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn) |
This signal is emitted just before columns are moved within the model. More... | |
void | columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last) |
This signal is emitted just before columns are removed from the model. More... | |
void | columnsInserted (const QModelIndex &parent, int first, int last) |
This signal is emitted after columns have been inserted into the model. More... | |
void | columnsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column) |
This signal is emitted after columns have been moved within the model. More... | |
void | columnsRemoved (const QModelIndex &parent, int first, int last) |
This signal is emitted after columns have been removed from the model. More... | |
void | dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight) |
This signal is emitted whenever the data in an existing item changes. More... | |
void | headerDataChanged (Qt::Orientation orientation, int first, int last) |
This signal is emitted whenever a header is changed. More... | |
void | layoutAboutToBeChanged () |
This signal is emitted just before the layout of a model is changed. More... | |
void | layoutChanged () |
This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted. More... | |
void | modelAboutToBeReset () |
This signal is emitted when reset() is called, before the model's internal state (e. More... | |
void | modelReset () |
This signal is emitted when reset() is called, after the model's internal state (e. More... | |
void | rowsAboutToBeInserted (const QModelIndex &parent, int first, int last) |
This signal is emitted just before rows are inserted into the model. More... | |
void | rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) |
This signal is emitted just before rows are moved within the model. More... | |
void | rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last) |
This signal is emitted just before rows are removed from the model. More... | |
void | rowsInserted (const QModelIndex &parent, int first, int last) |
This signal is emitted after rows have been inserted into the model. More... | |
void | rowsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) |
This signal is emitted after rows have been moved within the model. More... | |
void | rowsRemoved (const QModelIndex &parent, int first, int last) |
This signal is emitted after rows have been removed from the model. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More... | |
Static Public Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More... | |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
Disconnects signal in object sender from method in object receiver. More... | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
static QString | tr (const char *sourceText, const char *comment=0, int n=-1) |
static QString | trUtf8 (const char *sourceText, const char *comment=0, int n=-1) |
Static Public Variables inherited from QObject | |
static const QMetaObject | staticMetaObject |
This variable stores the meta-object for the class. More... | |
Protected Slots inherited from QAbstractItemModel | |
void | resetInternalData () |
This slot is called just after the internal data of a model is cleared while it is being reset. More... | |
Protected Variables inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
The QSortFilterProxyModel class provides support for sorting and filtering data passed between another model and a view.
QSortFilterProxyModel can be used for sorting items, filtering out items, or both. The model transforms the structure of a source model by mapping the model indexes it supplies to new indexes, corresponding to different locations, for views to use. This approach allows a given source model to be restructured as far as views are concerned without requiring any transformations on the underlying data, and without duplicating the data in memory.
Let's assume that we want to sort and filter the items provided by a custom model. The code to set up the model and the view, without sorting and filtering, would look like this:
To add sorting and filtering support to MyItemModel
, we need to create a QSortFilterProxyModel, call setSourceModel() with the MyItemModel
as argument, and install the QSortFilterProxyModel on the view:
At this point, neither sorting nor filtering is enabled; the original data is displayed in the view. Any changes made through the QSortFilterProxyModel are applied to the original model.
The QSortFilterProxyModel acts as a wrapper for the original model. If you need to convert source to sorted/filtered model indexes or vice versa, use mapToSource(), mapFromSource(), mapSelectionToSource(), and mapSelectionFromSource(). By default, the model does not dynamically re-sort and re-filter data whenever the original model changes. This behavior can be changed by setting the QSortFilterProxyModel::dynamicSortFilter "dynamicSortFilter" property. The itemviews/basicsortfiltermodel "Basic Sort/Filter Model" and itemviews/customsortfiltermodel "Custom Sort/Filter Model" examples illustrate how to use QSortFilterProxyModel to perform basic sorting and filtering and how to subclass it to implement custom behavior. Sorting QTableView and QTreeView have a sortingEnabled property that controls whether the user can sort the view by clicking the view's horizontal header. For example:
When this feature is on (the default is off), clicking on a header section sorts the items according to that column. By clicking repeatedly, the user can alternate between ascending and descending order.
Behind the scene, the view calls the sort() virtual function on the model to reorder the data in the model. To make your data sortable, you can either implement sort() in your model, or use a QSortFilterProxyModel to wrap your model – QSortFilterProxyModel provides a generic sort() reimplementation that operates on the sortRole() (Qt::DisplayRole by default) of the items and that understands several data types, including int
, QString, and QDateTime. For hierarchical models, sorting is applied recursively to all child items. String comparisons are case sensitive by default; this can be changed by setting the QSortFilterProxyModel::sortCaseSensitivity property.
Custom sorting behavior is achieved by subclassing QSortFilterProxyModel and reimplementing lessThan(), which is used to compare items. For example:
(This code snippet comes from the Custom Sort/Filter Model example.)
An alternative approach to sorting is to disable sorting on the view and to impose a certain order to the user. This is done by explicitly calling sort() with the desired column and order as arguments on the QSortFilterProxyModel (or on the original model if it implements sort()). For example:
QSortFilterProxyModel can be sorted by column -1, in which case it returns to the sort order of the underlying source model.
In addition to sorting, QSortFilterProxyModel can be used to hide items that do not match a certain filter. The filter is specified using a QRegExp object and is applied to the filterRole() (Qt::DisplayRole by default) of each item, for a given column. The QRegExp object can be used to match a regular expression, a wildcard pattern, or a fixed string. For example:
For hierarchical models, the filter is applied recursively to all children. If a parent item doesn't match the filter, none of its children will be shown.
A common use case is to let the user specify the filter regexp, wildcard pattern, or fixed string in a QLineEdit and to connect the textChanged() signal to setFilterRegExp(), setFilterWildcard(), or setFilterFixedString() to reapply the filter.
Custom filtering behavior can be achieved by reimplementing the filterAcceptsRow() and filterAcceptsColumn() functions. For example (from the Custom Sort/Filter Model example), the following implementation ignores the filterKeyColumn property and performs filtering on columns 0, 1, and 2:
(This code snippet comes from the Custom Sort/Filter Model example.)
If you are working with large amounts of filtering and have to invoke invalidateFilter() repeatedly, using reset() may be more efficient, depending on the implementation of your model. However, reset() returns the proxy model to its original state, losing selection information, and will cause the proxy model to be repopulated.
Since QAbstractProxyModel and its subclasses are derived from QAbstractItemModel, much of the same advice about subclassing normal models also applies to proxy models. In addition, it is worth noting that many of the default implementations of functions in this class are written so that they call the equivalent functions in the relevant source model. This simple proxying mechanism may need to be overridden for source models with more complex behavior; for example, if the source model provides a custom hasChildren() implementation, you should also provide one in the proxy model.
Definition at line 61 of file qsortfilterproxymodel.h.
QSortFilterProxyModel::QSortFilterProxyModel | ( | QObject * | parent = 0 | ) |
Constructs a sorting filter model with the given parent.
Definition at line 1569 of file qsortfilterproxymodel.cpp.
QSortFilterProxyModel::~QSortFilterProxyModel | ( | ) |
Destroys this sorting filter model.
Definition at line 1587 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 2049 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 2025 of file qsortfilterproxymodel.cpp.
|
slot |
This function is obsolete.
Use invalidate() instead.
Definition at line 2406 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Implements QAbstractItemModel.
Definition at line 1737 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 1769 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractItemModel.
Definition at line 1868 of file qsortfilterproxymodel.cpp.
bool QSortFilterProxyModel::dynamicSortFilter | ( | ) | const |
Referenced by setFilterFixedString().
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 2013 of file qsortfilterproxymodel.cpp.
|
protectedvirtual |
Returns true if the item in the column indicated by the given source_column and source_parent should be included in the model; otherwise returns false.
The default implementation returns true if the value held by the relevant item matches the filter string, wildcard string or regular expression.
Definition at line 2587 of file qsortfilterproxymodel.cpp.
|
protectedvirtual |
Returns true if the item in the row indicated by the given source_row and source_parent should be included in the model; otherwise returns false.
The default implementation returns true if the value held by the relevant item matches the filter string, wildcard string or regular expression.
Definition at line 2553 of file qsortfilterproxymodel.cpp.
Qt::CaseSensitivity QSortFilterProxyModel::filterCaseSensitivity | ( | ) | const |
Referenced by setFilterKeyColumn().
|
protected |
This function is obsolete.
Use invalidateFilter() instead.
Definition at line 2440 of file qsortfilterproxymodel.cpp.
int QSortFilterProxyModel::filterKeyColumn | ( | ) | const |
Referenced by setFilterRegExp().
QRegExp QSortFilterProxyModel::filterRegExp | ( | ) | const |
Referenced by sortOrder().
int QSortFilterProxyModel::filterRole | ( | ) | const |
Referenced by setSortRole().
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 2037 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 1750 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 1793 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Implements QAbstractItemModel.
Definition at line 1692 of file qsortfilterproxymodel.cpp.
Referenced by buddy(), and dropMimeData().
|
virtual |
Reimplemented Function
Reimplemented from QAbstractItemModel.
Definition at line 1914 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractItemModel.
Definition at line 1894 of file qsortfilterproxymodel.cpp.
|
slot |
Invalidates the current sorting and filtering.
Definition at line 2424 of file qsortfilterproxymodel.cpp.
|
protected |
Invalidates the current filtering.
This function should be called if you are implementing custom filtering (e.g. filterAcceptsRow()), and your filter parameters have changed.
Definition at line 2459 of file qsortfilterproxymodel.cpp.
bool QSortFilterProxyModel::isSortLocaleAware | ( | ) | const |
Referenced by setSortCaseSensitivity().
|
protectedvirtual |
Returns true if the value of the item referred to by the given index left is less than the value of the item referred to by the given index right, otherwise returns false.
This function is used as the < operator when sorting, and handles the following QVariant types:
Any other type will be converted to a QString using QVariant::toString().
Comparison of QString is case sensitive by default; this can be changed using the QSortFilterProxyModel::sortCaseSensitivity {sortCaseSensitivity} property.
By default, the Qt::DisplayRole associated with the is used for comparisons. This can be changed by setting the QSortFilterProxyModel::sortRole {sortRole} property.
Definition at line 2501 of file qsortfilterproxymodel.cpp.
Referenced by QSortFilterProxyModelLessThan::operator()(), and QSortFilterProxyModelGreaterThan::operator()().
|
virtual |
Returns the model index in the QSortFilterProxyModel given the sourceIndex from the source model.
Implements QAbstractProxyModel.
Definition at line 2612 of file qsortfilterproxymodel.cpp.
Referenced by buddy(), and parent().
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 2629 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 2621 of file qsortfilterproxymodel.cpp.
|
virtual |
Returns the source model index corresponding to the given proxyIndex from the sorting filter model.
Implements QAbstractProxyModel.
Definition at line 2600 of file qsortfilterproxymodel.cpp.
Referenced by buddy(), canFetchMore(), columnCount(), data(), dropMimeData(), fetchMore(), flags(), hasChildren(), index(), insertColumns(), insertRows(), mimeData(), removeColumns(), removeRows(), rowCount(), setData(), and span().
|
virtual |
Reimplemented Function
Reimplemented from QAbstractItemModel.
Definition at line 2064 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 1838 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 1850 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Implements QAbstractItemModel.
Definition at line 1709 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractItemModel.
Definition at line 1975 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractItemModel.
Definition at line 1934 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Implements QAbstractItemModel.
Definition at line 1724 of file qsortfilterproxymodel.cpp.
Referenced by dropMimeData().
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 1781 of file qsortfilterproxymodel.cpp.
void QSortFilterProxyModel::setDynamicSortFilter | ( | bool | enable | ) |
Definition at line 2336 of file qsortfilterproxymodel.cpp.
void QSortFilterProxyModel::setFilterCaseSensitivity | ( | Qt::CaseSensitivity | cs | ) |
Definition at line 2199 of file qsortfilterproxymodel.cpp.
|
slot |
Sets the fixed string used to filter the contents of the source model to the given pattern.
Definition at line 2303 of file qsortfilterproxymodel.cpp.
void QSortFilterProxyModel::setFilterKeyColumn | ( | int | column | ) |
Definition at line 2173 of file qsortfilterproxymodel.cpp.
void QSortFilterProxyModel::setFilterRegExp | ( | const QRegExp & | regExp | ) |
Definition at line 2149 of file qsortfilterproxymodel.cpp.
|
slot |
Sets the regular expression used to filter the contents of the source model to pattern.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2275 of file qsortfilterproxymodel.cpp.
void QSortFilterProxyModel::setFilterRole | ( | int | role | ) |
Definition at line 2389 of file qsortfilterproxymodel.cpp.
|
slot |
Sets the wildcard expression used to filter the contents of the source model to the given pattern.
Definition at line 2289 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 1815 of file qsortfilterproxymodel.cpp.
void QSortFilterProxyModel::setSortCaseSensitivity | ( | Qt::CaseSensitivity | cs | ) |
Definition at line 2226 of file qsortfilterproxymodel.cpp.
void QSortFilterProxyModel::setSortLocaleAware | ( | bool | on | ) |
Definition at line 2254 of file qsortfilterproxymodel.cpp.
void QSortFilterProxyModel::setSortRole | ( | int | role | ) |
Definition at line 2362 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 1597 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 2086 of file qsortfilterproxymodel.cpp.
Qt::CaseSensitivity QSortFilterProxyModel::sortCaseSensitivity | ( | ) | const |
Referenced by setFilterCaseSensitivity().
int QSortFilterProxyModel::sortColumn | ( | ) | const |
the column currently used for sorting
This returns the most recently used sort column.
Definition at line 2106 of file qsortfilterproxymodel.cpp.
Qt::SortOrder QSortFilterProxyModel::sortOrder | ( | ) | const |
the order currently used for sorting
This returns the most recently used sort order.
Definition at line 2121 of file qsortfilterproxymodel.cpp.
int QSortFilterProxyModel::sortRole | ( | ) | const |
Referenced by setDynamicSortFilter().
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 2074 of file qsortfilterproxymodel.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QAbstractProxyModel.
Definition at line 1859 of file qsortfilterproxymodel.cpp.
|
friend |
Definition at line 64 of file qsortfilterproxymodel.h.
|
friend |
Definition at line 63 of file qsortfilterproxymodel.h.
|
private |
whether the proxy model is dynamically sorted and filtered whenever the contents of the source model change
Note that you should not update the source model through the proxy model when dynamicSortFilter is true. For instance, if you set the proxy model on a QComboBox, then using functions that update the model, e.g., QComboBox::addItem(), will not work as expected. An alternative is to set dynamicSortFilter to false and call QSortFilterProxyModel::sort() after adding items to the QComboBox.
The default value is false.
Definition at line 69 of file qsortfilterproxymodel.h.
|
private |
the case sensitivity of the QRegExp pattern used to filter the contents of the source model
By default, the filter is case sensitive.
Definition at line 70 of file qsortfilterproxymodel.h.
|
private |
the column where the key used to filter the contents of the source model is read from.
The default value is 0. If the value is -1, the keys will be read from all columns.
Definition at line 68 of file qsortfilterproxymodel.h.
|
private |
the QRegExp used to filter the contents of the source model
Setting this property overwrites the current filterCaseSensitivity. By default, the QRegExp is an empty string matching all contents.
If no QRegExp or an empty string is set, everything in the source model will be accepted.
Definition at line 67 of file qsortfilterproxymodel.h.
|
private |
the item role that is used to query the source model's data when filtering items
The default value is Qt::DisplayRole.
Definition at line 74 of file qsortfilterproxymodel.h.
|
private |
the local aware setting used for comparing strings when sorting
By default, sorting is not local aware.
Definition at line 72 of file qsortfilterproxymodel.h.
|
private |
the case sensitivity setting used for comparing strings when sorting
By default, sorting is case sensitive.
Definition at line 71 of file qsortfilterproxymodel.h.
|
private |
the item role that is used to query the source model's data when sorting items
The default value is Qt::DisplayRole.
Definition at line 73 of file qsortfilterproxymodel.h.