QAbstractItemModel Class Reference

#include <qabstractitemmodel.h>

Inheritance diagram for QAbstractItemModel:

Inheritance graph
[legend]
Collaboration diagram for QAbstractItemModel:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QAbstractItemModel class provides the abstract interface for item model classes.

The QAbstractItemModel class defines the standard interface that item models must use to be able to interoperate with other components in the model/view architecture. It is not supposed to be instantiated directly. Instead, you should subclass it to create new models.

The QAbstractItemModel class is one of the {Model/View Classes} and is part of Qt's {Model/View Programming}{model/view framework}.

If you need a model to use with a QListView or a QTableView, you should consider subclassing QAbstractListModel or QAbstractTableModel instead of this class.

The underlying data model is exposed to views and delegates as a hierarchy of tables. If you don't make use of the hierarchy, then the model is a simple table of rows and columns. Each item has a unique index specified by a QModelIndex.

modelindex-no-parent.png

Every item of data that can be accessed via a model has an associated model index that is obtained using the index() function. Each index may have a sibling() index; child items have a parent() index.

Each item has a number of data elements associated with it, and each of these can be retrieved by specifying a role (see Qt::ItemDataRole) to the model's data() function. Data for all available roles can be obtained at the same time using the itemData() function.

Data for each role is set using a particular Qt::ItemDataRole. Data for individual roles are set individually with setData(), or they can be set for all roles with setItemData().

Items can be queried with flags() (see Qt::ItemFlag) to see if they can be selected, dragged, or manipulated in other ways.

If an item has child objects, hasChildren() returns true for the corresponding index.

The model has a rowCount() and a columnCount() for each level of the hierarchy. Rows and columns can be inserted and removed with insertRows(), insertColumns(), removeRows(), and removeColumns().

The model emits signals to indicate changes. For example, dataChanged() is emitted whenever items of data made available by the model are changed. Changes to the headers supplied by the model cause headerDataChanged() to be emitted. If the structure of the underlying data changes, the model can emit layoutChanged() to indicate to any attached views that they should redisplay any items shown, taking the new structure into account.

The items available through the model can be searched for particular data using the match() function.

If the model is sortable, it can be sorted with sort().

\bold{Note:} Some general guidelines for subclassing models are available in the \l{Model Subclassing Reference}. When subclassing QAbstractItemModel, at the very least you must implement index(), parent(), rowCount(), columnCount(), and data(). These functions are used in all read-only models, and form the basis of editable models. You can also reimplement hasChildren() to provide special behavior for models where the implementation of rowCount() is expensive. This makes it possible for models to restrict the amount of data requested by views, and can be used as a way to implement lazy population of model data. To enable editing in your model, you must also implement setData(), and reimplement flags() to ensure that \c ItemIsEditable is returned. You can also reimplement headerData() and setHeaderData() to control the way the headers for your model are presented. Note that the dataChanged() and headerDataChanged() signals must be emitted explicitly when reimplementing the setData() and setHeaderData() functions, respectively. Custom models need to create model indexes for other components to use. To do this, call createIndex() with suitable row and column numbers for the item, and supply a unique identifier for the item, either as a pointer or as an integer value. Custom models typically use these unique identifiers in other reimplemented functions to retrieve item data and access information about the item's parents and children. See the \l{itemviews/simpletreemodel}{Simple Tree Model} example for more information about unique identifiers. It is not necessary to support every role defined in Qt::ItemDataRole. Depending on the type of data contained within a model, it may only be useful to implement the data() function to return valid information for some of the more common roles. Most models provide at least a textual representation of item data for the Qt::DisplayRole, and well-behaved models should also provide valid information for the Qt::ToolTipRole and Qt::WhatsThisRole. Supporting these roles enables models to be used with standard Qt views. However, for some models that handle highly-specialized data, it may be appropriate to provide data only for user-defined roles. Models that provide interfaces to resizable data structures can provide implementations of insertRows(), removeRows(), insertColumns(), and removeColumns(). When implementing these functions, it is important to notify any connected views about changes to the model's dimensions both \e before and \e after they occur: \list \o An insertRows() implementation must call beginInsertRows() \e before inserting new rows into the data structure, and it must call endInsertRows() \e{immediately afterwards}. \o An insertColumns() implementation must call beginInsertColumns() \e before inserting new columns into the data structure, and it must call endInsertColumns() \e{immediately afterwards}. \o A removeRows() implementation must call beginRemoveRows() \e before the rows are removed from the data structure, and it must call endRemoveRows() \e{immediately afterwards}. \o A removeColumns() implementation must call beginRemoveColumns() \e before the columns are removed from the data structure, and it must call endRemoveColumns() \e{immediately afterwards}. \endlist The \e private signals that these functions emit give attached components the chance to take action before any data becomes unavailable. The encapsulation of the insert and remove operations with these begin and end functions also enables the model to manage \l{QPersistentModelIndex}{persistent model indexes} correctly. \bold{If you want selections to be handled properly, you must ensure that you call these functions.} \sa {Model/View Programming}, QModelIndex, QAbstractItemView, {Using Drag and Drop with Item Views}, {Simple DOM Model Example}, {Simple Tree Model Example} Definition at line 127 of file qabstractitemmodel.h.

Public Slots

virtual bool submit ()
virtual void revert ()

Signals

void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
void headerDataChanged (Qt::Orientation orientation, int first, int last)
void layoutChanged ()
void layoutAboutToBeChanged ()

Public Member Functions

 QAbstractItemModel (QObject *parent=0)
virtual ~QAbstractItemModel ()
bool hasIndex (int row, int column, const QModelIndex &parent=QModelIndex()) const
virtual QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const=0
virtual QModelIndex parent (const QModelIndex &child) const=0
QModelIndex sibling (int row, int column, const QModelIndex &idx) const
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const=0
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const=0
virtual bool hasChildren (const QModelIndex &parent=QModelIndex()) const
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const =0
virtual bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
virtual QMap< int, QVariantitemData (const QModelIndex &index) const
virtual bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
virtual QStringList mimeTypes () const
virtual QMimeDatamimeData (const QModelIndexList &indexes) const
virtual bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
virtual Qt::DropActions supportedDropActions () const
Qt::DropActions supportedDragActions () const
void setSupportedDragActions (Qt::DropActions)
virtual bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex())
virtual bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex())
virtual bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
virtual bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex())
bool insertRow (int row, const QModelIndex &parent=QModelIndex())
bool insertColumn (int column, const QModelIndex &parent=QModelIndex())
bool removeRow (int row, const QModelIndex &parent=QModelIndex())
bool removeColumn (int column, const QModelIndex &parent=QModelIndex())
virtual void fetchMore (const QModelIndex &parent)
virtual bool canFetchMore (const QModelIndex &parent) const
virtual Qt::ItemFlags flags (const QModelIndex &index) const
virtual void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
virtual QModelIndex buddy (const QModelIndex &index) const
virtual QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
virtual QSize span (const QModelIndex &index) const

Protected Member Functions

 QAbstractItemModel (QAbstractItemModelPrivate &dd, QObject *parent=0)
QModelIndex createIndex (int row, int column, void *data=0) const
QModelIndex createIndex (int row, int column, int id) const
QModelIndex createIndex (int row, int column, quint32 id) const
void encodeData (const QModelIndexList &indexes, QDataStream &stream) const
bool decodeData (int row, int column, const QModelIndex &parent, QDataStream &stream)
void beginInsertRows (const QModelIndex &parent, int first, int last)
void endInsertRows ()
void beginRemoveRows (const QModelIndex &parent, int first, int last)
void endRemoveRows ()
void beginInsertColumns (const QModelIndex &parent, int first, int last)
void endInsertColumns ()
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
void endRemoveColumns ()
void reset ()
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
QModelIndexList persistentIndexList () const

Private Member Functions

void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
void rowsInserted (const QModelIndex &parent, int first, int last)
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
void rowsRemoved (const QModelIndex &parent, int first, int last)
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
void columnsInserted (const QModelIndex &parent, int first, int last)
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
void columnsRemoved (const QModelIndex &parent, int first, int last)
void modelAboutToBeReset ()
void modelReset ()

Friends

class QPersistentModelIndexData


Constructor & Destructor Documentation

QAbstractItemModel::QAbstractItemModel ( QObject parent = 0  )  [explicit]

Constructs an abstract item model with the given parent.

Definition at line 1083 of file qabstractitemmodel.cpp.

01084     : QObject(*new QAbstractItemModelPrivate, parent)
01085 {
01086 }

QAbstractItemModel::~QAbstractItemModel (  )  [virtual]

Destroys the abstract item model.

Definition at line 1099 of file qabstractitemmodel.cpp.

01100 {
01101     d_func()->invalidatePersistentIndexes();
01102 }

QAbstractItemModel::QAbstractItemModel ( QAbstractItemModelPrivate dd,
QObject parent = 0 
) [protected]

Definition at line 1091 of file qabstractitemmodel.cpp.

01092     : QObject(dd, parent)
01093 {
01094 }


Member Function Documentation

bool QAbstractItemModel::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.

Definition at line 1270 of file qabstractitemmodel.cpp.

References columnCount(), QObject::parent(), and rowCount().

Referenced by QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), QListModel::index(), QAbstractTableModel::index(), QAbstractListModel::index(), and QTableWidget::setRangeSelected().

01271 {
01272     if (row < 0 || column < 0)
01273         return false;
01274     return row < rowCount(parent) && column < columnCount(parent);
01275 }

Here is the call graph for this function:

QModelIndex QAbstractItemModel::index ( int  row,
int  column,
const QModelIndex parent = QModelIndex() 
) const [pure virtual]

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.

See also:
createIndex()

Referenced by addMail(), buddy(), QUnsortedModelEngine::buildIndices(), QTableWidget::cellWidget(), QModelIndex::child(), QAccessibleItemView::childIndex(), Main::collapseView(), Main::completelyExpandIndex(), QPersistentModelIndexData::create(), qdesigner_internal::ConnectionDelegate::createEditor(), QListViewPrivate::createItems(), PieView::dataChanged(), decodeData(), QListViewPrivate::doStaticLayout(), QTableViewPrivate::drawAndClipSpans(), QTreeWidget::dropEvent(), QListWidget::dropEvent(), QTableWidget::dropMimeData(), QListWidget::dropMimeData(), QAbstractItemViewPrivate::fetchMore(), QCompletionEngine::filter(), QSortedModelEngine::filter(), MySortFilterProxyModel::filterAcceptsRow(), QCompletionEngine::filterHistory(), QComboBox::findData(), flags(), QAbstractProxyModel::flags(), foreachIndex(), foreachIndex_helper(), PieView::indexAt(), QDataWidgetMapperPrivate::indexAt(), QItemSelectionRange::indexes(), QComboBox::insertItem(), QItemSelectionRange::intersect(), QListViewPrivate::intersectingStaticSet(), itemData(), QComboBox::itemData(), PieView::itemRect(), PieView::itemRegion(), QListViewPrivate::itemSize(), QComboBox::itemText(), TextEdit::keyPressEvent(), QTreeViewPrivate::layout(), QListViewPrivate::listViewItemToIndex(), QCompletionModel::mapToSource(), match(), PieView::moveCursor(), MainWindow::openFile(), QSortFilterProxyModelGreaterThan::operator()(), QSortFilterProxyModelLessThan::operator()(), PieView::paintEvent(), MainWindow::printImage(), QSortFilterProxyModelPrivate::proxy_intervals_for_source_items_to_add(), QSortFilterProxyModelPrivate::proxy_to_source(), QAccessibleItemRow::rect(), MainWindow::saveFile(), QTreeViewPrivate::select(), QItemSelectionModel::selectedColumns(), QItemSelectionModel::selectedRows(), QTableWidget::setCellWidget(), QComboBox::setCurrentIndex(), setData(), QComboBox::setItemData(), setItemData(), QComboBox::setItemIcon(), QComboBox::setItemText(), QTableWidget::setRangeSelected(), QModelIndex::sibling(), QSortFilterProxyModelPrivate::source_items_removed(), QItemSelection::split(), QTableViewPrivate::trimHiddenSelections(), and PieView::visualRegionForSelection().

QModelIndex QAbstractItemModel::parent ( const QModelIndex index  )  const [pure virtual]

Returns the parent of the model item with the given index, 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. When reimplementing this function in a subclass that provides a tree model, you should return a model index corresponding to an item in the first column by calling createIndex() with a value of 0 for the column number.

See also:
createIndex()

Referenced by QAbstractItemViewPrivate::_q_columnsAboutToBeRemoved(), qdesigner_internal::level(), qdesigner_internal::SheetDelegate::paint(), MessagesItemDelegate::paint(), QModelIndex::parent(), QTreeViewPrivate::reexpandChildren(), and QModelIndex::sibling().

QModelIndex QAbstractItemModel::sibling ( int  row,
int  column,
const QModelIndex index 
) const [inline]

Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location.

sibling() is just a convenience function that finds the item's parent, and uses it to retrieve the index of the child item in the specified row and column.

See also:
index(), QModelIndex::row(), QModelIndex::column()

Definition at line 142 of file qabstractitemmodel.h.

References index, and QObject::parent().

Referenced by QAbstractItemViewPrivate::_q_columnsAboutToBeRemoved(), QTreeViewPrivate::select(), and QDirModel::setData().

00143         { return index(row, column, parent(idx)); }

Here is the call graph for this function:

int QAbstractItemModel::rowCount ( const QModelIndex parent = QModelIndex()  )  const [pure virtual]

Returns the number of rows under the given parent.

See also:
columnCount()

Referenced by QAccessibleItemView::childCount(), Main::collapseView(), Main::completelyExpandIndex(), QComboBox::count(), QSortFilterProxyModelPrivate::create_mapping(), PieView::dataChanged(), QListViewPrivate::doDynamicLayout(), QListViewPrivate::doItemsLayout(), dropMimeData(), QAbstractItemViewPrivate::fetchMore(), QCompletionEngine::filter(), QUnsortedModelEngine::filter(), QCompletionEngine::filterHistory(), QUnsortedModelEngine::filterOnDemand(), foreachIndex(), foreachIndex_helper(), QAbstractListModel::hasChildren(), hasChildren(), QAbstractTableModel::hasChildren(), hasIndex(), QTreeViewPrivate::hasVisibleChildren(), QCompletionModel::index(), PieView::indexAt(), QSortedModelEngine::indexHint(), QListViewPrivate::initDynamicLayout(), QDataWidgetMapperPrivate::itemCount(), PieView::itemRegion(), QListViewPrivate::itemSize(), QTreeViewPrivate::layout(), match(), MainWindow::openFile(), PieView::paintEvent(), QListViewPrivate::prepareItemsLayout(), MainWindow::printImage(), QCompletionModel::rowCount(), PieView::rows(), MainWindow::saveFile(), QItemSelectionModel::selectedColumns(), QTableView::selectRow(), PieView::setSelection(), QTableWidget::setVerticalHeaderLabels(), and QCompleterPrivate::showPopup().

int QAbstractItemModel::columnCount ( const QModelIndex parent = QModelIndex()  )  const [pure virtual]

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

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

itemviews/simpledommodel/dommodel.cpp columnCount /^$/

See also:
rowCount()

Referenced by QAbstractItemViewPrivate::_q_columnsAboutToBeRemoved(), QAccessibleItemRow::childCount(), QAbstractItemViewPrivate::clearOrRemove(), QCompletionModel::columnCount(), QSortFilterProxyModelPrivate::create_mapping(), decodeData(), hasChildren(), QAbstractTableModel::hasChildren(), hasIndex(), QDataWidgetMapperPrivate::itemCount(), QListViewPrivate::prepareItemsLayout(), MainWindow::printImage(), QAccessibleItemRow::rect(), rowAt(), QTableView::selectColumn(), QItemSelectionModel::selectedRows(), QTableWidget::setHorizontalHeaderLabels(), and PieView::setSelection().

bool QAbstractItemModel::hasChildren ( const QModelIndex parent = QModelIndex()  )  const [virtual]

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

See also:
parent() index()

Definition at line 1284 of file qabstractitemmodel.cpp.

References columnCount(), QObject::parent(), and rowCount().

Referenced by QTreeViewPrivate::expand(), QCompletionModel::hasChildren(), QTreeViewPrivate::hasVisibleChildren(), QTreeViewPrivate::layout(), and match().

01285 {
01286     return (rowCount(parent) > 0) && (columnCount(parent) > 0);
01287 }

Here is the call graph for this function:

QVariant QAbstractItemModel::data ( const QModelIndex index,
int  role = Qt::DisplayRole 
) const [pure virtual]

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

See also:
Qt::ItemDataRole, setData(), headerData()

Referenced by QUnsortedModelEngine::buildIndices(), qdesigner_internal::ConnectionDelegate::createEditor(), QModelIndex::data(), QCompletionModel::data(), PieView::dataChanged(), decodeData(), QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), dropMimeData(), QSortedModelEngine::filter(), PieView::indexAt(), itemData(), QComboBox::itemData(), QComboBox::itemIcon(), PieView::itemRegion(), QAbstractItemView::keyPressEvent(), MySortFilterProxyModel::lessThan(), match(), mimeData(), qdesigner_internal::SheetDelegate::paint(), BookDelegate::paint(), PieView::paintEvent(), QCompleter::pathFromIndex(), PieView::rowsAboutToBeRemoved(), PieView::rowsInserted(), MainWindow::saveFile(), QItemDelegate::setModelData(), qdesigner_internal::ActionRepository::startDrag(), and QAccessibleItemRow::text().

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

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.

See also:
Qt::ItemDataRole, data(), itemData()

Definition at line 1323 of file qabstractitemmodel.cpp.

References index(), and value.

Referenced by addMail(), BookDelegate::editorEvent(), QItemDelegate::editorEvent(), QComboBox::insertItems(), MainWindow::openFile(), CheckStateSetter::operator()(), QSqlTableModel::setData(), QComboBox::setItemData(), setItemData(), QComboBox::setItemIcon(), QComboBox::setItemText(), VariantDelegate::setModelData(), ImageDelegate::setModelData(), SpreadSheetDelegate::setModelData(), QItemDelegate::setModelData(), SpinBoxDelegate::setModelData(), and qdesigner_internal::ColorDelegate::setModelData().

01324 {
01325     Q_UNUSED(index);
01326     Q_UNUSED(value);
01327     Q_UNUSED(role);
01328     return false;
01329 }

Here is the call graph for this function:

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

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

See also:
Qt::ItemDataRole, setHeaderData(), QHeaderView

Definition at line 1767 of file qabstractitemmodel.cpp.

References Qt::AlignCenter, Qt::DisplayRole, and Qt::TextAlignmentRole.

Referenced by qdesigner_internal::QPropertyEditorModel::headerData(), QSqlQueryModel::headerData(), QStandardItemModel::headerData(), QDirModel::headerData(), Model::headerData(), and QAccessibleHeader::text().

01768 {
01769     Q_UNUSED(orientation);
01770     if (role == Qt::DisplayRole)
01771         return section + 1;
01772     if (role == Qt::TextAlignmentRole)
01773         return Qt::AlignCenter;
01774     return QVariant();
01775 }

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

Sets the role for the header section to value. The orientation gives the orientation of the header.

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

See also:
Qt::ItemDataRole, headerData()

Definition at line 1787 of file qabstractitemmodel.cpp.

References value.

Referenced by MainWindow::setupModel().

01789 {
01790     Q_UNUSED(section);
01791     Q_UNUSED(orientation);
01792     Q_UNUSED(value);
01793     Q_UNUSED(role);
01794     return false;
01795 }

QMap< int, QVariant > QAbstractItemModel::itemData ( const QModelIndex index  )  const [virtual]

Returns a map with values for all predefined roles in the model for the item at the given index.

Reimplemented this function if you want to extend the default behavior of this function to include custom roles in the map.

See also:
Qt::ItemDataRole, data()

Definition at line 1299 of file qabstractitemmodel.cpp.

References data(), i, index(), QMap< Key, T >::insert(), QVariant::Invalid, and Qt::UserRole.

Referenced by QAbstractItemViewPrivate::clearOrRemove(), and encodeData().

01300 {
01301     QMap<int, QVariant> roles;
01302     for (int i = 0; i < Qt::UserRole; ++i) {
01303         QVariant variantData = data(index, i);
01304         if (variantData.type() != QVariant::Invalid)
01305             roles.insert(i, variantData);
01306     }
01307     return roles;
01308 }

Here is the call graph for this function:

bool QAbstractItemModel::setItemData ( const QModelIndex index,
const QMap< int, QVariant > &  roles 
) [virtual]

For every Qt::ItemDataRole in roles, sets the role data for the item at index to the associated value in roles. Returns true if successful; otherwise returns false.

See also:
setData() data() itemData()

Definition at line 1347 of file qabstractitemmodel.cpp.

References b, QMap< Key, T >::begin(), QMap< Key, T >::end(), index(), and setData().

Referenced by QAbstractItemViewPrivate::clearOrRemove(), decodeData(), QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), and QComboBox::insertItem().

01348 {
01349     bool b = true;
01350     for (QMap<int, QVariant>::ConstIterator it = roles.begin(); it != roles.end(); ++it)
01351         b = b && setData(index, it.value(), it.key());
01352     return b;
01353 }

Here is the call graph for this function:

QStringList QAbstractItemModel::mimeTypes (  )  const [virtual]

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

See also:
mimeData()

Definition at line 1361 of file qabstractitemmodel.cpp.

References types.

Referenced by QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), dropMimeData(), and mimeData().

01362 {
01363     QStringList types;
01364     types << QLatin1String("application/x-qabstractitemmodeldatalist");
01365     return types;
01366 }

QMimeData * QAbstractItemModel::mimeData ( const QModelIndexList indexes  )  const [virtual]

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.

See also:
mimeTypes(), dropMimeData()

Definition at line 1378 of file qabstractitemmodel.cpp.

References QList< T >::count(), data(), encodeData(), mimeTypes(), QTest::stream, types, and QIODevice::WriteOnly.

Referenced by QTreeModel::internalMimeData(), QTableModel::internalMimeData(), and QListModel::internalMimeData().

01379 {
01380     if (indexes.count() <= 0)
01381         return 0;
01382     QStringList types = mimeTypes();
01383     if (types.isEmpty())
01384         return 0;
01385     QMimeData *data = new QMimeData();
01386     QString format = types.at(0);
01387     QByteArray encoded;
01388     QDataStream stream(&encoded, QIODevice::WriteOnly);
01389     encodeData(indexes, stream);
01390     data->setData(format, encoded);
01391     return data;
01392 }

Here is the call graph for this function:

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

Handles the data supplied by a drag and drop operation that ended with the given action. 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.

See also:
supportedDropActions(), {Using Drag and Drop with Item Views}

Definition at line 1407 of file qabstractitemmodel.cpp.

References Qt::CopyAction, QVariant::data(), data(), decodeData(), mimeTypes(), Qt::MoveAction, QObject::parent(), QIODevice::ReadOnly, rowCount(), QTest::stream, and types.

01409 {
01410     // check if the action is supported
01411     if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
01412         return false;
01413     // check if the format is supported
01414     QStringList types = mimeTypes();
01415     if (types.isEmpty())
01416         return false;
01417     QString format = types.at(0);
01418     if (!data->hasFormat(format))
01419         return false;
01420     if (row > rowCount(parent))
01421         row = rowCount(parent);
01422     if (row == -1)
01423         row = rowCount(parent);
01424     if (column == -1)
01425         column = 0;
01426     // decode and insert
01427     QByteArray encoded = data->data(format);
01428     QDataStream stream(&encoded, QIODevice::ReadOnly);
01429     return decodeData(row, column, parent, stream);
01430 }

Here is the call graph for this function:

Qt::DropActions QAbstractItemModel::supportedDropActions (  )  const [virtual]

Since:
4.2
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.

See also:
dropMimeData(), Qt::DropActions, {Using Drag and Drop with Item Views}

Definition at line 1445 of file qabstractitemmodel.cpp.

References Qt::CopyAction.

Referenced by QAbstractItemViewPrivate::dropOn(), and supportedDragActions().

01446 {
01447     return Qt::CopyAction;
01448 }

Qt::DropActions QAbstractItemModel::supportedDragActions (  )  const

Returns the actions supported by the data in this model.

The default implementation returns supportedDropActions() unless specific values have been set with setSupportedDragActions().

supportedDragActions() is used by QAbstractItemView::startDrag() as the default values when a drag occurs.

See also:
Qt::DropActions, {Using Drag and Drop with Item Views}

Definition at line 1461 of file qabstractitemmodel.cpp.

References d, and supportedDropActions().

01462 {
01463     // ### Qt 5: make this virtual or these properties
01464     Q_D(const QAbstractItemModel);
01465     if (d->supportedDragActions != -1)
01466         return d->supportedDragActions;
01467     return supportedDropActions();
01468 }

Here is the call graph for this function:

void QAbstractItemModel::setSupportedDragActions ( Qt::DropActions  actions  ) 

Since:
4.2
Sets the supported drag actions for the items in the model.

See also:
supportedDragActions(), {Using Drag and Drop with Item Views}

Definition at line 1477 of file qabstractitemmodel.cpp.

References d.

01478 {
01479     Q_D(QAbstractItemModel);
01480     d->supportedDragActions = actions;
01481 }

bool QAbstractItemModel::insertRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
) [virtual]

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.

See also:
insertColumns(), removeRows(), beginInsertRows(), endInsertRows()

Definition at line 1504 of file qabstractitemmodel.cpp.

Referenced by decodeData(), and MainWindow::openFile().

01505 {
01506     return false;
01507 }

bool QAbstractItemModel::insertColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
) [virtual]

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.

See also:
insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns()

Definition at line 1530 of file qabstractitemmodel.cpp.

Referenced by decodeData(), and insertColumn().

01531 {
01532     return false;
01533 }

bool QAbstractItemModel::removeRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
) [virtual]

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.

See also:
removeRow(), removeColumns(), insertColumns(), beginRemoveRows(), endRemoveRows()

Definition at line 1548 of file qabstractitemmodel.cpp.

Referenced by QComboBox::clear(), QAbstractItemViewPrivate::clearOrRemove(), QComboBox::insertItem(), QComboBox::insertItems(), MainWindow::openFile(), QComboBox::removeItem(), removeRow(), and QComboBox::setMaxCount().

01549 {
01550     return false;
01551 }

bool QAbstractItemModel::removeColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
) [virtual]

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.

See also:
removeColumn(), removeRows(), insertColumns(), beginRemoveColumns(), endRemoveColumns()

Definition at line 1566 of file qabstractitemmodel.cpp.

Referenced by removeColumn().

01567 {
01568     return false;
01569 }

bool QAbstractItemModel::insertRow ( int  row,
const QModelIndex parent = QModelIndex() 
) [inline]

Inserts a single row before the given row in the child items of the parent specified. Returns true if the row is inserted; otherwise returns false.

See also:
insertRows() insertColumn() removeRow()

Definition at line 257 of file qabstractitemmodel.h.

Referenced by addMail(), QSqlTableModel::insertRecord(), QStandardItemModel::insertRow(), Browser::insertRow(), and QCalendarModel::setHorizontalHeaderFormat().

00258 { return insertRows(arow, 1, aparent); }

bool QAbstractItemModel::insertColumn ( int  column,
const QModelIndex parent = QModelIndex() 
) [inline]

Inserts a single column before the given column in the child items of the parent specified. Returns true if the column is inserted; otherwise returns false.

See also:
insertColumns() insertRow() removeColumn()

Definition at line 259 of file qabstractitemmodel.h.

References insertColumns().

Referenced by QStandardItemModel::insertColumn(), and QCalendarModel::setWeekNumbersShown().

00260 { return insertColumns(acolumn, 1, aparent); }

Here is the call graph for this function:

bool QAbstractItemModel::removeRow ( int  row,
const QModelIndex parent = QModelIndex() 
) [inline]

Removes the given row from the child items of the parent specified. Returns true if the row is removed; otherwise returns false.

See also:
removeRows(), removeColumn(), insertRow()

Definition at line 261 of file qabstractitemmodel.h.

References removeRows().

Referenced by Browser::deleteRow(), and QCalendarModel::setHorizontalHeaderFormat().

00262 { return removeRows(arow, 1, aparent); }

Here is the call graph for this function:

bool QAbstractItemModel::removeColumn ( int  column,
const QModelIndex parent = QModelIndex() 
) [inline]

Removes the given column from the child items of the parent specified. Returns true if the column is removed; otherwise returns false.

See also:
removeColumns(), removeRow(), insertColumn()

Definition at line 263 of file qabstractitemmodel.h.

References removeColumns().

Referenced by QCalendarModel::setWeekNumbersShown().

00264 { return removeColumns(acolumn, 1, aparent); }

Here is the call graph for this function:

void QAbstractItemModel::fetchMore ( const QModelIndex parent  )  [virtual]

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.

See also:
canFetchMore()

Definition at line 1581 of file qabstractitemmodel.cpp.

Referenced by QTreeViewPrivate::expand(), and QAbstractItemViewPrivate::fetchMore().

01582 {
01583     // do nothing
01584 }

bool QAbstractItemModel::canFetchMore ( const QModelIndex parent  )  const [virtual]

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

The default implementation always returns false.

See also:
fetchMore()

Definition at line 1594 of file qabstractitemmodel.cpp.

Referenced by QTreeViewPrivate::expand(), and QAbstractItemViewPrivate::fetchMore().

01595 {
01596     return false;
01597 }

Qt::ItemFlags QAbstractItemModel::flags ( const QModelIndex index  )  const [virtual]

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

See also:
Qt::ItemFlags

Definition at line 1608 of file qabstractitemmodel.cpp.

References d, index(), Qt::ItemIsEnabled, and Qt::ItemIsSelectable.

Referenced by QTableViewPrivate::drawCell(), QAbstractItemViewPrivate::dropOn(), QItemDelegate::editorEvent(), QDirModel::flags(), QModelIndex::flags(), EditableSqlModel::flags(), qdesigner_internal::FlagBoxModel::flags(), qdesigner_internal::QPropertyEditorModel::flags(), QCalendarModel::flags(), QStringListModel::flags(), QListView::paintEvent(), and QAbstractItemViewPrivate::shouldEdit().

01609 {
01610     Q_D(const QAbstractItemModel);
01611     if (!d->indexValid(index))
01612         return 0;
01613 
01614     return Qt::ItemIsSelectable|Qt::ItemIsEnabled;
01615 }

Here is the call graph for this function:

void QAbstractItemModel::sort ( int  column,
Qt::SortOrder  order = Qt::AscendingOrder 
) [virtual]

Sorts the model by column in the given order.

The base class implementation does nothing.

Definition at line 1622 of file qabstractitemmodel.cpp.

01623 {
01624     Q_UNUSED(column);
01625     Q_UNUSED(order);
01626     // do nothing
01627 }

QModelIndex QAbstractItemModel::buddy ( const QModelIndex index  )  const [virtual]

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.

Definition at line 1637 of file qabstractitemmodel.cpp.

References index().

Referenced by QAbstractItemViewPrivate::openEditor(), and QAbstractItemViewPrivate::sendDelegateEvent().

01638 {
01639     return index;
01640 }

Here is the call graph for this function:

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

Returns a list of indexes for the items 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.

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.

Definition at line 1657 of file qabstractitemmodel.cpp.

References QList< T >::append(), Qt::CaseInsensitive, Qt::CaseSensitive, QList< T >::count(), data(), hasChildren(), i, index(), QString::isEmpty(), Qt::MatchCaseSensitive, Qt::MatchContains, Qt::MatchEndsWith, Qt::MatchExactly, Qt::MatchFixedString, Qt::MatchRecursive, Qt::MatchRegExp, Qt::MatchStartsWith, Qt::MatchWildcard, Qt::MatchWrap, p, QObject::parent(), rowCount(), start, t, QVariant::toString(), value, and QRegExp::Wildcard.

Referenced by IndexListModel::filter(), QComboBox::findData(), QStandardItemModel::findItems(), QSortFilterProxyModel::match(), QFileDialogPrivate::matchDir(), and QFileDialogPrivate::matchName().

01660 {
01661     QModelIndexList result;
01662     uint matchType = flags & 0x0F;
01663     Qt::CaseSensitivity cs = flags & Qt::MatchCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
01664     bool recurse = flags & Qt::MatchRecursive;
01665     bool wrap = flags & Qt::MatchWrap;
01666     bool allHits = (hits == -1);
01667     QString text; // only convert to a string if it is needed
01668     QModelIndex p = parent(start);
01669     int from = start.row();
01670     int to = rowCount(p);
01671 
01672     // iterates twice if wrapping
01673     for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
01674         for (int r = from; (r < to) && (allHits || result.count() < hits); ++r) {
01675             QModelIndex idx = index(r, start.column(), p);
01676             if (!idx.isValid())
01677                  continue;
01678             QVariant v = data(idx, role);
01679             // QVariant based matching
01680             if (matchType == Qt::MatchExactly) {
01681                 if (value == v)
01682                     result.append(idx);
01683             } else { // QString based matching
01684                 if (text.isEmpty()) // lazy conversion
01685                     text = value.toString();
01686                 QString t = v.toString();
01687                 switch (matchType) {
01688                 case Qt::MatchRegExp:
01689                     if (QRegExp(text, cs).exactMatch(t))
01690                         result.append(idx);
01691                     break;
01692                 case Qt::MatchWildcard:
01693                     if (QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t))
01694                         result.append(idx);
01695                     break;
01696                 case Qt::MatchStartsWith:
01697                     if (t.startsWith(text, cs))
01698                         result.append(idx);
01699                     break;
01700                 case Qt::MatchEndsWith:
01701                     if (t.endsWith(text, cs))
01702                         result.append(idx);
01703                     break;
01704                 case Qt::MatchFixedString:
01705                     if (t.compare(text, cs) == 0)
01706                         result.append(idx);
01707                     break;
01708                 case Qt::MatchContains:
01709                 default:
01710                     if (t.contains(text, cs))
01711                         result.append(idx);
01712                 }
01713             }
01714             if (recurse && hasChildren(idx)) { // search the hierarchy
01715                 result += match(index(0, idx.column(), idx), role,
01716                                 (text.isEmpty() ? value : text),
01717                                 (allHits ? -1 : hits - result.count()), flags);
01718             }
01719         }
01720         // prepare for the next iteration
01721         from = 0;
01722         to = start.row();
01723     }
01724     return result;
01725 }

Here is the call graph for this function:

QSize QAbstractItemModel::span ( const QModelIndex index  )  const [virtual]

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

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

Definition at line 1733 of file qabstractitemmodel.cpp.

01734 {
01735     return QSize(1, 1);
01736 }

void QAbstractItemModel::dataChanged ( const QModelIndex topLeft,
const QModelIndex bottomRight 
) [signal]

This signal is emitted whenever the data in an existing item changes. The affected items are those between topLeft and bottomRight inclusive (of the same parent).

Note that this signal must be emitted explicitly when reimplementing the setData() function.

See also:
headerDataChanged(), setData(), layoutChanged()

Referenced by qdesigner_internal::ResourceModel::changePrefix(), qdesigner_internal::ConnectionModel::connectionChanged(), QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), QTreeModel::emitDataChanged(), FeatureTreeModel::featureChanged(), QCalendarModel::internalUpdate(), QTreeModel::itemChanged(), QTableModel::itemChanged(), QListModel::itemChanged(), qdesigner_internal::QPropertyEditorModel::refresh(), QTableModel::removeItem(), QSqlTableModel::revertRow(), QDirModel::setData(), qdesigner_internal::PaletteModel::setData(), QSqlTableModel::setData(), FeatureTreeModel::setData(), QStringListModel::setData(), qdesigner_internal::FlagBoxModel::setData(), QTableModel::setItem(), qdesigner_internal::PaletteModel::setPalette(), PhraseModel::setPhrase(), QCompletionModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), MessageModel::setTranslation(), ContextModel::sort(), PhraseModel::sort(), MessageModel::sort(), ContextModel::updateItem(), and MessageModel::updateItem().

void QAbstractItemModel::headerDataChanged ( Qt::Orientation  orientation,
int  first,
int  last 
) [signal]

This signal is emitted whenever a header is changed. The orientation indicates whether the horizontal or vertical header has changed. The sections in the header from the first to the last need to be updated.

Note that this signal must be emitted explicitly when reimplementing the setHeaderData() function.

If you are changing the number of columns or rows you don't need to emit this signal, but use the begin/end functions.

See also:
headerData(), setHeaderData(), dataChanged()

Referenced by QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), QTreeModel::emitDataChanged(), QCalendarModel::internalUpdate(), QTableModel::itemChanged(), QTableModel::removeItem(), QSqlQueryModel::setHeaderData(), QTableModel::setHorizontalHeaderItem(), QStandardItemModel::setHorizontalHeaderItem(), QSortFilterProxyModel::setSourceModel(), QTableModel::setVerticalHeaderItem(), and QStandardItemModel::setVerticalHeaderItem().

void QAbstractItemModel::layoutChanged (  )  [signal]

This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted. When this signal is received by a view, it should update the layout of items to reflect this change.

When subclassing QAbstractItemModel or QAbstractProxyModel, ensure that you emit layoutAboutToBeChanged() before changing the order of items or altering the structure of the data you expose to views, and emit layoutChanged() after changing the layout.

Subclasses should update any persistent model indexes before emitting layoutChanged().

See also:
layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), reset(), changePersistentIndex()

Referenced by FeatureTreeModel::addFeature(), QSortFilterProxyModel::clear(), FeatureTreeModel::clear(), QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), QListModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::ensureSorted(), FeatureTreeModel::featureChanged(), QDirModel::refresh(), QDirModel::setFilter(), QTableModel::setItem(), QDirModel::setNameFilters(), QDirModel::setSorting(), QCompletionModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QTableModel::sort(), QListModel::sort(), QTreeModel::sort(), and QStringListModel::sort().

void QAbstractItemModel::layoutAboutToBeChanged (  )  [signal]

Since:
4.2
This signal is emitted just before the layout of a model is changed. Components connected to this signal use it to adapt to changes in the model's layout.

Subclasses should update any persistent model indexes after emitting layoutAboutToBeChanged().

See also:
layoutChanged(), changePersistentIndex()

Referenced by QSortFilterProxyModel::clear(), QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), QListModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::ensureSorted(), QDirModel::refresh(), QDirModel::setFilter(), QTableModel::setItem(), QDirModel::setNameFilters(), QDirModel::setSorting(), QSortFilterProxyModel::setSourceModel(), QTableModel::sort(), QListModel::sort(), QTreeModel::sort(), and QStringListModel::sort().

void QAbstractItemModel::rowsAboutToBeInserted ( const QModelIndex parent,
int  start,
int  end 
) [private]

This signal is emitted just before rows are inserted into the model. The new items will be positioned between start and end inclusive, under the given parent item.

{Note:} Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.

See also:
insertRows(), beginInsertRows()

Referenced by beginInsertRows(), QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), and QSortFilterProxyModel::setSourceModel().

void QAbstractItemModel::rowsInserted ( const QModelIndex parent,
int  start,
int  end 
) [private]

This signal is emitted after rows have been inserted into the model. The new items are those between start and end inclusive, under the given parent item.

{Note:} Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.

See also:
insertRows(), beginInsertRows()

Referenced by QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), endInsertRows(), QCompletionModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

void QAbstractItemModel::rowsAboutToBeRemoved ( const QModelIndex parent,
int  start,
int  end 
) [private]

This signal is emitted just before rows are removed from the model. The items that will be removed are those between start and end inclusive, under the given parent item.

{Note:} Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.

See also:
removeRows(), beginRemoveRows()

Referenced by beginRemoveRows(), QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), and QSortFilterProxyModel::setSourceModel().

void QAbstractItemModel::rowsRemoved ( const QModelIndex parent,
int  start,
int  end 
) [private]

This signal is emitted after rows have been removed from the model. The removed items are those between start and end inclusive, under the given parent item.

{Note:} Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.

See also:
removeRows(), beginRemoveRows()

Referenced by QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), endRemoveRows(), QCompletionModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

void QAbstractItemModel::columnsAboutToBeInserted ( const QModelIndex parent,
int  start,
int  end 
) [private]

This signal is emitted just before columns are inserted into the model. The new items will be positioned between start and end inclusive, under the given parent item.

{Note:} Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.

See also:
insertColumns(), beginInsertColumns()

Referenced by beginInsertColumns(), QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), and QSortFilterProxyModel::setSourceModel().

void QAbstractItemModel::columnsInserted ( const QModelIndex parent,
int  start,
int  end 
) [private]

This signal is emitted after columns have been inserted into the model. The new items are those between start and end inclusive, under the given parent item.

{Note:} Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.

See also:
insertColumns(), beginInsertColumns()

Referenced by QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), endInsertColumns(), QCompletionModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

void QAbstractItemModel::columnsAboutToBeRemoved ( const QModelIndex parent,
int  start,
int  end 
) [private]

This signal is emitted just before columns are removed from the model. The items to be removed are those between start and end inclusive, under the given parent item.

{Note:} Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.

See also:
removeColumns(), beginRemoveColumns()

Referenced by beginRemoveColumns(), QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), and QSortFilterProxyModel::setSourceModel().

void QAbstractItemModel::columnsRemoved ( const QModelIndex parent,
int  start,
int  end 
) [private]

This signal is emitted after columns have been removed from the model. The removed items are those between start and end inclusive, under the given parent item.

{Note:} Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.

See also:
removeColumns(), beginRemoveColumns()

Referenced by QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), endRemoveColumns(), QCompletionModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

QAbstractItemModel::modelAboutToBeReset (  )  [private]

Since:
4.2
This signal is emitted when reset() is called, before the model's internal state (e.g. persistent model indexes) has been invalidated.

See also:
reset(), modelReset()

Referenced by reset().

QAbstractItemModel::modelReset (  )  [private]

Since:
4.1
This signal is emitted when reset() is called, after the model's internal state (e.g. persistent model indexes) has been invalidated.

See also:
reset(), modelAboutToBeReset()

Referenced by QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), QSortFilterProxyModel::QSortFilterProxyModel(), reset(), QCompletionModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

bool QAbstractItemModel::submit (  )  [virtual, slot]

Called to let the model know that it should submit whatever it has cached to the permanent storage. Typically used for row editing.

Returns false on error, otherwise true.

Definition at line 1745 of file qabstractitemmodel.cpp.

01746 {
01747     return true;
01748 }

void QAbstractItemModel::revert (  )  [virtual, slot]

Called to let the model know that it should discart whatever it has cached. Typically used for row editing.

Definition at line 1755 of file qabstractitemmodel.cpp.

01756 {
01757     // do nothing
01758 }

QModelIndex QAbstractItemModel::createIndex ( int  row,
int  column,
void *  ptr = 0 
) const [inline, protected]

Creates a model index for the given row and column with the internal pointer ptr.

This function provides a consistent interface that model subclasses must use to create model indexes.

Definition at line 266 of file qabstractitemmodel.h.

Referenced by qdesigner_internal::QPropertyEditorModel::buddy(), qdesigner_internal::ConnectionModel::connectionChanged(), qdesigner_internal::ConnectionModel::connectionToIndex(), FeatureTreeModel::createIndex(), QCompletionModel::currentIndex(), QTreeModel::emitDataChanged(), QListModel::ensureSorted(), QTreeModel::ensureSorted(), FeatureTreeModel::index(), PPDOptionsModel::index(), qdesigner_internal::QPropertyEditorModel::index(), MessageModel::index(), QListModel::index(), QCompletionModel::index(), qdesigner_internal::ConnectionModel::index(), qdesigner_internal::FlagBoxModel::index(), QDirModel::index(), QDBusModel::index(), DomModel::index(), QAbstractTableModel::index(), Model::index(), QAbstractListModel::index(), TreeModel::index(), QUndoModel::index(), QTreeModel::index(), qdesigner_internal::ResourceModel::index(), QStandardItemModel::index(), QStandardItemModel::indexFromItem(), QSqlQueryModel::indexInQuery(), QSqlTableModel::indexInQuery(), qdesigner_internal::QPropertyEditorModel::indexOf(), QCompletionModel::mapFromSource(), PPDOptionsModel::parent(), Model::parent(), qdesigner_internal::ResourceModel::parent(), QDirModel::parent(), QDBusModel::parent(), MessageModel::parent(), TreeModel::parent(), DomModel::parent(), QSqlQueryModel::record(), QSqlTableModel::revertRow(), QUndoModel::selectedIndex(), QSqlQueryModel::setQuery(), QTableModel::sort(), QListModel::sort(), QStandardItemPrivate::sortChildren(), QTreeModel::sortItems(), and ContextModel::updateItem().

00267 { return QModelIndex(arow, acolumn, adata, this); }

QModelIndex QAbstractItemModel::createIndex ( int  row,
int  column,
int  id 
) const [inline, protected]

Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead.

Definition at line 268 of file qabstractitemmodel.h.

00271                          : 4312 ) // avoid conversion warning on 64-bit
00272 #endif
00273 { return QModelIndex(arow, acolumn, reinterpret_cast<void*>(aid), this); }

QModelIndex QAbstractItemModel::createIndex ( int  row,
int  column,
quint32  id 
) const [inline, protected]

Creates a model index for the given row and column with the internal identifier, id.

This function provides a consistent interface that model subclasses must use to create model indexes.

Definition at line 277 of file qabstractitemmodel.h.

00280                          : 4312 ) // avoid conversion warning on 64-bit
00281 #endif
00282 { return QModelIndex(arow, acolumn, reinterpret_cast<void*>(aid), this); }

void QAbstractItemModel::encodeData ( const QModelIndexList indexes,
QDataStream stream 
) const [protected]

Definition at line 1826 of file qabstractitemmodel.cpp.

References QList< T >::begin(), QList< T >::end(), itemData(), and QTest::stream.

Referenced by mimeData().

01827 {
01828     QModelIndexList::ConstIterator it = indexes.begin();
01829     for (; it != indexes.end(); ++it)
01830         stream << (*it).row() << (*it).column() << itemData(*it);
01831 }

Here is the call graph for this function:

bool QAbstractItemModel::decodeData ( int  row,
int  column,
const QModelIndex parent,
QDataStream stream 
) [protected]

Definition at line 1836 of file qabstractitemmodel.cpp.

References QVector< T >::append(), QVector< T >::at(), c, columnCount(), QVector< T >::count(), data(), i, index(), insertColumns(), insertRows(), j, left(), QObject::parent(), qMax(), qMin(), QBitArray::resize(), right(), QBitArray::setBit(), setItemData(), QTest::stream, and QBitArray::testBit().

Referenced by QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), and dropMimeData().

01838 {
01839     int top = INT_MAX;
01840     int left = INT_MAX;
01841     int bottom = 0;
01842     int right = 0;
01843     QVector<int> rows, columns;
01844     QVector<QMap<int, QVariant> > data;
01845 
01846     while (!stream.atEnd()) {
01847         int r, c;
01848         QMap<int, QVariant> v;
01849         stream >> r >> c >> v;
01850         rows.append(r);
01851         columns.append(c);
01852         data.append(v);
01853         top = qMin(r, top);
01854         left = qMin(c, left);
01855         bottom = qMax(r, bottom);
01856         right = qMax(c, right);
01857     }
01858 
01859     // insert the dragged items into the table, use a bit array to avoid overwriting items,
01860     // since items from different tables can have the same row and column
01861     int dragRowCount = 0;
01862     int dragColumnCount = right - left + 1;
01863 
01864     // Compute the number of continuous rows upon insertion and modify the rows to match
01865     QVector<int> rowsToInsert(bottom + 1);
01866     for (int i = 0; i < rows.count(); ++i)
01867         rowsToInsert[rows.at(i)] = 1;
01868     for (int i = 0; i < rowsToInsert.count(); ++i) {
01869         if (rowsToInsert[i] == 1){
01870             rowsToInsert[i] = dragRowCount;
01871             ++dragRowCount;
01872         }
01873     }
01874     for (int i = 0; i < rows.count(); ++i)
01875         rows[i] = top + rowsToInsert[rows[i]];
01876 
01877     QBitArray isWrittenTo(dragRowCount * dragColumnCount);
01878 
01879     // make space in the table for the dropped data
01880     int colCount = columnCount(parent);
01881     if (colCount == 0) {
01882         insertColumns(colCount, dragColumnCount - colCount, parent);
01883         colCount = columnCount(parent);
01884     }
01885     insertRows(row, dragRowCount, parent);
01886 
01887     row = qMax(0, row);
01888     column = qMax(0, column);
01889 
01890     // set the data in the table
01891     for (int j = 0; j < data.size(); ++j) {
01892         int relativeRow = rows.at(j) - top;
01893         int relativeColumn = columns.at(j) - left;
01894         int destinationRow = relativeRow + row;
01895         int destinationColumn = relativeColumn + column;
01896         int flat = (relativeRow * dragColumnCount) + relativeColumn;
01897         // if the item was already written to, or we just can't fit it in the table, create a new row
01898         if (destinationColumn >= colCount || isWrittenTo.testBit(flat)) {
01899             destinationColumn = qBound(column, destinationColumn, colCount - 1);
01900             destinationRow = row + dragRowCount;
01901             insertRows(row + dragRowCount, 1, parent);
01902             flat = (dragRowCount * dragColumnCount) + relativeColumn;
01903             isWrittenTo.resize(++dragRowCount * dragColumnCount);
01904         }
01905         if (!isWrittenTo.testBit(flat)) {
01906             QModelIndex idx = index(destinationRow, destinationColumn, parent);
01907             setItemData(idx, data.at(j));
01908             isWrittenTo.setBit(flat);
01909         }
01910     }
01911 
01912     return true;
01913 }

Here is the call graph for this function:

void QAbstractItemModel::beginInsertRows ( const QModelIndex parent,
int  first,
int  last 
) [protected]

Begins a row insertion operation.

When reimplementing insertRows() in a subclass, you must call this function before inserting data into the model's underlying data store.

The parent index corresponds to the parent into which the new rows are inserted; first and last are the row numbers that the new rows will have after they have been inserted.

80% modelview-begin-insert-rows.png Inserting rows Specify the first and last row numbers for the span of rows you want to insert into an item in a model.

For example, as shown in the diagram, we insert three rows before row 2, so first is 2 and last is 4:

This inserts the three new rows as rows 2, 3, and 4. modelview-begin-append-rows.png Appending rows To append rows, insert them after the last row.

For example, as shown in the diagram, we append two rows to a collection of 4 existing rows (ending in row 3), so first is 4 and last is 5:

This appends the two new rows as rows 4 and 5.

See also:
endInsertRows()

Definition at line 1952 of file qabstractitemmodel.cpp.

References d, emit, QObject::parent(), and rowsAboutToBeInserted().

Referenced by qdesigner_internal::ConnectionModel::aboutToAddConnection(), qdesigner_internal::ResourceModel::addFiles(), qdesigner_internal::ResourceModel::addNewPrefix(), PhraseModel::addPhrase(), PiecesModel::addPiece(), QTreeModel::beginInsertItems(), PiecesModel::dropMimeData(), QListModel::insert(), QTreeModel::insertRows(), QStringListModel::insertRows(), QCalendarModel::insertRows(), QTableModel::insertRows(), QListModel::insertRows(), QSqlTableModel::insertRows(), QDBusModel::refresh(), and QSqlQueryModel::setQuery().

01953 {
01954     Q_ASSERT(first >= 0);
01955     Q_ASSERT(last >= first);
01956     Q_D(QAbstractItemModel);
01957     d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
01958     emit rowsAboutToBeInserted(parent, first, last);
01959     d->rowsAboutToBeInserted(parent, first, last);
01960 }

Here is the call graph for this function:

void QAbstractItemModel::endInsertRows (  )  [protected]

Ends a row insertion operation.

When reimplementing insertRows() in a subclass, you must call this function after inserting data into the model's underlying data store.

See also:
beginInsertRows()

Definition at line 1971 of file qabstractitemmodel.cpp.

References d, emit, QAbstractItemModelPrivate::Change::first, QAbstractItemModelPrivate::Change::last, QAbstractItemModelPrivate::Change::parent, and rowsInserted().

Referenced by qdesigner_internal::ResourceModel::addFiles(), qdesigner_internal::ResourceModel::addNewPrefix(), PhraseModel::addPhrase(), PiecesModel::addPiece(), qdesigner_internal::ConnectionModel::connectionAdded(), PiecesModel::dropMimeData(), QTreeModel::endInsertItems(), QListModel::insert(), QTreeModel::insertRows(), QStringListModel::insertRows(), QCalendarModel::insertRows(), QTableModel::insertRows(), QSqlTableModel::insertRows(), QListModel::insertRows(), QDBusModel::refresh(), and QSqlQueryModel::setQuery().

01972 {
01973     Q_D(QAbstractItemModel);
01974     QAbstractItemModelPrivate::Change change = d->changes.pop();
01975     d->rowsInserted(change.parent, change.first, change.last);
01976     emit rowsInserted(change.parent, change.first, change.last);
01977 }

Here is the call graph for this function:

void QAbstractItemModel::beginRemoveRows ( const QModelIndex parent,
int  first,
int  last 
) [protected]

Begins a row removal operation.

When reimplementing removeRows() in a subclass, you must call this function before removing data from the model's underlying data store.

The parent index corresponds to the parent from which the new rows are removed; first and last are the row numbers of the rows to be removed.

80% modelview-begin-remove-rows.png Removing rows Specify the first and last row numbers for the span of rows you want to remove from an item in a model.

For example, as shown in the diagram, we remove the two rows from row 2 to row 3, so first is 2 and last is 3:

See also:
endRemoveRows()

Definition at line 2004 of file qabstractitemmodel.cpp.

References d, emit, QObject::parent(), and rowsAboutToBeRemoved().

Referenced by qdesigner_internal::ConnectionModel::aboutToRemoveConnection(), PiecesModel::addPieces(), QTreeModel::beginRemoveItems(), qdesigner_internal::ResourceModel::deleteItem(), QDBusModel::refresh(), QListModel::remove(), PhraseModel::removePhrase(), QCalendarModel::removeRows(), PiecesModel::removeRows(), QTreeModel::removeRows(), QStringListModel::removeRows(), QTableModel::removeRows(), QListModel::removeRows(), QSqlQueryModel::setQuery(), and QListModel::take().

02005 {
02006     Q_ASSERT(first >= 0);
02007     Q_ASSERT(last >= first);
02008     Q_D(QAbstractItemModel);
02009     d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
02010     emit rowsAboutToBeRemoved(parent, first, last);
02011     d->rowsAboutToBeRemoved(parent, first, last);
02012 }

Here is the call graph for this function:

void QAbstractItemModel::endRemoveRows (  )  [protected]

Ends a row removal operation.

When reimplementing removeRows() in a subclass, you must call this function after removing data from the model's underlying data store.

See also:
beginRemoveRows()

Definition at line 2023 of file qabstractitemmodel.cpp.

References d, emit, QAbstractItemModelPrivate::Change::first, QAbstractItemModelPrivate::Change::last, QAbstractItemModelPrivate::Change::parent, and rowsRemoved().

Referenced by PiecesModel::addPieces(), qdesigner_internal::ConnectionModel::connectionRemoved(), qdesigner_internal::ResourceModel::deleteItem(), QTreeModel::endRemoveItems(), QDBusModel::refresh(), QListModel::remove(), PhraseModel::removePhrase(), QCalendarModel::removeRows(), PiecesModel::removeRows(), QTreeModel::removeRows(), QStringListModel::removeRows(), QTableModel::removeRows(), QListModel::removeRows(), QSqlQueryModel::setQuery(), and QListModel::take().

02024 {
02025     Q_D(QAbstractItemModel);
02026     QAbstractItemModelPrivate::Change change = d->changes.pop();
02027     d->rowsRemoved(change.parent, change.first, change.last);
02028     emit rowsRemoved(change.parent, change.first, change.last);
02029 }

Here is the call graph for this function:

void QAbstractItemModel::beginInsertColumns ( const QModelIndex parent,
int  first,
int  last 
) [protected]

Begins a column insertion operation.

When reimplementing insertColumns() in a subclass, you must call this function before inserting data into the model's underlying data store.

The parent index corresponds to the parent into which the new columns are inserted; first and last are the column numbers of the new columns will have after they have been inserted.

80% modelview-begin-insert-columns.png Inserting columns Specify the first and last column numbers for the span of columns you want to insert into an item in a model.

For example, as shown in the diagram, we insert three columns before column 4, so first is 4 and last is 6:

This inserts the three new columns as columns 4, 5, and 6. modelview-begin-append-columns.png Appending columns To append columns, insert them after the last column.

For example, as shown in the diagram, we append three columns to a collection of six existing columns (ending in column 5), so first is 6 and last is 8:

This appends the two new columns as columns 6, 7, and 8.

See also:
endInsertColumns()

Definition at line 2068 of file qabstractitemmodel.cpp.

References columnsAboutToBeInserted(), d, emit, and QObject::parent().

Referenced by QTableModel::insertColumns(), QCalendarModel::insertColumns(), QTreeModel::insertColumns(), QSqlQueryModel::insertColumns(), QTreeModel::setColumnCount(), and QSqlQueryModel::setQuery().

02069 {
02070     Q_ASSERT(first >= 0);
02071     Q_ASSERT(last >= first);
02072     Q_D(QAbstractItemModel);
02073     d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
02074     emit columnsAboutToBeInserted(parent, first, last);
02075     d->columnsAboutToBeInserted(parent, first, last);
02076 }

Here is the call graph for this function:

void QAbstractItemModel::endInsertColumns (  )  [protected]

Ends a column insertion operation.

When reimplementing insertColumns() in a subclass, you must call this function after inserting data into the model's underlying data store.

See also:
beginInsertColumns()

Definition at line 2087 of file qabstractitemmodel.cpp.

References columnsInserted(), d, emit, QAbstractItemModelPrivate::Change::first, QAbstractItemModelPrivate::Change::last, and QAbstractItemModelPrivate::Change::parent.

Referenced by QTableModel::insertColumns(), QCalendarModel::insertColumns(), QTreeModel::insertColumns(), QSqlQueryModel::insertColumns(), QTreeModel::setColumnCount(), and QSqlQueryModel::setQuery().

02088 {
02089     Q_D(QAbstractItemModel);
02090     QAbstractItemModelPrivate::Change change = d->changes.pop();
02091     d->columnsInserted(change.parent, change.first, change.last);
02092     emit columnsInserted(change.parent, change.first, change.last);
02093 }

Here is the call graph for this function:

void QAbstractItemModel::beginRemoveColumns ( const QModelIndex parent,
int  first,
int  last 
) [protected]

Begins a column removal operation.

When reimplementing removeColumns() in a subclass, you must call this function before removing data from the model's underlying data store.

The parent index corresponds to the parent from which the new columns are removed; first and last are the column numbers of the first and last columns to be removed.

80% modelview-begin-remove-columns.png Removing columns Specify the first and last column numbers for the span of columns you want to remove from an item in a model.

For example, as shown in the diagram, we remove the three columns from column 4 to column 6, so first is 4 and last is 6:

See also:
endRemoveColumns()

Definition at line 2120 of file qabstractitemmodel.cpp.

References columnsAboutToBeRemoved(), d, emit, and QObject::parent().

Referenced by QCalendarModel::removeColumns(), QSqlQueryModel::removeColumns(), QTableModel::removeColumns(), and QTreeModel::setColumnCount().

02121 {
02122     Q_ASSERT(first >= 0);
02123     Q_ASSERT(last >= first);
02124     Q_D(QAbstractItemModel);
02125     d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
02126     emit columnsAboutToBeRemoved(parent, first, last);
02127     d->columnsAboutToBeRemoved(parent, first, last);
02128 }

Here is the call graph for this function:

void QAbstractItemModel::endRemoveColumns (  )  [protected]

Ends a column removal operation.

When reimplementing removeColumns() in a subclass, you must call this function after removing data from the model's underlying data store.

See also:
beginRemoveColumns()

Definition at line 2139 of file qabstractitemmodel.cpp.

References columnsRemoved(), d, emit, QAbstractItemModelPrivate::Change::first, QAbstractItemModelPrivate::Change::last, and QAbstractItemModelPrivate::Change::parent.

Referenced by QCalendarModel::removeColumns(), QSqlQueryModel::removeColumns(), QTableModel::removeColumns(), and QTreeModel::setColumnCount().

02140 {
02141     Q_D(QAbstractItemModel);
02142     QAbstractItemModelPrivate::Change change = d->changes.pop();
02143     d->columnsRemoved(change.parent, change.first, change.last);
02144     emit columnsRemoved(change.parent, change.first, change.last);
02145 }

Here is the call graph for this function:

void QAbstractItemModel::reset (  )  [protected]

Resets the model to its original state in any attached views.

When a model is reset it means that any previous data reported from the model is now invalid and has to be queried for again.

When a model radically changes its data it can sometimes be easier to just call this function rather than emit dataChanged() to inform other components when the underlying data source, or its structure, has changed.

See also:
modelAboutToBeReset(), modelReset()

Definition at line 2160 of file qabstractitemmodel.cpp.

References d, emit, modelAboutToBeReset(), and modelReset().

Referenced by QStandardItemModel::clear(), QTreeModel::clear(), QListModel::clear(), QTableModel::clearContents(), MessageModel::clearContextList(), ContextModel::clearContextList(), QCompletionModel::filter(), PhraseModel::removePhrases(), QCompletionModel::setFiltered(), ImageModel::setImage(), qdesigner_internal::QPropertyEditorModel::setInitialInput(), qdesigner_internal::FlagBoxModel::setItems(), QSqlQueryModel::setQuery(), QSortFilterProxyModel::setSourceModel(), QStringListModel::setStringList(), QUndoModel::stackChanged(), ContextModel::updateAll(), and MessageModel::updateAll().

02161 {
02162     Q_D(QAbstractItemModel);
02163     emit modelAboutToBeReset();
02164     d->reset();
02165     emit modelReset();
02166 }

Here is the call graph for this function:

void QAbstractItemModel::changePersistentIndex ( const QModelIndex from,
const QModelIndex to 
) [protected]

Changes the QPersistentModelIndex that is equal to the given from model index to the given to model index.

If no persistent model index equal to the given from model index was found, nothing is changed.

See also:
persistentIndexList(), changePersistentIndexList()

Definition at line 2177 of file qabstractitemmodel.cpp.

References QList< T >::at(), QList< T >::count(), d, i, and QPersistentModelIndexData::index.

Referenced by QStandardItemPrivate::sortChildren(), and QTreeModel::sortItems().

02178 {
02179     // ### optimize (use QMap ?)
02180     Q_D(QAbstractItemModel);
02181     QList<QPersistentModelIndexData*> persistentIndexes = d->persistent.indexes;
02182     for (int i = 0; i < persistentIndexes.count(); ++i) {
02183         if (persistentIndexes.at(i)->index == from) {
02184             persistentIndexes.at(i)->index = to;
02185             break;
02186         }
02187     }
02188 }

Here is the call graph for this function:

void QAbstractItemModel::changePersistentIndexList ( const QModelIndexList from,
const QModelIndexList to 
) [protected]

Since:
4.1
Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list to the given to model index list.

If no persistent model indexes equal to the indexes in the given from model index list was found, nothing is changed.

See also:
persistentIndexList(), changePersistentIndex()

Definition at line 2201 of file qabstractitemmodel.cpp.

References QList< T >::at(), QList< T >::count(), d, i, QPersistentModelIndexData::index, and j.

Referenced by QListModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::ensureSorted(), QTableModel::setItem(), QTableModel::sort(), and QListModel::sort().

02203 {
02204     // ### optimize (use QMap ?)
02205     Q_D(QAbstractItemModel);
02206     QList<QPersistentModelIndexData*> persistentIndexes = d->persistent.indexes;
02207     QBitArray changed(persistentIndexes.count());
02208     for (int i = 0; i < from.count(); ++i) {
02209         for (int j = 0; j < persistentIndexes.count(); ++j) {
02210             if (!changed.at(j) && persistentIndexes.at(j)->index == from.at(i)) {
02211                 persistentIndexes.at(j)->index = to.at(i);
02212                 changed.setBit(j);
02213                 break;
02214             }
02215         }
02216     }
02217 }

Here is the call graph for this function:

QModelIndexList QAbstractItemModel::persistentIndexList (  )  const [protected]

Since:
4.2
Returns the list of indexes stored as persistent indexes in the model.

Definition at line 2224 of file qabstractitemmodel.cpp.

References QList< T >::append(), QList< T >::at(), QList< T >::count(), d, i, and QPersistentModelIndexData::index.

Referenced by QListModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::ensureSorted(), QTableModel::setItem(), and QStandardItemPrivate::sortChildren().

02225 {
02226     Q_D(const QAbstractItemModel);
02227     QList<QPersistentModelIndexData*> persistentIndexes = d->persistent.indexes;
02228     QModelIndexList result;
02229     for (int i = 0; i < persistentIndexes.count(); ++i)
02230         result.append(persistentIndexes.at(i)->index);
02231     return result;
02232 }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class QPersistentModelIndexData [friend]

Definition at line 131 of file qabstractitemmodel.h.


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:41:00 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1