Qyoto
4.0.5
Qyoto is a C# language binding for Qt
|
The QSortFilterProxyModel class provides support for sorting and filtering data passed between another model and a view. More...
Public Member Functions | |
QSortFilterProxyModel (QObject parent=null) | |
| |
override void | CreateProxy () |
override QModelIndex | Buddy (QModelIndex index) |
| |
override bool | CanFetchMore (QModelIndex parent) |
| |
new void | Clear () |
| |
new int | ColumnCount () |
| |
override int | ColumnCount (QModelIndex parent) |
| |
override object | Data (QModelIndex index, int role=(int) Qt.ItemDataRole.DisplayRole) |
| |
override bool | DropMimeData (QMimeData data, Qt.DropAction action, int row, int column, QModelIndex parent) |
| |
override void | FetchMore (QModelIndex parent) |
| |
override Qt.ItemFlag | Flags (QModelIndex index) |
| |
new bool | HasChildren () |
| |
override bool | HasChildren (QModelIndex parent) |
| |
override object | HeaderData (int section, Qt.Orientation orientation, int role=(int) Qt.ItemDataRole.DisplayRole) |
| |
new QModelIndex | Index (int row, int column) |
| |
override QModelIndex | Index (int row, int column, QModelIndex parent) |
| |
new bool | InsertColumns (int column, int count) |
| |
override bool | InsertColumns (int column, int count, QModelIndex parent) |
| |
new bool | InsertRows (int row, int count) |
| |
override bool | InsertRows (int row, int count, QModelIndex parent) |
| |
new void | Invalidate () |
| |
override QModelIndex | MapFromSource (QModelIndex sourceIndex) |
| |
override QItemSelection | MapSelectionFromSource (QItemSelection sourceSelection) |
| |
override QItemSelection | MapSelectionToSource (QItemSelection proxySelection) |
| |
override QModelIndex | MapToSource (QModelIndex proxyIndex) |
| |
override System.Collections.Generic.List < QModelIndex > | Match (QModelIndex start, int role, object value, int hits=1, Qt.MatchFlag flags=Qt.MatchFlag.MatchStartsWith|Qt.MatchFlag.MatchWrap) |
| |
override QMimeData | MimeData (System.Collections.Generic.List< QModelIndex > indexes) |
| |
override System.Collections.Generic.List < string > | MimeTypes () |
| |
new QObject | parent () |
| |
override QModelIndex | Parent (QModelIndex child) |
| |
new bool | RemoveColumns (int column, int count) |
| |
override bool | RemoveColumns (int column, int count, QModelIndex parent) |
| |
new bool | RemoveRows (int row, int count) |
| |
override bool | RemoveRows (int row, int count, QModelIndex parent) |
| |
new int | RowCount () |
| |
override int | RowCount (QModelIndex parent) |
| |
override bool | SetData (QModelIndex index, object value, int role=(int) Qt.ItemDataRole.EditRole) |
| |
new void | SetFilterFixedString (string pattern) |
| |
new void | SetFilterRegExp (string pattern) |
new void | SetFilterWildcard (string pattern) |
| |
override bool | SetHeaderData (int section, Qt.Orientation orientation, object value, int role=(int) Qt.ItemDataRole.EditRole) |
| |
override void | Sort (int column, Qt.SortOrder order=Qt.SortOrder.AscendingOrder) |
| |
new int | SortColumn () |
| |
new Qt.SortOrder | SortOrder () |
| |
override QSize | Span (QModelIndex index) |
| |
override Qt.DropAction | SupportedDropActions () |
| |
new void | Dispose () |
Public Member Functions inherited from QtGui.QAbstractProxyModel | |
QAbstractProxyModel (QObject parent=null) | |
| |
new bool | HasChildren () |
| |
override System.Collections.Generic.Dictionary < System.Int32, System.Object > | ItemData (QModelIndex index) |
| |
override void | Revert () |
| |
override bool | SetItemData (QModelIndex index, System.Collections.Generic.Dictionary< System.Int32, System.Object > roles) |
| |
override bool | Submit () |
| |
new void | Dispose () |
Public Member Functions inherited from QtCore.QAbstractItemModel | |
QAbstractItemModel (QObject parent=null) | |
| |
new bool | HasChildren () |
| |
new bool | HasIndex (int row, int column) |
| |
new bool | HasIndex (int row, int column, QModelIndex parent) |
| |
new QModelIndex | Index (int row, int column) |
| |
new bool | InsertColumn (int column) |
| |
new bool | InsertColumn (int column, QModelIndex parent) |
| |
new bool | InsertColumns (int column, int count) |
| |
new bool | InsertRow (int row) |
| |
new bool | InsertRow (int row, QModelIndex parent) |
| |
new bool | InsertRows (int row, int count) |
| |
new QObject | Parent () |
| |
new bool | RemoveColumn (int column) |
| |
new bool | RemoveColumn (int column, QModelIndex parent) |
| |
new bool | RemoveColumns (int column, int count) |
| |
new bool | RemoveRow (int row) |
| |
new bool | RemoveRow (int row, QModelIndex parent) |
| |
new bool | RemoveRows (int row, int count) |
| |
new System.Collections.Generic.Dictionary < System.Int32, QByteArray > | RoleNames () |
| |
new int | RowCount () |
| |
new QModelIndex | Sibling (int row, int column, QModelIndex idx) |
| |
new void | Dispose () |
Public Member Functions inherited from QtCore.QObject | |
QObject (QObject parent=null) | |
| |
new bool | BlockSignals (bool b) |
| |
new System.Collections.Generic.List < QObject > | Children () |
| |
new bool | Connect (QObject sender, string signal, string member, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection) |
| |
new void | DeleteLater () |
| |
new bool | Disconnect (QObject receiver, string member=null) |
| |
new bool | Disconnect (string signal=null, QObject receiver=null, string member=null) |
| |
new void | DumpObjectInfo () |
| |
new void | DumpObjectTree () |
| |
new System.Collections.Generic.List < QByteArray > | DynamicPropertyNames () |
| |
virtual bool | OnEvent (QEvent arg1) |
| |
virtual bool | EventFilter (QObject arg1, QEvent arg2) |
| |
new bool | Inherits (string classname) |
| |
new void | InstallEventFilter (QObject arg1) |
| |
new bool | IsWidgetType () |
| |
new void | KillTimer (int id) |
| |
new object | Property (string name) |
| |
new void | RemoveEventFilter (QObject arg1) |
| |
new bool | SetProperty (string name, object value) |
| |
new void | SetUserData (uint id, QObjectUserData data) |
new bool | SignalsBlocked () |
| |
new int | StartTimer (int interval) |
| |
new QObjectUserData | UserData (uint id) |
new void | Dispose () |
Public Member Functions inherited from QtCore.Qt | |
delegate QTextStream | FuncQTextStreamQTextStream (QTextStream qTextStream) |
delegate string | FuncStringQByteArray (QByteArray qByteArray) |
delegate QByteArray | FuncQByteArrayString (string @string) |
delegate void | ActionQtMsgTypeString (QtMsgType qtMsgType, string @string) |
delegate QObject | FuncQObject () |
Static Public Member Functions | |
static string | Tr (string s, string c=null) |
static string | Tr (string s, string c, int n) |
static string | TrUtf8 (string s, string c=null) |
static string | TrUtf8 (string s, string c, int n) |
Static Public Member Functions inherited from QtGui.QAbstractProxyModel | |
static string | Tr (string s, string c=null) |
static string | Tr (string s, string c, int n) |
static string | TrUtf8 (string s, string c=null) |
static string | TrUtf8 (string s, string c, int n) |
Static Public Member Functions inherited from QtCore.QAbstractItemModel | |
static string | Tr (string s, string c=null) |
static string | Tr (string s, string c, int n) |
static string | TrUtf8 (string s, string c=null) |
static string | TrUtf8 (string s, string c, int n) |
Static Public Member Functions inherited from QtCore.QObject | |
static bool | Connect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod method, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection) |
| |
static bool | Connect (QObject sender, string signal, QObject receiver, string member, Qt.ConnectionType arg5=Qt.ConnectionType.AutoConnection) |
| |
static bool | Disconnect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod member) |
| |
static bool | Disconnect (QObject sender, string signal, QObject receiver, string member) |
| |
static uint | RegisterUserData () |
static string | Tr (string s, string c=null) |
| |
static string | Tr (string s, string c, int n) |
| |
static string | TrUtf8 (string s, string c=null) |
| |
static string | TrUtf8 (string s, string c, int n) |
| |
Static Public Member Functions inherited from QtCore.Qt | |
static QDataStream | Write (QDataStream s, object p) |
static QDataStream | Write (QDataStream arg1, QSizeF arg2) |
static QTextStream | Write (QTextStream s, Qt.FuncQTextStreamQTextStream f) |
static QDataStream | Write (QDataStream arg1, QPoint arg2) |
static QDataStream | Write (QDataStream arg1, QLineF arg2) |
static QDataStream | Write (QDataStream arg1, QPointF arg2) |
static QDataStream | Write (QDataStream arg1, QChar arg2) |
static QDataStream | Write (QDataStream arg1, QByteArray arg2) |
static QDataStream | Write (QDataStream arg1, QEasingCurve arg2) |
static QDataStream | Write (QDataStream arg1, QRectF arg2) |
static QDataStream | Write (QDataStream arg1, QDateTime arg2) |
static QDataStream | Write (QDataStream arg1, QUrl arg2) |
static QDataStream | Write (QDataStream arg1, QTime arg2) |
static QDataStream | Write (QDataStream arg1, QLocale arg2) |
static QDataStream | Write (QDataStream arg1, QBitArray arg2) |
static QDataStream | Write (QDataStream arg1, QUuid arg2) |
static QDataStream | Write (QDataStream arg1, QLine arg2) |
static QDataStream | Write (QDataStream arg1, QDate arg2) |
static QDataStream | Write (QDataStream @out, QRegExp regExp) |
static QDataStream | Write (QDataStream arg1, QRect arg2) |
static QDataStream | Write (QDataStream arg1, QSize arg2) |
static QDataStream | Write (QDataStream s, QVariant.Type p) |
static QDataStream | Write (QDataStream arg1, string arg2) |
static QDataStream | Write (QDataStream @out, System.Collections.Generic.List< string > list) |
static QDataStream | Read (QDataStream arg1, QChar arg2) |
static QDataStream | Read (QDataStream arg1, QLocale arg2) |
static QDataStream | Read (QDataStream arg1, QRect arg2) |
static QDataStream | Read (QDataStream arg1, QEasingCurve arg2) |
static QDataStream | Read (QDataStream arg1, QDate arg2) |
static QDataStream | Read (QDataStream arg1, QUrl arg2) |
static QDataStream | Read (QDataStream arg1, QUuid arg2) |
static QTextStream | Read (QTextStream s, Qt.FuncQTextStreamQTextStream f) |
static QDataStream | Read (QDataStream arg1, QLineF arg2) |
static QDataStream | Read (QDataStream arg1, QRectF arg2) |
static QDataStream | Read (QDataStream arg1, QPointF arg2) |
static QDataStream | Read (QDataStream arg1, QLine arg2) |
static QDataStream | Read (QDataStream arg1, QBitArray arg2) |
static QDataStream | Read (QDataStream arg1, QSize arg2) |
static QDataStream | Read (QDataStream arg1, QDateTime arg2) |
static QDataStream | Read (QDataStream arg1, QTime arg2) |
static QDataStream | Read (QDataStream arg1, QPoint arg2) |
static QDataStream | Read (QDataStream @in, QRegExp regExp) |
static QDataStream | Read (QDataStream s, object p) |
static QDataStream | Read (QDataStream arg1, QByteArray arg2) |
static QDataStream | Read (QDataStream arg1, QSizeF arg2) |
static QDataStream | Read (QDataStream arg1, string arg2) |
static QDataStream | Read (QDataStream s, QVariant.Type p) |
static QDataStream | Read (QDataStream @in, System.Collections.Generic.List< string > list) |
static double | qAcos (double v) |
static void | qAddPostRoutine (System.Action arg1) |
static string | qAppName () |
static double | qAsin (double v) |
static double | qAtan (double v) |
static double | qAtan2 (double x, double y) |
static void | qBadAlloc () |
static int | qCeil (double v) |
static ushort | qChecksum (string s, uint len) |
static QByteArray | qCompress (QByteArray data) |
static QByteArray | qCompress (QByteArray data, int compressionLevel=-1) |
static QByteArray | qCompress (Pointer< byte > data, int nbytes) |
static QByteArray | qCompress (Pointer< byte > data, int nbytes, int compressionLevel=-1) |
static double | qCos (double v) |
static double | qExp (double v) |
static double | qFabs (double v) |
static double | qFastCos (double x) |
static double | qFastSin (double x) |
static string | qFlagLocation (string method) |
static int | qFloor (double v) |
static bool | qFuzzyCompare (double p1, double p2) |
static bool | qFuzzyCompare (float p1, float p2) |
static bool | qFuzzyIsNull (double d) |
static bool | qFuzzyIsNull (float f) |
static uint | qHash (QBitArray key) |
static uint | qHash (QChar key) |
static uint | qHash (QStringRef key) |
static uint | qHash (QUrl url) |
static uint | qHash (QPersistentModelIndex index) |
static uint | qHash (QByteArray key) |
static uint | qHash (QModelIndex index) |
static uint | qHash (uint key) |
static uint | qHash (sbyte key) |
static uint | qHash (byte key) |
static uint | qHash (short key) |
static uint | qHash (NativeLong key) |
static uint | qHash (ushort key) |
static uint | qHash (long key) |
static uint | qHash (ulong key) |
static uint | qHash (int key) |
static uint | qHash (string key) |
static uint | qHash (NativeULong key) |
static double | qInf () |
static Qt.ActionQtMsgTypeString | qInstallMsgHandler (Qt.ActionQtMsgTypeString arg1) |
static int | qIntCast (float f) |
static int | qIntCast (double f) |
static bool | qIsFinite (double d) |
static bool | qIsFinite (float f) |
static bool | qIsInf (float f) |
static bool | qIsInf (double d) |
static bool | qIsNaN (float f) |
static bool | qIsNaN (double d) |
static bool | qIsNull (float f) |
static bool | qIsNull (double d) |
static double | qLn (double v) |
static double | qPow (double x, double y) |
static double | qQNaN () |
static void | qRegisterStaticPluginInstanceFunction (Qt.FuncQObject function) |
static void | qRemovePostRoutine (System.Action arg1) |
static int | qRound (double d) |
static long | qRound64 (double d) |
static double | qSNaN () |
static bool | qSharedBuild () |
static double | qSin (double v) |
static double | qSqrt (double v) |
static bool | qStringComparisonHelper (QStringRef s1, string s2) |
static double | qTan (double v) |
static QByteArray | qUncompress (QByteArray data) |
static QByteArray | qUncompress (Pointer< byte > data, int nbytes) |
static string | qVersion () |
static void | Qbswap_helper (Pointer< byte > src, Pointer< byte > dest, int size) |
static QByteArray | Qgetenv (string varName) |
static bool | Qputenv (string varName, QByteArray value) |
static int | Qrand () |
static void | Qsrand (uint seed) |
static int | Qstrcmp (QByteArray str1, QByteArray str2) |
static int | Qstrcmp (QByteArray str1, string str2) |
static int | Qstrcmp (string str1, QByteArray str2) |
static int | Qstrcmp (string str1, string str2) |
static Pointer< sbyte > | Qstrcpy (Pointer< sbyte > dst, string src) |
static Pointer< sbyte > | Qstrdup (string arg1) |
static int | Qstricmp (string arg1, string arg2) |
static uint | Qstrlen (string str) |
static int | Qstrncmp (string str1, string str2, uint len) |
static Pointer< sbyte > | Qstrncpy (Pointer< sbyte > dst, string src, uint len) |
static int | Qstrnicmp (string arg1, string arg2, uint len) |
static uint | Qstrnlen (string str, uint maxlen) |
static string | QtTrId (string id, int n=-1) |
Protected Member Functions | |
QSortFilterProxyModel (System.Type dummy) | |
virtual bool | FilterAcceptsColumn (int source_column, QModelIndex source_parent) |
| |
virtual bool | FilterAcceptsRow (int source_row, QModelIndex source_parent) |
| |
new void | FilterChanged () |
| |
new void | InvalidateFilter () |
| |
virtual bool | LessThan (QModelIndex left, QModelIndex right) |
| |
Protected Member Functions inherited from QtGui.QAbstractProxyModel | |
QAbstractProxyModel (System.Type dummy) | |
Protected Member Functions inherited from QtCore.QAbstractItemModel | |
QAbstractItemModel (System.Type dummy) | |
new void | BeginInsertColumns (QModelIndex parent, int first, int last) |
| |
new void | BeginInsertRows (QModelIndex parent, int first, int last) |
| |
new bool | BeginMoveColumns (QModelIndex sourceParent, int sourceFirst, int sourceLast, QModelIndex destinationParent, int destinationColumn) |
| |
new bool | BeginMoveRows (QModelIndex sourceParent, int sourceFirst, int sourceLast, QModelIndex destinationParent, int destinationRow) |
| |
new void | BeginRemoveColumns (QModelIndex parent, int first, int last) |
| |
new void | BeginRemoveRows (QModelIndex parent, int first, int last) |
| |
new void | BeginResetModel () |
| |
new void | ChangePersistentIndex (QModelIndex from, QModelIndex to) |
| |
new void | ChangePersistentIndexList (System.Collections.Generic.List< QModelIndex > from, System.Collections.Generic.List< QModelIndex > to) |
| |
new QModelIndex | CreateIndex (int row, int column) |
| |
new QModelIndex | CreateIndex (int row, int column, int id) |
| |
new QModelIndex | CreateIndex (int row, int column, uint id) |
| |
new void | OnDataChanged (QModelIndex topLeft, QModelIndex bottomRight) |
| |
new bool | DecodeData (int row, int column, QModelIndex parent, QDataStream stream) |
new void | EncodeData (System.Collections.Generic.List< QModelIndex > indexes, QDataStream stream) |
new void | EndInsertColumns () |
| |
new void | EndInsertRows () |
| |
new void | EndMoveColumns () |
| |
new void | EndMoveRows () |
| |
new void | EndRemoveColumns () |
| |
new void | EndRemoveRows () |
| |
new void | EndResetModel () |
| |
new void | OnHeaderDataChanged (Qt.Orientation orientation, int first, int last) |
| |
new void | OnLayoutAboutToBeChanged () |
| |
new void | OnLayoutChanged () |
| |
new System.Collections.Generic.List < QModelIndex > | PersistentIndexList () |
| |
new void | Reset () |
| |
new void | ResetInternalData () |
| |
new void | SetRoleNames (System.Collections.Generic.Dictionary< System.Int32, QByteArray > roleNames) |
| |
Protected Member Functions inherited from QtCore.QObject | |
QObject (System.Type dummy) | |
virtual void | OnChildEvent (QChildEvent arg1) |
| |
virtual void | ConnectNotify (string signal) |
| |
virtual void | OnCustomEvent (QEvent arg1) |
| |
new void | OnDestroyed (QObject arg1=null) |
| |
virtual void | DisconnectNotify (string signal) |
| |
new int | Receivers (string signal) |
| |
new QObject | Sender () |
| |
new int | SenderSignalIndex () |
| |
virtual void | OnTimerEvent (QTimerEvent arg1) |
| |
Properties | |
override QAbstractItemModel | SourceModel [get, set] |
| |
new QRegExp | FilterRegExp [get, set] |
| |
new int | FilterKeyColumn [get, set] |
| |
new bool | DynamicSortFilter [get, set] |
| |
new Qt.CaseSensitivity | FilterCaseSensitivity [get, set] |
| |
new Qt.CaseSensitivity | SortCaseSensitivity [get, set] |
| |
new bool | IsSortLocaleAware [get, set] |
| |
new int | SortRole [get, set] |
| |
new int | FilterRole [get, set] |
| |
static new QMetaObject | StaticMetaObject [get] |
new IQSortFilterProxyModelSignals | Emit [get] |
Properties inherited from QtGui.QAbstractProxyModel | |
virtual QAbstractItemModel | SourceModel [get, set] |
| |
static new QMetaObject | StaticMetaObject [get] |
new IQAbstractProxyModelSignals | Emit [get] |
Properties inherited from QtCore.QAbstractItemModel | |
Slot< QModelIndex, QModelIndex > | DataChanged |
| |
Slot< Qt.Orientation, System.Int32, System.Int32 > | HeaderDataChanged |
| |
Slot | LayoutChanged |
| |
Slot | LayoutAboutToBeChanged |
| |
Slot< QModelIndex, System.Int32, System.Int32 > | RowsAboutToBeInserted |
Slot< QModelIndex, System.Int32, System.Int32 > | RowsInserted |
Slot< QModelIndex, System.Int32, System.Int32 > | RowsAboutToBeRemoved |
Slot< QModelIndex, System.Int32, System.Int32 > | RowsRemoved |
Slot< QModelIndex, System.Int32, System.Int32 > | ColumnsAboutToBeInserted |
Slot< QModelIndex, System.Int32, System.Int32 > | ColumnsInserted |
Slot< QModelIndex, System.Int32, System.Int32 > | ColumnsAboutToBeRemoved |
Slot< QModelIndex, System.Int32, System.Int32 > | ColumnsRemoved |
Slot | ModelAboutToBeReset |
Slot | ModelReset |
Slot< QModelIndex, System.Int32, System.Int32, QModelIndex, System.Int32 > | RowsAboutToBeMoved |
Slot< QModelIndex, System.Int32, System.Int32, QModelIndex, System.Int32 > | RowsMoved |
Slot< QModelIndex, System.Int32, System.Int32, QModelIndex, System.Int32 > | ColumnsAboutToBeMoved |
Slot< QModelIndex, System.Int32, System.Int32, QModelIndex, System.Int32 > | ColumnsMoved |
new Qt.DropAction | SupportedDragActions [get, set] |
| |
static new QMetaObject | StaticMetaObject [get] |
new IQAbstractItemModelSignals | Emit [get] |
Properties inherited from QtCore.QObject | |
virtual EventHandler < QEventArgs< QChildEvent > > | ChildEvent |
| |
virtual EventHandler < QEventArgs< QEvent > > | CustomEvent |
| |
virtual EventHandler < QEventArgs< QEvent > > | Event |
| |
virtual EventHandler < QEventArgs< QTimerEvent > > | TimerEvent |
| |
Slot< QObject > | DestroyedQObject |
Slot | Destroyed |
| |
new QObject | Parent [get, set] |
| |
virtual System.IntPtr | SmokeObject [get, set] |
new string | ObjectName [get, set] |
| |
static new QMetaObject | StaticMetaObject [get] |
| |
static new QMetaObject | StaticQtMetaObject [get] |
new IQObjectSignals | Emit [get] |
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:
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);
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(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 QModelIndexes to sorted/filtered model indexes or vice versa, use mapToSource(), mapFromSource(), mapSelectionToSource(), and mapSelectionFromSource().
Note: 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 dynamicSortFilter property.
The Basic Sort/Filter Model and 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.
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 sortCaseSensitivity property.
Custom sorting behavior is achieved by subclassing QSortFilterProxyModel and reimplementing lessThan(), which is used to compare items. For example:
bool MySortFilterProxyModel::lessThan(const QModelIndex &left,
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:
proxyModel->setFilterRegExp(QRegExp(".png", Qt::CaseInsensitive,
QRegExp::FixedString));
proxyModel->setFilterKeyColumn(1);
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, and QIdentityProxyModel.
|
protected |
QtGui.QSortFilterProxyModel.QSortFilterProxyModel | ( | QObject | parent = null | ) |
Constructs a sorting filter model with the given parent.
|
virtual |
Reimplemented from QAbstractItemModel::buddy().
Reimplemented from QtGui.QAbstractProxyModel.
|
virtual |
Reimplemented from QAbstractItemModel::canFetchMore().
Reimplemented from QtGui.QAbstractProxyModel.
new void QtGui.QSortFilterProxyModel.Clear | ( | ) |
This function is obsolete. Use invalidate() instead.
new int QtGui.QSortFilterProxyModel.ColumnCount | ( | ) |
Reimplemented from QAbstractItemModel::columnCount().
override int QtGui.QSortFilterProxyModel.ColumnCount | ( | QModelIndex | parent | ) |
Reimplemented from QAbstractItemModel::columnCount().
|
virtual |
Reimplemented from QtGui.QAbstractProxyModel.
|
virtual |
Reimplemented from QAbstractItemModel::data().
See also setData().
Reimplemented from QtGui.QAbstractProxyModel.
new void QtGui.QSortFilterProxyModel.Dispose | ( | ) |
|
virtual |
Reimplemented from QAbstractItemModel::dropMimeData().
Reimplemented from QtCore.QAbstractItemModel.
|
virtual |
Reimplemented from QAbstractItemModel::fetchMore().
Reimplemented from QtGui.QAbstractProxyModel.
|
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(), and setFilterWildcard().
|
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(), and setFilterWildcard().
|
protected |
This function is obsolete. Use invalidateFilter() instead.
|
virtual |
Reimplemented from QAbstractItemModel::flags().
Reimplemented from QtGui.QAbstractProxyModel.
new bool QtGui.QSortFilterProxyModel.HasChildren | ( | ) |
Reimplemented from QAbstractItemModel::hasChildren().
|
virtual |
Reimplemented from QAbstractItemModel::hasChildren().
Reimplemented from QtGui.QAbstractProxyModel.
|
virtual |
Reimplemented from QAbstractItemModel::headerData().
See also setHeaderData().
Reimplemented from QtGui.QAbstractProxyModel.
new QModelIndex QtGui.QSortFilterProxyModel.Index | ( | int | row, |
int | column | ||
) |
Reimplemented from QAbstractItemModel::index().
|
virtual |
Reimplemented from QAbstractItemModel::index().
Implements QtCore.QAbstractItemModel.
new bool QtGui.QSortFilterProxyModel.InsertColumns | ( | int | column, |
int | count | ||
) |
Reimplemented from QAbstractItemModel::insertColumns().
|
virtual |
Reimplemented from QAbstractItemModel::insertColumns().
Reimplemented from QtCore.QAbstractItemModel.
new bool QtGui.QSortFilterProxyModel.InsertRows | ( | int | row, |
int | count | ||
) |
Reimplemented from QAbstractItemModel::insertRows().
|
virtual |
Reimplemented from QAbstractItemModel::insertRows().
Reimplemented from QtCore.QAbstractItemModel.
new void QtGui.QSortFilterProxyModel.Invalidate | ( | ) |
Invalidates the current sorting and filtering.
This function was introduced in Qt 4.3.
See also invalidateFilter().
|
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.
This function was introduced in Qt 4.3.
See also invalidate().
|
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:
QVariant::Int
QVariant::UInt
QVariant::LongLong
QVariant::ULongLong
QVariant::Double
QVariant::Char
QVariant::Date
QVariant::Time
QVariant::DateTime
QVariant::String
Any other type will be converted to a QString using QVariant::toString().
Comparison of QStrings is case sensitive by default; this can be changed using the sortCaseSensitivity property.
By default, the Qt::DisplayRole associated with the QModelIndexes is used for comparisons. This can be changed by setting the sortRole property.
Note: The indices passed in correspond to the source model.
See also sortRole, sortCaseSensitivity, and dynamicSortFilter.
|
virtual |
Reimplemented from QAbstractProxyModel::mapFromSource().
Returns the model index in the QSortFilterProxyModel given the sourceIndex from the source model.
See also mapToSource().
Implements QtGui.QAbstractProxyModel.
|
virtual |
Reimplemented from QAbstractProxyModel::mapSelectionFromSource().
Reimplemented from QtGui.QAbstractProxyModel.
|
virtual |
Reimplemented from QAbstractProxyModel::mapSelectionToSource().
Reimplemented from QtGui.QAbstractProxyModel.
|
virtual |
Reimplemented from QAbstractProxyModel::mapToSource().
Returns the source model index corresponding to the given proxyIndex from the sorting filter model.
See also mapFromSource().
Implements QtGui.QAbstractProxyModel.
|
virtual |
Reimplemented from QAbstractItemModel::match().
Reimplemented from QtCore.QAbstractItemModel.
|
virtual |
Reimplemented from QAbstractItemModel::mimeData().
Reimplemented from QtGui.QAbstractProxyModel.
|
virtual |
Reimplemented from QAbstractItemModel::mimeTypes().
Reimplemented from QtGui.QAbstractProxyModel.
new QObject QtGui.QSortFilterProxyModel.parent | ( | ) |
Reimplemented from QAbstractItemModel::parent().
|
virtual |
Reimplemented from QAbstractItemModel::parent().
Implements QtCore.QAbstractItemModel.
new bool QtGui.QSortFilterProxyModel.RemoveColumns | ( | int | column, |
int | count | ||
) |
Reimplemented from QAbstractItemModel::removeColumns().
|
virtual |
Reimplemented from QAbstractItemModel::removeColumns().
Reimplemented from QtCore.QAbstractItemModel.
new bool QtGui.QSortFilterProxyModel.RemoveRows | ( | int | row, |
int | count | ||
) |
Reimplemented from QAbstractItemModel::removeRows().
|
virtual |
Reimplemented from QAbstractItemModel::removeRows().
Reimplemented from QtCore.QAbstractItemModel.
new int QtGui.QSortFilterProxyModel.RowCount | ( | ) |
Reimplemented from QAbstractItemModel::rowCount().
|
virtual |
Reimplemented from QAbstractItemModel::rowCount().
Implements QtCore.QAbstractItemModel.
|
virtual |
Reimplemented from QAbstractItemModel::setData().
See also data().
Reimplemented from QtGui.QAbstractProxyModel.
new void QtGui.QSortFilterProxyModel.SetFilterFixedString | ( | string | pattern | ) |
Sets the fixed string used to filter the contents of the source model to the given pattern.
See also setFilterCaseSensitivity(), setFilterRegExp(), setFilterWildcard(), and filterRegExp().
new void QtGui.QSortFilterProxyModel.SetFilterRegExp | ( | string | pattern | ) |
new void QtGui.QSortFilterProxyModel.SetFilterWildcard | ( | string | pattern | ) |
Sets the wildcard expression used to filter the contents of the source model to the given pattern.
See also setFilterCaseSensitivity(), setFilterRegExp(), setFilterFixedString(), and filterRegExp().
|
virtual |
Reimplemented from QAbstractItemModel::setHeaderData().
See also headerData().
Reimplemented from QtGui.QAbstractProxyModel.
|
virtual |
Reimplemented from QAbstractItemModel::sort().
Reimplemented from QtGui.QAbstractProxyModel.
new int QtGui.QSortFilterProxyModel.SortColumn | ( | ) |
the column currently used for sorting
This returns the most recently used sort column.
This function was introduced in Qt 4.5.
new Qt.SortOrder QtGui.QSortFilterProxyModel.SortOrder | ( | ) |
the order currently used for sorting
This returns the most recently used sort order.
This function was introduced in Qt 4.5.
|
virtual |
Reimplemented from QAbstractItemModel::span().
Reimplemented from QtGui.QAbstractProxyModel.
|
virtual |
Reimplemented from QAbstractItemModel::supportedDropActions().
Reimplemented from QtGui.QAbstractProxyModel.
|
static |
|
static |
|
static |
|
static |
|
getset |
This property holds 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., addItem(), will not work as expected. An alternative is to set dynamicSortFilter to false and call sort() after adding items to the QComboBox.
The default value is false.
This property was introduced in Qt 4.2.
|
getprotected |
|
getset |
This property holds the case sensitivity of the QRegExp pattern used to filter the contents of the source model.
By default, the filter is case sensitive.
|
getset |
This property holds 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.
|
getset |
This property holds 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.
|
getset |
This property holds the item role that is used to query the source model's data when filtering items.
The default value is Qt::DisplayRole.
This property was introduced in Qt 4.2.
|
getset |
This property holds the local aware setting used for comparing strings when sorting.
By default, sorting is not local aware.
This property was introduced in Qt 4.3.
|
getset |
This property holds the case sensitivity setting used for comparing strings when sorting.
By default, sorting is case sensitive.
This property was introduced in Qt 4.2.
|
getset |
This property holds the item role that is used to query the source model's data when sorting items.
The default value is Qt::DisplayRole.
This property was introduced in Qt 4.2.
|
getset |
Reimplemented from QAbstractProxyModel::setSourceModel().
|
staticget |