Qt Jambi Home

com.trolltech.qt.gui
Class QSortFilterProxyModel

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.core.QAbstractItemModel
                  extended by com.trolltech.qt.gui.QAbstractProxyModel
                      extended by com.trolltech.qt.gui.QSortFilterProxyModel
All Implemented Interfaces:
QtJambiInterface

public class QSortFilterProxyModel
extends QAbstractProxyModel

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.

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 you 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);

Filtering

In addition to sorting, QSortFilterProxyModel can be used to hide items that don't 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, 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, note that reset returns the proxy model to its original state, losing selection information, and will cause the proxy model to be repopulated.

Subclassing

Note: Some general guidelines for subclassing models are available in the Model Subclassing Reference.

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.

See Also:
QAbstractProxyModel, QAbstractItemModel, Model/View Programming, Sort/Filter Model Example, Custom Sort/Filter Model Example

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 
Fields inherited from class com.trolltech.qt.core.QAbstractItemModel
dataChanged, headerDataChanged, layoutAboutToBeChanged, layoutChanged
 
Constructor Summary
QSortFilterProxyModel()
          Equivalent to QSortFilterProxyModel(0).
QSortFilterProxyModel(QObject parent)
          Constructs a sorting filter model with the given parent.
 
Method Summary
 QModelIndex buddy(QModelIndex index)
          

Returns a model index for the buddy of the item represented by index.

 boolean canFetchMore(QModelIndex parent)
          

Returns true if there is more data available for parent, otherwise false.

 int columnCount(QModelIndex parent)
          

Returns the number of columns for the children of the given parent.

 java.lang.Object data(QModelIndex index, int role)
          

Returns the data stored under the given role for the item referred to by the index.

 boolean dropMimeData(QMimeData data, Qt.DropAction action, int row, int column, QModelIndex parent)
          

Handles the data supplied by a drag and drop operation that ended with the given action.

 boolean dynamicSortFilter()
          Returns whether the proxy model is dynamically sorted and filtered whenever the contents of the source model change.
 void fetchMore(QModelIndex parent)
          

Fetches any available data for the items with the parent specified by the parent index.

protected  boolean filterAcceptsColumn(int source_column, QModelIndex source_parent)
          Returns true if the value in the item in the column indicated by the given source_column and source_parent should be included in the model.
protected  boolean filterAcceptsRow(int source_row, QModelIndex source_parent)
          Returns true if the value in the item in the row indicated by the given source_row and source_parent should be included in the model.
 Qt.CaseSensitivity filterCaseSensitivity()
          Returns the case sensitivity of the QRegExp pattern used to filter the contents of the source model.
 int filterKeyColumn()
          Returns the column where the key used to filter the contents of the source model is read from..
 QRegExp filterRegExp()
          Returns the QRegExp used to filter the contents of the source model.
 int filterRole()
          Returns the item role that is used to query the source model's data when filtering items.
 Qt.ItemFlags flags(QModelIndex index)
          

Returns the item flags for the given index.

The base class implementation returns a combination of flags that enables the item (ItemIsEnabled) and allows it to be selected (ItemIsSelectable).

static QSortFilterProxyModel fromNativePointer(QNativePointer nativePointer)
          This function returns the QSortFilterProxyModel instance pointed to by nativePointer
 boolean hasChildren(QModelIndex parent)
          

Returns true if parent has any children; otherwise returns false.

 java.lang.Object headerData(int section, Qt.Orientation orientation, int role)
          

Returns the data for the given role and section in the header with the specified orientation.

 QModelIndex index(int row, int column, QModelIndex parent)
          

Returns the index of the item in the model specified by the given row, column and parent index.

 boolean insertColumns(int column, int count, QModelIndex parent)
          

On models that support this, inserts count new columns into the model before the given column.

 boolean insertRows(int row, int count, QModelIndex parent)
          

On models that support this, inserts count rows into the model before the given row.

 void invalidate()
          Invalidates the current sorting and filtering.
protected  void invalidateFilter()
          Invalidates the current filtering.
 boolean isSortLocaleAware()
          Returns the local aware setting used for comparing strings when sorting.
protected  boolean lessThan(QModelIndex left, QModelIndex right)
          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.
 QModelIndex mapFromSource(QModelIndex sourceIndex)
          Returns the model index in the QSortFilterProxyModel given the sourceIndex from the source model.
 QItemSelection mapSelectionFromSource(QItemSelection sourceSelection)
          

Returns a proxy selection mapped from the specified selection.

 QItemSelection mapSelectionToSource(QItemSelection proxySelection)
          

Returns a source selection mapped from the specified selection.

 QModelIndex mapToSource(QModelIndex proxyIndex)
          Returns the source model index corresponding to the given proxyIndex from the sorting filter model.
 java.util.List<QModelIndex> match(QModelIndex start, int role, java.lang.Object value, int hits, Qt.MatchFlags flags)
          Returns a list of indexes for the items in the column of the start index where the data stored under the given role matches the specified value.
 QMimeData mimeData(java.util.List<QModelIndex> indexes)
          Returns an object that contains serialized items of data corresponding to the list of indexes specified.
 java.util.List<java.lang.String> mimeTypes()
          

Returns a list of MIME types that can be used to describe a list of model indexes.

 QModelIndex parent(QModelIndex child)
          

Returns the parent of the model item with the given child, or QModelIndex() if it has no parent.

 boolean removeColumns(int column, int count, QModelIndex parent)
          

On models that support this, removes count columns starting with the given column under parent parent from the model.

 boolean removeRows(int row, int count, QModelIndex parent)
          

On models that support this, removes count rows starting with the given row under parent parent from the model.

 int rowCount(QModelIndex parent)
          

Returns the number of rows under the given parent.

 boolean setData(QModelIndex index, java.lang.Object value, int role)
          

Sets the role data for the item at index to value.

 void setDynamicSortFilter(boolean enable)
          Sets whether the proxy model is dynamically sorted and filtered whenever the contents of the source model change to enable.
 void setFilterCaseSensitivity(Qt.CaseSensitivity cs)
          Sets the case sensitivity of the QRegExp pattern used to filter the contents of the source model to cs.
 void setFilterFixedString(java.lang.String pattern)
          Sets the fixed string used to filter the contents of the source model to the given pattern.
 void setFilterKeyColumn(int column)
          Sets the column where the key used to filter the contents of the source model is read from.
 void setFilterRegExp(QRegExp regExp)
          Sets the QRegExp used to filter the contents of the source model to regExp.
 void setFilterRegExp(java.lang.String pattern)
          Sets the QRegExp used to filter the contents of the source model to pattern.
 void setFilterRole(int role)
          Sets the item role that is used to query the source model's data when filtering items to role.
 void setFilterWildcard(java.lang.String pattern)
          Sets the wildcard expression used to filter the contents of the source model to the given pattern.
 boolean setHeaderData(int section, Qt.Orientation orientation, java.lang.Object value, int role)
          

Sets the data for the given role and section in the header with the specified orientation to the value supplied.

 void setSortCaseSensitivity(Qt.CaseSensitivity cs)
          Sets the case sensitivity setting used for comparing strings when sorting to cs.
 void setSortLocaleAware(boolean on)
          Sets the local aware setting used for comparing strings when sorting to on.
 void setSortRole(int role)
          Sets the item role that is used to query the source model's data when sorting items to role.
 void setSourceModel(QAbstractItemModel sourceModel)
          

Sets the given sourceModel to be processed by the proxy model.

 void sort(int column, Qt.SortOrder order)
          

Sorts the model by column in the given order.

 Qt.CaseSensitivity sortCaseSensitivity()
          Returns the case sensitivity setting used for comparing strings when sorting.
 int sortRole()
          Returns the item role that is used to query the source model's data when sorting items.
 QSize span(QModelIndex index)
          

Returns the row and column span of the item represented by index.

 Qt.DropActions supportedDropActions()
          

Returns the drop actions supported by this model.

 
Methods inherited from class com.trolltech.qt.gui.QAbstractProxyModel
itemData, revert, sourceModel, submit
 
Methods inherited from class com.trolltech.qt.core.QAbstractItemModel
beginInsertColumns, beginInsertRows, beginRemoveColumns, beginRemoveRows, changePersistentIndex, changePersistentIndexList, columnCount, createIndex, createIndex, createIndex, data, data, data, decodeData, encodeData, endInsertColumns, endInsertRows, endRemoveColumns, endRemoveRows, hasChildren, hasIndex, hasIndex, headerData, index, insertColumn, insertColumn, insertColumns, insertRow, insertRow, insertRows, match, match, match, persistentIndexList, removeColumn, removeColumn, removeColumns, removeRow, removeRow, removeRows, reset, rowCount, setData, setData, setData, setHeaderData, setItemData, setSupportedDragActions, setSupportedDragActions, sibling, sort, supportedDragActions
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QSortFilterProxyModel

public QSortFilterProxyModel()

Equivalent to QSortFilterProxyModel(0).


QSortFilterProxyModel

public QSortFilterProxyModel(QObject parent)

Constructs a sorting filter model with the given parent.

Method Detail

dynamicSortFilter

public final boolean dynamicSortFilter()

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

The default value is false.

See Also:
setDynamicSortFilter

filterCaseSensitivity

public final Qt.CaseSensitivity filterCaseSensitivity()

Returns 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:
setFilterCaseSensitivity, filterRegExp, sortCaseSensitivity

filterKeyColumn

public final int filterKeyColumn()

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

See Also:
setFilterKeyColumn

filterRegExp

public final QRegExp filterRegExp()

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

See Also:
setFilterRegExp, filterCaseSensitivity, setFilterWildcard, setFilterFixedString

filterRole

public final int filterRole()

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

The default value is Qt::DisplayRole.

See Also:
setFilterRole, filterAcceptsRow

invalidate

public final void invalidate()

Invalidates the current sorting and filtering.

See Also:
invalidateFilter

invalidateFilter

protected final void invalidateFilter()

Invalidates the current filtering.

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

See Also:
invalidate

isSortLocaleAware

public final boolean isSortLocaleAware()

Returns the local aware setting used for comparing strings when sorting.

By default, sorting is not local aware.

See Also:
sortCaseSensitivity, lessThan

setDynamicSortFilter

public final void setDynamicSortFilter(boolean enable)

Sets whether the proxy model is dynamically sorted and filtered whenever the contents of the source model change to enable.

The default value is false.

See Also:
dynamicSortFilter

setFilterCaseSensitivity

public final void setFilterCaseSensitivity(Qt.CaseSensitivity cs)

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

By default, the filter is case sensitive.

See Also:
filterCaseSensitivity, filterRegExp, sortCaseSensitivity

setFilterFixedString

public final void setFilterFixedString(java.lang.String pattern)

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

See Also:
setFilterCaseSensitivity, setFilterRegExp, setFilterWildcard, filterRegExp

setFilterKeyColumn

public final void setFilterKeyColumn(int column)

Sets the column where the key used to filter the contents of the source model is read from. to column.

The default value is 0. If the value is -1, the keys will be read from all columns.

See Also:
filterKeyColumn

setFilterRegExp

public final void setFilterRegExp(java.lang.String pattern)

Sets the QRegExp used to filter the contents of the source model to pattern.

Setting this property overwrites the current filterCaseSensitivity. By default, the QRegExp is an empty string matching all contents.

See Also:
filterCaseSensitivity, setFilterWildcard, setFilterFixedString

setFilterRegExp

public final void setFilterRegExp(QRegExp regExp)

Sets the QRegExp used to filter the contents of the source model to regExp.

Setting this property overwrites the current filterCaseSensitivity. By default, the QRegExp is an empty string matching all contents.

See Also:
filterRegExp, filterCaseSensitivity, setFilterWildcard, setFilterFixedString

setFilterRole

public final void setFilterRole(int role)

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

The default value is Qt::DisplayRole.

See Also:
filterRole, filterAcceptsRow

setFilterWildcard

public final void setFilterWildcard(java.lang.String pattern)

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

See Also:
setFilterCaseSensitivity, setFilterRegExp, setFilterFixedString, filterRegExp

setSortCaseSensitivity

public final void setSortCaseSensitivity(Qt.CaseSensitivity cs)

Sets the case sensitivity setting used for comparing strings when sorting to cs.

By default, sorting is case sensitive.

See Also:
sortCaseSensitivity, filterCaseSensitivity, lessThan

setSortLocaleAware

public final void setSortLocaleAware(boolean on)

Sets the local aware setting used for comparing strings when sorting to on.

By default, sorting is not local aware.

See Also:
isSortLocaleAware, sortCaseSensitivity, lessThan

setSortRole

public final void setSortRole(int role)

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

The default value is Qt::DisplayRole.

See Also:
sortRole, lessThan

sortCaseSensitivity

public final Qt.CaseSensitivity sortCaseSensitivity()

Returns the case sensitivity setting used for comparing strings when sorting.

By default, sorting is case sensitive.

See Also:
setSortCaseSensitivity, filterCaseSensitivity, lessThan

sortRole

public final int sortRole()

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

The default value is Qt::DisplayRole.

See Also:
setSortRole, lessThan

buddy

public QModelIndex buddy(QModelIndex index)

Returns a model index for the buddy of the item represented by index. When the user wants to edit an item, the view will call this function to check whether another item in the model should be edited instead, and construct a delegate using the model index returned by the buddy item.

In the default implementation each item is its own buddy.

Overrides:
buddy in class QAbstractItemModel

canFetchMore

public boolean canFetchMore(QModelIndex parent)

Returns true if there is more data available for parent, otherwise false.

The default implementation always returns false.

Overrides:
canFetchMore in class QAbstractItemModel
See Also:
fetchMore

columnCount

public int columnCount(QModelIndex parent)

Returns the number of columns for the children of the given parent. When the parent is valid it means that rowCount is returning the number of children of parent.

In most subclasses, the number of columns is independent of the parent. For example:

    int DomModel::columnCount(const QModelIndex &/*parent*<!-- noop -->/) const
    {
        return 3;
    }

Tip: When implementing a table based model, columnCount should return 0 when the parent is valid.

Specified by:
columnCount in class QAbstractItemModel
See Also:
rowCount

data

public java.lang.Object data(QModelIndex index,
                             int role)

Returns the data stored under the given role for the item referred to by the index.

Overrides:
data in class QAbstractProxyModel
See Also:
setData

dropMimeData

public boolean dropMimeData(QMimeData data,
                            Qt.DropAction action,
                            int row,
                            int column,
                            QModelIndex parent)

Handles the data supplied by a drag and drop operation that ended with the given action. Returns true if the data and action can be handled by the model; otherwise returns false.

Although the specified row, column and parent indicate the location of an item in the model where the operation ended, it is the responsibility of the view to provide a suitable location for where the data should be inserted.

For instance, a drop action on an item in a QTreeView can result in new items either being inserted as children of the item specified by row, column, and parent, or as siblings of the item.

When row and column are -1 it means that it is up to the model to decide where to place the data. This can occur in a tree when data is dropped on a parent. Models will usually append the data to the parent in this case.

Returns true if the dropping was successful otherwise false.

Overrides:
dropMimeData in class QAbstractItemModel
See Also:
supportedDropActions, Using Drag and Drop with Item Views

fetchMore

public void fetchMore(QModelIndex parent)

Fetches any available data for the items with the parent specified by the parent index.

Reimplement this if you have incremental data.

The default implementation does nothing.

Overrides:
fetchMore in class QAbstractItemModel
See Also:
canFetchMore

filterAcceptsColumn

protected boolean filterAcceptsColumn(int source_column,
                                      QModelIndex source_parent)

Returns true if the value in the item in the column indicated by the given source_column and source_parent should be included in the model.

The default implementation returns true.

See Also:
filterAcceptsRow

filterAcceptsRow

protected boolean filterAcceptsRow(int source_row,
                                   QModelIndex source_parent)

Returns true if the value in the item in the row indicated by the given source_row and source_parent should be included in the model.

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:
filterRole, filterKeyColumn, filterRegExp, filterAcceptsColumn

flags

public Qt.ItemFlags flags(QModelIndex index)

Returns the item flags for the given index.

The base class implementation returns a combination of flags that enables the item (ItemIsEnabled) and allows it to be selected (ItemIsSelectable).

Overrides:
flags in class QAbstractProxyModel
See Also:
Qt::ItemFlags

hasChildren

public boolean hasChildren(QModelIndex parent)

Returns true if parent has any children; otherwise returns false. Use rowCount on the parent to find out the number of children.

Overrides:
hasChildren in class QAbstractItemModel
See Also:
parent, index

headerData

public java.lang.Object headerData(int section,
                                   Qt.Orientation orientation,
                                   int role)

Returns the data for the given role and section in the header with the specified orientation.

Overrides:
headerData in class QAbstractProxyModel
See Also:
setHeaderData

index

public QModelIndex index(int row,
                         int column,
                         QModelIndex parent)

Returns the index of the item in the model specified by the given row, column and parent index.

When reimplementing this function in a subclass, call createIndex to generate model indexes that other components can use to refer to items in your model.

Specified by:
index in class QAbstractItemModel
See Also:
createIndex

insertColumns

public boolean insertColumns(int column,
                             int count,
                             QModelIndex parent)

On models that support this, inserts count new columns into the model before the given column. The items in each new column will be children of the item represented by the parent model index.

If column is 0, the columns are prepended to any existing columns. If column is columnCount, the columns are appended to any existing columns. If parent has no children, a single row with count columns is inserted.

Returns true if the columns were successfully inserted; otherwise returns false.

The base class implementation does nothing and returns false.

If you implement your own model, you can reimplement this function if you want to support insertions. Alternatively, you can provide you own API for altering the data.

Overrides:
insertColumns in class QAbstractItemModel
See Also:
insertRows, removeColumns, beginInsertColumns, endInsertColumns

insertRows

public boolean insertRows(int row,
                          int count,
                          QModelIndex parent)

On models that support this, inserts count rows into the model before the given row. The items in the new row will be children of the item represented by the parent model index.

If row is 0, the rows are prepended to any existing rows in the parent. If row is rowCount, the rows are appended to any existing rows in the parent. If parent has no children, a single column with count rows is inserted.

Returns true if the rows were successfully inserted; otherwise returns false.

The base class implementation does nothing and returns false.

If you implement your own model, you can reimplement this function if you want to support insertions. Alternatively, you can provide you own API for altering the data.

Overrides:
insertRows in class QAbstractItemModel
See Also:
insertColumns, removeRows, beginInsertRows, endInsertRows

lessThan

protected boolean lessThan(QModelIndex left,
                           QModelIndex right)

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

See Also:
sortRole, sortCaseSensitivity, dynamicSortFilter

mapFromSource

public QModelIndex mapFromSource(QModelIndex sourceIndex)

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

Specified by:
mapFromSource in class QAbstractProxyModel
See Also:
mapToSource

mapSelectionFromSource

public QItemSelection mapSelectionFromSource(QItemSelection sourceSelection)

Returns a proxy selection mapped from the specified selection.

Reimplement this method to map source selections to proxy selections.

Overrides:
mapSelectionFromSource in class QAbstractProxyModel

mapSelectionToSource

public QItemSelection mapSelectionToSource(QItemSelection proxySelection)

Returns a source selection mapped from the specified selection.

Reimplement this method to map proxy selections to source selections.

Overrides:
mapSelectionToSource in class QAbstractProxyModel

mapToSource

public QModelIndex mapToSource(QModelIndex proxyIndex)

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

Specified by:
mapToSource in class QAbstractProxyModel
See Also:
mapFromSource

match

public java.util.List<QModelIndex> match(QModelIndex start,
                                         int role,
                                         java.lang.Object value,
                                         int hits,
                                         Qt.MatchFlags flags)

Returns a list of indexes for the items in the column of the start index where the data stored under the given role matches the specified value. The way the search is performed is defined by the flags given. The list that is returned may be empty.

The search starts from the start index, and continues until the number of matching data items equals hits, the search reaches the last row, or the search reaches start again, depending on whether MatchWrap is specified in flags. If you want to search for all matching items, use hits = -1.

By default, this function will perform a wrapping, string-based comparison on all items, searching for items that begin with the search term specified by value.

Note: The default implementation of this function only searches columns, This function can be reimplemented to include other search behavior.

Overrides:
match in class QAbstractItemModel

mimeData

public QMimeData mimeData(java.util.List<QModelIndex> indexes)

Returns an object that contains serialized items of data corresponding to the list of indexes specified. The formats used to describe the encoded data is obtained from the mimeTypes function.

If the list of indexes is empty, or there are no supported MIME types, 0 is returned rather than a serialized empty list.

Overrides:
mimeData in class QAbstractItemModel
See Also:
mimeTypes, dropMimeData

mimeTypes

public java.util.List<java.lang.String> mimeTypes()

Returns a list of MIME types that can be used to describe a list of model indexes.

Overrides:
mimeTypes in class QAbstractItemModel
See Also:
mimeData

parent

public QModelIndex parent(QModelIndex child)

Returns the parent of the model item with the given child, or QModelIndex() if it has no parent.

A common convention used in models that expose tree data structures is that only items in the first column have children. For that case, when reimplementing this function in a subclass the column of the returned QModelIndex would be 0.

Specified by:
parent in class QAbstractItemModel
See Also:
createIndex

removeColumns

public boolean removeColumns(int column,
                             int count,
                             QModelIndex parent)

On models that support this, removes count columns starting with the given column under parent parent from the model. Returns true if the columns were successfully removed; otherwise returns false.

The base class implementation does nothing and returns false.

If you implement your own model, you can reimplement this function if you want to support removing. Alternatively, you can provide you own API for altering the data.

Overrides:
removeColumns in class QAbstractItemModel
See Also:
removeColumn, removeRows, insertColumns, beginRemoveColumns, endRemoveColumns

removeRows

public boolean removeRows(int row,
                          int count,
                          QModelIndex parent)

On models that support this, removes count rows starting with the given row under parent parent from the model. Returns true if the rows were successfully removed; otherwise returns false.

The base class implementation does nothing and returns false.

If you implement your own model, you can reimplement this function if you want to support removing. Alternatively, you can provide you own API for altering the data.

Overrides:
removeRows in class QAbstractItemModel
See Also:
removeRow, removeColumns, insertColumns, beginRemoveRows, endRemoveRows

rowCount

public int rowCount(QModelIndex parent)

Returns the number of rows under the given parent. When the parent is valid it means that rowCount is returning the number of children of parent.

Tip: When implementing a table based model, rowCount should return 0 when the parent is valid.

Specified by:
rowCount in class QAbstractItemModel
See Also:
columnCount

setData

public boolean setData(QModelIndex index,
                       java.lang.Object value,
                       int role)

Sets the role data for the item at index to value. Returns true if successful; otherwise returns false.

The dataChanged signal should be emitted if the data was successfully set.

The base class implementation returns false. This function and data must be reimplemented for editable models. Note that the dataChanged signal must be emitted explicitly when reimplementing this function.

Overrides:
setData in class QAbstractItemModel
See Also:
data

setHeaderData

public boolean setHeaderData(int section,
                             Qt.Orientation orientation,
                             java.lang.Object value,
                             int role)

Sets the data for the given role and section in the header with the specified orientation to the value supplied. Returns true if the header's data was updated; otherwise returns false.

Note that the headerDataChanged signal must be emitted explicitly when reimplementing this function.

Overrides:
setHeaderData in class QAbstractItemModel
See Also:
headerData

setSourceModel

public void setSourceModel(QAbstractItemModel sourceModel)

Sets the given sourceModel to be processed by the proxy model.

Overrides:
setSourceModel in class QAbstractProxyModel
See Also:
sourceModel

sort

public void sort(int column,
                 Qt.SortOrder order)

Sorts the model by column in the given order.

The base class implementation does nothing.

Overrides:
sort in class QAbstractItemModel

span

public QSize span(QModelIndex index)

Returns the row and column span of the item represented by index.

Note: span is not used currently, but will be in the future.

Overrides:
span in class QAbstractItemModel

supportedDropActions

public Qt.DropActions supportedDropActions()

Returns the drop actions supported by this model.

The default implementation returns Qt::CopyAction. Reimplement this function if you wish to support additional actions. Note that you must also reimplement the dropMimeData function to handle the additional operations.

Overrides:
supportedDropActions in class QAbstractItemModel
See Also:
dropMimeData, Qt::DropActions, Using Drag and Drop with Item Views

fromNativePointer

public static QSortFilterProxyModel fromNativePointer(QNativePointer nativePointer)
This function returns the QSortFilterProxyModel instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

Qt Jambi Home