Qt 4.8
Public Slots | Signals | Public Functions | Protected Slots | Protected Functions | Friends | List of all members
QAbstractItemModel Class Referenceabstract

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

#include <qabstractitemmodel.h>

Inheritance diagram for QAbstractItemModel:
QObject QAbstractListModel QAbstractProxyModel QAbstractTableModel QDirModel QEmptyItemModel QEmptyModel QEmptyModel QFileSystemModel QPPDOptionsModel QProxyModel QScriptBreakpointsModel QScriptDebuggerLocalsModel QScriptDebuggerScriptsModel QStandardItemModel QTreeModel QUndoModel

Public Slots

virtual void revert ()
 Lets the model know that it should discard cached information. More...
 
virtual bool submit ()
 Lets the model know that it should submit cached information to permanent storage. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted just before columns are inserted into the model. More...
 
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 This signal is emitted just before columns are moved within the model. More...
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted just before columns are removed from the model. More...
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted after columns have been inserted into the model. More...
 
void columnsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
 This signal is emitted after columns have been moved within the model. More...
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted after columns have been removed from the model. More...
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 This signal is emitted whenever the data in an existing item changes. More...
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 This signal is emitted whenever a header is changed. More...
 
void layoutAboutToBeChanged ()
 This signal is emitted just before the layout of a model is changed. More...
 
void layoutChanged ()
 This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted. More...
 
void modelAboutToBeReset ()
 This signal is emitted when reset() is called, before the model's internal state (e. More...
 
void modelReset ()
 This signal is emitted when reset() is called, after the model's internal state (e. More...
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted just before rows are inserted into the model. More...
 
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 This signal is emitted just before rows are moved within the model. More...
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted just before rows are removed from the model. More...
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted after rows have been inserted into the model. More...
 
void rowsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
 This signal is emitted after rows have been moved within the model. More...
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted after rows have been removed from the model. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

virtual QModelIndex buddy (const QModelIndex &index) const
 Returns a model index for the buddy of the item represented by index. More...
 
virtual bool canFetchMore (const QModelIndex &parent) const
 Returns true if there is more data available for parent; otherwise returns false. More...
 
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const =0
 Returns the number of columns for the children of the given parent. More...
 
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const =0
 Returns the data stored under the given role for the item referred to by the index. More...
 
virtual bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Handles the data supplied by a drag and drop operation that ended with the given action. More...
 
virtual void fetchMore (const QModelIndex &parent)
 Fetches any available data for the items with the parent specified by the parent index. More...
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const
 Returns the item flags for the given index. More...
 
virtual bool hasChildren (const QModelIndex &parent=QModelIndex()) const
 Returns true if parent has any children; otherwise returns false. More...
 
bool hasIndex (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Returns true if the model returns a valid QModelIndex for row and column with parent, otherwise returns false. More...
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 Returns the data for the given role and section in the header with the specified orientation. More...
 
virtual QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const =0
 Returns the index of the item in the model specified by the given row, column and parent index. More...
 
bool insertColumn (int column, const QModelIndex &parent=QModelIndex())
 Inserts a single column before the given column in the child items of the parent specified. More...
 
virtual bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, inserts count new columns into the model before the given column. More...
 
bool insertRow (int row, const QModelIndex &parent=QModelIndex())
 Inserts a single row before the given row in the child items of the parent specified. More...
 
virtual bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, inserts count rows into the model before the given row. More...
 
virtual QMap< int, QVariantitemData (const QModelIndex &index) const
 Returns a map with values for all predefined roles in the model for the item at the given index. More...
 
virtual QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
 Returns a list of indexes for the items in the column of the start index where data stored under the given role matches the specified value. More...
 
virtual QMimeDatamimeData (const QModelIndexList &indexes) const
 Returns an object that contains serialized items of data corresponding to the list of indexes specified. More...
 
virtual QStringList mimeTypes () const
 Returns a list of MIME types that can be used to describe a list of model indexes. More...
 
virtual QModelIndex parent (const QModelIndex &child) const =0
 Returns the parent of the model item with the given index. More...
 
 QAbstractItemModel (QObject *parent=0)
 Constructs an abstract item model with the given parent. More...
 
bool removeColumn (int column, const QModelIndex &parent=QModelIndex())
 Removes the given column from the child items of the parent specified. More...
 
virtual bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, removes count columns starting with the given column under parent parent from the model. More...
 
bool removeRow (int row, const QModelIndex &parent=QModelIndex())
 Removes the given row from the child items of the parent specified. More...
 
virtual bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, removes count rows starting with the given row under parent parent from the model. More...
 
const QHash< int, QByteArray > & roleNames () const
 Returns the model's role names. More...
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const =0
 Returns the number of rows under the given parent. More...
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 Sets the role data for the item at index to value. More...
 
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
 Sets the data for the given role and section in the header with the specified orientation to the value supplied. More...
 
virtual bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
 Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole. More...
 
void setSupportedDragActions (Qt::DropActions)
 Sets the supported drag actions for the items in the model. More...
 
QModelIndex sibling (int row, int column, const QModelIndex &idx) const
 Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location. More...
 
virtual void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
 Sorts the model by column in the given order. More...
 
virtual QSize span (const QModelIndex &index) const
 Returns the row and column span of the item represented by index. More...
 
Qt::DropActions supportedDragActions () const
 Returns the actions supported by the data in this model. More...
 
virtual Qt::DropActions supportedDropActions () const
 Returns the drop actions supported by this model. More...
 
virtual ~QAbstractItemModel ()
 Destroys the abstract item model. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Slots

void resetInternalData ()
 This slot is called just after the internal data of a model is cleared while it is being reset. More...
 

Protected Functions

void beginInsertColumns (const QModelIndex &parent, int first, int last)
 Begins a column insertion operation. More...
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 Begins a row insertion operation. More...
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn)
 Begins a column move operation. More...
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
 Begins a row move operation. More...
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 Begins a column removal operation. More...
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 Begins a row removal operation. More...
 
void beginResetModel ()
 Begins a model reset operation. More...
 
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 Changes the QPersistentModelIndex that is equal to the given from model index to the given to model index. More...
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list to the given to model index list. More...
 
QModelIndex createIndex (int row, int column, void *data=0) const
 Creates a model index for the given row and column with the internal pointer ptr. More...
 
QModelIndex createIndex (int row, int column, int id) const
 Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead. More...
 
QModelIndex createIndex (int row, int column, quint32 id) const
 Creates a model index for the given row and column with the internal identifier, id. More...
 
bool decodeData (int row, int column, const QModelIndex &parent, QDataStream &stream)
 
void encodeData (const QModelIndexList &indexes, QDataStream &stream) const
 
void endInsertColumns ()
 Ends a column insertion operation. More...
 
void endInsertRows ()
 Ends a row insertion operation. More...
 
void endMoveColumns ()
 Ends a column move operation. More...
 
void endMoveRows ()
 Ends a row move operation. More...
 
void endRemoveColumns ()
 Ends a column removal operation. More...
 
void endRemoveRows ()
 Ends a row removal operation. More...
 
void endResetModel ()
 Completes a model reset operation. More...
 
QModelIndexList persistentIndexList () const
 Returns the list of indexes stored as persistent indexes in the model. More...
 
 QAbstractItemModel (QAbstractItemModelPrivate &dd, QObject *parent=0)
 
void reset ()
 Resets the model to its original state in any attached views. More...
 
void setRoleNames (const QHash< int, QByteArray > &roleNames)
 Sets the model's role names to roleNames. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Friends

class QAbstractItemViewPrivate
 
class QIdentityProxyModel
 
class QPersistentModelIndexData
 

Additional Inherited Members

- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

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

modelindex-no-parent.png

Every item of data that can be accessed via a model has an associated model index. You can obtain this model index 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 they 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.

To sort the model, you can use sort().

Subclassing

Note
Some general guidelines for subclassing models are available in the 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 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 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 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 functions to retrieve item data and access information about the item's parents and children. See the 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 before and after they occur:

The 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 persistent model indexes correctly. If you want selections to be handled properly, you must ensure that you call these functions. If you insert or remove an item with children, you do not need to call these functions for the child items. In other words, the parent item will take care of its child items.

To create models that populate incrementally, you can reimplement fetchMore() and canFetchMore(). If the reimplementation of fetchMore() adds rows to the model, QAbstractItemModel::beginInsertRows() and QAbstractItemModel::endInsertRows() must be called.

See also
{Model Classes}, {Model Subclassing Reference}, QModelIndex, QAbstractItemView, {Using drag and drop with item views}, {Simple DOM Model Example}, {Simple Tree Model Example}, {Editable Tree Model Example}, {Fetch More Example}

Definition at line 159 of file qabstractitemmodel.h.

Constructors and Destructors

◆ QAbstractItemModel() [1/2]

QAbstractItemModel::QAbstractItemModel ( QObject parent = 0)
explicit

Constructs an abstract item model with the given parent.

Definition at line 1486 of file qabstractitemmodel.cpp.

Referenced by sibling().

1487  : QObject(*new QAbstractItemModelPrivate, parent)
1488 {
1489 }
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QAbstractItemModel()

QAbstractItemModel::~QAbstractItemModel ( )
virtual

Destroys the abstract item model.

Definition at line 1502 of file qabstractitemmodel.cpp.

1503 {
1504  d_func()->invalidatePersistentIndexes();
1505 }

◆ QAbstractItemModel() [2/2]

QAbstractItemModel::QAbstractItemModel ( QAbstractItemModelPrivate dd,
QObject parent = 0 
)
protected
Warning
This function is not part of the public interface.

Definition at line 1494 of file qabstractitemmodel.cpp.

1495  : QObject(dd, parent)
1496 {
1497 }
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

Functions

◆ beginInsertColumns()

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.

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:

beginInsertColumns(parent, 4, 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:

beginInsertColumns(parent, 6, 8);

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

Note
This function 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.
See also
endInsertColumns()

Definition at line 2905 of file qabstractitemmodel.cpp.

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

2906 {
2907  Q_ASSERT(first >= 0);
2908  Q_ASSERT(last >= first);
2910  d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
2911  emit columnsAboutToBeInserted(parent, first, last);
2912  d->columnsAboutToBeInserted(parent, first, last);
2913 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last)
This signal is emitted just before columns are inserted into the model.
#define emit
Definition: qobjectdefs.h:76
The QAbstractItemModel class provides the abstract interface for item model classes.

◆ beginInsertRows()

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.

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:

beginInsertRows(parent, 2, 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:

beginInsertRows(parent, 4, 5);

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

Note
This function 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.
See also
endInsertRows()

Definition at line 2595 of file qabstractitemmodel.cpp.

Referenced by QScriptBreakpointsModel::addBreakpoint(), QTreeModel::beginInsertItems(), QListModel::insert(), QDeclarativeFolderListModel::inserted(), QStringListModel::insertRows(), QTableModel::insertRows(), QSqlTableModel::insertRows(), QListModel::insertRows(), QTreeModel::insertRows(), QDeclarativeFolderListModel::refresh(), QSqlQueryModel::setQuery(), and sibling().

2596 {
2597  Q_ASSERT(first >= 0);
2598  Q_ASSERT(last >= first);
2600  d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
2601  emit rowsAboutToBeInserted(parent, first, last);
2602  d->rowsAboutToBeInserted(parent, first, last);
2603 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last)
This signal is emitted just before rows are inserted into the model.
#define emit
Definition: qobjectdefs.h:76
The QAbstractItemModel class provides the abstract interface for item model classes.

◆ beginMoveColumns()

bool QAbstractItemModel::beginMoveColumns ( const QModelIndex sourceParent,
int  sourceFirst,
int  sourceLast,
const QModelIndex destinationParent,
int  destinationChild 
)
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 destinationChild is the column to which the columns will be moved. That is, the index at column sourceFirst in sourceParent will become column destinationChild 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 columnss will be placed before the destinationChild index. That is, if you wish to move columns 0 and 1 so they will become columns 1 and 2, destinationChild should be 3. In this case, the new index for the source column i (which is between sourceFirst and sourceLast) is equal to {(destinationChild-sourceLast-1+i)}.

Note that if sourceParent and destinationParent are the same, you must ensure that the destinationChild 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()
Since
4.6

Definition at line 3026 of file qabstractitemmodel.cpp.

Referenced by sibling().

3027 {
3028  Q_ASSERT(sourceFirst >= 0);
3029  Q_ASSERT(sourceLast >= sourceFirst);
3030  Q_ASSERT(destinationChild >= 0);
3032 
3033  if (!d->allowMove(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal)) {
3034  return false;
3035  }
3036 
3037  QAbstractItemModelPrivate::Change sourceChange(sourceParent, sourceFirst, sourceLast);
3038  sourceChange.needsAdjust = sourceParent.isValid() && sourceParent.row() >= destinationChild && sourceParent.parent() == destinationParent;
3039  d->changes.push(sourceChange);
3040  int destinationLast = destinationChild + (sourceLast - sourceFirst);
3041  QAbstractItemModelPrivate::Change destinationChange(destinationParent, destinationChild, destinationLast);
3042  destinationChange.needsAdjust = destinationParent.isValid() && destinationParent.row() >= sourceLast && destinationParent.parent() == sourceParent;
3043  d->changes.push(destinationChange);
3044 
3045  d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal);
3046 
3047  emit columnsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild);
3049  return true;
3050 }
double d
Definition: qnumeric_p.h:62
void columnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
This signal is emitted just before columns are moved within the model.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
int row() const
Returns the row this model index refers to.
#define emit
Definition: qobjectdefs.h:76
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QAbstractItemModel class provides the abstract interface for item model classes.

◆ beginMoveRows()

bool QAbstractItemModel::beginMoveRows ( const QModelIndex sourceParent,
int  sourceFirst,
int  sourceLast,
const QModelIndex destinationParent,
int  destinationChild 
)
protected

Begins a row move operation.

Since
4.6

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 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 destinationChild is the row to which the rows will be moved. That is, the index at row sourceFirst in sourceParent will become row destinationChild in destinationParent, followed by all other rows up to sourceLast.

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

Note that if sourceParent and destinationParent are the same, you must ensure that the destinationChild 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.

modelview-move-rows-1.png
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 destinationChild is 2.

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

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

modelview-move-rows-2.png
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 destinationChild 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.

modelview-move-rows-3.png
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 destinationChild is 0.

beginMoveRows(parent, 2, 2, parent, 0);

Note that 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)

modelview-move-rows-4.png
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 destinationChild is 4.

beginMoveRows(parent, 2, 2, parent, 4);

Note that other rows may be displaced accordingly.

See also
endMoveRows()

Definition at line 2803 of file qabstractitemmodel.cpp.

Referenced by QListModel::move(), and sibling().

2804 {
2805  Q_ASSERT(sourceFirst >= 0);
2806  Q_ASSERT(sourceLast >= sourceFirst);
2807  Q_ASSERT(destinationChild >= 0);
2809 
2810  if (!d->allowMove(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Vertical)) {
2811  return false;
2812  }
2813 
2814  QAbstractItemModelPrivate::Change sourceChange(sourceParent, sourceFirst, sourceLast);
2815  sourceChange.needsAdjust = sourceParent.isValid() && sourceParent.row() >= destinationChild && sourceParent.parent() == destinationParent;
2816  d->changes.push(sourceChange);
2817  int destinationLast = destinationChild + (sourceLast - sourceFirst);
2818  QAbstractItemModelPrivate::Change destinationChange(destinationParent, destinationChild, destinationLast);
2819  destinationChange.needsAdjust = destinationParent.isValid() && destinationParent.row() >= sourceLast && destinationParent.parent() == sourceParent;
2820  d->changes.push(destinationChange);
2821 
2822  emit rowsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild);
2824  d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Vertical);
2825  return true;
2826 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void rowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
This signal is emitted just before rows are moved within the model.
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
int row() const
Returns the row this model index refers to.
#define emit
Definition: qobjectdefs.h:76
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QAbstractItemModel class provides the abstract interface for item model classes.

◆ beginRemoveColumns()

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.

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:

Note
This function 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()

Definition at line 2960 of file qabstractitemmodel.cpp.

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

2961 {
2962  Q_ASSERT(first >= 0);
2963  Q_ASSERT(last >= first);
2965  d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
2966  emit columnsAboutToBeRemoved(parent, first, last);
2967  d->columnsAboutToBeRemoved(parent, first, last);
2968 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76
The QAbstractItemModel class provides the abstract interface for item model classes.
void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted just before columns are removed from the model.

◆ beginRemoveRows()

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.

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:

beginRemoveRows(parent, 2, 3);
Note
This function 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()

Definition at line 2649 of file qabstractitemmodel.cpp.

Referenced by QTreeModel::beginRemoveItems(), QDeclarativeFolderListModel::refresh(), QListModel::remove(), QScriptBreakpointsModel::removeBreakpoint(), QDeclarativeFolderListModel::removed(), QStringListModel::removeRows(), QTableModel::removeRows(), QListModel::removeRows(), QTreeModel::removeRows(), QSqlQueryModel::setQuery(), sibling(), and QListModel::take().

2650 {
2651  Q_ASSERT(first >= 0);
2652  Q_ASSERT(last >= first);
2654  d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
2655  emit rowsAboutToBeRemoved(parent, first, last);
2656  d->rowsAboutToBeRemoved(parent, first, last);
2657 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76
The QAbstractItemModel class provides the abstract interface for item model classes.
void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted just before rows are removed from the model.

◆ beginResetModel()

void QAbstractItemModel::beginResetModel ( )
protected

Begins a model reset operation.

A reset operation resets the model to its current state in any attached views.

Note
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 function rather than emit dataChanged() to inform other components when the underlying data source, or its structure, has changed.

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

See also
modelAboutToBeReset(), modelReset(), endResetModel()
Since
4.6

Definition at line 3125 of file qabstractitemmodel.cpp.

Referenced by QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QStringListModel::setStringList(), and sibling().

3126 {
3128 }
#define emit
Definition: qobjectdefs.h:76
void modelAboutToBeReset()
This signal is emitted when reset() is called, before the model&#39;s internal state (e.

◆ buddy()

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. Then, the view will construct a delegate using the model index returned by the buddy item.

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

Reimplemented in QSortFilterProxyModel, and QAbstractProxyModel.

Definition at line 2209 of file qabstractitemmodel.cpp.

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

2210 {
2211  return index;
2212 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...

◆ canFetchMore()

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() function is only called when the model is being populated incrementally.

See also
fetchMore()

Reimplemented in QSortFilterProxyModel, QSqlQueryModel, QFileSystemModel, QScriptDebuggerLocalsModel, and QAbstractProxyModel.

Definition at line 2165 of file qabstractitemmodel.cpp.

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

2166 {
2167  return false;
2168 }

◆ changePersistentIndex()

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 3156 of file qabstractitemmodel.cpp.

Referenced by sibling().

3157 {
3159  if (d->persistent.indexes.isEmpty())
3160  return;
3161  // find the data and reinsert it sorted
3162  const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = d->persistent.indexes.find(from);
3163  if (it != d->persistent.indexes.end()) {
3165  d->persistent.indexes.erase(it);
3166  data->index = to;
3167  if (to.isValid())
3168  d->persistent.insertMultiAtEnd(to, data);
3169  else
3170  data->model = 0;
3171  }
3172 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
#define Q_D(Class)
Definition: qglobal.h:2482
const QAbstractItemModel * model
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QAbstractItemModel class provides the abstract interface for item model classes.
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330

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

Since
4.1

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 3188 of file qabstractitemmodel.cpp.

Referenced by QListModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::ensureSorted(), QCompletionModel::resetModel(), QTableModel::setItem(), sibling(), QStringListModel::sort(), QFileSystemModel::sort(), QListModel::sort(), QTableModel::sort(), and QTreeModel::sortItems().

3190 {
3192  if (d->persistent.indexes.isEmpty())
3193  return;
3194  QVector<QPersistentModelIndexData *> toBeReinserted;
3195  toBeReinserted.reserve(to.count());
3196  for (int i = 0; i < from.count(); ++i) {
3197  if (from.at(i) == to.at(i))
3198  continue;
3199  const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = d->persistent.indexes.find(from.at(i));
3200  if (it != d->persistent.indexes.end()) {
3202  d->persistent.indexes.erase(it);
3203  data->index = to.at(i);
3204  if (data->index.isValid())
3205  toBeReinserted << data;
3206  else
3207  data->model = 0;
3208  }
3209  }
3210 
3212  it != toBeReinserted.constEnd() ; ++it) {
3213  QPersistentModelIndexData *data = *it;
3214  d->persistent.insertMultiAtEnd(data->index, data);
3215  }
3216 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
#define Q_D(Class)
Definition: qglobal.h:2482
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
const QAbstractItemModel * model
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QAbstractItemModel class provides the abstract interface for item model classes.
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
const T * const_iterator
The QVector::const_iterator typedef provides an STL-style const iterator for QVector and QStack...
Definition: qvector.h:245
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339

◆ columnCount()

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:

int DomModel::columnCount(const QModelIndex &/*parent*/) const
{
return 3;
}
Note
When implementing a table based model, columnCount() should return 0 when the parent is valid.
See also
rowCount()

Implemented in QCalendarModel, QEmptyItemModel, QAbstractListModel, QStandardItemModel, QCompletionModel, QPPDOptionsModel, QSortFilterProxyModel, QTableModel, QTreeModel, QEmptyModel, QFileSystemModel, QScriptBreakpointsModel, QScriptDebuggerScriptsModel, QDirModel, QScriptDebuggerLocalsModel, QScriptDebuggerStackModel, QProxyModel, QEmptyModel, QSqlQueryModel, QUndoModel, and QIdentityProxyModel.

Referenced by QAbstractItemViewPrivate::_q_columnsAboutToBeRemoved(), QItemSelectionModelPrivate::_q_layoutAboutToBeChanged(), QHeaderViewPrivate::_q_layoutAboutToBeChanged(), QItemSelectionModelPrivate::_q_layoutChanged(), QTableViewPrivate::accessibleTable2Index(), QAccessibleTree::childAt(), QAccessibleTable2::childCount(), QAccessibleTree::childCount(), QAccessibleTable2::childFromLogical(), QAccessibleItemView::childIndex(), QAccessibleItemRow::children(), QAbstractItemViewPrivate::clearOrRemove(), QAccessibleTable2::columnCount(), QAccessibleItemView::columnCount(), QAccessibleItemView::columnIndex(), QFileDialogPrivate::createWidgets(), QTreeView::currentChanged(), decodeData(), QItemSelectionModelPrivate::expandSelection(), hasChildren(), QAbstractTableModel::hasChildren(), hasIndex(), QAccessibleTable2::indexOfChild(), QAccessibleTree::indexOfChild(), QAccessibleTable2HeaderCell::isValid(), QDataWidgetMapperPrivate::itemCount(), QAccessibleTable2::logicalIndex(), QHeaderViewPrivate::modelIsEmpty(), QHeaderViewPrivate::modelSectionCount(), QTreeView::moveCursor(), QAccessibleTree::navigate(), QListViewPrivate::prepareItemsLayout(), QAccessibleItemRow::rect(), QFileDialog::restoreState(), QFileDialogPrivate::retranslateStrings(), rowAt(), QAccessibleItemView::rowIndex(), QAbstractItemViewPrivate::selectAll(), QListViewPrivate::selectAll(), QTreeView::selectionChanged(), and QTableViewPrivate::selectRow().

◆ columnsAboutToBeInserted

void QAbstractItemModel::columnsAboutToBeInserted ( const QModelIndex parent,
int  start,
int  end 
)
signal

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(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), and sibling().

◆ columnsAboutToBeMoved

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.

Since
4.6

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.

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

Referenced by beginMoveColumns(), QIdentityProxyModel::setSourceModel(), and sibling().

◆ columnsAboutToBeRemoved

void QAbstractItemModel::columnsAboutToBeRemoved ( const QModelIndex parent,
int  start,
int  end 
)
signal

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(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), and sibling().

◆ columnsInserted

void QAbstractItemModel::columnsInserted ( const QModelIndex parent,
int  start,
int  end 
)
signal

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(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QCompletionModel::setSourceModel(), and sibling().

◆ columnsMoved

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.

Since
4.6

The items between sourceStart and sourceEnd inclusive, under the given sourceParent item have been moved to destinationParent starting at the column destinationColumn.

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

Referenced by endMoveColumns(), QIdentityProxyModel::setSourceModel(), and sibling().

◆ columnsRemoved

void QAbstractItemModel::columnsRemoved ( const QModelIndex parent,
int  start,
int  end 
)
signal

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(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QCompletionModel::setSourceModel(), and sibling().

◆ createIndex() [1/3]

QModelIndex QAbstractItemModel::createIndex ( int  row,
int  column,
void *  ptr = 0 
) const
inlineprotected

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

When using a QSortFilterProxyModel, its indexes have their own internal pointer. It is not advisable to access this internal pointer outside of the model. Use the data() function instead.

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

Definition at line 323 of file qabstractitemmodel.h.

Referenced by QTreeModel::createIndexFromItem(), QCompletionModel::currentIndex(), QTreeModel::emitDataChanged(), endMoveColumns(), endMoveRows(), QListModel::ensureSorted(), QTreeModel::ensureSorted(), QSqlQueryModel::headerData(), QUndoModel::index(), QDirModel::index(), QScriptDebuggerLocalsModel::index(), QFileSystemModel::index(), QScriptDebuggerScriptsModel::index(), QScriptBreakpointsModel::index(), QTreeModel::index(), QListModel::index(), QPPDOptionsModel::index(), QCompletionModel::index(), QStandardItemModel::index(), QAbstractTableModel::index(), QAbstractListModel::index(), QStandardItemModel::indexFromItem(), QScriptDebuggerScriptsModel::indexFromScriptId(), QSqlQueryModel::indexInQuery(), QSqlTableModel::indexInQuery(), QIdentityProxyModel::mapFromSource(), QCompletionModel::mapFromSource(), QScriptBreakpointsModel::modifyBreakpoint(), QDirModel::parent(), QFileSystemModel::parent(), QPPDOptionsModel::parent(), QSqlQueryModel::record(), QSqlTableModel::removeRows(), QSqlTableModel::revertRow(), QUndoModel::selectedIndex(), QSqlQueryModel::setQuery(), QSqlTableModel::setRecord(), sibling(), QListModel::sort(), QTableModel::sort(), and QTreeModel::sortItems().

324 { return QModelIndex(arow, acolumn, adata, this); }
The QModelIndex class is used to locate data in a data model.

◆ createIndex() [2/3]

QModelIndex QAbstractItemModel::createIndex ( int  row,
int  column,
int  id 
) const
inlineprotected

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

Definition at line 325 of file qabstractitemmodel.h.

328  : 4312 ) // avoid conversion warning on 64-bit
329 #endif
330 { return QModelIndex(arow, acolumn, reinterpret_cast<void*>(aid), this); }
The QModelIndex class is used to locate data in a data model.

◆ createIndex() [3/3]

QModelIndex QAbstractItemModel::createIndex ( int  row,
int  column,
quint32  id 
) const
inlineprotected

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.

See also
QModelIndex::internalId()

Definition at line 334 of file qabstractitemmodel.h.

337  : 4312 ) // avoid conversion warning on 64-bit
338 #endif
339 { return QModelIndex(arow, acolumn, reinterpret_cast<void*>(aid), this); }
The QModelIndex class is used to locate data in a data model.

◆ data()

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.

Note
If you do not have a value to return, return an invalid QVariant instead of returning 0.
See also
Qt::ItemDataRole, setData(), headerData()

Implemented in QCalendarModel, QEmptyItemModel, QStandardItemModel, QCompletionModel, QPPDOptionsModel, QSortFilterProxyModel, QTableModel, ControlList, QTreeModel, QListModel, QFileSystemModel, QEmptyModel, QScriptBreakpointsModel, QScriptDebuggerScriptsModel, QDeclarativeFolderListModel, QSqlRelationalTableModel, QDirModel, QScriptDebuggerLocalsModel, QAbstractProxyModel, QProxyModel, QScriptDebuggerStackModel, QSqlTableModel, QEmptyModel, QSqlQueryModel, QUndoModel, and QStringListModel.

Referenced by QInputDialogPrivate::_q_currentRowChanged(), QUnsortedModelEngine::buildIndices(), changePersistentIndex(), changePersistentIndexList(), QAbstractItemViewPrivate::checkMouseMove(), QModelIndex::data(), decodeData(), QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), QSortedModelEngine::filter(), QComboMenuDelegate::getStyleOption(), QDeclarativeVisualDataModelDataMetaObject::initialValue(), itemData(), QComboBoxPrivate::itemIcon(), QComboBoxPrivate::itemText(), QSortFilterProxyModel::lessThan(), match(), mimeData(), QCompleter::pathFromIndex(), persistentIndexList(), QStyledItemDelegate::setModelData(), QItemDelegate::setModelData(), QSortedModelEngine::sortOrder(), QAccessibleItemRow::state(), QAccessibleTable2Cell::state(), QAccessibleItemRow::text(), QAccessibleTable2Cell::text(), and QAccessibleItemRow::text_helper().

◆ dataChanged

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

◆ decodeData()

bool QAbstractItemModel::decodeData ( int  row,
int  column,
const QModelIndex parent,
QDataStream stream 
)
protected
Warning
This function is not part of the public interface.

Definition at line 2471 of file qabstractitemmodel.cpp.

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

2473 {
2474  int top = INT_MAX;
2475  int left = INT_MAX;
2476  int bottom = 0;
2477  int right = 0;
2478  QVector<int> rows, columns;
2480 
2481  while (!stream.atEnd()) {
2482  int r, c;
2484  stream >> r >> c >> v;
2485  rows.append(r);
2486  columns.append(c);
2487  data.append(v);
2488  top = qMin(r, top);
2489  left = qMin(c, left);
2490  bottom = qMax(r, bottom);
2491  right = qMax(c, right);
2492  }
2493 
2494  // insert the dragged items into the table, use a bit array to avoid overwriting items,
2495  // since items from different tables can have the same row and column
2496  int dragRowCount = 0;
2497  int dragColumnCount = right - left + 1;
2498 
2499  // Compute the number of continuous rows upon insertion and modify the rows to match
2500  QVector<int> rowsToInsert(bottom + 1);
2501  for (int i = 0; i < rows.count(); ++i)
2502  rowsToInsert[rows.at(i)] = 1;
2503  for (int i = 0; i < rowsToInsert.count(); ++i) {
2504  if (rowsToInsert[i] == 1){
2505  rowsToInsert[i] = dragRowCount;
2506  ++dragRowCount;
2507  }
2508  }
2509  for (int i = 0; i < rows.count(); ++i)
2510  rows[i] = top + rowsToInsert[rows[i]];
2511 
2512  QBitArray isWrittenTo(dragRowCount * dragColumnCount);
2513 
2514  // make space in the table for the dropped data
2515  int colCount = columnCount(parent);
2516  if (colCount == 0) {
2517  insertColumns(colCount, dragColumnCount - colCount, parent);
2518  colCount = columnCount(parent);
2519  }
2520  insertRows(row, dragRowCount, parent);
2521 
2522  row = qMax(0, row);
2523  column = qMax(0, column);
2524 
2525  QVector<QPersistentModelIndex> newIndexes(data.size());
2526  // set the data in the table
2527  for (int j = 0; j < data.size(); ++j) {
2528  int relativeRow = rows.at(j) - top;
2529  int relativeColumn = columns.at(j) - left;
2530  int destinationRow = relativeRow + row;
2531  int destinationColumn = relativeColumn + column;
2532  int flat = (relativeRow * dragColumnCount) + relativeColumn;
2533  // if the item was already written to, or we just can't fit it in the table, create a new row
2534  if (destinationColumn >= colCount || isWrittenTo.testBit(flat)) {
2535  destinationColumn = qBound(column, destinationColumn, colCount - 1);
2536  destinationRow = row + dragRowCount;
2537  insertRows(row + dragRowCount, 1, parent);
2538  flat = (dragRowCount * dragColumnCount) + relativeColumn;
2539  isWrittenTo.resize(++dragRowCount * dragColumnCount);
2540  }
2541  if (!isWrittenTo.testBit(flat)) {
2542  newIndexes[j] = index(destinationRow, destinationColumn, parent);
2543  isWrittenTo.setBit(flat);
2544  }
2545  }
2546 
2547  for(int k = 0; k < newIndexes.size(); k++) {
2548  if (newIndexes.at(k).isValid())
2549  setItemData(newIndexes.at(k), data.at(k));
2550  }
2551 
2552  return true;
2553 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
bool atEnd() const
Returns true if the I/O device has reached the end position (end of the stream or file) or if there i...
virtual bool setItemData(const QModelIndex &index, const QMap< int, QVariant > &roles)
Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole...
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
virtual bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
On models that support this, inserts count rows into the model before the given row.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QBitArray class provides an array of bits.
Definition: qbitarray.h:54
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
virtual bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
On models that support this, inserts count new columns into the model before the given column...
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
#define INT_MAX
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ dropMimeData()

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.

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 -1 it means that 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(), {Using drag and drop with item views}

Reimplemented in QStandardItemModel, QAbstractListModel, QAbstractTableModel, QTableModel, QSortFilterProxyModel, QTreeModel, QListModel, QFileSystemModel, QDirModel, QUrlModel, QProxyModel, and QIdentityProxyModel.

Definition at line 1950 of file qabstractitemmodel.cpp.

Referenced by QStandardItemModel::dropMimeData().

1952 {
1953  // check if the action is supported
1954  if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
1955  return false;
1956  // check if the format is supported
1958  if (types.isEmpty())
1959  return false;
1960  QString format = types.at(0);
1961  if (!data->hasFormat(format))
1962  return false;
1963  if (row > rowCount(parent))
1964  row = rowCount(parent);
1965  if (row == -1)
1966  row = rowCount(parent);
1967  if (column == -1)
1968  column = 0;
1969  // decode and insert
1970  QByteArray encoded = data->data(format);
1972  return decodeData(row, column, parent, stream);
1973 }
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
virtual QStringList mimeTypes() const
Returns a list of MIME types that can be used to describe a list of model indexes.
QByteArray data(const QString &mimetype) const
Returns the data stored in the object in the format described by the MIME type specified by mimeType...
Definition: qmimedata.cpp:524
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool decodeData(int row, int column, const QModelIndex &parent, QDataStream &stream)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static FILE * stream
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
virtual bool hasFormat(const QString &mimetype) const
Returns true if the object can return data for the MIME type specified by mimeType; otherwise returns...
Definition: qmimedata.cpp:563
static const struct @32 types[]
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71

◆ encodeData()

void QAbstractItemModel::encodeData ( const QModelIndexList indexes,
QDataStream stream 
) const
protected
Warning
This function is not part of the public interface.

Definition at line 2461 of file qabstractitemmodel.cpp.

Referenced by mimeData(), and sibling().

2462 {
2464  for (; it != indexes.end(); ++it)
2465  stream << (*it).row() << (*it).column() << itemData(*it);
2466 }
virtual QMap< int, QVariant > itemData(const QModelIndex &index) const
Returns a map with values for all predefined roles in the model for the item at the given index...
#define it(className, varName)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279

◆ endInsertColumns()

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 2924 of file qabstractitemmodel.cpp.

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

2925 {
2927  QAbstractItemModelPrivate::Change change = d->changes.pop();
2928  d->columnsInserted(change.parent, change.first, change.last);
2929  emit columnsInserted(change.parent, change.first, change.last);
2930 }
double d
Definition: qnumeric_p.h:62
void columnsInserted(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been inserted into the model.
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76
The QAbstractItemModel class provides the abstract interface for item model classes.

◆ endInsertRows()

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 2613 of file qabstractitemmodel.cpp.

Referenced by QScriptBreakpointsModel::addBreakpoint(), QTreeModel::endInsertItems(), QListModel::insert(), QDeclarativeFolderListModel::inserted(), QStringListModel::insertRows(), QTableModel::insertRows(), QSqlTableModel::insertRows(), QListModel::insertRows(), QTreeModel::insertRows(), QDeclarativeFolderListModel::refresh(), QSqlQueryModel::setQuery(), and sibling().

2614 {
2616  QAbstractItemModelPrivate::Change change = d->changes.pop();
2617  d->rowsInserted(change.parent, change.first, change.last);
2618  emit rowsInserted(change.parent, change.first, change.last);
2619 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76
The QAbstractItemModel class provides the abstract interface for item model classes.
void rowsInserted(const QModelIndex &parent, int first, int last)
This signal is emitted after rows have been inserted into the model.

◆ endMoveColumns()

void QAbstractItemModel::endMoveColumns ( )
protected

Ends a column move operation.

When implementing a subclass, you must call this function after moving data within the model's underlying data store.

layoutChanged is emitted by this method for compatibility reasons.

See also
beginMoveColumns()
Since
4.6

Definition at line 3065 of file qabstractitemmodel.cpp.

Referenced by sibling().

3066 {
3068 
3069  QAbstractItemModelPrivate::Change insertChange = d->changes.pop();
3070  QAbstractItemModelPrivate::Change removeChange = d->changes.pop();
3071 
3072  QModelIndex adjustedSource = removeChange.parent;
3073  QModelIndex adjustedDestination = insertChange.parent;
3074 
3075  const int numMoved = removeChange.last - removeChange.first + 1;
3076  if (insertChange.needsAdjust)
3077  adjustedDestination = createIndex(adjustedDestination.row(), adjustedDestination.column() - numMoved, adjustedDestination.internalPointer());
3078 
3079  if (removeChange.needsAdjust)
3080  adjustedSource = createIndex(adjustedSource.row(), adjustedSource.column() + numMoved, adjustedSource.internalPointer());
3081 
3082  d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Horizontal);
3083 
3084  emit columnsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first);
3085  emit layoutChanged();
3086 }
double d
Definition: qnumeric_p.h:62
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
#define Q_D(Class)
Definition: qglobal.h:2482
int row() const
Returns the row this model index refers to.
#define emit
Definition: qobjectdefs.h:76
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
The QAbstractItemModel class provides the abstract interface for item model classes.
The QModelIndex class is used to locate data in a data model.
void columnsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
This signal is emitted after columns have been moved within the model.
int column() const
Returns the column this model index refers to.

◆ endMoveRows()

void QAbstractItemModel::endMoveRows ( )
protected

Ends a row move operation.

When implementing a subclass, you must call this function after moving data within the model's underlying data store.

layoutChanged is emitted by this method for compatibility reasons.

See also
beginMoveRows()
Since
4.6

Definition at line 2841 of file qabstractitemmodel.cpp.

Referenced by QListModel::move(), and sibling().

2842 {
2844 
2845  QAbstractItemModelPrivate::Change insertChange = d->changes.pop();
2846  QAbstractItemModelPrivate::Change removeChange = d->changes.pop();
2847 
2848  QModelIndex adjustedSource = removeChange.parent;
2849  QModelIndex adjustedDestination = insertChange.parent;
2850 
2851  const int numMoved = removeChange.last - removeChange.first + 1;
2852  if (insertChange.needsAdjust)
2853  adjustedDestination = createIndex(adjustedDestination.row() - numMoved, adjustedDestination.column(), adjustedDestination.internalPointer());
2854 
2855  if (removeChange.needsAdjust)
2856  adjustedSource = createIndex(adjustedSource.row() + numMoved, adjustedSource.column(), adjustedSource.internalPointer());
2857 
2858  d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Vertical);
2859 
2860  emit rowsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first);
2861  emit layoutChanged();
2862 }
double d
Definition: qnumeric_p.h:62
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
#define Q_D(Class)
Definition: qglobal.h:2482
void rowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
This signal is emitted after rows have been moved within the model.
int row() const
Returns the row this model index refers to.
#define emit
Definition: qobjectdefs.h:76
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
The QAbstractItemModel class provides the abstract interface for item model classes.
The QModelIndex class is used to locate data in a data model.
int column() const
Returns the column this model index refers to.

◆ endRemoveColumns()

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 2978 of file qabstractitemmodel.cpp.

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

2979 {
2981  QAbstractItemModelPrivate::Change change = d->changes.pop();
2982  d->columnsRemoved(change.parent, change.first, change.last);
2983  emit columnsRemoved(change.parent, change.first, change.last);
2984 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76
The QAbstractItemModel class provides the abstract interface for item model classes.
void columnsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been removed from the model.

◆ endRemoveRows()

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 2667 of file qabstractitemmodel.cpp.

Referenced by QTreeModel::endRemoveItems(), QDeclarativeFolderListModel::refresh(), QListModel::remove(), QScriptBreakpointsModel::removeBreakpoint(), QDeclarativeFolderListModel::removed(), QStringListModel::removeRows(), QTableModel::removeRows(), QListModel::removeRows(), QTreeModel::removeRows(), QSqlQueryModel::setQuery(), sibling(), QListModel::take(), and QTreeWidgetItem::takeChild().

2668 {
2670  QAbstractItemModelPrivate::Change change = d->changes.pop();
2671  d->rowsRemoved(change.parent, change.first, change.last);
2672  emit rowsRemoved(change.parent, change.first, change.last);
2673 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76
The QAbstractItemModel class provides the abstract interface for item model classes.
void rowsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after rows have been removed from the model.

◆ endResetModel()

void QAbstractItemModel::endResetModel ( )
protected

Completes a model reset operation.

You must call this function after resetting any internal data structure in your model or proxy model.

See also
beginResetModel()
Since
4.6

Definition at line 3139 of file qabstractitemmodel.cpp.

Referenced by QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QStringListModel::setStringList(), and sibling().

3140 {
3142  d->invalidatePersistentIndexes();
3143  QMetaObject::invokeMethod(this, "resetInternalData");
3144  emit modelReset();
3145 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76
The QAbstractItemModel class provides the abstract interface for item model classes.
void modelReset()
This signal is emitted when reset() is called, after the model&#39;s internal state (e.
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ fetchMore()

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 are populating your model incrementally.

The default implementation does nothing.

See also
canFetchMore()

Reimplemented in QSortFilterProxyModel, QProxyModel, QFileSystemModel, QScriptDebuggerLocalsModel, QSqlQueryModel, and QAbstractProxyModel.

Definition at line 2148 of file qabstractitemmodel.cpp.

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

2149 {
2150  // do nothing
2151 }

◆ flags()

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

Reimplemented in QCalendarModel, QStandardItemModel, QPPDOptionsModel, QSortFilterProxyModel, QTableModel, QTreeModel, QListModel, QFileSystemModel, QScriptBreakpointsModel, QProxyModel, QUrlModel, QDirModel, QScriptDebuggerLocalsModel, QAbstractProxyModel, QSqlTableModel, and QStringListModel.

Definition at line 2179 of file qabstractitemmodel.cpp.

Referenced by QLineControl::advanceToEnabledItem(), QUnsortedModelEngine::buildIndices(), QStyledItemDelegate::editorEvent(), QItemDelegate::editorEvent(), QStringListModel::flags(), QModelIndex::flags(), QDirModel::flags(), QFileSystemModel::flags(), QCalendarModel::flags(), QComboMenuDelegate::getStyleOption(), indexesFromRange(), QItemSelectionRange::isEmpty(), QColumnViewDelegate::paint(), QListView::paintEvent(), QAbstractItemViewPrivate::position(), and QAbstractItemViewPrivate::shouldEdit().

2180 {
2181  Q_D(const QAbstractItemModel);
2182  if (!d->indexValid(index))
2183  return 0;
2184 
2186 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAbstractItemModel class provides the abstract interface for item model classes.

◆ hasChildren()

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 QEmptyItemModel, QAbstractListModel, QAbstractTableModel, QStandardItemModel, QCompletionModel, QSortFilterProxyModel, QTreeModel, QEmptyModel, QAbstractProxyModel, QFileSystemModel, QDirModel, QScriptDebuggerLocalsModel, QProxyModel, and QEmptyModel.

Definition at line 1808 of file qabstractitemmodel.cpp.

Referenced by QColumnViewPrivate::checkColumnCreation(), QColumnViewPrivate::closeColumns(), QColumnViewPrivate::createColumn(), QColumnView::currentChanged(), QTreeViewPrivate::hasVisibleChildren(), QDeclarativeVisualDataModelDataMetaObject::initialValue(), QAccessibleTable2Cell::isExpandable(), QTreeViewPrivate::layout(), match(), QColumnView::moveCursor(), and QColumnViewDelegate::paint().

1809 {
1810  return (rowCount(parent) > 0) && (columnCount(parent) > 0);
1811 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.

◆ hasIndex()

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 1793 of file qabstractitemmodel.cpp.

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

1794 {
1795  if (row < 0 || column < 0)
1796  return false;
1797  return row < rowCount(parent) && column < columnCount(parent);
1798 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.

◆ headerData()

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, QPPDOptionsModel, QSortFilterProxyModel, QTableModel, QTreeModel, QFileSystemModel, QScriptBreakpointsModel, QDirModel, QScriptDebuggerLocalsModel, QProxyModel, QSqlTableModel, QAbstractProxyModel, QScriptDebuggerStackModel, and QSqlQueryModel.

Definition at line 2388 of file qabstractitemmodel.cpp.

Referenced by QAccessibleTable2::columnDescription(), QAccessibleItemView::columnDescription(), QHeaderViewPrivate::flipSortIndicator(), QSqlQueryModel::headerData(), QDirModel::headerData(), QFileSystemModel::headerData(), QStandardItemModel::headerData(), QFileDialogPrivate::retranslateStrings(), QAccessibleTable2::rowDescription(), QAccessibleItemView::rowDescription(), QAccessibleHeader::text(), QAccessibleItemRow::text(), QAccessibleTable2HeaderCell::text(), and QAccessibleItemRow::text_helper().

2389 {
2390  Q_UNUSED(orientation);
2391  if (role == Qt::DisplayRole)
2392  return section + 1;
2393  return QVariant();
2394 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ headerDataChanged

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() function, 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 functions (refer to the section on subclassing in the QAbstractItemModel class description for details).

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

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

◆ index()

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

Implemented in QEmptyItemModel, QAbstractListModel, QAbstractTableModel, QStandardItemModel, QCompletionModel, QPPDOptionsModel, QSortFilterProxyModel, QTableModel, QListModel, QTreeModel, QEmptyModel, QScriptBreakpointsModel, QScriptDebuggerScriptsModel, QFileSystemModel, QScriptDebuggerLocalsModel, QDirModel, QProxyModel, QEmptyModel, QIdentityProxyModel, and QUndoModel.

Referenced by QItemSelectionModelPrivate::_q_columnsAboutToBeInserted(), QItemSelectionModelPrivate::_q_columnsAboutToBeRemoved(), QAbstractItemViewPrivate::_q_columnsAboutToBeRemoved(), QHeaderViewPrivate::_q_layoutAboutToBeChanged(), QItemSelectionModelPrivate::_q_layoutChanged(), QItemSelectionModelPrivate::_q_rowsAboutToBeInserted(), QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(), QFileDialogPrivate::_q_useNameFilter(), buddy(), QUnsortedModelEngine::buildIndices(), QAccessibleTable2::cellAt(), QTableWidget::cellWidget(), QModelIndex::child(), QAccessibleItemView::childCount(), QAccessibleTable2::childFromLogical(), QAccessibleItemRow::children(), QSidebar::clicked(), decodeData(), QListWidget::dropEvent(), QTreeWidget::dropEvent(), QListWidget::dropMimeData(), QTableWidget::dropMimeData(), QItemSelectionModelPrivate::expandSelection(), QAbstractItemViewPrivate::fetchMore(), QCompletionEngine::filter(), QSortedModelEngine::filter(), QCompletionEngine::filterHistory(), QAbstractProxyModel::headerData(), QAccessibleItemView::index(), QDataWidgetMapperPrivate::indexAt(), indexesFromRange(), QAccessibleTree::indexFromLogical(), QDeclarativeVisualDataModelDataMetaObject::initialValue(), QItemSelectionRange::intersect(), QItemSelectionRange::isEmpty(), QListViewPrivate::itemSize(), QTreeViewPrivate::layout(), match(), QAbstractProxyModel::mimeData(), QCommonListViewBase::modelIndex(), ModelIndexIterator::ModelIndexIterator(), QColumnView::moveCursor(), QSortFilterProxyModelLessThan::operator()(), QSortFilterProxyModelGreaterThan::operator()(), QAccessibleItemRow::rect(), QTreeViewPrivate::select(), QColumnView::selectAll(), QAbstractItemViewPrivate::selectAll(), QListViewPrivate::selectAll(), QAccessibleTable2::selectColumn(), QTableViewPrivate::selectColumn(), QAccessibleTable2::selectRow(), QTableViewPrivate::selectRow(), QSidebar::selectUrl(), QTableWidget::setCellWidget(), QComboBoxPrivate::setCurrentIndex(), QAbstractProxyModel::setHeaderData(), QFileDialogComboBox::setHistory(), QInputDialogPrivate::setListViewText(), QTableWidget::setRangeSelected(), QFileDialogComboBox::showPopup(), QModelIndex::sibling(), QSortedModelEngine::sortOrder(), QItemSelection::split(), QAccessibleTable2::unselectColumn(), QAccessibleTable2::unselectRow(), and QColumnView::visualRegionForSelection().

◆ insertColumn()

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 316 of file qabstractitemmodel.h.

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

317 { return insertColumns(acolumn, 1, aparent); }
virtual bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
On models that support this, inserts count new columns into the model before the given column...

◆ insertColumns()

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 your own API for altering the data.

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

Reimplemented in QCalendarModel, QStandardItemModel, QSortFilterProxyModel, QTreeModel, QTableModel, QProxyModel, QSqlQueryModel, and QIdentityProxyModel.

Definition at line 2091 of file qabstractitemmodel.cpp.

Referenced by decodeData().

2092 {
2093  return false;
2094 }

◆ insertRow()

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.

Note
The base class implementation of this function does nothing and returns false.

Returns true if the row is inserted; otherwise returns false.

See also
insertRows() insertColumn() removeRow()

Definition at line 314 of file qabstractitemmodel.h.

Referenced by QSqlTableModel::insertRecord(), QStandardItemModel::insertRow(), QCalendarModel::setHorizontalHeaderFormat(), QFileDialogComboBox::showPopup(), and sibling().

315 { return insertRows(arow, 1, aparent); }
virtual bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
On models that support this, inserts count rows into the model before the given row.

◆ insertRows()

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.

Note
The base class implementation of this function does nothing and returns false.

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.

If you implement your own model, you can reimplement this function 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 QCalendarModel, QStandardItemModel, QSortFilterProxyModel, QTreeModel, QListModel, QSqlTableModel, QTableModel, QProxyModel, QIdentityProxyModel, and QStringListModel.

Definition at line 2062 of file qabstractitemmodel.cpp.

Referenced by decodeData().

2063 {
2064  return false;
2065 }

◆ itemData()

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

See also
Qt::ItemDataRole, data()

Reimplemented in QStandardItemModel, QTableModel, QTreeModel, QListModel, and QAbstractProxyModel.

Definition at line 1823 of file qabstractitemmodel.cpp.

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

1824 {
1825  QMap<int, QVariant> roles;
1826  for (int i = 0; i < Qt::UserRole; ++i) {
1827  QVariant variantData = data(index, i);
1828  if (variantData.isValid())
1829  roles.insert(i, variantData);
1830  }
1831  return roles;
1832 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ layoutAboutToBeChanged

void QAbstractItemModel::layoutAboutToBeChanged ( )
signal

◆ layoutChanged

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(). In other words, when the structure changes:

See also
layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), modelReset(), changePersistentIndex()

Referenced by QSortFilterProxyModel::clear(), QScriptDebuggerScriptsModel::commit(), QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), endMoveColumns(), endMoveRows(), QListModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::ensureSorted(), QDirModel::index(), QSortFilterProxyModel::invalidate(), QPPDOptionsModel::parseItems(), QDeclarativeFolderListModel::QDeclarativeFolderListModel(), QDirModel::refresh(), QCompletionModel::resetModel(), QScriptDebuggerStackModel::setContextInfos(), QDirModel::setFilter(), QTableModel::setItem(), QDirModel::setNameFilters(), QDirModel::setSorting(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QCompletionModel::setSourceModel(), sibling(), QStringListModel::sort(), QFileSystemModel::sort(), QListModel::sort(), QTableModel::sort(), and QTreeWidgetItem::sortChildren().

◆ match()

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 function will perform a wrapping, string-based comparison on all items, searching for items that begin with the search term specified by value.

Note
The default implementation of this function only searches columns. Reimplement this function to include a different search behavior.

Reimplemented in QSortFilterProxyModel, QProxyModel, and QIdentityProxyModel.

Definition at line 2233 of file qabstractitemmodel.cpp.

Referenced by QStandardItemModel::findItems(), and QSortFilterProxyModel::match().

2236 {
2237  QModelIndexList result;
2238  uint matchType = flags & 0x0F;
2240  bool recurse = flags & Qt::MatchRecursive;
2241  bool wrap = flags & Qt::MatchWrap;
2242  bool allHits = (hits == -1);
2243  QString text; // only convert to a string if it is needed
2244  QModelIndex p = parent(start);
2245  int from = start.row();
2246  int to = rowCount(p);
2247 
2248  // iterates twice if wrapping
2249  for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
2250  for (int r = from; (r < to) && (allHits || result.count() < hits); ++r) {
2251  QModelIndex idx = index(r, start.column(), p);
2252  if (!idx.isValid())
2253  continue;
2254  QVariant v = data(idx, role);
2255  // QVariant based matching
2256  if (matchType == Qt::MatchExactly) {
2257  if (value == v)
2258  result.append(idx);
2259  } else { // QString based matching
2260  if (text.isEmpty()) // lazy conversion
2261  text = value.toString();
2262  QString t = v.toString();
2263  switch (matchType) {
2264  case Qt::MatchRegExp:
2265  if (QRegExp(text, cs).exactMatch(t))
2266  result.append(idx);
2267  break;
2268  case Qt::MatchWildcard:
2269  if (QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t))
2270  result.append(idx);
2271  break;
2272  case Qt::MatchStartsWith:
2273  if (t.startsWith(text, cs))
2274  result.append(idx);
2275  break;
2276  case Qt::MatchEndsWith:
2277  if (t.endsWith(text, cs))
2278  result.append(idx);
2279  break;
2280  case Qt::MatchFixedString:
2281  if (t.compare(text, cs) == 0)
2282  result.append(idx);
2283  break;
2284  case Qt::MatchContains:
2285  default:
2286  if (t.contains(text, cs))
2287  result.append(idx);
2288  }
2289  }
2290  if (recurse && hasChildren(idx)) { // search the hierarchy
2291  result += match(index(0, idx.column(), idx), role,
2292  (text.isEmpty() ? value : text),
2293  (allHits ? -1 : hits - result.count()), flags);
2294  }
2295  }
2296  // prepare for the next iteration
2297  from = 0;
2298  to = start.row();
2299  }
2300  return result;
2301 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
Returns a list of indexes for the items in the column of the start index where data stored under the ...
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
virtual bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Returns true if parent has any children; otherwise returns false.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int row() const
Returns the row this model index refers to.
unsigned int uint
Definition: qglobal.h:996
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
CaseSensitivity
Definition: qnamespace.h:1451
int compare(const QString &s) const
Definition: qstring.cpp:5037
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
#define text
Definition: qobjectdefs.h:80
int column() const
Returns the column this model index refers to.

◆ mimeData()

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

Reimplemented in QStandardItemModel, QTableModel, QSortFilterProxyModel, QTreeModel, QListModel, QFileSystemModel, QDirModel, QAbstractProxyModel, QUrlModel, and QProxyModel.

Definition at line 1911 of file qabstractitemmodel.cpp.

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

1912 {
1913  if (indexes.count() <= 0)
1914  return 0;
1916  if (types.isEmpty())
1917  return 0;
1918  QMimeData *data = new QMimeData();
1919  QString format = types.at(0);
1920  QByteArray encoded;
1922  encodeData(indexes, stream);
1923  data->setData(format, encoded);
1924  return data;
1925 }
void setData(const QString &mimetype, const QByteArray &data)
Sets the data associated with the MIME type given by mimeType to the specified data.
Definition: qmimedata.cpp:547
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
virtual QStringList mimeTypes() const
Returns a list of MIME types that can be used to describe a list of model indexes.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static FILE * stream
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void encodeData(const QModelIndexList &indexes, QDataStream &stream) const
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
static const struct @32 types[]
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71

◆ mimeTypes()

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, QSortFilterProxyModel, QTableModel, QTreeModel, QListModel, QFileSystemModel, QAbstractProxyModel, QDirModel, QUrlModel, and QProxyModel.

Definition at line 1894 of file qabstractitemmodel.cpp.

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

1895 {
1897  types << QLatin1String("application/x-qabstractitemmodeldatalist");
1898  return types;
1899 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static const struct @32 types[]

◆ modelAboutToBeReset

QAbstractItemModel::modelAboutToBeReset ( )
signal

This signal is emitted when reset() is called, before the model's internal state (e.

Since
4.2

g. persistent model indexes) has been invalidated.

\sa beginResetModel(), modelReset()

Referenced by beginResetModel(), reset(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), and sibling().

◆ modelReset

QAbstractItemModel::modelReset ( )
signal

This signal is emitted when reset() is called, after the model's internal state (e.

Since
4.1

g. persistent model indexes) has been invalidated.

\sa endResetModel(), modelAboutToBeReset()

Referenced by QProxyModel::connectToModel(), QProxyModel::disconnectFromModel(), endResetModel(), QDeclarativeFolderListModel::QDeclarativeFolderListModel(), QSortFilterProxyModel::QSortFilterProxyModel(), reset(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QCompletionModel::setSourceModel(), and sibling().

◆ parent()

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

Returns the parent of the model item with the given index.

Warning
This function is not part of the public interface.

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

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

See also
createIndex()

Implemented in QEmptyItemModel, QAbstractListModel, QAbstractTableModel, QStandardItemModel, QCompletionModel, QPPDOptionsModel, QSortFilterProxyModel, QTreeModel, QEmptyModel, QScriptBreakpointsModel, QScriptDebuggerScriptsModel, QFileSystemModel, QScriptDebuggerLocalsModel, QDirModel, QProxyModel, QIdentityProxyModel, QEmptyModel, and QUndoModel.

Referenced by QAbstractItemViewPrivate::_q_columnsAboutToBeRemoved(), QModelIndex::parent(), and QModelIndex::sibling().

◆ persistentIndexList()

QModelIndexList QAbstractItemModel::persistentIndexList ( ) const
protected

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

Since
4.2

Definition at line 3226 of file qabstractitemmodel.cpp.

Referenced by QListModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::ensureSorted(), QCompletionModel::resetModel(), QTableModel::setItem(), QFileSystemModel::setNameFilters(), sibling(), QStringListModel::sort(), and QFileSystemModel::sort().

3227 {
3228  Q_D(const QAbstractItemModel);
3229  QModelIndexList result;
3230  for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = d->persistent.indexes.constBegin();
3231  it != d->persistent.indexes.constEnd(); ++it) {
3233  result.append(data->index);
3234  }
3235  return result;
3236 }
double d
Definition: qnumeric_p.h:62
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
#define Q_D(Class)
Definition: qglobal.h:2482
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
The QAbstractItemModel class provides the abstract interface for item model classes.

◆ removeColumn()

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 320 of file qabstractitemmodel.h.

Referenced by QCalendarModel::setWeekNumbersShown(), and sibling().

321 { return removeColumns(acolumn, 1, aparent); }
virtual bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
On models that support this, removes count columns starting with the given column under parent parent...

◆ removeColumns()

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 your own API for altering the data.

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

Reimplemented in QCalendarModel, QStandardItemModel, QSortFilterProxyModel, QTableModel, QSqlTableModel, QSqlRelationalTableModel, QIdentityProxyModel, and QSqlQueryModel.

Definition at line 2133 of file qabstractitemmodel.cpp.

2134 {
2135  return false;
2136 }

◆ removeRow()

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.

This is a convenience function that calls removeRows(). The QAbstractItemModel implementation of removeRows() does nothing.

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

Definition at line 318 of file qabstractitemmodel.h.

Referenced by QUrlModel::addUrls(), QSidebar::removeEntry(), QCalendarModel::setHorizontalHeaderFormat(), and sibling().

319 { return removeRows(arow, 1, aparent); }
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
On models that support this, removes count rows starting with the given row under parent parent from ...

◆ removeRows()

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 your own API for altering the data.

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

Reimplemented in QCalendarModel, QStandardItemModel, QSortFilterProxyModel, QTreeModel, QListModel, QTableModel, QSqlTableModel, QIdentityProxyModel, and QStringListModel.

Definition at line 2112 of file qabstractitemmodel.cpp.

Referenced by QAbstractItemViewPrivate::clearOrRemove().

2113 {
2114  return false;
2115 }

◆ reset()

void QAbstractItemModel::reset ( )
protected

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

Note
Use beginResetModel() and endResetModel() instead whenever possible. Use this method only if there is no way to call beginResetModel() before invalidating the model. Otherwise it could lead to unexpected behaviour, especially when used with proxy models.

Definition at line 3095 of file qabstractitemmodel.cpp.

Referenced by QListModel::clear(), QTreeModel::clear(), QStandardItemModel::clear(), QTableModel::clearContents(), QCompletionModel::resetModel(), QSqlQueryModel::setQuery(), and QUndoModel::stackChanged().

3096 {
3099  d->invalidatePersistentIndexes();
3100  QMetaObject::invokeMethod(this, "resetInternalData");
3101  emit modelReset();
3102 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76
void modelAboutToBeReset()
This signal is emitted when reset() is called, before the model&#39;s internal state (e.
The QAbstractItemModel class provides the abstract interface for item model classes.
void modelReset()
This signal is emitted when reset() is called, after the model&#39;s internal state (e.
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ resetInternalData

void QAbstractItemModel::resetInternalData ( )
protectedslot

This slot is called just after the internal data of a model is cleared while it is being reset.

Since
4.8

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
{
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 slots:
{
m_customData.clear();
}
private:
QHash<int, QVariant> m_customData;
};
See also
modelAboutToBeReset(), modelReset()

Definition at line 1477 of file qabstractitemmodel.cpp.

Referenced by sibling().

1478 {
1479 
1480 }

◆ revert

void QAbstractItemModel::revert ( )
virtualslot

Lets the model know that it should discard cached information.

This function is typically used for row editing.

See also
submit()

Reimplemented in QProxyModel, and QAbstractProxyModel.

Definition at line 2372 of file qabstractitemmodel.cpp.

2373 {
2374  // do nothing
2375 }

◆ roleNames()

const QHash< int, QByteArray > & QAbstractItemModel::roleNames ( ) const

Returns the model's role names.

Since
4.6
See also
setRoleNames()

Definition at line 2345 of file qabstractitemmodel.cpp.

Referenced by QDeclarativeVisualDataModelPrivate::ensureRoles(), setRoleNames(), and sibling().

2346 {
2347  Q_D(const QAbstractItemModel);
2348  return d->roleNames;
2349 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAbstractItemModel class provides the abstract interface for item model classes.

◆ rowCount()

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.

Note
When implementing a table based model, rowCount() should return 0 when the parent is valid.
See also
columnCount()

Implemented in QCalendarModel, QEmptyItemModel, QStandardItemModel, QCompletionModel, QPPDOptionsModel, QSortFilterProxyModel, QTableModel, ControlList, QSqlTableModel, QTreeModel, QListModel, QEmptyModel, QScriptBreakpointsModel, QFileSystemModel, QScriptDebuggerScriptsModel, QDeclarativeFolderListModel, QScriptDebuggerLocalsModel, QDirModel, QScriptDebuggerStackModel, QProxyModel, QIdentityProxyModel, QEmptyModel, QSqlQueryModel, QUndoModel, and QStringListModel.

Referenced by QItemSelectionModelPrivate::_q_columnsAboutToBeRemoved(), QItemSelectionModelPrivate::_q_layoutAboutToBeChanged(), QHeaderViewPrivate::_q_layoutAboutToBeChanged(), QItemSelectionModelPrivate::_q_layoutChanged(), QFileDialogPrivate::_q_useNameFilter(), QListViewPrivate::doItemsLayout(), dropMimeData(), QAbstractListModel::dropMimeData(), QItemSelectionModelPrivate::expandSelection(), QAbstractItemViewPrivate::fetchMore(), QCompletionEngine::filter(), QUnsortedModelEngine::filter(), QCompletionEngine::filterHistory(), QUnsortedModelEngine::filterOnDemand(), hasChildren(), QAbstractTableModel::hasChildren(), QAbstractListModel::hasChildren(), hasIndex(), QTreeViewPrivate::hasVisibleChildren(), QSortedModelEngine::indexHint(), QDataWidgetMapperPrivate::itemCount(), QListViewPrivate::itemSize(), QTreeViewPrivate::layout(), match(), QDeclarativeVisualDataModelPrivate::modelCount(), QHeaderViewPrivate::modelIsEmpty(), QHeaderViewPrivate::modelSectionCount(), ModelIndexIterator::next(), QListViewPrivate::prepareItemsLayout(), QAccessibleTable2::rowCount(), QAccessibleItemView::rowCount(), QAbstractItemViewPrivate::selectAll(), QListViewPrivate::selectAll(), QTableViewPrivate::selectColumn(), QSidebar::selectUrl(), QCompleterPrivate::showPopup(), QSortedModelEngine::sortOrder(), and QAccessibleItemRow::text().

◆ rowsAboutToBeInserted

void QAbstractItemModel::rowsAboutToBeInserted ( const QModelIndex parent,
int  start,
int  end 
)
signal

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(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), and sibling().

◆ rowsAboutToBeMoved

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.

Since
4.6

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.

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

Referenced by beginMoveRows(), QIdentityProxyModel::setSourceModel(), and sibling().

◆ rowsAboutToBeRemoved

void QAbstractItemModel::rowsAboutToBeRemoved ( const QModelIndex parent,
int  start,
int  end 
)
signal

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(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), and sibling().

◆ rowsInserted

void QAbstractItemModel::rowsInserted ( const QModelIndex parent,
int  start,
int  end 
)
signal

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(), QDeclarativeFolderListModel::QDeclarativeFolderListModel(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), and sibling().

◆ rowsMoved

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.

Since
4.6

The items between sourceStart and sourceEnd inclusive, under the given sourceParent item have been moved to destinationParent starting at the row destinationRow.

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

Referenced by endMoveRows(), QIdentityProxyModel::setSourceModel(), and sibling().

◆ rowsRemoved

void QAbstractItemModel::rowsRemoved ( const QModelIndex parent,
int  start,
int  end 
)
signal

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(), QDeclarativeFolderListModel::QDeclarativeFolderListModel(), QUrlModel::setFileSystemModel(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QCompletionModel::setSourceModel(), and sibling().

◆ setData()

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.

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

Reimplemented in QStandardItemModel, QSortFilterProxyModel, QTableModel, QTreeModel, QListModel, QFileSystemModel, QScriptBreakpointsModel, QUrlModel, QSqlRelationalTableModel, QDirModel, QScriptDebuggerLocalsModel, QAbstractProxyModel, QProxyModel, QSqlTableModel, and QStringListModel.

Definition at line 1847 of file qabstractitemmodel.cpp.

Referenced by QDataWidgetMapperPrivate::commit(), QStyledItemDelegate::editorEvent(), QItemDelegate::editorEvent(), QSqlTableModel::setData(), setItemData(), QStyledItemDelegate::setModelData(), QItemDelegate::setModelData(), QComboBoxDelegate::setSeparator(), and QAccessibleTable2Cell::setText().

1848 {
1849  Q_UNUSED(index);
1850  Q_UNUSED(value);
1851  Q_UNUSED(role);
1852  return false;
1853 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ setHeaderData()

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 function, the headerDataChanged() signal must be emitted explicitly.

See also
Qt::ItemDataRole, headerData()

Reimplemented in QStandardItemModel, QSortFilterProxyModel, QTableModel, QTreeModel, QAbstractProxyModel, QProxyModel, and QSqlQueryModel.

Definition at line 2408 of file qabstractitemmodel.cpp.

Referenced by QAccessibleItemRow::setText().

2410 {
2411  Q_UNUSED(section);
2412  Q_UNUSED(orientation);
2413  Q_UNUSED(value);
2414  Q_UNUSED(role);
2415  return false;
2416 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ setItemData()

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, QTableModel, and QAbstractProxyModel.

Definition at line 1880 of file qabstractitemmodel.cpp.

Referenced by QAbstractItemViewPrivate::clearOrRemove(), decodeData(), QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), and QAbstractProxyModel::setItemData().

1881 {
1882  bool b = true;
1883  for (QMap<int, QVariant>::ConstIterator it = roles.begin(); it != roles.end(); ++it)
1884  b = b && setData(index, it.value(), it.key());
1885  return b;
1886 }
#define it(className, varName)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
Definition: qmap.h:301
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375

◆ setRoleNames()

void QAbstractItemModel::setRoleNames ( const QHash< int, QByteArray > &  roleNames)
protected

Sets the model's role names to roleNames.

Since
4.6

This function allows mapping of role identifiers to role property names in Declarative UI. This function must be called before the model is used. Modifying the role names after the model has been set may result in undefined behaviour.

See also
roleNames()

Definition at line 2329 of file qabstractitemmodel.cpp.

Referenced by QDeclarativeFolderListModel::QDeclarativeFolderListModel(), and sibling().

2330 {
2332  d->roleNames = roleNames;
2333 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAbstractItemModel class provides the abstract interface for item model classes.
const QHash< int, QByteArray > & roleNames() const
Returns the model&#39;s role names.

◆ setSupportedDragActions()

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

Sets the supported drag actions for the items in the model.

Since
4.2
See also
supportedDragActions(), {Using drag and drop with item views}

Definition at line 2026 of file qabstractitemmodel.cpp.

Referenced by sibling().

2027 {
2029  d->supportedDragActions = actions;
2030 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QAbstractItemModel class provides the abstract interface for item model classes.

◆ 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 176 of file qabstractitemmodel.h.

Referenced by QModelIndex::internalId(), and QDirModel::setData().

177  { return index(row, column, parent(idx)); }
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273

◆ sort()

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.

Reimplemented in QStandardItemModel, QSortFilterProxyModel, QTableModel, QTreeModel, QListModel, QFileSystemModel, QProxyModel, QDirModel, QSqlTableModel, QAbstractProxyModel, and QStringListModel.

Definition at line 2193 of file qabstractitemmodel.cpp.

Referenced by QTreeViewPrivate::_q_sortIndicatorChanged().

2194 {
2195  Q_UNUSED(column);
2196  Q_UNUSED(order);
2197  // do nothing
2198 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ span()

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

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

Note
Currently, span is not used.

Reimplemented in QSortFilterProxyModel, QProxyModel, and QAbstractProxyModel.

Definition at line 2309 of file qabstractitemmodel.cpp.

2310 {
2311  return QSize(1, 1);
2312 }
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ submit

bool QAbstractItemModel::submit ( )
virtualslot

Lets the model know that it should submit cached information to permanent storage.

This function is typically used for row editing.

Returns true if there is no error; otherwise returns false.

See also
revert()

Reimplemented in QProxyModel, and QAbstractProxyModel.

Definition at line 2360 of file qabstractitemmodel.cpp.

2361 {
2362  return true;
2363 }

◆ supportedDragActions()

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 2007 of file qabstractitemmodel.cpp.

Referenced by sibling().

2008 {
2009  // ### Qt 5: make this virtual or these properties
2010  Q_D(const QAbstractItemModel);
2011  if (d->supportedDragActions != -1)
2012  return d->supportedDragActions;
2013  return supportedDropActions();
2014 }
double d
Definition: qnumeric_p.h:62
virtual Qt::DropActions supportedDropActions() const
Returns the drop actions supported by this model.
#define Q_D(Class)
Definition: qglobal.h:2482
The QAbstractItemModel class provides the abstract interface for item model classes.

◆ supportedDropActions()

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

Returns the drop actions supported by this model.

Since
4.2

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

See also
dropMimeData(), Qt::DropActions, {Using drag and drop with item views}

Reimplemented in QStandardItemModel, QSortFilterProxyModel, QTableModel, QTreeModel, QListModel, QFileSystemModel, QDirModel, QAbstractProxyModel, QProxyModel, and QStringListModel.

Definition at line 1991 of file qabstractitemmodel.cpp.

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

1992 {
1993  return Qt::CopyAction;
1994 }

Friends and Related Functions

◆ QAbstractItemViewPrivate

Definition at line 164 of file qabstractitemmodel.h.

◆ QIdentityProxyModel

friend class QIdentityProxyModel
friend

Definition at line 165 of file qabstractitemmodel.h.

◆ QPersistentModelIndexData

Definition at line 163 of file qabstractitemmodel.h.


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