Qt 4.8
Public Slots | Public Functions | Protected Functions | Properties | Friends | List of all members
QSortFilterProxyModel Class Reference

The QSortFilterProxyModel class provides support for sorting and filtering data passed between another model and a view. More...

#include <qsortfilterproxymodel.h>

Inheritance diagram for QSortFilterProxyModel:
QAbstractProxyModel QAbstractItemModel QObject

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...
 
QMimeDatamimeData (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 &regExp)
 
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, QVariantitemData (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...
 
QAbstractItemModelsourceModel () 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 QObjectListchildren () 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< QByteArraydynamicPropertyNames () 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 >
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 QMetaObjectmetaObject () 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
 
QObjectparent () 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...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (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...
 
QObjectsender () 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< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QSortFilterProxyModel class provides support for sorting and filtering data passed between another model and a view.

Since
4.1

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:

QTreeView *treeView = new QTreeView;
MyItemModel *model = new MyItemModel(this);
treeView->setModel(model);

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:

QTreeView *treeView = new QTreeView;
MyItemModel *sourceModel = new MyItemModel(this);
proxyModel->setSourceModel(sourceModel);
treeView->setModel(proxyModel);

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:

treeView->setSortingEnabled(true);

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.

qsortfilterproxymodel-sorting.png
A sorted QTreeView

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:

const QModelIndex &right) const
{
QVariant leftData = sourceModel()->data(left);
QVariant rightData = sourceModel()->data(right);
if (leftData.type() == QVariant::DateTime) {
return leftData.toDateTime() < rightData.toDateTime();
} else {
QRegExp *emailPattern = new QRegExp("([\\w\\.]*@[\\w\\.]*)");
QString leftString = leftData.toString();
if(left.column() == 1 && emailPattern->indexIn(leftString) != -1)
leftString = emailPattern->cap(1);
QString rightString = rightData.toString();
if(right.column() == 1 && emailPattern->indexIn(rightString) != -1)
rightString = emailPattern->cap(1);
return QString::localeAwareCompare(leftString, rightString) < 0;
}
}

(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:

proxyModel->sort(2, Qt::AscendingOrder);

QSortFilterProxyModel can be sorted by column -1, in which case it returns to the sort order of the underlying source model.

Filtering

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:

bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const
{
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
return (sourceModel()->data(index0).toString().contains(filterRegExp())
|| sourceModel()->data(index1).toString().contains(filterRegExp()))
&& dateInRange(sourceModel()->data(index2).toDate());
}

(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.

Subclassing

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.

Note
Some general guidelines for subclassing models are available in the Model Subclassing Reference.
See also
QAbstractProxyModel, QAbstractItemModel, {Model/View Programming}, {Basic Sort/Filter Model Example}, {Custom Sort/Filter Model Example}, QIdentityProxyModel

Definition at line 61 of file qsortfilterproxymodel.h.

Constructors and Destructors

◆ QSortFilterProxyModel()

QSortFilterProxyModel::QSortFilterProxyModel ( QObject parent = 0)

Constructs a sorting filter model with the given parent.

Definition at line 1569 of file qsortfilterproxymodel.cpp.

1571 {
1573  d->proxy_sort_column = d->source_sort_column = -1;
1574  d->sort_order = Qt::AscendingOrder;
1575  d->sort_casesensitivity = Qt::CaseSensitive;
1576  d->sort_role = Qt::DisplayRole;
1577  d->sort_localeaware = false;
1578  d->filter_column = 0;
1579  d->filter_role = Qt::DisplayRole;
1580  d->dynamic_sortfilter = false;
1581  connect(this, SIGNAL(modelReset()), this, SLOT(_q_clearMapping()));
1582 }
double d
Definition: qnumeric_p.h:62
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractProxyModel(QObject *parent=0)
Constructs a proxy model with the given parent.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
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 rece...
Definition: qobject.cpp:2580
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
void modelReset()
This signal is emitted when reset() is called, after the model&#39;s internal state (e.

◆ ~QSortFilterProxyModel()

QSortFilterProxyModel::~QSortFilterProxyModel ( )

Destroys this sorting filter model.

Definition at line 1587 of file qsortfilterproxymodel.cpp.

1588 {
1590  qDeleteAll(d->source_index_mapping);
1591  d->source_index_mapping.clear();
1592 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

Functions

◆ buddy()

QModelIndex QSortFilterProxyModel::buddy ( const QModelIndex index) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 2049 of file qsortfilterproxymodel.cpp.

2050 {
2051  Q_D(const QSortFilterProxyModel);
2052  if (!d->indexValid(index))
2053  return QModelIndex();
2054  QModelIndex source_index = mapToSource(index);
2055  QModelIndex source_buddy = d->model->buddy(source_index);
2056  if (source_index == source_buddy)
2057  return index;
2058  return mapFromSource(source_buddy);
2059 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Returns the model index in the QSortFilterProxyModel given the sourceIndex from the source model...

◆ canFetchMore()

bool QSortFilterProxyModel::canFetchMore ( const QModelIndex parent) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 2025 of file qsortfilterproxymodel.cpp.

2026 {
2027  Q_D(const QSortFilterProxyModel);
2028  QModelIndex source_parent;
2029  if (d->indexValid(parent))
2030  source_parent = mapToSource(parent);
2031  return d->model->canFetchMore(source_parent);
2032 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ clear

void QSortFilterProxyModel::clear ( )
slot

This function is obsolete.

Use invalidate() instead.

Definition at line 2406 of file qsortfilterproxymodel.cpp.

2407 {
2410  d->_q_clearMapping();
2411  emit layoutChanged();
2412 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
#define emit
Definition: qobjectdefs.h:76
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ columnCount()

int QSortFilterProxyModel::columnCount ( const QModelIndex parent = QModelIndex()) const
virtual

Reimplemented Function

Implements QAbstractItemModel.

Definition at line 1737 of file qsortfilterproxymodel.cpp.

1738 {
1739  Q_D(const QSortFilterProxyModel);
1740  QModelIndex source_parent = mapToSource(parent);
1741  if (parent.isValid() && !source_parent.isValid())
1742  return 0;
1743  IndexMap::const_iterator it = d->create_mapping(source_parent);
1744  return it.value()->source_columns.count();
1745 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
#define it(className, varName)
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ data()

QVariant QSortFilterProxyModel::data ( const QModelIndex index,
int  role = Qt::DisplayRole 
) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 1769 of file qsortfilterproxymodel.cpp.

1770 {
1771  Q_D(const QSortFilterProxyModel);
1772  QModelIndex source_index = mapToSource(index);
1773  if (index.isValid() && !source_index.isValid())
1774  return QVariant();
1775  return d->model->data(source_index, role);
1776 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ dropMimeData()

bool QSortFilterProxyModel::dropMimeData ( const QMimeData data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex parent 
)
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 1868 of file qsortfilterproxymodel.cpp.

1870 {
1872  if ((row == -1) && (column == -1))
1873  return d->model->dropMimeData(data, action, -1, -1, mapToSource(parent));
1874  int source_destination_row = -1;
1875  int source_destination_column = -1;
1876  QModelIndex source_parent;
1877  if (row == rowCount(parent)) {
1878  source_parent = mapToSource(parent);
1879  source_destination_row = d->model->rowCount(source_parent);
1880  } else {
1881  QModelIndex proxy_index = index(row, column, parent);
1882  QModelIndex source_index = mapToSource(proxy_index);
1883  source_destination_row = source_index.row();
1884  source_destination_column = source_index.column();
1885  source_parent = source_index.parent();
1886  }
1887  return d->model->dropMimeData(data, action, source_destination_row,
1888  source_destination_column, source_parent);
1889 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
int rowCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Reimplemented Function
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
int row() const
Returns the row this model index refers to.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.
int column() const
Returns the column this model index refers to.

◆ dynamicSortFilter()

bool QSortFilterProxyModel::dynamicSortFilter ( ) const

Referenced by setFilterFixedString().

◆ fetchMore()

void QSortFilterProxyModel::fetchMore ( const QModelIndex parent)
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 2013 of file qsortfilterproxymodel.cpp.

2014 {
2016  QModelIndex source_parent;
2017  if (d->indexValid(parent))
2018  source_parent = mapToSource(parent);
2019  d->model->fetchMore(source_parent);
2020 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ filterAcceptsColumn()

bool QSortFilterProxyModel::filterAcceptsColumn ( int  source_column,
const QModelIndex source_parent 
) const
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.

Note
By default, the Qt::DisplayRole is used to determine if the row should be accepted or not. This can be changed by setting the filterRole property.
See also
filterAcceptsRow(), setFilterFixedString(), setFilterRegExp(), setFilterWildcard()

Definition at line 2587 of file qsortfilterproxymodel.cpp.

2588 {
2589  Q_UNUSED(source_column);
2590  Q_UNUSED(source_parent);
2591  return true;
2592 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ filterAcceptsRow()

bool QSortFilterProxyModel::filterAcceptsRow ( int  source_row,
const QModelIndex source_parent 
) const
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.

Note
By default, the Qt::DisplayRole is used to determine if the row should be accepted or not. This can be changed by setting the filterRole property.
See also
filterAcceptsColumn(), setFilterFixedString(), setFilterRegExp(), setFilterWildcard()

Definition at line 2553 of file qsortfilterproxymodel.cpp.

2554 {
2555  Q_D(const QSortFilterProxyModel);
2556  if (d->filter_regexp.isEmpty())
2557  return true;
2558  if (d->filter_column == -1) {
2559  int column_count = d->model->columnCount(source_parent);
2560  for (int column = 0; column < column_count; ++column) {
2561  QModelIndex source_index = d->model->index(source_row, column, source_parent);
2562  QString key = d->model->data(source_index, d->filter_role).toString();
2563  if (key.contains(d->filter_regexp))
2564  return true;
2565  }
2566  return false;
2567  }
2568  QModelIndex source_index = d->model->index(source_row, d->filter_column, source_parent);
2569  if (!source_index.isValid()) // the column may not exist
2570  return true;
2571  QString key = d->model->data(source_index, d->filter_role).toString();
2572  return key.contains(d->filter_regexp);
2573 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
double d
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
int key
The QModelIndex class is used to locate data in a data model.

◆ filterCaseSensitivity()

Qt::CaseSensitivity QSortFilterProxyModel::filterCaseSensitivity ( ) const

Referenced by setFilterKeyColumn().

◆ filterChanged()

void QSortFilterProxyModel::filterChanged ( )
protected

This function is obsolete.

Use invalidateFilter() instead.

Definition at line 2440 of file qsortfilterproxymodel.cpp.

2441 {
2443  d->filter_changed();
2444 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ filterKeyColumn()

int QSortFilterProxyModel::filterKeyColumn ( ) const

Referenced by setFilterRegExp().

◆ filterRegExp()

QRegExp QSortFilterProxyModel::filterRegExp ( ) const

Referenced by sortOrder().

◆ filterRole()

int QSortFilterProxyModel::filterRole ( ) const

Referenced by setSortRole().

◆ flags()

Qt::ItemFlags QSortFilterProxyModel::flags ( const QModelIndex index) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 2037 of file qsortfilterproxymodel.cpp.

2038 {
2039  Q_D(const QSortFilterProxyModel);
2040  QModelIndex source_index;
2041  if (d->indexValid(index))
2042  source_index = mapToSource(index);
2043  return d->model->flags(source_index);
2044 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ hasChildren()

bool QSortFilterProxyModel::hasChildren ( const QModelIndex parent = QModelIndex()) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 1750 of file qsortfilterproxymodel.cpp.

1751 {
1752  Q_D(const QSortFilterProxyModel);
1753  QModelIndex source_parent = mapToSource(parent);
1754  if (parent.isValid() && !source_parent.isValid())
1755  return false;
1756  if (!d->model->hasChildren(source_parent))
1757  return false;
1758 
1759  if (d->model->canFetchMore(source_parent))
1760  return true; //we assume we might have children that can be fetched
1761 
1762  QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value();
1763  return m->source_rows.count() != 0 && m->source_columns.count() != 0;
1764 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ headerData()

QVariant QSortFilterProxyModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 1793 of file qsortfilterproxymodel.cpp.

1794 {
1795  Q_D(const QSortFilterProxyModel);
1796  IndexMap::const_iterator it = d->create_mapping(QModelIndex());
1797  if (it.value()->source_rows.count() * it.value()->source_columns.count() > 0)
1798  return QAbstractProxyModel::headerData(section, orientation, role);
1799  int source_section;
1800  if (orientation == Qt::Vertical) {
1801  if (section < 0 || section >= it.value()->source_rows.count())
1802  return QVariant();
1803  source_section = it.value()->source_rows.at(section);
1804  } else {
1805  if (section < 0 || section >= it.value()->source_columns.count())
1806  return QVariant();
1807  source_section = it.value()->source_columns.at(section);
1808  }
1809  return d->model->headerData(source_section, orientation, role);
1810 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Reimplemented Function
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.
T value() const
Returns the stored value converted to the template type T.
Definition: qvariant.h:332

◆ index()

QModelIndex QSortFilterProxyModel::index ( int  row,
int  column,
const QModelIndex parent = QModelIndex() 
) const
virtual

Reimplemented Function

Implements QAbstractItemModel.

Definition at line 1692 of file qsortfilterproxymodel.cpp.

Referenced by buddy(), and dropMimeData().

1693 {
1694  Q_D(const QSortFilterProxyModel);
1695  if (row < 0 || column < 0)
1696  return QModelIndex();
1697 
1698  QModelIndex source_parent = mapToSource(parent); // parent is already mapped at this point
1699  IndexMap::const_iterator it = d->create_mapping(source_parent); // but make sure that the children are mapped
1700  if (it.value()->source_rows.count() <= row || it.value()->source_columns.count() <= column)
1701  return QModelIndex();
1702 
1703  return d->create_index(row, column, it);
1704 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
#define it(className, varName)
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ insertColumns()

bool QSortFilterProxyModel::insertColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
)
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 1914 of file qsortfilterproxymodel.cpp.

1915 {
1917  if (column < 0|| count <= 0)
1918  return false;
1919  QModelIndex source_parent = mapToSource(parent);
1920  if (parent.isValid() && !source_parent.isValid())
1921  return false;
1922  QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value();
1923  if (column > m->source_columns.count())
1924  return false;
1925  int source_column = (column >= m->source_columns.count()
1926  ? m->source_columns.count()
1927  : m->source_columns.at(column));
1928  return d->model->insertColumns(source_column, count, source_parent);
1929 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ insertRows()

bool QSortFilterProxyModel::insertRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 1894 of file qsortfilterproxymodel.cpp.

1895 {
1897  if (row < 0 || count <= 0)
1898  return false;
1899  QModelIndex source_parent = mapToSource(parent);
1900  if (parent.isValid() && !source_parent.isValid())
1901  return false;
1902  QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value();
1903  if (row > m->source_rows.count())
1904  return false;
1905  int source_row = (row >= m->source_rows.count()
1906  ? m->source_rows.count()
1907  : m->source_rows.at(row));
1908  return d->model->insertRows(source_row, count, source_parent);
1909 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ invalidate

void QSortFilterProxyModel::invalidate ( )
slot

Invalidates the current sorting and filtering.

Since
4.3
See also
invalidateFilter()

Definition at line 2424 of file qsortfilterproxymodel.cpp.

2425 {
2428  d->_q_clearMapping();
2429  emit layoutChanged();
2430 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
#define emit
Definition: qobjectdefs.h:76
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ invalidateFilter()

void QSortFilterProxyModel::invalidateFilter ( )
protected

Invalidates the current filtering.

Since
4.3

This function should be called if you are implementing custom filtering (e.g. filterAcceptsRow()), and your filter parameters have changed.

See also
invalidate()

Definition at line 2459 of file qsortfilterproxymodel.cpp.

2460 {
2462  d->filter_changed();
2463 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ isSortLocaleAware()

bool QSortFilterProxyModel::isSortLocaleAware ( ) const

Referenced by setSortCaseSensitivity().

◆ lessThan()

bool QSortFilterProxyModel::lessThan ( const QModelIndex left,
const QModelIndex right 
) const
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.

Note
The indices passed in correspond to the source model.
See also
sortRole, sortCaseSensitivity, dynamicSortFilter

Definition at line 2501 of file qsortfilterproxymodel.cpp.

Referenced by QSortFilterProxyModelLessThan::operator()(), and QSortFilterProxyModelGreaterThan::operator()().

2502 {
2503  Q_D(const QSortFilterProxyModel);
2504  QVariant l = (left.model() ? left.model()->data(left, d->sort_role) : QVariant());
2505  QVariant r = (right.model() ? right.model()->data(right, d->sort_role) : QVariant());
2506  switch (l.userType()) {
2507  case QVariant::Invalid:
2508  return (r.type() != QVariant::Invalid);
2509  case QVariant::Int:
2510  return l.toInt() < r.toInt();
2511  case QVariant::UInt:
2512  return l.toUInt() < r.toUInt();
2513  case QVariant::LongLong:
2514  return l.toLongLong() < r.toLongLong();
2515  case QVariant::ULongLong:
2516  return l.toULongLong() < r.toULongLong();
2517  case QMetaType::Float:
2518  return l.toFloat() < r.toFloat();
2519  case QVariant::Double:
2520  return l.toDouble() < r.toDouble();
2521  case QVariant::Char:
2522  return l.toChar() < r.toChar();
2523  case QVariant::Date:
2524  return l.toDate() < r.toDate();
2525  case QVariant::Time:
2526  return l.toTime() < r.toTime();
2527  case QVariant::DateTime:
2528  return l.toDateTime() < r.toDateTime();
2529  case QVariant::String:
2530  default:
2531  if (d->sort_localeaware)
2532  return l.toString().localeAwareCompare(r.toString()) < 0;
2533  else
2534  return l.toString().compare(r.toString(), d->sort_casesensitivity) < 0;
2535  }
2536  return false;
2537 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
#define Q_D(Class)
Definition: qglobal.h:2482
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
qulonglong toULongLong(bool *ok=0) const
Returns the variant as as an unsigned long long int if the variant has type() ULongLong ...
Definition: qvariant.cpp:2675
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
int localeAwareCompare(const QString &s) const
Definition: qstring.cpp:5197
QDate toDate() const
Returns the variant as a QDate if the variant has type() Date , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2311
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
int compare(const QString &s) const
Definition: qstring.cpp:5037
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
uint toUInt(bool *ok=0) const
Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray ...
Definition: qvariant.cpp:2644
float toFloat(bool *ok=0) const
Returns the variant as a float if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2725
QFactoryLoader * l
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
QTime toTime() const
Returns the variant as a QTime if the variant has type() Time , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2330
QChar toChar() const
Returns the variant as a QChar if the variant has type() Char , Int , or UInt ; otherwise returns an ...
Definition: qvariant.cpp:2579

◆ mapFromSource()

QModelIndex QSortFilterProxyModel::mapFromSource ( const QModelIndex sourceIndex) const
virtual

Returns the model index in the QSortFilterProxyModel given the sourceIndex from the source model.

See also
mapToSource()

Implements QAbstractProxyModel.

Definition at line 2612 of file qsortfilterproxymodel.cpp.

Referenced by buddy(), and parent().

2613 {
2614  Q_D(const QSortFilterProxyModel);
2615  return d->source_to_proxy(sourceIndex);
2616 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ mapSelectionFromSource()

QItemSelection QSortFilterProxyModel::mapSelectionFromSource ( const QItemSelection sourceSelection) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 2629 of file qsortfilterproxymodel.cpp.

2630 {
2631  return QAbstractProxyModel::mapSelectionFromSource(sourceSelection);
2632 }
virtual QItemSelection mapSelectionFromSource(const QItemSelection &selection) const
Returns a proxy selection mapped from the specified sourceSelection.

◆ mapSelectionToSource()

QItemSelection QSortFilterProxyModel::mapSelectionToSource ( const QItemSelection proxySelection) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 2621 of file qsortfilterproxymodel.cpp.

2622 {
2623  return QAbstractProxyModel::mapSelectionToSource(proxySelection);
2624 }
virtual QItemSelection mapSelectionToSource(const QItemSelection &selection) const
Returns a source selection mapped from the specified proxySelection.

◆ mapToSource()

QModelIndex QSortFilterProxyModel::mapToSource ( const QModelIndex proxyIndex) const
virtual

Returns the source model index corresponding to the given proxyIndex from the sorting filter model.

See also
mapFromSource()

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().

2601 {
2602  Q_D(const QSortFilterProxyModel);
2603  return d->proxy_to_source(proxyIndex);
2604 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ match()

QModelIndexList QSortFilterProxyModel::match ( const QModelIndex start,
int  role,
const QVariant value,
int  hits = 1,
Qt::MatchFlags  flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap) 
) const
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 2064 of file qsortfilterproxymodel.cpp.

2067 {
2068  return QAbstractProxyModel::match(start, role, value, hits, flags);
2069 }
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 ...
Qt::ItemFlags flags(const QModelIndex &index) const
Reimplemented Function

◆ mimeData()

QMimeData * QSortFilterProxyModel::mimeData ( const QModelIndexList indexes) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 1838 of file qsortfilterproxymodel.cpp.

1839 {
1840  Q_D(const QSortFilterProxyModel);
1841  QModelIndexList source_indexes;
1842  for (int i = 0; i < indexes.count(); ++i)
1843  source_indexes << mapToSource(indexes.at(i));
1844  return d->model->mimeData(source_indexes);
1845 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_D(Class)
Definition: qglobal.h:2482
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ mimeTypes()

QStringList QSortFilterProxyModel::mimeTypes ( ) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 1850 of file qsortfilterproxymodel.cpp.

1851 {
1852  Q_D(const QSortFilterProxyModel);
1853  return d->model->mimeTypes();
1854 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ parent()

QObject * QSortFilterProxyModel::parent ( const QModelIndex child) const
virtual

Reimplemented Function

Warning
This function is not part of the public interface.

Implements QAbstractItemModel.

Definition at line 1709 of file qsortfilterproxymodel.cpp.

1710 {
1711  Q_D(const QSortFilterProxyModel);
1712  if (!d->indexValid(child))
1713  return QModelIndex();
1714  IndexMap::const_iterator it = d->index_to_iterator(child);
1715  Q_ASSERT(it != d->source_index_mapping.constEnd());
1716  QModelIndex source_parent = it.key();
1717  QModelIndex proxy_parent = mapFromSource(source_parent);
1718  return proxy_parent;
1719 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Returns the model index in the QSortFilterProxyModel given the sourceIndex from the source model...

◆ removeColumns()

bool QSortFilterProxyModel::removeColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
)
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 1975 of file qsortfilterproxymodel.cpp.

1976 {
1978  if (column < 0 || count <= 0)
1979  return false;
1980  QModelIndex source_parent = mapToSource(parent);
1981  if (parent.isValid() && !source_parent.isValid())
1982  return false;
1983  QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value();
1984  if (column + count > m->source_columns.count())
1985  return false;
1986  if ((count == 1) || (m->proxy_columns.count() == m->source_columns.count())) {
1987  int source_column = m->source_columns.at(column);
1988  return d->model->removeColumns(source_column, count, source_parent);
1989  }
1990  // remove corresponding source intervals
1991  QVector<int> columns;
1992  for (int i = column; i < column + count; ++i)
1993  columns.append(m->source_columns.at(i));
1994 
1995  int pos = columns.count() - 1;
1996  bool ok = true;
1997  while (pos >= 0) {
1998  const int source_end = columns.at(pos--);
1999  int source_start = source_end;
2000  while ((pos >= 0) && (columns.at(pos) == (source_start - 1))) {
2001  --source_start;
2002  --pos;
2003  }
2004  ok = ok && d->model->removeColumns(source_start, source_end - source_start + 1,
2005  source_parent);
2006  }
2007  return ok;
2008 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
#define Q_D(Class)
Definition: qglobal.h:2482
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ removeRows()

bool QSortFilterProxyModel::removeRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 1934 of file qsortfilterproxymodel.cpp.

1935 {
1937  if (row < 0 || count <= 0)
1938  return false;
1939  QModelIndex source_parent = mapToSource(parent);
1940  if (parent.isValid() && !source_parent.isValid())
1941  return false;
1942  QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value();
1943  if (row + count > m->source_rows.count())
1944  return false;
1945  if ((count == 1)
1946  || ((d->source_sort_column < 0) && (m->proxy_rows.count() == m->source_rows.count()))) {
1947  int source_row = m->source_rows.at(row);
1948  return d->model->removeRows(source_row, count, source_parent);
1949  }
1950  // remove corresponding source intervals
1951  // ### if this proves to be slow, we can switch to single-row removal
1952  QVector<int> rows;
1953  for (int i = row; i < row + count; ++i)
1954  rows.append(m->source_rows.at(i));
1955  qSort(rows.begin(), rows.end());
1956 
1957  int pos = rows.count() - 1;
1958  bool ok = true;
1959  while (pos >= 0) {
1960  const int source_end = rows.at(pos--);
1961  int source_start = source_end;
1962  while ((pos >= 0) && (rows.at(pos) == (source_start - 1))) {
1963  --source_start;
1964  --pos;
1965  }
1966  ok = ok && d->model->removeRows(source_start, source_end - source_start + 1,
1967  source_parent);
1968  }
1969  return ok;
1970 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
#define Q_D(Class)
Definition: qglobal.h:2482
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
The QModelIndex class is used to locate data in a data model.

◆ rowCount()

int QSortFilterProxyModel::rowCount ( const QModelIndex parent = QModelIndex()) const
virtual

Reimplemented Function

Implements QAbstractItemModel.

Definition at line 1724 of file qsortfilterproxymodel.cpp.

Referenced by dropMimeData().

1725 {
1726  Q_D(const QSortFilterProxyModel);
1727  QModelIndex source_parent = mapToSource(parent);
1728  if (parent.isValid() && !source_parent.isValid())
1729  return 0;
1730  IndexMap::const_iterator it = d->create_mapping(source_parent);
1731  return it.value()->source_rows.count();
1732 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
#define it(className, varName)
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ setData()

bool QSortFilterProxyModel::setData ( const QModelIndex index,
const QVariant value,
int  role = Qt::EditRole 
)
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 1781 of file qsortfilterproxymodel.cpp.

1782 {
1784  QModelIndex source_index = mapToSource(index);
1785  if (index.isValid() && !source_index.isValid())
1786  return false;
1787  return d->model->setData(source_index, value, role);
1788 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ setDynamicSortFilter()

void QSortFilterProxyModel::setDynamicSortFilter ( bool  enable)

Definition at line 2336 of file qsortfilterproxymodel.cpp.

2337 {
2339  d->dynamic_sortfilter = enable;
2340  if (enable)
2341  d->sort();
2342 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ setFilterCaseSensitivity()

void QSortFilterProxyModel::setFilterCaseSensitivity ( Qt::CaseSensitivity  cs)

Definition at line 2199 of file qsortfilterproxymodel.cpp.

2200 {
2202  if (cs == d->filter_regexp.caseSensitivity())
2203  return;
2204  d->filter_regexp.setCaseSensitivity(cs);
2205  d->filter_changed();
2206 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ setFilterFixedString

void QSortFilterProxyModel::setFilterFixedString ( const QString pattern)
slot

Sets the fixed string used to filter the contents of the source model to the given pattern.

See also
setFilterCaseSensitivity(), setFilterRegExp(), setFilterWildcard(), filterRegExp()

Definition at line 2303 of file qsortfilterproxymodel.cpp.

2304 {
2306  d->filter_regexp.setPatternSyntax(QRegExp::FixedString);
2307  d->filter_regexp.setPattern(pattern);
2308  d->filter_changed();
2309 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ setFilterKeyColumn()

void QSortFilterProxyModel::setFilterKeyColumn ( int  column)

Definition at line 2173 of file qsortfilterproxymodel.cpp.

2174 {
2176  d->filter_column = column;
2177  d->filter_changed();
2178 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ setFilterRegExp() [1/2]

void QSortFilterProxyModel::setFilterRegExp ( const QRegExp regExp)

Definition at line 2149 of file qsortfilterproxymodel.cpp.

2150 {
2152  d->filter_regexp = regExp;
2153  d->filter_changed();
2154 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ setFilterRegExp [2/2]

void QSortFilterProxyModel::setFilterRegExp ( const QString pattern)
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.

See also
setFilterCaseSensitivity(), setFilterWildcard(), setFilterFixedString(), filterRegExp()

Definition at line 2275 of file qsortfilterproxymodel.cpp.

2276 {
2278  d->filter_regexp.setPatternSyntax(QRegExp::RegExp);
2279  d->filter_regexp.setPattern(pattern);
2280  d->filter_changed();
2281 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ setFilterRole()

void QSortFilterProxyModel::setFilterRole ( int  role)

Definition at line 2389 of file qsortfilterproxymodel.cpp.

2390 {
2392  if (d->filter_role == role)
2393  return;
2394  d->filter_role = role;
2395  d->filter_changed();
2396 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ setFilterWildcard

void QSortFilterProxyModel::setFilterWildcard ( const QString pattern)
slot

Sets the wildcard expression used to filter the contents of the source model to the given pattern.

See also
setFilterCaseSensitivity(), setFilterRegExp(), setFilterFixedString(), filterRegExp()

Definition at line 2289 of file qsortfilterproxymodel.cpp.

2290 {
2292  d->filter_regexp.setPatternSyntax(QRegExp::Wildcard);
2293  d->filter_regexp.setPattern(pattern);
2294  d->filter_changed();
2295 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ setHeaderData()

bool QSortFilterProxyModel::setHeaderData ( int  section,
Qt::Orientation  orientation,
const QVariant value,
int  role = Qt::EditRole 
)
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 1815 of file qsortfilterproxymodel.cpp.

1817 {
1819  IndexMap::const_iterator it = d->create_mapping(QModelIndex());
1820  if (it.value()->source_rows.count() * it.value()->source_columns.count() > 0)
1821  return QAbstractProxyModel::setHeaderData(section, orientation, value, role);
1822  int source_section;
1823  if (orientation == Qt::Vertical) {
1824  if (section < 0 || section >= it.value()->source_rows.count())
1825  return false;
1826  source_section = it.value()->source_rows.at(section);
1827  } else {
1828  if (section < 0 || section >= it.value()->source_columns.count())
1829  return false;
1830  source_section = it.value()->source_columns.at(section);
1831  }
1832  return d->model->setHeaderData(source_section, orientation, value, role);
1833 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
#define Q_D(Class)
Definition: qglobal.h:2482
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
Reimplemented Function
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.

◆ setSortCaseSensitivity()

void QSortFilterProxyModel::setSortCaseSensitivity ( Qt::CaseSensitivity  cs)

Definition at line 2226 of file qsortfilterproxymodel.cpp.

2227 {
2229  if (d->sort_casesensitivity == cs)
2230  return;
2231 
2232  d->sort_casesensitivity = cs;
2233  d->sort();
2234 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ setSortLocaleAware()

void QSortFilterProxyModel::setSortLocaleAware ( bool  on)

Definition at line 2254 of file qsortfilterproxymodel.cpp.

2255 {
2257  if (d->sort_localeaware == on)
2258  return;
2259 
2260  d->sort_localeaware = on;
2261  d->sort();
2262 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ setSortRole()

void QSortFilterProxyModel::setSortRole ( int  role)

Definition at line 2362 of file qsortfilterproxymodel.cpp.

2363 {
2365  if (d->sort_role == role)
2366  return;
2367  d->sort_role = role;
2368  d->sort();
2369 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ setSourceModel()

void QSortFilterProxyModel::setSourceModel ( QAbstractItemModel sourceModel)
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 1597 of file qsortfilterproxymodel.cpp.

1598 {
1600 
1601  beginResetModel();
1602 
1604  this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex)));
1605 
1607  this, SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int)));
1608 
1610  this, SLOT(_q_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
1611 
1612  disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
1613  this, SLOT(_q_sourceRowsInserted(QModelIndex,int,int)));
1614 
1616  this, SLOT(_q_sourceColumnsAboutToBeInserted(QModelIndex,int,int)));
1617 
1618  disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),
1619  this, SLOT(_q_sourceColumnsInserted(QModelIndex,int,int)));
1620 
1622  this, SLOT(_q_sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
1623 
1624  disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
1625  this, SLOT(_q_sourceRowsRemoved(QModelIndex,int,int)));
1626 
1628  this, SLOT(_q_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)));
1629 
1630  disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
1631  this, SLOT(_q_sourceColumnsRemoved(QModelIndex,int,int)));
1632 
1634  this, SLOT(_q_sourceLayoutAboutToBeChanged()));
1635 
1636  disconnect(d->model, SIGNAL(layoutChanged()),
1637  this, SLOT(_q_sourceLayoutChanged()));
1638 
1639  disconnect(d->model, SIGNAL(modelAboutToBeReset()), this, SLOT(_q_sourceAboutToBeReset()));
1640  disconnect(d->model, SIGNAL(modelReset()), this, SLOT(_q_sourceReset()));
1641 
1643 
1645  this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex)));
1646 
1647  connect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
1648  this, SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int)));
1649 
1650  connect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
1651  this, SLOT(_q_sourceRowsAboutToBeInserted(QModelIndex,int,int)));
1652 
1653  connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
1654  this, SLOT(_q_sourceRowsInserted(QModelIndex,int,int)));
1655 
1657  this, SLOT(_q_sourceColumnsAboutToBeInserted(QModelIndex,int,int)));
1658 
1659  connect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),
1660  this, SLOT(_q_sourceColumnsInserted(QModelIndex,int,int)));
1661 
1662  connect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
1663  this, SLOT(_q_sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
1664 
1665  connect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
1666  this, SLOT(_q_sourceRowsRemoved(QModelIndex,int,int)));
1667 
1669  this, SLOT(_q_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)));
1670 
1671  connect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
1672  this, SLOT(_q_sourceColumnsRemoved(QModelIndex,int,int)));
1673 
1675  this, SLOT(_q_sourceLayoutAboutToBeChanged()));
1676 
1677  connect(d->model, SIGNAL(layoutChanged()),
1678  this, SLOT(_q_sourceLayoutChanged()));
1679 
1680  connect(d->model, SIGNAL(modelAboutToBeReset()), this, SLOT(_q_sourceAboutToBeReset()));
1681  connect(d->model, SIGNAL(modelReset()), this, SLOT(_q_sourceReset()));
1682 
1683  d->_q_clearMapping();
1684  endResetModel();
1685  if (d->update_source_sort_column() && d->dynamic_sortfilter)
1686  d->sort();
1687 }
double d
Definition: qnumeric_p.h:62
virtual void setSourceModel(QAbstractItemModel *sourceModel)
Sets the given sourceModel to be processed by the proxy model.
#define SLOT(a)
Definition: qobjectdefs.h:226
void columnsInserted(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been inserted into the model.
#define Q_D(Class)
Definition: qglobal.h:2482
void endResetModel()
Completes a model reset operation.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last)
This signal is emitted just before columns are inserted into the model.
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
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 rece...
Definition: qobject.cpp:2580
void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last)
This signal is emitted just before rows are inserted into the model.
void modelAboutToBeReset()
This signal is emitted when reset() is called, before the model&#39;s internal state (e.
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted just before columns are removed from the model.
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.
Definition: qobject.cpp:2895
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
void headerDataChanged(Qt::Orientation orientation, int first, int last)
This signal is emitted whenever a header is changed.
void rowsInserted(const QModelIndex &parent, int first, int last)
This signal is emitted after rows have been inserted into the model.
The QModelIndex class is used to locate data in a data model.
void modelReset()
This signal is emitted when reset() is called, after the model&#39;s internal state (e.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This signal is emitted whenever the data in an existing item changes.
void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted just before rows are removed from the model.
Orientation
Definition: qnamespace.h:174
void rowsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after rows have been removed from the model.
void columnsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been removed from the model.
void beginResetModel()
Begins a model reset operation.

◆ sort()

void QSortFilterProxyModel::sort ( int  column,
Qt::SortOrder  order = Qt::AscendingOrder 
)
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 2086 of file qsortfilterproxymodel.cpp.

2087 {
2089  if (d->dynamic_sortfilter && d->proxy_sort_column == column && d->sort_order == order)
2090  return;
2091  d->sort_order = order;
2092  d->proxy_sort_column = column;
2093  d->update_source_sort_column();
2094  d->sort();
2095 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ sortCaseSensitivity()

Qt::CaseSensitivity QSortFilterProxyModel::sortCaseSensitivity ( ) const

◆ sortColumn()

int QSortFilterProxyModel::sortColumn ( ) const

the column currently used for sorting

Since
4.5

This returns the most recently used sort column.

Definition at line 2106 of file qsortfilterproxymodel.cpp.

2107 {
2108  Q_D(const QSortFilterProxyModel);
2109  return d->proxy_sort_column;
2110 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ sortOrder()

Qt::SortOrder QSortFilterProxyModel::sortOrder ( ) const

the order currently used for sorting

Since
4.5

This returns the most recently used sort order.

Definition at line 2121 of file qsortfilterproxymodel.cpp.

2122 {
2123  Q_D(const QSortFilterProxyModel);
2124  return d->sort_order;
2125 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

◆ sortRole()

int QSortFilterProxyModel::sortRole ( ) const

Referenced by setDynamicSortFilter().

◆ span()

QSize QSortFilterProxyModel::span ( const QModelIndex index) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 2074 of file qsortfilterproxymodel.cpp.

2075 {
2076  Q_D(const QSortFilterProxyModel);
2077  QModelIndex source_index = mapToSource(index);
2078  if (index.isValid() && !source_index.isValid())
2079  return QSize();
2080  return d->model->span(source_index);
2081 }
double d
Definition: qnumeric_p.h:62
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source model index corresponding to the given proxyIndex from the sorting filter model...
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
The QModelIndex class is used to locate data in a data model.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ supportedDropActions()

Qt::DropActions QSortFilterProxyModel::supportedDropActions ( ) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 1859 of file qsortfilterproxymodel.cpp.

1860 {
1861  Q_D(const QSortFilterProxyModel);
1862  return d->model->supportedDropActions();
1863 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...

Friends and Related Functions

◆ QSortFilterProxyModelGreaterThan

Definition at line 64 of file qsortfilterproxymodel.h.

◆ QSortFilterProxyModelLessThan

Definition at line 63 of file qsortfilterproxymodel.h.

Properties

◆ dynamicSortFilter

bool QSortFilterProxyModel::dynamicSortFilter
private

whether the proxy model is dynamically sorted and filtered whenever the contents of the source model change

Since
4.2

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.

◆ filterCaseSensitivity

Qt::CaseSensitivity QSortFilterProxyModel::filterCaseSensitivity
private

the case sensitivity of the QRegExp pattern used to filter the contents of the source model

By default, the filter is case sensitive.

See also
filterRegExp, sortCaseSensitivity

Definition at line 70 of file qsortfilterproxymodel.h.

◆ filterKeyColumn

int QSortFilterProxyModel::filterKeyColumn
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.

◆ filterRegExp

QRegExp QSortFilterProxyModel::filterRegExp
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.

See also
filterCaseSensitivity, setFilterWildcard(), setFilterFixedString()

Definition at line 67 of file qsortfilterproxymodel.h.

◆ filterRole

int QSortFilterProxyModel::filterRole
private

the item role that is used to query the source model's data when filtering items

Since
4.2

The default value is Qt::DisplayRole.

See also
filterAcceptsRow()

Definition at line 74 of file qsortfilterproxymodel.h.

◆ isSortLocaleAware

bool QSortFilterProxyModel::isSortLocaleAware
private

the local aware setting used for comparing strings when sorting

Since
4.3

By default, sorting is not local aware.

See also
sortCaseSensitivity, lessThan()

Definition at line 72 of file qsortfilterproxymodel.h.

◆ sortCaseSensitivity

Qt::CaseSensitivity QSortFilterProxyModel::sortCaseSensitivity
private

the case sensitivity setting used for comparing strings when sorting

Since
4.2

By default, sorting is case sensitive.

See also
filterCaseSensitivity, lessThan()

Definition at line 71 of file qsortfilterproxymodel.h.

◆ sortRole

int QSortFilterProxyModel::sortRole
private

the item role that is used to query the source model's data when sorting items

Since
4.2

The default value is Qt::DisplayRole.

See also
lessThan()

Definition at line 73 of file qsortfilterproxymodel.h.


The documentation for this class was generated from the following files: