CopperSpice API  1.9.1
QAbstractItemModel Class Referenceabstract

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

Inheritance diagram for QAbstractItemModel:
QObject QAbstractListModel QAbstractProxyModel QAbstractTableModel QDirModel QFileSystemModel QStandardItemModel QStringListModel QIdentityProxyModel QSortFilterProxyModel QSqlQueryModel QSqlTableModel QSqlRelationalTableModel

Public Signals

void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 
void columnsMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >())
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 
void layoutAboutToBeChanged (const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
 
void layoutChanged (const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
 
void modelAboutToBeReset ()
 
void modelReset ()
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 
void rowsMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

virtual void revert ()
 
virtual bool submit ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QAbstractItemModel (QObject *parent=nullptr)
 
virtual ~QAbstractItemModel ()
 
virtual QModelIndex buddy (const QModelIndex &index) const
 
virtual bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
 
virtual bool canFetchMore (const QModelIndex &parent) const
 
virtual int columnCount (const QModelIndex &parent=QModelIndex ()) const = 0
 
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const = 0
 
virtual bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 
virtual void fetchMore (const QModelIndex &parent)
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const
 
virtual bool hasChildren (const QModelIndex &parent=QModelIndex ()) const
 
bool hasIndex (int row, int column, const QModelIndex &parent=QModelIndex ()) const
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
virtual QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex ()) const = 0
 
bool insertColumn (int column, const QModelIndex &parent=QModelIndex ())
 
virtual bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex ())
 
bool insertRow (int row, const QModelIndex &parent=QModelIndex ())
 
virtual bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex ())
 
virtual QMap< int, QVariantitemData (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 QMimeDatamimeData (const QModelIndexList &indexes) const
 
virtual QStringList mimeTypes () const
 
bool moveColumn (const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild)
 
virtual bool moveColumns (const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild)
 
bool moveRow (const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild)
 
virtual bool moveRows (const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
 
QObjectparent () const
 
virtual QModelIndex parent (const QModelIndex &index) const = 0
 
bool removeColumn (int column, const QModelIndex &parent=QModelIndex ())
 
virtual bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex ())
 
bool removeRow (int row, const QModelIndex &parent=QModelIndex ())
 
virtual bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex ())
 
virtual QMultiHash< int, QStringroleNames () const
 
virtual int rowCount (const QModelIndex &parent=QModelIndex ()) const = 0
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
 
virtual bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
 
virtual QModelIndex sibling (int row, int column, const QModelIndex &index) const
 
virtual void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
 
virtual QSize span (const QModelIndex &index) const
 
virtual Qt::DropActions supportedDragActions () const
 
virtual Qt::DropActions supportedDropActions () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Protected Slots

void resetInternalData ()
 

Protected Methods

void beginInsertColumns (const QModelIndex &parent, int first, int last)
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn)
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 
void beginResetModel ()
 
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 
QModelIndex createIndex (int row, int column, quintptr id) const
 
QModelIndex createIndex (int row, int column, void *data=nullptr) const
 
void endInsertColumns ()
 
void endInsertRows ()
 
void endMoveColumns ()
 
void endMoveRows ()
 
void endRemoveColumns ()
 
void endRemoveRows ()
 
void endResetModel ()
 
QModelIndexList persistentIndexList () const
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Friends

class QIdentityProxyModel
 

Additional Inherited Members

- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Properties inherited from QObject
 objectName
 

Detailed Description

The QAbstractItemModel class provides the abstract interface for item model classes. This 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.

If you need a model to use with a QListView or a QTableView, you should consider inheriting from QAbstractListModel or QAbstractTableModel instead of this class. The underlying data model is exposed to views and delegates as a hierarchy of tables. If you do not 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.

Every item of data which can be accessed from a model has an associated model index. The model index is retrieved using the index() method. Each index may have a sibling() index and child items have a parent() index. 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().

Each item stores data elements and they can be retrieved by specifying a role when calling the model data() method. Data for all available roles can be obtained at the same time using the itemData() method. Data for each role is set using a particular Qt::ItemDataRole. Data for specific roles are set using setData() or all roles can be set simultaneously with setItemData(). Items can be queried with flags() to see if they can be selected, dragged, or modified in other ways.

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

Inheriting

General guidelines for inheriting from models are available in the Custom Models documentation.

When inheriting from QAbstractItemModel you must implement index(), parent(), rowCount(), columnCount(), and data(). These methods are used in all read only models and are the basis of editable models. You can also override hasChildren() 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 ItemIsEditable is returned. You can also reimplement headerData() and setHeaderData() to control the way the headers for your model are presented.

The dataChanged() and headerDataChanged() signals must be emitted explicitly when implementing the setData() and setHeaderData() methods. To create models which populate incrementally implement fetchMore() and canFetchMore(). If fetchMore() adds rows to the model, beginInsertRows() and endInsertRows() must be called.

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 an identifier for it, either as a pointer or as an integer value. The combination of these values must be unique for each item. Custom models typically use these unique identifiers in other reimplemented methods to retrieve item data and access information about the item's parents and children.

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() method 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 CopperSpice views. However, for some models that handle highly-specialized data, it may be appropriate to provide data only for user-defined roles.

Models which provide interfaces to resizable data structures can also implement of insertRows(), removeRows(), insertColumns(),and removeColumns(). When implementing these methods, it is important to notify any connected views about changes to the model's dimensions both before and after they occur. The signals all these methods emit give the view a chance to take some action before data is removed. The encapsulation of the insert and remove operations enables the model to manage persistent model indexes correctly. If you insert or remove an item with children you do not need to call these methods for the child items.

insertRows()
Implementation must call beginInsertRows() before inserting new rows into the data structure, and then call endInsertRows() immediately afterwards
insertColumns()
Implementation must call beginInsertColumns() before inserting new columns into the data structure, and then call endInsertColumns() immediately afterwards
removeRows()
Implementation must call beginRemoveRows() before the rows are removed from the data structure, and then call endRemoveRows() immediately afterwards
removeColumns()
Implementation must call beginRemoveColumns() before the columns are removed from the data structure, and then call endRemoveColumns() immediately afterwards
See also
QModelIndex, QAbstractItemView, Model/View Architecture, Models, Custom Models, Drag and Drop

Constructor & Destructor Documentation

QAbstractItemModel::QAbstractItemModel ( QObject parent = nullptr)
explicit

Constructs an abstract item model with the given parent.

QAbstractItemModel::~QAbstractItemModel ( )
virtual

Destroys the abstract item model.

Method Documentation

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

This method emits the columnsAboutToBeInserted() signal which connected views (or proxies) must handle before the data is inserted. Otherwise, the views may end up in an invalid state.

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.

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

This method emits the rowsAboutToBeInserted() signal which connected views (or proxies) must handle before the data is inserted. Otherwise, the views may end up in an invalid state.

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.

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()
bool QAbstractItemModel::beginMoveColumns ( const QModelIndex sourceParent,
int  sourceFirst,
int  sourceLast,
const QModelIndex destinationParent,
int  destinationColumn 
)
protected

Begins a column move operation.

When reimplementing a subclass, this method simplifies moving entities in your model. This method is responsible for moving persistent indexes in the model, which you would otherwise be required to do yourself. Using beginMoveRows and endMoveRows is an alternative to emitting layoutAboutToBeChanged and layoutChanged directly along with changePersistentIndexes. layoutAboutToBeChanged is emitted by this method for compatibility reasons.

The sourceParent index corresponds to the parent from which the columns are moved, sourceFirst and sourceLast are the first and last column numbers of the columns to be moved. The destinationParent index corresponds to the parent into which those columns are moved. The destinationColumn is the column to which the columns will be moved. The index at column sourceFirst in sourceParent will become column destinationColumn in destinationParent, followed by all other columns up to sourceLast.

However, when moving columns down in the same parent (sourceParent and destinationParent are equal), the columns will be placed before the destinationColumn index. That is, if you wish to move columns 0 and 1 so they will become columns 1 and 2, destinationColumn should be 3. In this case, the new index for the source column i (which is between sourceFirst and sourceLast) is equal to (destinationColumn - sourceLast - 1 + i).

If sourceParent and destinationParen are the same, you must ensure that the destinationColumn is not within the range of sourceFirst and (sourceLast + 1). You must also ensure that you do not attempt to move a column to one of its own children or ancestors. This method returns false if either condition is true, in which case you should abort your move operation.

See also
endMoveColumns()
bool QAbstractItemModel::beginMoveRows ( const QModelIndex sourceParent,
int  sourceFirst,
int  sourceLast,
const QModelIndex destinationParent,
int  destinationRow 
)
protected

Begins a row move operation.

When reimplementing a subclass this method simplifies moving entities in your model. This method is responsible for moving persistent indexes in the model, which you would otherwise be required to do yourself. Using the methods beginMoveRows() and endMoveRows() is an alternative to emitting layoutAboutToBeChanged and layoutChanged directly along with changePersistentIndexes. The layoutAboutToBeChanged signal is emitted by this method for compatibility reasons.

The sourceParent index corresponds to the parent from which the rows are moved, sourceFirst and sourceLast are the first and last row numbers of the rows to be moved. The destinationParent index corresponds to the parent into which those rows are moved. The destinationRow is the row to which the rows will be moved. That is, the index at row sourceFirst in sourceParent will become row destinationRow in destinationParent, followed by all other rows up to sourceLast.

When moving rows down in the same parent (sourceParent and destinationParent are equal), the rows will be placed before the destinationRow index. That is, if you wish to move rows 0 and 1 so they will become rows 1 and 2, destinationRow should be 3. In this case, the new index for the source row i (which is between sourceFirst and sourceLast) is equal to (destinationRow - sourceLast - 1 + i).

If sourceParent and destinationParent are the same, you must ensure that the destinationRow is not within the range of sourceFirst and (sourceLast + 1). You must also ensure that you do not attempt to move a row to one of its own children or ancestors. This method returns false if either condition is true, in which case you should abort your move operation.

Moving rows to another parent

Specify the first and last row numbers for the span of rows in the source parent you want to move in the model. Also specify the row in the destination parent to move the span to. For example, as shown in the diagram, we move three rows from row 2 to 4 in the source, so sourceFirst is 2 and sourceLast is 4. We move those items to above row 2 in the destination, so destinationRow is 2.

beginMoveRows(sourceParent, 2, 4, destinationParent, 2);

This moves the three rows 2, 3, and 4 in the source to become 2, 3 and 4 in the destination. Other affected siblings are displaced accordingly.

Moving rows to append to another parent

To append rows to another parent, move them to after the last row. For example, as shown in the diagram, we move three rows to a collection of 6 existing rows (ending in row 5), so destinationRow is 6.

beginMoveRows(sourceParent, 2, 4, destinationParent, 6);

This moves the target rows to the end of the target parent as 6, 7 and 8.

Moving rows in the same parent up

To move rows within the same parent, specify the row to move them to. For example, as shown in the diagram, we move one item from row 2 to row 0, so sourceFirst and sourceLast are 2 and destinationRow is 0.

Other rows may be displaced accordingly. Note also that when moving items within the same parent you should not attempt invalid or no-op moves. In the above example, item 2 is at row 2 before the move, so it can not be moved to row 2 (where it is already) or row 3 (no-op as row 3 means above row 3, where it is already)

Moving rows in the same parent down

To move rows within the same parent, specify the row to move them to. For example, as shown in the diagram, we move one item from row 2 to row 4, so sourceFirst and sourceLast are 2 and destinationRow is 4.

Other rows may be displaced accordingly.

See also
endMoveRows()
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 method 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.

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.

Note
This method emits the columnsAboutToBeRemoved() signal which connected views (or proxies) must handle before the data is removed. Otherwise, the views may end up in an invalid state.
See also
endRemoveColumns()
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 method 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.

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.

Note
This method emits the rowsAboutToBeRemoved() signal which connected views (or proxies) must handle before the data is removed. Otherwise, the views may end up in an invalid state.
See also
endRemoveRows()
void QAbstractItemModel::beginResetModel ( )
protected

Begins a model reset operation.

A reset operation resets the model to its current state in any attached views. Any views attached to this model will be reset as well. 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. This also means that the current item and any selected items will become invalid. When a model radically changes its data it can sometimes be easier to just call this method rather than emit dataChanged() to inform other components when the underlying data source, or its structure, has changed.

You must call this method before resetting any internal data structures in your model or proxy model.

See also
modelAboutToBeReset(), modelReset(), endResetModel()
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 method to check whether another item in the model should be edited instead. Then, the view will construct a delegate using the model index returned by the buddy item.

The default implementation of this method has each item as its own buddy.

Reimplemented in QSortFilterProxyModel::buddy(), QAbstractProxyModel::buddy()

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

Returns true if a model can accept a drop of the data. This default implementation only checks if data has at least one format in the list of mimeTypes() and if action is among the model's supportedDropActions(). Reimplement this method in your custom model, if you want to test whether the data can be dropped at row, column, parent with action. If you do not need that test, it is not necessary to reimplement this method.

See also
dropMimeData(), Drag and Drop

Reimplemented in QAbstractProxyModel::canDropMimeData()

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

Returns true if there is more data available for parent, otherwise returns false. The default implementation always returns false. If canFetchMore() returns true, QAbstractItemView will call fetchMore(). However, the fetchMore() method is only called when the model is being populated incrementally.

See also
fetchMore()

Reimplemented in QSqlQueryModel::canFetchMore(), QSortFilterProxyModel::canFetchMore(), QFileSystemModel::canFetchMore(), QAbstractProxyModel::canFetchMore()

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()
void QAbstractItemModel::changePersistentIndexList ( const QModelIndexList from,
const QModelIndexList to 
)
protected

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()
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. When implementing a table based model this methods should return 0 when the parent is valid.

int DomModel::columnCount(const QModelIndex &) const
{
return 3;
}
See also
rowCount()

Implemented in QStandardItemModel::columnCount(), QSortFilterProxyModel::columnCount(), QFileSystemModel::columnCount(), QDirModel::columnCount(), QIdentityProxyModel::columnCount(), QSqlQueryModel::columnCount()

void QAbstractItemModel::columnsAboutToBeInserted ( const QModelIndex parent,
int  first,
int  last 
)
signal

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

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 can not be explicitly emitted in subclass code.

See also
insertColumns(), beginInsertColumns()
void QAbstractItemModel::columnsAboutToBeMoved ( const QModelIndex sourceParent,
int  sourceStart,
int  sourceEnd,
const QModelIndex destinationParent,
int  destinationColumn 
)
signal

This signal is emitted just before columns are moved within the model. The items that will be moved are those between sourceStart and sourceEnd inclusive, under the given sourceParent item. They will be moved to destinationParent starting at the column destinationColumn.

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 can not be explicitly emitted in subclass code.

See also
beginMoveRows()
void QAbstractItemModel::columnsAboutToBeRemoved ( const QModelIndex parent,
int  first,
int  last 
)
signal

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

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 can not be explicitly emitted in subclass code.

See also
removeColumns(), beginRemoveColumns()
void QAbstractItemModel::columnsInserted ( const QModelIndex parent,
int  first,
int  last 
)
signal

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

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 can not be explicitly emitted in subclass code.

See also
insertColumns(), beginInsertColumns()
void QAbstractItemModel::columnsMoved ( const QModelIndex sourceParent,
int  sourceStart,
int  sourceEnd,
const QModelIndex destinationParent,
int  destinationColumn 
)
signal

This signal is emitted after columns have been moved within the model. The items between sourceStart and sourceEnd inclusive, under the given sourceParent item have been moved to destinationParent starting at the column destinationColumn.

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 can not be explicitly emitted in subclass code.

See also
beginMoveRows()
void QAbstractItemModel::columnsRemoved ( const QModelIndex parent,
int  first,
int  last 
)
signal

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

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 can not be explicitly emitted in subclass code.

See also
removeColumns(), beginRemoveColumns()
QModelIndex QAbstractItemModel::createIndex ( int  row,
int  column,
quintptr  id 
) const
inlineprotected

Creates a model index for the given row and column with the internal identifier, id. This method provides a consistent interface that model subclasses must use to create model indexes.

See also
QModelIndex::internalId()
QModelIndex QAbstractItemModel::createIndex ( int  row,
int  column,
void *  data = nullptr 
) const
inlineprotected

Creates a model index for the given row and column with the given data.

When using a QSortFilterProxyModel the indexes have their own internal pointer. It is not advisable to access this pointer outside of the model. Use the data() method instead. This method provides a consistent interface that model subclasses must use to create model indexes.

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. If there is no return value then return an invalid QVariant.

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

Implemented in QAbstractProxyModel::data(), QSqlQueryModel::data(), QStandardItemModel::data(), QSortFilterProxyModel::data(), QFileSystemModel::data(), QSqlRelationalTableModel::data(), QDirModel::data(), QSqlTableModel::data(), QStringListModel::data()

void QAbstractItemModel::dataChanged ( const QModelIndex topLeft,
const QModelIndex bottomRight,
const QVector< int > &  roles = QVector<int>() 
)
signal

This signal is emitted whenever the data in an existing item changes. If the items are of the same parent, the affected ones are those between topLeft and bottomRight inclusive. If the items do not have the same parent, the behavior is undefined.

When reimplementing the setData() method this signal must be emitted explicitly.

See also
headerDataChanged(), setData(), layoutChanged()
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 which ended with the given action. Returns true if the data and action can be handled by the model, otherwise returns false. 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 model to complete the action at the correct location.

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 both -1 it means the dropped data should be considered as dropped directly on parent. Usually this will mean appending the data as child items of parent. If row and column are greater than or equal zero, it means that the drop occurred just before the specified row and column in the specified parent.

See also
supportedDropActions(), Drag and Drop

Reimplemented in QAbstractListModel::dropMimeData(), QAbstractTableModel::dropMimeData(), QStandardItemModel::dropMimeData(), QSortFilterProxyModel::dropMimeData(), QFileSystemModel::dropMimeData(), QAbstractProxyModel::dropMimeData(), QDirModel::dropMimeData(), QIdentityProxyModel::dropMimeData()

void QAbstractItemModel::endInsertColumns ( )
protected

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

See also
beginInsertColumns()
void QAbstractItemModel::endInsertRows ( )
protected

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

See also
beginInsertRows()
void QAbstractItemModel::endMoveColumns ( )
protected

Ends a column move operation. When implementing a subclass, you must call this method after moving data within the model's underlying data store. The layoutChanged signal is emitted by this method for compatibility reasons.

See also
beginMoveColumns()
void QAbstractItemModel::endMoveRows ( )
protected

Ends a row move operation. When implementing a subclass, you must call this method after moving data within the model's underlying data store. The layoutChanged is emitted by this method for compatibility reasons.

See also
beginMoveRows()
void QAbstractItemModel::endRemoveColumns ( )
protected

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

See also
beginRemoveColumns()
void QAbstractItemModel::endRemoveRows ( )
protected

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

See also
beginRemoveRows()
void QAbstractItemModel::endResetModel ( )
protected

Completes a model reset operation. You must call this method after resetting any internal data structure in your model or proxy model.

See also
beginResetModel()
void QAbstractItemModel::fetchMore ( const QModelIndex parent)
virtual

Fetches any available data for the items with the parent specified by the parent index. Reimplement this method if you are populating your model incrementally. The default implementation does nothing.

See also
canFetchMore()

Reimplemented in QSqlQueryModel::fetchMore(), QSortFilterProxyModel::fetchMore(), QFileSystemModel::fetchMore(), QAbstractProxyModel::fetchMore()

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 which enables the item (ItemIsEnabled) and allows it to be selected (ItemIsSelectable).

See also
Qt::ItemFlags

Reimplemented in QAbstractListModel::flags(), QAbstractTableModel::flags(), QStandardItemModel::flags(), QSortFilterProxyModel::flags(), QFileSystemModel::flags(), QDirModel::flags(), QAbstractProxyModel::flags(), QSqlTableModel::flags(), QStringListModel::flags()

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

Reimplemented in QStandardItemModel::hasChildren(), QSortFilterProxyModel::hasChildren(), QFileSystemModel::hasChildren(), QAbstractProxyModel::hasChildren(), QDirModel::hasChildren()

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.

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. For horizontal headers, the section number corresponds to the column number. Similarly, for vertical headers, the section number corresponds to the row number.

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

Reimplemented in QStandardItemModel::headerData(), QSortFilterProxyModel::headerData(), QFileSystemModel::headerData(), QDirModel::headerData(), QSqlTableModel::headerData(), QIdentityProxyModel::headerData(), QSqlQueryModel::headerData(), QAbstractProxyModel::headerData()

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. When reimplementing the setHeaderData() method, this signal must be emitted explicitly. If you are changing the number of columns or rows you do not need to emit this signal, but use the begin/end methods.

See also
headerData(), setHeaderData(), dataChanged()
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 method in a subclass, call createIndex() to generate model indexes that other components can use to refer to items in your model.

See also
createIndex()

Implemented in QAbstractListModel::index(), QAbstractTableModel::index(), QStandardItemModel::index(), QSortFilterProxyModel::index(), QFileSystemModel::index(), QDirModel::index(), QIdentityProxyModel::index()

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()
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. Returns true if the columns were successfully inserted, otherwise returns false.

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 the given count columns is inserted.

The base class implementation does nothing and returns false. If you implement your own model, you can reimplement this method if you want to support insertions. Alternatively, you can provide your own API for altering the data.

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

Reimplemented in QStandardItemModel::insertColumns(), QSortFilterProxyModel::insertColumns(), QIdentityProxyModel::insertColumns(), QSqlQueryModel::insertColumns()

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. The base class implementation of this method does nothing and returns false.

See also
insertRows(), insertColumn(), removeRow()
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. Items in the new row will be children of the item represented by the parent model index. Returns true if the rows were successfully inserted, otherwise returns false.

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 the given count rows is inserted.

The base class implementation of this method does nothing and returns false. If you implement your own model, you can reimplement this method if you want to support insertions. Alternatively, you can provide your own API for altering the data. In either case, you will need to call beginInsertRows() and endInsertRows() to notify other components that the model has changed.

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

Reimplemented in QStandardItemModel::insertRows(), QSortFilterProxyModel::insertRows(), QSqlTableModel::insertRows(), QIdentityProxyModel::insertRows(), QStringListModel::insertRows()

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. Reimplement this method if you want to extend the default behavior of this method to include custom roles in the map.

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

Reimplemented in QAbstractProxyModel::itemData(), QStandardItemModel::itemData()

void QAbstractItemModel::layoutAboutToBeChanged ( const QList< QPersistentModelIndex > &  parents = QList<QPersistentModelIndex>(),
QAbstractItemModel::LayoutChangeHint  hint = QAbstractItemModel::NoLayoutChangeHint 
)
signal

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()
void QAbstractItemModel::layoutChanged ( const QList< QPersistentModelIndex > &  parents = QList<QPersistentModelIndex>(),
QAbstractItemModel::LayoutChangeHint  hint = QAbstractItemModel::NoLayoutChangeHint 
)
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(). In other words, when the structure changes:

See also
layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), modelReset(), changePersistentIndex()
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 in the column of the start index where 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 begins 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 method 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 method only searches columns. Reimplement this method to include a different search behavior.

Reimplemented in QSortFilterProxyModel::match(), QIdentityProxyModel::match()

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

Reimplemented in QStandardItemModel::mimeData(), QSortFilterProxyModel::mimeData(), QFileSystemModel::mimeData(), QDirModel::mimeData(), QAbstractProxyModel::mimeData()

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

Reimplemented in QStandardItemModel::mimeTypes(), QSortFilterProxyModel::mimeTypes(), QFileSystemModel::mimeTypes(), QAbstractProxyModel::mimeTypes(), QDirModel::mimeTypes()

void QAbstractItemModel::modelAboutToBeReset ( )
signal

This signal is emitted when beginResetModel() is called, before the model's internal state (for example all persistent model indexes) has been invalidated.

See also
beginResetModel(), modelReset()
void QAbstractItemModel::modelReset ( )
signal

This signal is emitted when endResetModel() is called, after the model's internal state (for example, all persistent model indexes) has been invalidated.

See also
endResetModel(), modelAboutToBeReset()
bool QAbstractItemModel::moveColumn ( const QModelIndex sourceParent,
int  sourceColumn,
const QModelIndex destinationParent,
int  destinationChild 
)
inline

On models that support this, moves sourceColumn from sourceParent to destinationChild under destinationParent. Returns true if the columns were successfully moved, otherwise returns false.

See also
moveColumns(), moveRow()
bool QAbstractItemModel::moveColumns ( const QModelIndex sourceParent,
int  sourceColumn,
int  count,
const QModelIndex destinationParent,
int  destinationChild 
)
virtual

On models that support this, moves count columns starting with the given sourceColumn under parent sourceParent to column destinationChild under parent destinationParent. Returns true if the columns were successfully moved, otherwise returns false.

The base class implementation does nothing and returns false. If you implement your own model, you can reimplement this method if you want to support moving. Alternatively, you can provide your own API for altering the data.

See also
beginMoveColumns(), endMoveColumns()
bool QAbstractItemModel::moveRow ( const QModelIndex sourceParent,
int  sourceRow,
const QModelIndex destinationParent,
int  destinationChild 
)
inline

On models which support this, moves sourceRow from sourceParent to destinationChild under destinationParent. Returns true if the rows were successfully moved, otherwise returns false.

See also
moveRows(), moveColumn()
bool QAbstractItemModel::moveRows ( const QModelIndex sourceParent,
int  sourceRow,
int  count,
const QModelIndex destinationParent,
int  destinationChild 
)
virtual

On models that support this, moves count rows starting with the given sourceRow under parent sourceParent to row destinationChild under parent destinationParent. Returns true if the rows were successfully moved, otherwise returns false.

The base class implementation does nothing and returns false. If you implement your own model, you can reimplement this method if you want to support moving. Alternatively, you can provide your own API for altering the data.

See also
beginMoveRows(), endMoveRows()
QObject * QObject::parent ( ) const
using

Returns a pointer to the parent object.

See also
setParent(), children()
QModelIndex QAbstractItemModel::parent ( const QModelIndex index) const
pure virtual

Returns the parent of the model item with the given index. If the item has no parent an invalid QModelIndex is returned.

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 method in a subclass the column of the returned QModelIndex would be 0.

When reimplementing this method in a subclass, be careful to avoid calling QModelIndex member methods, such as QModelIndex::parent(), since indexes belonging to your model will simply call your implementation, leading to infinite recursion.

See also
createIndex()

Implemented in QFileSystemModel::parent(), QStandardItemModel::parent(), QSortFilterProxyModel::parent(), QDirModel::parent(), QIdentityProxyModel::parent()

QModelIndexList QAbstractItemModel::persistentIndexList ( ) const
protected

Returns the list of indexes stored as persistent indexes in the model.

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()
bool QAbstractItemModel::removeColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
)
virtual

For models which support removing columns, the methods removes count columns starting with column using the given parent. 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, reimplement this method to support removing columns. Alternatively, can provide your own API for altering the data.

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

Reimplemented in QStandardItemModel::removeColumns(), QSortFilterProxyModel::removeColumns(), QSqlTableModel::removeColumns(), QSqlRelationalTableModel::removeColumns(), QIdentityProxyModel::removeColumns(), QSqlQueryModel::removeColumns()

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. Equivalent to calling removeRows().

The base class implementation does nothing and returns false.

See also
removeRows(), removeColumn(), insertRow()
bool QAbstractItemModel::removeRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
virtual

For models which support removing rows, removes count rows starting with row using the given parent. 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, reimplement this method to support removing rows. Alternatively, provide your own API for altering the data.

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

Reimplemented in QStandardItemModel::removeRows(), QSortFilterProxyModel::removeRows(), QSqlTableModel::removeRows(), QIdentityProxyModel::removeRows(), QStringListModel::removeRows()

void QAbstractItemModel::resetInternalData ( )
protectedslot

This slot is called just after the internal data of a model is cleared while it is being reset. This slot is provided the convenience of subclasses of concrete proxy models, such as subclasses of QSortFilterProxyModel which maintain extra data.

class CustomDataProxy : public QSortFilterProxyModel
{
CS_OBJECT(CustomDataProxy)
public:
CustomDataProxy(QObject *parent)
{ }
QVariant data(const QModelIndex &index, int role) {
if (role != Qt::BackgroundRole) {
return QSortFilterProxyModel::data(index, role);
}
if (m_customData.contains(index.row())) {
return m_customData.value(index.row());
}
return QSortFilterProxyModel::data(index, role);
}
private:
CS_SLOT_1(Private, void resetInternalData() { m_customData.clear(); })
CS_SLOT_2(resetInternalData)
QHash<int, QVariant> m_customData;
};
See also
modelAboutToBeReset(), modelReset()
void QAbstractItemModel::revert ( )
slot

Lets the model know that it should discard cached information. This method is typically used for row editing.

See also
submit()
QMultiHash< int, QString > QAbstractItemModel::roleNames ( ) const
virtual

Returns the role names for this model. Inherit from QAbstractItemModel and reimplement this method to return a different group of role names.

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

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. When implementing a table based model this method should return 0 when the parent is valid.

See also
columnCount()

Implemented in QStandardItemModel::rowCount(), QSortFilterProxyModel::rowCount(), QFileSystemModel::rowCount(), QSqlTableModel::rowCount(), QDirModel::rowCount(), QIdentityProxyModel::rowCount(), QStringListModel::rowCount(), QSqlQueryModel::rowCount()

void QAbstractItemModel::rowsAboutToBeInserted ( const QModelIndex parent,
int  first,
int  last 
)
signal

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

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 can not be explicitly emitted in subclass code.

See also
insertRows(), beginInsertRows()
void QAbstractItemModel::rowsAboutToBeMoved ( const QModelIndex sourceParent,
int  sourceStart,
int  sourceEnd,
const QModelIndex destinationParent,
int  destinationRow 
)
signal

This signal is emitted just before rows are moved within the model. The items that will be moved are those between sourceStart and sourceEnd inclusive, under the given sourceParent item. They will be moved to destinationParent starting at the row destinationRow.

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 can not be explicitly emitted in subclass code.

See also
beginMoveRows()
void QAbstractItemModel::rowsAboutToBeRemoved ( const QModelIndex parent,
int  first,
int  last 
)
signal

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

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 can not be explicitly emitted in subclass code.

See also
removeRows(), beginRemoveRows()
void QAbstractItemModel::rowsInserted ( const QModelIndex parent,
int  first,
int  last 
)
signal

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

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 can not be explicitly emitted in subclass code.

See also
insertRows(), beginInsertRows()
void QAbstractItemModel::rowsMoved ( const QModelIndex sourceParent,
int  sourceStart,
int  sourceEnd,
const QModelIndex destinationParent,
int  destinationRow 
)
signal

This signal is emitted after rows have been moved within the model. The items between sourceStart and sourceEnd inclusive, under the given sourceParent item have been moved to destinationParent starting at the row destinationRow.

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 can not be explicitly emitted in subclass code.

See also
beginMoveRows()
void QAbstractItemModel::rowsRemoved ( const QModelIndex parent,
int  first,
int  last 
)
signal

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

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 can not be explicitly emitted in subclass code.

See also
removeRows(), beginRemoveRows()
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 method and data() must be reimplemented for editable models.

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

Reimplemented in QStandardItemModel::setData(), QSortFilterProxyModel::setData(), QFileSystemModel::setData(), QSqlRelationalTableModel::setData(), QDirModel::setData(), QAbstractProxyModel::setData(), QSqlTableModel::setData(), QStringListModel::setData()

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

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.

When reimplementing this method the headerDataChanged() signal must be emitted explicitly.

See also
Qt::ItemDataRole, headerData()

Reimplemented in QStandardItemModel::setHeaderData(), QSortFilterProxyModel::setHeaderData(), QAbstractProxyModel::setHeaderData(), QSqlQueryModel::setHeaderData()

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

Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole. Returns true if successful, otherwise returns false. Roles that are not in roles will not be modified.

See also
setData(), data(), itemData()

Reimplemented in QStandardItemModel::setItemData(), QAbstractProxyModel::setItemData()

QModelIndex QAbstractItemModel::sibling ( int  row,
int  column,
const QModelIndex index 
) const
virtual

Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location. The sibling() is just a convenience method 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()

Reimplemented in QAbstractListModel::sibling(), QAbstractTableModel::sibling(), QSortFilterProxyModel::sibling(), QAbstractProxyModel::sibling(), QIdentityProxyModel::sibling(), QStringListModel::sibling()

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

Subclasses should implement this method to sorts the model by column in the given order. This base class implementation does nothing.

Reimplemented in QStandardItemModel::sort(), QSortFilterProxyModel::sort(), QFileSystemModel::sort(), QDirModel::sort(), QAbstractProxyModel::sort(), QStringListModel::sort(), QSqlTableModel::sort()

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

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

Note
Currently not used.

Reimplemented in QSortFilterProxyModel::span(), QAbstractProxyModel::span()

bool QAbstractItemModel::submit ( )
slot

Lets the model know that it should submit cached information to permanent storage. This method is typically used for row editing. Returns true if there is no error, otherwise returns false.

See also
revert()
Qt::DropActions QAbstractItemModel::supportedDragActions ( ) const
virtual

Returns the actions supported by the data in this model. The default implementation calls supportedDropActions() and returns the default enum value of Qt::CopyAction. This method is used by QAbstractItemView::startDrag() as the default values when a drag occurs.

Inherit from QAbstractItemModel and reimplement this method to return some other Qt::DropActions enum value.

See also
Qt::DropActions, Drag and Drop

Reimplemented in QAbstractProxyModel::supportedDragActions()

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

Returns the drop actions supported by this model. The default implementation returns Qt::CopyAction. Inherit from QAbstractItemModel and reimplement this method to return some other Qt::DropActions enum value. You must also reimplement the dropMimeData() method to handle any additional operations.

See also
dropMimeData(), Qt::DropActions, Drag and Drop

Reimplemented in QStandardItemModel::supportedDropActions(), QSortFilterProxyModel::supportedDropActions(), QFileSystemModel::supportedDropActions(), QAbstractProxyModel::supportedDropActions(), QDirModel::supportedDropActions(), QStringListModel::supportedDropActions()