Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QAbstractItemModel Class Referenceabstract

\inmodule QtCore More...

#include <qabstractitemmodel.h>

+ Inheritance diagram for QAbstractItemModel:
+ Collaboration diagram for QAbstractItemModel:

Public Types

enum  LayoutChangeHint { NoLayoutChangeHint , VerticalSortHint , HorizontalSortHint }
 This enum describes the way the model changes layout. More...
 
enum class  CheckIndexOption { NoOption = 0x0000 , IndexIsValid = 0x0001 , DoNotUseParent = 0x0002 , ParentIsInvalid = 0x0004 }
 

Public Slots

virtual bool submit ()
 Lets the model know that it should submit cached information to permanent storage.
 
virtual void revert ()
 Lets the model know that it should discard cached information.
 
- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 

Signals

void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
 This signal is emitted whenever the data in an existing item changes.
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 This signal is emitted whenever a header is changed.
 
void layoutChanged (const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
 
void layoutAboutToBeChanged (const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted just before rows are inserted into the model.
 
void rowsInserted (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted after rows have been inserted into the model.
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted just before rows are removed from the model.
 
void rowsRemoved (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted after rows have been removed from the model.
 
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted just before columns are inserted into the model.
 
void columnsInserted (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted after columns have been inserted into the model.
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted just before columns are removed from the model.
 
void columnsRemoved (const QModelIndex &parent, int first, int last, QPrivateSignal)
 This signal is emitted after columns have been removed from the model.
 
void modelAboutToBeReset (QPrivateSignal)
 
void modelReset (QPrivateSignal)
 
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal)
 
void rowsMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal)
 
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal)
 
void columnsMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal)
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 

Public Member Functions

 QAbstractItemModel (QObject *parent=nullptr)
 Constructs an abstract item model with the given parent.
 
virtual ~QAbstractItemModel ()
 Destroys the abstract item model.
 
Q_INVOKABLE 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}.
 
virtual Q_INVOKABLE 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.
 
virtual Q_INVOKABLE QModelIndex parent (const QModelIndex &child) const =0
 
virtual Q_INVOKABLE 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.
 
virtual Q_INVOKABLE int rowCount (const QModelIndex &parent=QModelIndex()) const =0
 Returns the number of rows under the given parent.
 
virtual Q_INVOKABLE int columnCount (const QModelIndex &parent=QModelIndex()) const =0
 Returns the number of columns for the children of the given parent.
 
virtual Q_INVOKABLE bool hasChildren (const QModelIndex &parent=QModelIndex()) const
 Returns {true} if parent has any children; otherwise returns {false}.
 
virtual Q_INVOKABLE 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 Q_INVOKABLE bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 Sets the role data for the item at index to value.
 
virtual Q_INVOKABLE 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.
 
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.
 
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.
 
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.
 
virtual bool clearItemData (const QModelIndex &index)
 
virtual QStringList mimeTypes () const
 Returns the list of allowed MIME types.
 
virtual QMimeDatamimeData (const QModelIndexList &indexes) const
 Returns an object that contains serialized items of data corresponding to the list of indexes specified.
 
virtual bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
 Returns {true} if a model can accept a drop of the data.
 
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.
 
virtual Qt::DropActions supportedDropActions () const
 
virtual Qt::DropActions supportedDragActions () const
 Returns the actions supported by the data in this model.
 
Q_INVOKABLE Q_REVISION (6, 4) virtual bool insertRows(int row
 
Q_INVOKABLE Q_REVISION (6, 4) virtual bool insertColumns(int column
 
Q_INVOKABLE Q_REVISION (6, 4) virtual bool removeRows(int row
 
Q_INVOKABLE Q_REVISION (6, 4) virtual bool removeColumns(int column
 
Q_INVOKABLE Q_REVISION (6, 4) virtual bool moveRows(const QModelIndex &sourceParent
 
Q_INVOKABLE Q_REVISION (6, 4) virtual bool moveColumns(const QModelIndex &sourceParent
 
Q_INVOKABLE Q_REVISION (6, 4) inline bool insertRow(int row
 
Q_INVOKABLE Q_REVISION (6, 4) inline bool insertColumn(int column
 
Q_INVOKABLE Q_REVISION (6, 4) inline bool removeRow(int row
 
Q_INVOKABLE Q_REVISION (6, 4) inline bool removeColumn(int column
 
Q_INVOKABLE Q_REVISION (6, 4) inline bool moveRow(const QModelIndex &sourceParent
 
Q_INVOKABLE Q_REVISION (6, 4) inline bool moveColumn(const QModelIndex &sourceParent
 
virtual Q_INVOKABLE void fetchMore (const QModelIndex &parent)
 Fetches any available data for the items with the parent specified by the parent index.
 
virtual Q_INVOKABLE bool canFetchMore (const QModelIndex &parent) const
 Returns {true} if there is more data available for parent; otherwise returns {false}.
 
virtual Q_INVOKABLE Qt::ItemFlags flags (const QModelIndex &index) const
 Returns the item flags for the given index.
 
Q_INVOKABLE Q_REVISION (6, 4) virtual void sort(int column
 
virtual QModelIndex buddy (const QModelIndex &index) const
 Returns a model index for the buddy of the item represented by index.
 
virtual Q_INVOKABLE 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.
 
virtual QSize span (const QModelIndex &index) const
 Returns the row and column span of the item represented by index.
 
virtual QHash< int, QByteArrayroleNames () const
 
bool checkIndex (const QModelIndex &index, CheckIndexOptions options=CheckIndexOption::NoOption) const
 
virtual void multiData (const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool event (QEvent *event)
 This virtual function receives events to an object and should return true if the event e was recognized and processed.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) 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.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
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.
 

Public Attributes

Q_INVOKABLE int count
 
Q_INVOKABLE int const QModelIndexparent = QModelIndex())
 Returns the parent of the model item with the given index.
 
Q_INVOKABLE int sourceRow
 
Q_INVOKABLE int int count
 
Q_INVOKABLE int int const QModelIndexdestinationParent
 
Q_INVOKABLE int int const QModelIndex int destinationChild
 
Q_INVOKABLE int sourceColumn
 
Q_INVOKABLE const QModelIndexparent = QModelIndex())
 
Q_INVOKABLE int const QModelIndexdestinationParent
 
Q_INVOKABLE int const QModelIndex int destinationChild
 
Q_INVOKABLE Qt::SortOrder order = Qt::AscendingOrder)
 

Protected Slots

virtual void resetInternalData ()
 

Protected Member Functions

 QAbstractItemModel (QAbstractItemModelPrivate &dd, QObject *parent=nullptr)
 
QModelIndex createIndex (int row, int column, const void *data=nullptr) const
 Creates a model index for the given row and column with the internal pointer ptr.
 
QModelIndex createIndex (int row, int column, quintptr id) const
 Creates a model index for the given row and column with the internal identifier, id.
 
void encodeData (const QModelIndexList &indexes, QDataStream &stream) const
 
bool decodeData (int row, int column, const QModelIndex &parent, QDataStream &stream)
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 Begins a row insertion operation.
 
void endInsertRows ()
 Ends a row insertion operation.
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 Begins a row removal operation.
 
void endRemoveRows ()
 Ends a row removal operation.
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
 
void endMoveRows ()
 Ends a row move operation.
 
void beginInsertColumns (const QModelIndex &parent, int first, int last)
 Begins a column insertion operation.
 
void endInsertColumns ()
 Ends a column insertion operation.
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 Begins a column removal operation.
 
void endRemoveColumns ()
 Ends a column removal operation.
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn)
 Begins a column move operation.
 
void endMoveColumns ()
 Ends a column move operation.
 
void beginResetModel ()
 Begins a model reset operation.
 
void endResetModel ()
 Completes a model reset operation.
 
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.
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 
QModelIndexList persistentIndexList () const
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 

Friends

class QPersistentModelIndexData
 
class QAbstractItemViewPrivate
 
class QAbstractProxyModel
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Detailed Description

\inmodule QtCore

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 \l{Model/View Classes} and is part of Qt's \l{Model/View Programming}{model/view framework}. It can be used as the underlying data model for the item view elements in QML or the item view classes in the Qt Widgets module.

If you need a model to use with an item view such as QML's List View element or the C++ widgets QListView or 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.

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 \l 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 \l 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 \l 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().

Definition at line 233 of file qabstractitemmodel.h.

Member Enumeration Documentation

◆ CheckIndexOption

Since
5.11

This enum can be used to control the checks performed by QAbstractItemModel::checkIndex().

\value NoOption No check options are specified.

\value IndexIsValid The model index passed to QAbstractItemModel::checkIndex() is checked to be a valid model index.

\value DoNotUseParent Does not perform any check involving the usage of the parent of the index passed to QAbstractItemModel::checkIndex().

\value ParentIsInvalid The parent of the model index passed to QAbstractItemModel::checkIndex() is checked to be an invalid model index. If both this option and DoNotUseParent are specified, then this option is ignored.

Enumerator
NoOption 
IndexIsValid 
DoNotUseParent 
ParentIsInvalid 

Definition at line 317 of file qabstractitemmodel.h.

◆ LayoutChangeHint

This enum describes the way the model changes layout.

\value NoLayoutChangeHint No hint is available. \value VerticalSortHint Rows are being sorted. \value HorizontalSortHint Columns are being sorted.

Note that VerticalSortHint and HorizontalSortHint carry the meaning that items are being moved within the same parent, not moved to a different parent in the model, and not filtered out or in.

Enumerator
NoLayoutChangeHint 
VerticalSortHint 
HorizontalSortHint 

Definition at line 309 of file qabstractitemmodel.h.

Constructor & Destructor Documentation

◆ QAbstractItemModel() [1/2]

QAbstractItemModel::QAbstractItemModel ( QObject * parent = nullptr)
explicit

Constructs an abstract item model with the given parent.

Definition at line 1704 of file qabstractitemmodel.cpp.

◆ ~QAbstractItemModel()

QAbstractItemModel::~QAbstractItemModel ( )
virtual

Destroys the abstract item model.

Definition at line 1720 of file qabstractitemmodel.cpp.

◆ QAbstractItemModel() [2/2]

QAbstractItemModel::QAbstractItemModel ( QAbstractItemModelPrivate & dd,
QObject * parent = nullptr )
protected

Definition at line 1712 of file qabstractitemmodel.cpp.

Member Function Documentation

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

\table 80% \row

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

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

This inserts the three new columns as columns 4, 5, and 6. \row

  • \inlineimage 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
    \a first is 6 and \a last is 8:
    
    \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 4
    
    This appends the two new columns as columns 6, 7, and 8.
    
    \endtable
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 3195 of file qabstractitemmodel.cpp.

References columnCount(), columnsAboutToBeInserted(), d, emit, parent, and Q_ASSERT.

Referenced by QSqlQueryModel::beginInsertColumns(), QTreeModel::insertColumns(), QTableModel::insertColumns(), TableModel::insertColumns(), QTreeModel::setColumnCount(), and QtPrivate::QCalendarModel::setWeekNumbersShown().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

\table 80% \row

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

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

This inserts the three new rows as rows 2, 3, and 4. \row

  • \inlineimage 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 \a first is 4
    and \a last is 5:
    
    \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 1
    
    This appends the two new rows as rows 4 and 5.
    
    \endtable
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 2885 of file qabstractitemmodel.cpp.

References d, emit, parent, Q_ASSERT, rowCount(), and rowsAboutToBeInserted().

Referenced by QConcatenateTablesProxyModel::addSourceModel(), QTreeModel::beginInsertItems(), QSqlQueryModel::beginInsertRows(), QListModel::insert(), QListModel::insert(), TableModel::insertRows(), QTreeModel::insertRows(), QStringListModel::insertRows(), QListModel::insertRows(), QTableModel::insertRows(), QtPrivate::QCalendarModel::setHorizontalHeaderFormat(), and QQmlTreeModelToTableModel::showModelChildItems().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 beginMoveColumns and endMoveColumns is an alternative to emitting layoutAboutToBeChanged and layoutChanged directly along with changePersistentIndex.

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

References columnsAboutToBeMoved(), d, destinationChild, destinationParent, emit, Qt::Horizontal, QModelIndex::isValid(), QModelIndex::parent(), Q_ASSERT, and QModelIndex::row().

+ Here is the call graph for this function:

◆ beginMoveRows()

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

Begins a row move operation.

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

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.

\table 80% \row

  • \inlineimage 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.

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

  • \inlineimage 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 \a destinationChild is 6:
    
    \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 7
    
    This moves the target rows to the end of the target parent as 6, 7 and 8.
    
    \row
  • \inlineimage 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 \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 0.
    
    \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 8
    
    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 cannot 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)
    
    \row
  • \inlineimage 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 \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 4.
    
    \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 9
    
    Note that other rows may be displaced accordingly.
    
    \endtable
See also
endMoveRows()

Definition at line 3097 of file qabstractitemmodel.cpp.

References d, destinationChild, destinationParent, emit, QModelIndex::isValid(), QModelIndex::parent(), Q_ASSERT, QModelIndex::row(), rowsAboutToBeMoved(), and Qt::Vertical.

Referenced by QQmlListModel::move(), QListModel::move(), QQmlTableModel::moveRow(), QStringListModel::moveRows(), and QListModel::moveRows().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

\table 80% \row

  • \inlineimage 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:

\endtable

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

References columnCount(), columnsAboutToBeRemoved(), d, emit, parent, and Q_ASSERT.

Referenced by QSqlQueryModel::beginRemoveColumns(), QTableModel::removeColumns(), TableModel::removeColumns(), QTreeModel::setColumnCount(), and QtPrivate::QCalendarModel::setWeekNumbersShown().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

\table 80% \row

  • \inlineimage 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:

\endtable

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

References d, emit, parent, Q_ASSERT, rowCount(), and rowsAboutToBeRemoved().

Referenced by QTreeModel::beginRemoveItems(), QSqlQueryModel::beginRemoveRows(), QListModel::remove(), QQmlTableModel::removeRow(), TableModel::removeRows(), QStringListModel::removeRows(), QTreeModel::removeRows(), QListModel::removeRows(), QTableModel::removeRows(), QConcatenateTablesProxyModel::removeSourceModel(), QQmlTreeModelToTableModel::removeVisibleRows(), QtPrivate::QCalendarModel::setHorizontalHeaderFormat(), and QListModel::take().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

This function emits the signal modelAboutToBeReset().

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

Definition at line 3395 of file qabstractitemmodel.cpp.

References emit, and modelAboutToBeReset().

Referenced by QSqlQueryModel::beginResetModel(), QStandardItemModel::clear(), QListModel::clear(), QTreeModel::clear(), QTableModel::clearContents(), QQmlTreeModelToTableModel::clearModelData(), QCompletionModel::filter(), QDeclarativePlaceContentModel::initializeCollection(), QDeclarativeSearchModelBase::initializePlugin(), QDeclarativeSearchSuggestionModel::queryFinished(), QDeclarativeGeocodeModel::reset(), QDeclarativeGeoRouteModel::reset(), QDeclarativeSearchModelBase::reset(), QCompletionModel::setFiltered(), QQuickFolderListModel::setFolder(), QQuick3DRenderStatsMeshesModel::setMeshData(), QHeaderDataProxyModel::setOrientation(), QQuick3DRenderStatsPassesModel::setPassData(), QDeclarativePlaceContentModel::setPlace(), QPdfSearchModel::setSearchString(), QHeaderDataProxyModel::setSourceModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QStringListModel::setStringList(), and QQuick3DRenderStatsTexturesModel::setTextureData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

Definition at line 2483 of file qabstractitemmodel.cpp.

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

+ Here is the caller graph for this function:

◆ canDropMimeData()

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

Returns {true} if a model can accept a drop of the data.

This default implementation only checks if data has at least one format in the list of mimeTypes() and if action is among the model's supportedDropActions().

Reimplement this function in your custom model, if you want to test whether the data can be dropped at row, column, parent with action. If you don't need that test, it is not necessary to reimplement this function.

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

Reimplemented in QAbstractProxyModel, QConcatenateTablesProxyModel, and DragDropListModel.

Definition at line 2161 of file qabstractitemmodel.cpp.

References i, mimeTypes(), parent, Q_UNUSED, and supportedDropActions().

Referenced by QConcatenateTablesProxyModel::canDropMimeData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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, the fetchMore() function should be called. This is the behavior of QAbstractItemView, for example.

See also
fetchMore()

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

Definition at line 2439 of file qabstractitemmodel.cpp.

Referenced by QTreeViewPrivate::expand(), QQmlTreeModelToTableModel::expandPendingRows(), QAbstractItemViewPrivate::fetchMore(), QTreeViewPrivate::layout(), QAbstractItemModelTesterPrivate::nonDestructiveBasicTest(), QQmlTreeModelToTableModel::showModelChildItems(), and QQmlTreeModelToTableModel::showModelTopLevelItems().

+ Here is the caller graph for this function:

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

References QSet< T >::cend(), QSet< T >::constFind(), d, QSet< T >::erase(), QModelIndex::isValid(), and it.

+ Here is the call graph for this function:

◆ changePersistentIndexList()

void QAbstractItemModel::changePersistentIndexList ( const QModelIndexList & from,
const QModelIndexList & to )
protected
Since
4.1

Changes the {QPersistentModelIndex}es that are equal to the indexes in the given from model index list to the given to model index list.

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

See also
persistentIndexList(), changePersistentIndex()

Definition at line 3455 of file qabstractitemmodel.cpp.

References QList< T >::at(), QSet< T >::cend(), QSet< T >::constFind(), d, QSet< T >::erase(), i, it, and QList< T >::size().

Referenced by QTableModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::setItem(), QListModel::sort(), QTableModel::sort(), QStringListModel::sort(), QFileSystemModel::sort(), QStandardItemPrivate::sortChildren(), and QTreeModel::sortItems().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkIndex()

bool QAbstractItemModel::checkIndex ( const QModelIndex & index,
CheckIndexOptions options = CheckIndexOption::NoOption ) const
Since
5.11

This function checks whether index is a legal model index for this model. A legal model index is either an invalid model index, or a valid model index for which all the following holds:

\list

  • the index' model is {this};
  • the index' row is greater or equal than zero;
  • the index' row is less than the row count for the index' parent;
  • the index' column is greater or equal than zero;
  • the index' column is less than the column count for the index' parent.

\endlist

The options argument may change some of these checks. If options contains {IndexIsValid}, then index must be a valid index; this is useful when reimplementing functions such as \l{data()} or \l{setData()}, which expect valid indexes.

If options contains {DoNotUseParent}, then the checks that would call \l{parent()} are omitted; this allows calling this function from a \l{parent()} reimplementation (otherwise, this would result in endless recursion and a crash).

If options does not contain {DoNotUseParent}, and it contains {ParentIsInvalid}, then an additional check is performed: the parent index is checked for not being valid. This is useful when implementing flat models such as lists or tables, where no model index should have a valid parent index.

This function returns true if all the checks succeeded, and false otherwise. This allows to use the function in \l{Q_ASSERT} and similar other debugging mechanisms. If some check failed, a warning message will be printed in the {qt.core.qabstractitemmodel.checkindex} logging category, containing some information that may be useful for debugging the failure.

Note
This function is a debugging helper for implementing your own item models. When developing complex models, as well as when building complicated model hierarchies (e.g. using proxy models), it is useful to call this function in order to catch bugs relative to illegal model indices (as defined above) accidentally passed to some QAbstractItemModel API.
Warning
Note that it's undefined behavior to pass illegal indices to item models, so applications must refrain from doing so, and not rely on any "defensive" programming that item models could employ to handle illegal indexes gracefully.
See also
QModelIndex

Definition at line 3569 of file qabstractitemmodel.cpp.

References columnCount(), DoNotUseParent, IndexIsValid, QModelIndex::isValid(), QModelIndex::parent(), ParentIsInvalid, qCWarning, and rowCount().

Referenced by QStandardItemModel::clearItemData(), QListModel::clearItemData(), QTableModel::clearItemData(), QTreeModel::clearItemData(), QTransposeProxyModel::columnCount(), QConcatenateTablesProxyModel::data(), QAbstractItemViewPrivate::delegateSizeHintChanged(), QConcatenateTablesProxyModel::flags(), QConcatenateTablesProxyModel::index(), QTransposeProxyModel::index(), QTransposeProxyModel::insertColumns(), QTransposeProxyModel::insertRows(), QStringListModel::itemData(), QTransposeProxyModel::itemData(), QConcatenateTablesProxyModel::itemData(), QConcatenateTablesProxyModel::mapToSource(), QTransposeProxyModel::mapToSource(), QConcatenateTablesProxyModel::mimeData(), QTransposeProxyModel::moveColumns(), QTransposeProxyModel::moveRows(), multiData(), QTransposeProxyModel::parent(), QTransposeProxyModel::removeColumns(), QTransposeProxyModel::removeRows(), QTransposeProxyModel::rowCount(), QConcatenateTablesProxyModel::setData(), QConcatenateTablesProxyModel::setItemData(), QTransposeProxyModel::setItemData(), QConcatenateTablesProxyModel::span(), and QTransposeProxyModel::span().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearItemData()

bool QAbstractItemModel::clearItemData ( const QModelIndex & index)
virtual
Since
6.0 Removes the data stored in all the roles for the given index. Returns {true} if successful; otherwise returns {false}. The dataChanged() signal should be emitted if the data was successfully removed. The base class implementation returns {false}
See also
data(), itemData(), setData(), setItemData()

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

Definition at line 2054 of file qabstractitemmodel.cpp.

References Q_UNUSED.

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

{
return 3;
}
Q_INVOKABLE int const QModelIndex & parent
Returns the parent of the model item with the given index.
virtual Q_INVOKABLE int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
\inmodule QtCore
#define Q_UNUSED(x)
Note
When implementing a table based model, columnCount() should return 0 when the parent is valid.
See also
rowCount()

Implemented in QEmptyItemModel, TableModel, QCompletionModel, QAbstractListModel, QtPrivate::QCalendarModel, QDeclarativeSupportedCategoriesModel, QQuick3DRenderStatsMeshesModel, QQuick3DRenderStatsPassesModel, QQuick3DRenderStatsTexturesModel, QConcatenateTablesProxyModel, QIdentityProxyModel, QSortFilterProxyModel, QTransposeProxyModel, QFileSystemModel, QStandardItemModel, QSqlQueryModel, TableModel, QTableModel, QTreeModel, QUndoModel, QQmlTableModel, QQmlTreeModelToTableModel, QHeaderDataProxyModel, QQuickViewTestUtils::QaimModel, and QPdfBookmarkModel.

Referenced by beginInsertColumns(), beginRemoveColumns(), checkIndex(), QAbstractItemViewPrivate::clearOrRemove(), QQmlTreeModelToTableModel::columnCount(), QHeaderDataProxyModel::columnCount(), QAbstractItemViewPrivate::columnsAboutToBeRemoved(), QAbstractItemModelTesterPrivate::data(), QAbstractItemModelTesterPrivate::dataChanged(), decodeData(), QAbstractTableModel::hasChildren(), hasChildren(), QAbstractItemModelTesterPrivate::hasIndex(), hasIndex(), QAbstractProxyModel::headerData(), QAbstractItemModelTesterPrivate::headerDataChanged(), QAbstractItemModelTesterPrivate::index(), QDataWidgetMapperPrivate::itemCount(), QHeaderViewPrivate::modelSectionCount(), QTreeView::moveCursor(), QAbstractItemModelTesterPrivate::nonDestructiveBasicTest(), QAbstractItemModelTesterPrivate::parent(), QListViewPrivate::prepareItemsLayout(), QHeaderViewPrivate::read(), QAbstractItemModelTesterPrivate::rowAndColumnCount(), QAbstractItemModelTesterPrivate::rowsAboutToBeRemoved(), QHeaderViewPrivate::sectionsAboutToBeChanged(), QAbstractItemViewPrivate::selectAll(), QListViewPrivate::selectAll(), and QTableWidget::setHorizontalHeaderLabels().

+ Here is the caller graph for this function:

◆ columnsAboutToBeInserted

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

This signal is emitted just before columns are inserted into the model.

The new items will be positioned between first and last inclusive, under the given parent item.

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 QAbstractItemModelTester::QAbstractItemModelTester(), QConcatenateTablesProxyModel::addSourceModel(), beginInsertColumns(), QItemSelectionModelPrivate::initModel(), QStandardItemPrivate::insertColumns(), QTransposeProxyModel::setSourceModel(), QAbstractProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

+ Here is the caller graph for this function:

◆ columnsAboutToBeMoved

void QAbstractItemModel::columnsAboutToBeMoved ( const QModelIndex & sourceParent,
int sourceStart,
int sourceEnd,
const QModelIndex & destinationParent,
int destinationColumn,
QPrivateSignal  )
signal
Since
4.6

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

{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 QAbstractItemModelTester::QAbstractItemModelTester(), beginMoveColumns(), QItemSelectionModelPrivate::initModel(), QHeaderView::setModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

+ Here is the caller graph for this function:

◆ columnsAboutToBeRemoved

void QAbstractItemModel::columnsAboutToBeRemoved ( const QModelIndex & parent,
int first,
int last,
QPrivateSignal  )
signal

This signal is emitted just before columns are removed from the model.

The items to be removed are those between first and last inclusive, under the given parent item.

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 QAbstractItemModelTester::QAbstractItemModelTester(), QConcatenateTablesProxyModel::addSourceModel(), beginRemoveColumns(), QItemSelectionModelPrivate::initModel(), QAbstractItemView::setModel(), QHeaderView::setModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

+ Here is the caller graph for this function:

◆ columnsInserted

void QAbstractItemModel::columnsInserted ( const QModelIndex & parent,
int first,
int last,
QPrivateSignal  )
signal

This signal is emitted after columns have been inserted into the model.

The new items are those between first and last inclusive, under the given parent item.

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 QAbstractItemModelTester::QAbstractItemModelTester(), QConcatenateTablesProxyModel::addSourceModel(), QQmlDelegateModelPrivate::connectToAbstractItemModel(), QQuickTableViewPrivate::connectToModel(), QQmlDelegateModelPrivate::disconnectFromAbstractItemModel(), QQuickTableViewPrivate::disconnectFromModel(), endInsertColumns(), QStandardItemPrivate::insertColumns(), QAbstractItemView::setModel(), QHeaderView::setModel(), QTableView::setModel(), QTransposeProxyModel::setSourceModel(), QAbstractProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), and QCompletionModel::setSourceModel().

+ Here is the caller graph for this function:

◆ columnsMoved

void QAbstractItemModel::columnsMoved ( const QModelIndex & sourceParent,
int sourceStart,
int sourceEnd,
const QModelIndex & destinationParent,
int destinationColumn,
QPrivateSignal  )
signal
Since
4.6

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

{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 QAbstractItemModelTester::QAbstractItemModelTester(), QQmlDelegateModelPrivate::connectToAbstractItemModel(), QQuickTableViewPrivate::connectToModel(), QQmlDelegateModelPrivate::disconnectFromAbstractItemModel(), QQuickTableViewPrivate::disconnectFromModel(), endMoveColumns(), QItemSelectionModelPrivate::initModel(), QAbstractItemView::setModel(), QHeaderView::setModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

+ Here is the caller graph for this function:

◆ columnsRemoved

void QAbstractItemModel::columnsRemoved ( const QModelIndex & parent,
int first,
int last,
QPrivateSignal  )
signal

This signal is emitted after columns have been removed from the model.

The removed items are those between first and last inclusive, under the given parent item.

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 QAbstractItemModelTester::QAbstractItemModelTester(), QTreeWidget::QTreeWidget(), QConcatenateTablesProxyModel::addSourceModel(), QQmlDelegateModelPrivate::connectToAbstractItemModel(), QQuickTableViewPrivate::connectToModel(), QQmlDelegateModelPrivate::disconnectFromAbstractItemModel(), QQuickTableViewPrivate::disconnectFromModel(), endRemoveColumns(), QStandardItem::removeColumns(), QAbstractItemView::setModel(), QHeaderView::setModel(), QTableView::setModel(), QTransposeProxyModel::setSourceModel(), QAbstractProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QCompletionModel::setSourceModel(), QListWidgetPrivate::setup(), and QTableWidgetPrivate::setup().

+ Here is the caller graph for this function:

◆ createIndex() [1/2]

QModelIndex QAbstractItemModel::createIndex ( int row,
int column,
const void * ptr = nullptr ) 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 420 of file qabstractitemmodel.h.

Referenced by QTreeModel::createIndexFromItem(), QAbstractProxyModel::createSourceIndex(), QCompletionModel::currentIndex(), QDeclarativeSearchResultModel::data(), QTreeModel::emitDataChanged(), endMoveColumns(), endMoveRows(), QTreeModel::ensureSorted(), QListModel::index(), QTreeModel::index(), QCompletionModel::index(), QTreeModel::index(), QQmlListModel::index(), QQmlXmlListModel::index(), QDeclarativeSupportedCategoriesModel::index(), QAbstractTableModel::index(), QFileSystemModel::index(), QStandardItemModel::index(), QUndoModel::index(), QQuickFolderListModel::index(), QQmlTableModel::index(), QQmlTreeModelToTableModel::index(), QHeaderDataProxyModel::index(), QPdfBookmarkModel::index(), QAbstractListModel::index(), QListModel::index(), QStandardItemModel::indexFromItem(), QSqlQueryModel::indexInQuery(), QSqlTableModel::indexInQuery(), QQuickFolderListModel::isFolder(), QConcatenateTablesProxyModel::mapFromSource(), QIdentityProxyModel::mapFromSource(), QCompletionModel::mapFromSource(), QFileSystemModel::parent(), QPdfBookmarkModel::parent(), QSqlQueryModel::record(), QUndoModel::selectedIndex(), QSqlTableModel::selectRow(), QSqlQueryModel::setQuery(), QSqlTableModel::setRecord(), QQmlTableModel::setRow(), QStringListModel::sibling(), QFileSystemModel::sibling(), QListModel::sort(), QTableModel::sort(), QStandardItemPrivate::sortChildren(), and QTreeModel::sortItems().

+ Here is the caller graph for this function:

◆ createIndex() [2/2]

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

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

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

See also
QModelIndex::internalId()

Definition at line 422 of file qabstractitemmodel.h.

◆ 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 (default-constructed) QVariant.
See also
Qt::ItemDataRole, setData(), headerData()

Implemented in QQmlTreeModelToTableModel, QEmptyItemModel, QQuickViewTestUtils::StressTestModel, QSqlTableModel, DateFormatProxyModel, TableModel, StringListModel, QtPrivate::QCalendarModel, QQmlListModel, QQmlXmlListModel, TableModel, QQuickCalendarModel, QQuickDayOfWeekModel, QQuickMonthModel, QQuickWeekNumberModel, QDeclarativeGeocodeModel, QDeclarativeGeoRouteModel, QDeclarativePlaceContentModel, QDeclarativeSearchSuggestionModel, QDeclarativeSupportedCategoriesModel, QQuick3DRenderStatsMeshesModel, QQuick3DRenderStatsPassesModel, QQuick3DRenderStatsTexturesModel, InstanceModel, QOpenXRSpatialAnchorModel, QPdfBookmarkModel, QPdfPageModel, QPdfLinkModel, QPdfSearchModel, QConcatenateTablesProxyModel, QSortFilterProxyModel, QStringListModel, QFileSystemModel, QStandardItemModel, QListModel, QTableModel, QTreeModel, QCompletionModel, QUndoModel, QQuickFolderListModel, QQmlTableModel, QHeaderDataProxyModel, QQuickViewTestUtils::QaimModel, QDeclarativeSearchResultModel, QQuickPlaylist, MyModel, MyModel, QSqlQueryModel, QSqlRelationalTableModel, and QAbstractProxyModel.

Referenced by QAbstractItemViewPrivate::checkMouseMove(), QAbstractItemModelTesterPrivate::columnsAboutToBeInserted(), QAbstractItemModelTesterPrivate::columnsAboutToBeMoved(), QAbstractItemModelTesterPrivate::columnsAboutToBeRemoved(), QAbstractItemModelTesterPrivate::columnsInserted(), QAbstractItemModelTesterPrivate::columnsMoved(), QAbstractItemModelTesterPrivate::columnsRemoved(), QInputDialogPrivate::currentRowChanged(), QAbstractItemModelTesterPrivate::data(), QQmlTreeModelToTableModel::data(), DateFormatProxyModel::data(), QComboBoxPrivate::itemIcon(), QComboBoxPrivate::itemText(), QCompleter::pathFromIndex(), QAbstractItemModelTesterPrivate::rowsAboutToBeInserted(), QAbstractItemModelTesterPrivate::rowsAboutToBeMoved(), QAbstractItemModelTesterPrivate::rowsAboutToBeRemoved(), QAbstractItemModelTesterPrivate::rowsInserted(), QAbstractItemModelTesterPrivate::rowsMoved(), and QAbstractItemModelTesterPrivate::rowsRemoved().

+ Here is the caller graph for this function:

◆ dataChanged

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

This signal is emitted whenever the data in an existing item changes.

If the items are of the same parent, the affected ones are those between topLeft and bottomRight inclusive. If the items do not have the same parent, the behavior is undefined.

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

The optional roles argument can be used to specify which data roles have actually been modified. An empty vector in the roles argument means that all roles should be considered modified. The order of elements in the roles argument does not have any relevance.

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

Referenced by QAbstractItemModelTester::QAbstractItemModelTester(), QPdfSearchModel::QPdfSearchModel(), QQuickTreeView::QQuickTreeView(), QTreeWidget::QTreeWidget(), QConcatenateTablesProxyModel::addSourceModel(), QStandardItemPrivate::childDeleted(), QListModel::clearItemData(), QTableModel::clearItemData(), QTreeModel::clearItemData(), QComboBoxPrivate::connectModel(), QQmlDelegateModelPrivate::connectToAbstractItemModel(), QQmlDelegateModelPrivate::disconnectFromAbstractItemModel(), QTreeModel::emitDataChanged(), QQmlTreeModelToTableModel::expandRow(), QtPrivate::QCalendarModel::internalUpdate(), QListModel::itemChanged(), QTableModel::itemChanged(), QTreeModel::itemChanged(), QTableModel::removeItem(), QSqlTableModel::selectRow(), QStandardItemPrivate::setChild(), QQmlTableModel::setData(), QStringListModel::setData(), QSqlTableModel::setData(), TableModel::setData(), QHeaderDataProxyModel::setData(), QUrlModel::setFileSystemModel(), QTableModel::setItem(), QQuickDayOfWeekModel::setLocale(), QQuickMonthModel::setLocale(), QQmlTableInstanceModel::setModel(), QQuickComboBox::setModel(), QAbstractItemView::setModel(), QDataWidgetMapper::setModel(), QQuickMonthModel::setMonth(), QQmlTableModel::setRow(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QCompletionModel::setSourceModel(), QListWidgetPrivate::setup(), QTableWidgetPrivate::setup(), QQuickMonthModel::setYear(), and QTableModel::takeItem().

+ Here is the caller graph for this function:

◆ decodeData()

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

Definition at line 2761 of file qabstractitemmodel.cpp.

References columnCount(), i, j, parent, qBound(), qMax(), qMin(), and setItemData().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

The mimeTypes() member is called to get the list of acceptable MIME types. This default implementation assumes the default implementation of mimeTypes(), which returns a single default MIME type. If you reimplement mimeTypes() in your custom model to return multiple MIME types, you must reimplement this function to make use of them.

See also
supportedDropActions(), canDropMimeData(), {Using drag and drop with item views}

Reimplemented in QAbstractTableModel, QAbstractListModel, QAbstractProxyModel, QConcatenateTablesProxyModel, QIdentityProxyModel, QSortFilterProxyModel, QFileSystemModel, QStandardItemModel, DragDropListModel, QTableModel, and QTreeModel.

Definition at line 2209 of file qabstractitemmodel.cpp.

References QString::at(), Qt::CopyAction, QByteArray::data(), decodeData(), encoded, mimeTypes(), Qt::MoveAction, parent, QIODeviceBase::ReadOnly, and rowCount().

Referenced by QConcatenateTablesProxyModel::dropMimeData(), and QStandardItemModel::dropMimeData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeData()

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

Definition at line 2752 of file qabstractitemmodel.cpp.

References itemData().

Referenced by mimeData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

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

Referenced by QSqlQueryModel::endInsertColumns(), QTreeModel::insertColumns(), QTableModel::insertColumns(), TableModel::insertColumns(), QTreeModel::setColumnCount(), QTransposeProxyModel::setSourceModel(), and QtPrivate::QCalendarModel::setWeekNumbersShown().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

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

Referenced by QConcatenateTablesProxyModel::addSourceModel(), QTreeModel::endInsertItems(), QSqlQueryModel::endInsertRows(), QListModel::insert(), QListModel::insert(), TableModel::insertRows(), QTreeModel::insertRows(), QStringListModel::insertRows(), QListModel::insertRows(), QTableModel::insertRows(), QtPrivate::QCalendarModel::setHorizontalHeaderFormat(), QTransposeProxyModel::setSourceModel(), and QQmlTreeModelToTableModel::showModelChildItems().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

See also
beginMoveColumns()
Since
4.6

Definition at line 3351 of file qabstractitemmodel.cpp.

References columnsMoved(), createIndex(), d, emit, Qt::Horizontal, and QModelIndex::parent().

Referenced by QTransposeProxyModel::setSourceModel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

See also
beginMoveRows()
Since
4.6

Definition at line 3132 of file qabstractitemmodel.cpp.

References createIndex(), d, emit, QModelIndex::parent(), rowsMoved(), and Qt::Vertical.

Referenced by QQmlListModel::move(), QListModel::move(), QQmlTableModel::moveRow(), QStringListModel::moveRows(), QListModel::moveRows(), and QTransposeProxyModel::setSourceModel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

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

Referenced by QSqlQueryModel::endRemoveColumns(), QTableModel::removeColumns(), TableModel::removeColumns(), QTreeModel::setColumnCount(), QTransposeProxyModel::setSourceModel(), and QtPrivate::QCalendarModel::setWeekNumbersShown().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

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

Referenced by QTreeModel::endRemoveItems(), QSqlQueryModel::endRemoveRows(), QListModel::remove(), QQmlTableModel::removeRow(), TableModel::removeRows(), QStringListModel::removeRows(), QTreeModel::removeRows(), QListModel::removeRows(), QTableModel::removeRows(), QConcatenateTablesProxyModel::removeSourceModel(), QQmlTreeModelToTableModel::removeVisibleRows(), QtPrivate::QCalendarModel::setHorizontalHeaderFormat(), QTransposeProxyModel::setSourceModel(), and QListModel::take().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

This function emits the signal modelReset().

See also
beginResetModel()
Since
4.6

Definition at line 3411 of file qabstractitemmodel.cpp.

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

Referenced by QStandardItemModel::clear(), QListModel::clear(), QTreeModel::clear(), QTableModel::clearContents(), QQmlTreeModelToTableModel::clearModelData(), QSqlQueryModel::endResetModel(), QCompletionModel::filter(), QDeclarativePlaceContentModel::initializeCollection(), QDeclarativeSearchModelBase::initializePlugin(), QDeclarativeSearchSuggestionModel::queryFinished(), QDeclarativeGeocodeModel::reset(), QDeclarativeGeoRouteModel::reset(), QDeclarativeSearchModelBase::reset(), QCompletionModel::setFiltered(), QQuickFolderListModel::setFolder(), QQuick3DRenderStatsMeshesModel::setMeshData(), QHeaderDataProxyModel::setOrientation(), QQuick3DRenderStatsPassesModel::setPassData(), QDeclarativePlaceContentModel::setPlace(), QPdfSearchModel::setSearchString(), QHeaderDataProxyModel::setSourceModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QStringListModel::setStringList(), and QQuick3DRenderStatsTexturesModel::setTextureData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 QAbstractProxyModel, QSortFilterProxyModel, QFileSystemModel, QDeclarativePlaceContentModel, and QSqlQueryModel.

Definition at line 2423 of file qabstractitemmodel.cpp.

Referenced by QTreeViewPrivate::expand(), QQmlTreeModelToTableModel::expandPendingRows(), QAbstractItemViewPrivate::fetchMore(), QTreeViewPrivate::layout(), QAbstractItemModelTesterPrivate::nonDestructiveBasicTest(), QQmlTreeModelToTableModel::showModelChildItems(), and QQmlTreeModelToTableModel::showModelTopLevelItems().

+ Here is the caller graph for this function:

◆ 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 QAbstractTableModel, QAbstractListModel, QAbstractProxyModel, QConcatenateTablesProxyModel, QSortFilterProxyModel, QStringListModel, QFileSystemModel, QStandardItemModel, QSqlTableModel, QUrlModel, TableModel, DragDropListModel, StringListModel, QListModel, QTableModel, QTreeModel, QtPrivate::QCalendarModel, QQmlTableModel, and QQmlTreeModelToTableModel.

Definition at line 2453 of file qabstractitemmodel.cpp.

References d, Qt::ItemIsEnabled, and Qt::ItemIsSelectable.

Referenced by QQuickTableViewPrivate::canEdit(), QTableViewPrivate::drawCell(), QAbstractTableModel::flags(), QAbstractListModel::flags(), QFileSystemModel::flags(), QSqlTableModel::flags(), QQmlTreeModelToTableModel::flags(), QAbstractItemModelTesterPrivate::nonDestructiveBasicTest(), and QAbstractItemViewPrivate::shouldEdit().

+ Here is the caller graph for this function:

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

Note that it is undefined behavior to report that a particular index hasChildren with this method if the same index has the flag Qt::ItemNeverHasChildren set.

See also
parent(), index()

Reimplemented in QEmptyItemModel, QAbstractTableModel, QAbstractListModel, QTreeModel, QQmlTreeModelToTableModel, QAbstractProxyModel, QSortFilterProxyModel, QFileSystemModel, QStandardItemModel, QCompletionModel, and QHeaderDataProxyModel.

Definition at line 1979 of file qabstractitemmodel.cpp.

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

Referenced by QQmlTreeModelToTableModel::collapse(), QQmlTreeModelToTableModel::collapseRecursively(), QQmlTreeModelToTableModel::collapseRow(), QQmlTreeModelToTableModel::dump(), QQmlTreeModelToTableModel::expand(), QQmlTreeModelToTableModel::expandPendingRows(), QQmlTreeModelToTableModel::expandRecursively(), QQmlTreeModelToTableModel::expandRow(), QQmlTreeModelToTableModel::hasChildren(), QTreeViewPrivate::hasVisibleChildren(), QTreeViewPrivate::layout(), match(), QAbstractItemModelTesterPrivate::nonDestructiveBasicTest(), QAbstractItemModelTesterPrivate::rowAndColumnCount(), QAbstractItemViewPrivate::selectAll(), QQmlTreeModelToTableModel::showModelChildItems(), and QQmlTreeModelToTableModel::showModelTopLevelItems().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

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

Referenced by QHeaderDataProxyModel::data(), QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), QAbstractItemModelTesterPrivate::hasIndex(), QAbstractTableModel::index(), QConcatenateTablesProxyModel::index(), QQmlTreeModelToTableModel::index(), QHeaderDataProxyModel::index(), QPdfBookmarkModel::index(), QAbstractListModel::index(), QListModel::index(), QAbstractItemModelTesterPrivate::nonDestructiveBasicTest(), QAbstractItemModelTesterPrivate::parent(), and QHeaderDataProxyModel::setData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 QTableModel, QTreeModel, QQmlTreeModelToTableModel, QQuick3DRenderStatsMeshesModel, QQuick3DRenderStatsPassesModel, QQuick3DRenderStatsTexturesModel, QAbstractProxyModel, QConcatenateTablesProxyModel, QIdentityProxyModel, QSortFilterProxyModel, QTransposeProxyModel, QFileSystemModel, QStandardItemModel, QSqlQueryModel, QSqlTableModel, TableModel, and StringListModel.

Definition at line 2693 of file qabstractitemmodel.cpp.

References Qt::DisplayRole, and Q_UNUSED.

Referenced by QHeaderDataProxyModel::data(), QHeaderViewPrivate::defaultSortOrderForSection(), QQmlTreeModelToTableModel::headerData(), QFileSystemModel::headerData(), QStandardItemModel::headerData(), QSqlQueryModel::headerData(), and QHeaderViewPrivate::setupSectionIndicator().

+ Here is the caller graph for this function:

◆ 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 QAbstractItemModelTester::QAbstractItemModelTester(), QTreeModel::emitDataChanged(), QtPrivate::QCalendarModel::internalUpdate(), QTableModel::itemChanged(), QTableModel::removeItem(), QSqlTableModel::removeRows(), QSqlTableModel::selectRow(), QSqlQueryModel::setHeaderData(), QStandardItemModel::setHorizontalHeaderItem(), QTableModel::setHorizontalHeaderItem(), QAbstractItemView::setModel(), QHeaderView::setModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QStandardItemModel::setVerticalHeaderItem(), and QTableModel::setVerticalHeaderItem().

+ Here is the caller graph for this function:

◆ 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 QCompletionModel, QTreeModel, QQmlListModel, QQmlXmlListModel, QDeclarativeSupportedCategoriesModel, QAbstractTableModel, QConcatenateTablesProxyModel, QIdentityProxyModel, QSortFilterProxyModel, QTransposeProxyModel, QFileSystemModel, QStandardItemModel, QTableModel, QUndoModel, QQuickFolderListModel, QQmlTableModel, QQmlTreeModelToTableModel, QHeaderDataProxyModel, QPdfBookmarkModel, QAbstractListModel, QListModel, and QEmptyItemModel.

Referenced by QCommonListViewBase::appendHiddenRow(), QTableWidget::cellWidget(), QQmlTreeModelToTableModel::collapseRecursively(), QQmlTreeModelToTableModel::collapseRow(), QAbstractItemModelTesterPrivate::columnsAboutToBeInserted(), QAbstractItemModelTesterPrivate::columnsAboutToBeRemoved(), QAbstractItemViewPrivate::columnsAboutToBeRemoved(), QAbstractItemModelTesterPrivate::data(), QTableViewPrivate::drawAndClipSpans(), QTableWidget::dropMimeData(), QQmlTreeModelToTableModel::expandRecursively(), QAbstractItemViewPrivate::fetchMore(), QTableWidget::findItems(), QAbstractItemModelTesterPrivate::index(), QDataWidgetMapperPrivate::indexAt(), QItemSelectionRange::intersected(), QAbstractItemViewPrivate::intersectedRect(), QTreeViewPrivate::intersectedRect(), QItemSelectionRange::isEmpty(), QListViewPrivate::itemSize(), QTreeViewPrivate::layout(), QAbstractItemModelTesterPrivate::layoutAboutToBeChanged(), QAbstractItemModelTesterPrivate::layoutChanged(), QQmlTreeModelToTableModel::mapToModel(), QCommonListViewBase::modelIndex(), QAbstractItemModelTesterPrivate::nonDestructiveBasicTest(), QSortFilterProxyModelLessThan::operator()(), QSortFilterProxyModelGreaterThan::operator()(), QAbstractItemModelTesterPrivate::parent(), QCommonListViewBase::removeHiddenRow(), QAbstractItemModelTesterPrivate::rowAndColumnCount(), QAbstractItemModelTesterPrivate::rowsAboutToBeInserted(), QAbstractItemModelTesterPrivate::rowsAboutToBeRemoved(), QAbstractItemModelTesterPrivate::rowsInserted(), QAbstractItemModelTesterPrivate::rowsRemoved(), QHeaderViewPrivate::sectionsAboutToBeChanged(), QTreeViewPrivate::select(), QAbstractItemViewPrivate::selectAll(), QListViewPrivate::selectAll(), QTableViewPrivate::selectColumn(), QItemSelectionModel::selectedColumns(), QTableViewPrivate::selectRow(), QSidebar::selectUrl(), QTableWidget::setCellWidget(), QInputDialogPrivate::setListViewText(), QTableWidget::setRangeSelected(), QQmlTreeModelToTableModel::showModelChildItems(), QFileDialogComboBox::showPopup(), QQmlTreeModelToTableModel::testConsistency(), QTableViewPrivate::trimHiddenSelections(), QComboBoxPrivate::trySetValidIndex(), and QQuickTableViewPrivate::updateSelection().

◆ 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 QAbstractProxyModel, QStringListModel, QTransposeProxyModel, QStandardItemModel, QListModel, QTableModel, QTreeModel, DateFormatProxyModel, and QConcatenateTablesProxyModel.

Definition at line 2013 of file qabstractitemmodel.cpp.

References i, QVariant::isValid(), and Qt::UserRole.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ layoutAboutToBeChanged

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

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

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

The optional parents parameter is used to give a more specific notification about what parts of the layout of the model are changing. An empty list indicates a change to the layout of the entire model. The order of elements in the parents list is not significant. The optional hint parameter is used to give a hint about what is happening while the model is relayouting.

See also
layoutChanged(), changePersistentIndex()

Referenced by QAbstractItemModelTester::QAbstractItemModelTester(), QConcatenateTablesProxyModel::addSourceModel(), QTableModel::ensureSorted(), QTreeModel::ensureSorted(), QItemSelectionModelPrivate::initModel(), QSortFilterProxyModel::invalidate(), QStandardItemPrivate::setChild(), QTableModel::setItem(), QHeaderView::setModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QListModel::sort(), QTableModel::sort(), QStringListModel::sort(), and QFileSystemModel::sort().

+ Here is the caller graph for this function:

◆ layoutChanged

Since
5.0

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.

The optional parents parameter is used to give a more specific notification about what parts of the layout of the model are changing. An empty list indicates a change to the layout of the entire model. The order of elements in the parents list is not significant. The optional hint parameter is used to give a hint about what is happening while the model is relayouting.

Subclasses should update any persistent model indexes before emitting layoutChanged(). In other words, when the structure changes:

\list

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

Referenced by QAbstractItemModelTester::QAbstractItemModelTester(), QConcatenateTablesProxyModel::addSourceModel(), QQmlDelegateModelPrivate::connectToAbstractItemModel(), QQuickTableViewPrivate::connectToModel(), QQmlDelegateModelPrivate::disconnectFromAbstractItemModel(), QQuickTableViewPrivate::disconnectFromModel(), QTableModel::ensureSorted(), QTreeModel::ensureSorted(), QItemSelectionModelPrivate::initModel(), QSortFilterProxyModel::invalidate(), QStandardItemPrivate::setChild(), QUrlModel::setFileSystemModel(), QTableModel::setItem(), QAbstractItemView::setModel(), QHeaderView::setModel(), QTreeView::setModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), QCompletionModel::setSourceModel(), QListModel::sort(), QTableModel::sort(), QStringListModel::sort(), and QFileSystemModel::sort().

+ Here is the caller graph for this function:

◆ 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. Note also that the order of results in the list may not correspond to the order in the model, if for example a proxy model is used. The order of the results cannot be relied upon.

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 QIdentityProxyModel, and QSortFilterProxyModel.

Definition at line 2509 of file qabstractitemmodel.cpp.

References Qt::CaseInsensitive, QRegularExpression::CaseInsensitiveOption, Qt::CaseSensitive, hasChildren(), i, QString::isEmpty(), QModelIndex::isValid(), match(), Qt::MatchCaseSensitive, Qt::MatchContains, Qt::MatchEndsWith, Qt::MatchExactly, Qt::MatchFixedString, Qt::MatchRecursive, Qt::MatchRegularExpression, Qt::MatchStartsWith, Qt::MatchTypeMask, Qt::MatchWildcard, Qt::MatchWrap, QRegularExpression::NonPathWildcardConversion, parent, Q_FALLTHROUGH, QModelIndex::row(), rowCount(), rx(), QModelIndex::sibling(), text, toInt(), QRegularExpression::wildcardToRegularExpression(), and wrap().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 format used to describe the encoded data is obtained from the mimeTypes() function. This default implementation uses the default MIME type returned by the default implementation of mimeTypes(). If you reimplement mimeTypes() in your custom model to return more MIME types, reimplement this function to make use of them.

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

See also
mimeTypes(), dropMimeData()

Reimplemented in QAbstractProxyModel, QConcatenateTablesProxyModel, QSortFilterProxyModel, QFileSystemModel, QStandardItemModel, QUrlModel, DragDropListModel, QListModel, QTableModel, and QTreeModel.

Definition at line 2132 of file qabstractitemmodel.cpp.

References QString::at(), encoded, encodeData(), mimeTypes(), QList< T >::size(), and QIODeviceBase::WriteOnly.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mimeTypes()

QStringList QAbstractItemModel::mimeTypes ( ) const
virtual

Returns the list of allowed MIME types.

By default, the built-in models and views use an internal MIME type: {application/x-qabstractitemmodeldatalist}.

When implementing drag and drop support in a custom model, if you will return data in formats other than the default internal MIME type, reimplement this function to return your list of MIME types.

If you reimplement this function in your custom model, you must also reimplement the member functions that call it: mimeData() and dropMimeData().

See also
mimeData(), dropMimeData()

Reimplemented in QAbstractProxyModel, QConcatenateTablesProxyModel, QSortFilterProxyModel, QFileSystemModel, QStandardItemModel, QUrlModel, DragDropListModel, QListModel, QTableModel, and QTreeModel.

Definition at line 2112 of file qabstractitemmodel.cpp.

References QStringLiteral.

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

+ Here is the caller graph for this function:

◆ modelAboutToBeReset

QAbstractItemModel::modelAboutToBeReset ( QPrivateSignal )
signal
Since
4.2

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

See also
beginResetModel(), modelReset()

Referenced by QAbstractItemModelTester::QAbstractItemModelTester(), QConcatenateTablesProxyModel::addSourceModel(), beginResetModel(), QComboBoxPrivate::connectModel(), QQmlDelegateModelPrivate::connectToAbstractItemModel(), QQmlDelegateModelPrivate::disconnectFromAbstractItemModel(), QQmlTableInstanceModel::setModel(), QTreeView::setModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

+ Here is the caller graph for this function:

◆ modelReset

QAbstractItemModel::modelReset ( QPrivateSignal )
signal
Since
4.1

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

Note that if a model is reset it should be considered that all information previously retrieved from it is invalid. This includes but is not limited to the rowCount() and columnCount(), flags(), data retrieved through data(), and roleNames().

See also
endResetModel(), modelAboutToBeReset()

Referenced by QAbstractItemModelTester::QAbstractItemModelTester(), QPdfSearchModel::QPdfSearchModel(), QSortFilterProxyModel::QSortFilterProxyModel(), QConcatenateTablesProxyModel::addSourceModel(), QComboBoxPrivate::connectModel(), QQuickTableViewPrivate::connectToModel(), QQuickTableViewPrivate::disconnectFromModel(), endResetModel(), QItemSelectionModelPrivate::initModel(), QAbstractItemView::setModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), and QCompletionModel::setSourceModel().

+ Here is the caller graph for this function:

◆ multiData()

void QAbstractItemModel::multiData ( const QModelIndex & index,
QModelRoleDataSpan roleDataSpan ) const
virtual
Since
6.0

Fills the roleDataSpan with the requested data for the given index.

The default implementation will call simply data() for each role in the span. A subclass can reimplement this function to provide data to views more efficiently:

void MyModel::multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const
{
for (QModelRoleData &roleData : roleDataSpan) {
int role = roleData.role();
// ... obtain the data for index and role ...
roleData.setData(result);
}
}

In the snippet above, {index} is the same for the entire call. This means that accessing to the necessary data structures in order to retrieve the information for {index} can be done only once (hoisting the relevant code out of the loop).

The usage of QModelRoleData::setData(), or similarly QVariant::setValue(), is encouraged over constructing a QVariant separately and using a plain assignment operator; this is because the former allow to re-use the memory already allocated for the QVariant object stored inside a QModelRoleData, while the latter always allocates the new variant and then destroys the old one.

Note that views may call multiData() with spans that have been used in previous calls, and therefore may already contain some data. Therefore, it is imperative that if the model cannot return the data for a given role, then it must clear the data in the corresponding QModelRoleData object. This can be done by calling QModelRoleData::clearData(), or similarly by setting a default constructed QVariant, and so on. Failure to clear the data will result in the view believing that the "old" data is meant to be used for the corresponding role.

Finally, in order to avoid code duplication, a subclass may also decide to reimplement data() in terms of multiData(), by supplying a span of just one element:

QVariant MyModel::data(const QModelIndex &index, int role) const
{
return roleData.data();
}
QVariant data(const QModelIndex &item, int role) const override
[15]
virtual void multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
Definition qhash.h:1007
T value(const Key &key) const noexcept
Definition qhash.h:1054
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
Definition qhash.h:951
\inmodule QtCore
The QSortFilterProxyModel class provides support for sorting and filtering data passed between anothe...
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
\reimp
QVariant data(const QModelIndex &item, int role=Qt::DisplayRole) const override
Returns the value for the specified item and role.
@ DecorationRole
@ BackgroundRole
@ CheckStateRole
@ DisplayRole
GLenum GLenum GLsizei void GLsizei void void * span
#define slots
beginInsertRows(parent, 2, 4)
[0]
QModelRoleDataSpan span(roleData)
beginMoveRows(sourceParent, 2, 4, destinationParent, 2)
[5]
std::array< QModelRoleData, 3 > roleData
[13]
beginInsertColumns(parent, 4, 6)
[2]
beginRemoveColumns(parent, 4, 6)
[4]
beginRemoveRows(parent, 2, 3)
[1]
Note
Models are not allowed to modify the roles in the span, or to rearrange the span elements. Doing so results in undefined behavior.
It is illegal to pass an invalid model index to this function.
See also
QModelRoleDataSpan, data()

Reimplemented in QStandardItemModel.

Definition at line 3677 of file qabstractitemmodel.cpp.

References checkIndex(), d, IndexIsValid, and Q_ASSERT.

Referenced by MyModel::data(), and QStandardItemModel::multiData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parent() [1/2]

QObject * QObject::parent ( ) const
inline

Returns a pointer to the parent object.

See also
children()

Definition at line 346 of file qobject.h.

◆ parent() [2/2]

◆ persistentIndexList()

QModelIndexList QAbstractItemModel::persistentIndexList ( ) const
protected
Since
4.2

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

Definition at line 3485 of file qabstractitemmodel.cpp.

References d, and QList< T >::reserve().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Q_REVISION() [1/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  )

◆ Q_REVISION() [2/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  )

◆ Q_REVISION() [3/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  ) const &

◆ Q_REVISION() [4/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  ) const &

◆ Q_REVISION() [5/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  )

◆ Q_REVISION() [6/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  )

◆ Q_REVISION() [7/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  )

◆ Q_REVISION() [8/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  )

◆ Q_REVISION() [9/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  ) const &

◆ Q_REVISION() [10/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  ) const &

◆ Q_REVISION() [11/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  )

◆ Q_REVISION() [12/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  )

◆ Q_REVISION() [13/13]

Q_INVOKABLE QAbstractItemModel::Q_REVISION ( 6 ,
4  )

◆ resetInternalData

void QAbstractItemModel::resetInternalData ( )
protectedvirtualslot
Since
4.8

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

This slot is provided the convenience of subclasses of concrete proxy models, such as subclasses of QSortFilterProxyModel which maintain extra data.

{
public:
{
}
...
QVariant data(const QModelIndex &index, int role) override
{
if (role != Qt::BackgroundRole)
if (m_customData.contains(index.row()))
return m_customData.value(index.row());
}
private slots:
void resetInternalData()
{
m_customData.clear();
}
private:
QHash<int, QVariant> m_customData;
};
Note
Due to a mistake, this slot is missing in Qt 5.0.
See also
modelAboutToBeReset(), modelReset()

Definition at line 1148 of file qabstractitemmodel.cpp.

Referenced by endResetModel().

+ Here is the caller graph for this function:

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

Definition at line 2677 of file qabstractitemmodel.cpp.

◆ roleNames()

QHash< int, QByteArray > QAbstractItemModel::roleNames ( ) const
virtual
Since
4.6

Returns the model's role names.

The default role names set by Qt are:

\table \header

Reimplemented in QAbstractProxyModel, QFileSystemModel, QStandardItemModel, QSqlQueryModel, QQuickFolderListModel, QQmlTableModel, QQmlListModel, QQmlTreeModelToTableModel, QQmlXmlListModel, TableModel, QQuickCalendarModel, QQuickDayOfWeekModel, QHeaderDataProxyModel, QQuickMonthModel, QQuickWeekNumberModel, QQuickViewTestUtils::QaimModel, QDeclarativeGeocodeModel, QDeclarativeGeoRouteModel, QDeclarativePlaceContentModel, QDeclarativeSearchResultModel, QDeclarativeSearchSuggestionModel, QDeclarativeSupportedCategoriesModel, QQuickPlaylist, QQuick3DRenderStatsMeshesModel, QQuick3DRenderStatsPassesModel, QQuick3DRenderStatsTexturesModel, InstanceModel, QOpenXRSpatialAnchorModel, QPdfBookmarkModel, QPdfPageModel, QPdfLinkModel, and QPdfSearchModel.

Definition at line 2651 of file qabstractitemmodel.cpp.

References QAbstractItemModelPrivate::defaultRoleNames().

Referenced by QPdfBookmarkModel::QPdfBookmarkModel(), QPdfPageModel::QPdfPageModel(), VDMAbstractItemModelDataType::initializeMetaType(), QAbstractItemModelTesterPrivate::nonDestructiveBasicTest(), QFileSystemModel::roleNames(), QQmlTreeModelToTableModel::roleNames(), QHeaderDataProxyModel::roleNames(), QQuickViewTestUtils::QaimModel::roleNames(), QDeclarativeGeocodeModel::roleNames(), QDeclarativeGeoRouteModel::roleNames(), QDeclarativePlaceContentModel::roleNames(), QDeclarativeSearchResultModel::roleNames(), QDeclarativeSearchSuggestionModel::roleNames(), and QDeclarativeSupportedCategoriesModel::roleNames().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 QEmptyItemModel, QQuickViewTestUtils::StressTestModel, TableModel, QPdfPageModel, QCompletionModel, QTreeModel, QtPrivate::QCalendarModel, QQmlListModel, QQmlXmlListModel, QDeclarativeGeocodeModel, QDeclarativeGeoRouteModel, QDeclarativePlaceContentModel, QDeclarativeSearchSuggestionModel, QDeclarativeSupportedCategoriesModel, QQuick3DRenderStatsMeshesModel, QQuick3DRenderStatsPassesModel, QQuick3DRenderStatsTexturesModel, InstanceModel, QOpenXRSpatialAnchorModel, QPdfLinkModel, QPdfSearchModel, QConcatenateTablesProxyModel, QIdentityProxyModel, QSortFilterProxyModel, QStringListModel, QTransposeProxyModel, QFileSystemModel, QStandardItemModel, QSqlQueryModel, QSqlTableModel, TableModel, StringListModel, QListModel, QTableModel, QUndoModel, QQuickFolderListModel, QQmlTableModel, QQmlTreeModelToTableModel, QQuickCalendarModel, QQuickDayOfWeekModel, QHeaderDataProxyModel, QQuickMonthModel, QQuickWeekNumberModel, QQuickViewTestUtils::QaimModel, QDeclarativeSearchResultModel, QQuickPlaylist, and QPdfBookmarkModel.

Referenced by QConcatenateTablesProxyModel::addSourceModel(), beginInsertRows(), beginRemoveRows(), checkIndex(), QQmlTreeModelToTableModel::collapseRecursively(), QQmlTreeModelToTableModel::collapseRow(), QAbstractItemModelTesterPrivate::columnsAboutToBeInserted(), QAbstractItemModelTesterPrivate::columnsAboutToBeRemoved(), QAbstractItemModelTesterPrivate::columnsInserted(), QAbstractItemModelTesterPrivate::columnsRemoved(), QAbstractItemModelTesterPrivate::data(), QAbstractItemModelTesterPrivate::dataChanged(), QListViewPrivate::doItemsLayout(), dropMimeData(), QAbstractListModel::dropMimeData(), QQmlTreeModelToTableModel::dump(), QQmlTreeModelToTableModel::expandPendingRows(), QQmlTreeModelToTableModel::expandRecursively(), QAbstractItemViewPrivate::fetchMore(), QAbstractTableModel::hasChildren(), QAbstractListModel::hasChildren(), hasChildren(), QAbstractItemModelTesterPrivate::hasIndex(), hasIndex(), QQmlTreeModelToTableModel::hasSiblings(), QTreeViewPrivate::hasVisibleChildren(), QAbstractProxyModel::headerData(), QAbstractItemModelTesterPrivate::headerDataChanged(), QAbstractItemModelTesterPrivate::index(), QDataWidgetMapperPrivate::itemCount(), QListViewPrivate::itemSize(), QTreeViewPrivate::layout(), QAbstractItemModelTesterPrivate::layoutAboutToBeChanged(), match(), QHeaderViewPrivate::modelSectionCount(), QAbstractItemModelTesterPrivate::nonDestructiveBasicTest(), QAbstractItemModelTesterPrivate::parent(), QListViewPrivate::prepareItemsLayout(), QHeaderViewPrivate::read(), QConcatenateTablesProxyModel::removeSourceModel(), QAbstractItemModelTesterPrivate::rowAndColumnCount(), QCommonListViewBase::rowCount(), QHeaderDataProxyModel::rowCount(), QAbstractItemModelTesterPrivate::rowsAboutToBeInserted(), QAbstractItemModelTesterPrivate::rowsAboutToBeRemoved(), QAbstractItemModelTesterPrivate::rowsInserted(), QAbstractItemModelTesterPrivate::rowsRemoved(), QComboBoxPrivate::rowsRemoved(), QHeaderViewPrivate::sectionsAboutToBeChanged(), QAbstractItemViewPrivate::selectAll(), QListViewPrivate::selectAll(), QSidebar::selectUrl(), QTableWidget::setVerticalHeaderLabels(), QQmlTreeModelToTableModel::showModelChildItems(), QQmlTreeModelToTableModel::showModelTopLevelItems(), QCompleterPrivate::showPopup(), and QQmlTreeModelToTableModel::testConsistency().

◆ rowsAboutToBeInserted

void QAbstractItemModel::rowsAboutToBeInserted ( const QModelIndex & parent,
int first,
int last,
QPrivateSignal  )
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 QAbstractItemModelTester::QAbstractItemModelTester(), QConcatenateTablesProxyModel::addSourceModel(), beginInsertRows(), QComboBoxPrivate::connectModel(), QItemSelectionModelPrivate::initModel(), QStandardItemPrivate::insertRows(), QStandardItemPrivate::insertRows(), QTransposeProxyModel::setSourceModel(), QAbstractProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

+ Here is the caller graph for this function:

◆ rowsAboutToBeMoved

void QAbstractItemModel::rowsAboutToBeMoved ( const QModelIndex & sourceParent,
int sourceStart,
int sourceEnd,
const QModelIndex & destinationParent,
int destinationRow,
QPrivateSignal  )
signal
Since
4.6

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

{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 QAbstractItemModelTester::QAbstractItemModelTester(), beginMoveRows(), QItemSelectionModelPrivate::initModel(), QHeaderView::setModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

+ Here is the caller graph for this function:

◆ rowsAboutToBeRemoved

void QAbstractItemModel::rowsAboutToBeRemoved ( const QModelIndex & parent,
int first,
int last,
QPrivateSignal  )
signal

This signal is emitted just before rows are removed from the model.

The items that will be removed are those between first and last inclusive, under the given parent item.

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 QAbstractItemModelTester::QAbstractItemModelTester(), QConcatenateTablesProxyModel::addSourceModel(), beginRemoveRows(), QComboBoxPrivate::connectModel(), QQmlDelegateModelPrivate::connectToAbstractItemModel(), QQmlDelegateModelPrivate::disconnectFromAbstractItemModel(), QItemSelectionModelPrivate::initModel(), QAbstractItemView::setModel(), QHeaderView::setModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

+ Here is the caller graph for this function:

◆ rowsInserted

void QAbstractItemModel::rowsInserted ( const QModelIndex & parent,
int first,
int last,
QPrivateSignal  )
signal

This signal is emitted after rows have been inserted into the model.

The new items are those between first and last inclusive, under the given parent item.

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 QAbstractItemModelTester::QAbstractItemModelTester(), QPdfSearchModel::QPdfSearchModel(), QConcatenateTablesProxyModel::addSourceModel(), QComboBoxPrivate::connectModel(), QQmlDelegateModelPrivate::connectToAbstractItemModel(), QQuickTableViewPrivate::connectToModel(), QFileDialogPrivate::createWidgets(), QQmlDelegateModelPrivate::disconnectFromAbstractItemModel(), QQuickTableViewPrivate::disconnectFromModel(), endInsertRows(), QStandardItemPrivate::insertRows(), QStandardItemPrivate::insertRows(), QAbstractItemView::setModel(), QHeaderView::setModel(), QTableView::setModel(), QTransposeProxyModel::setSourceModel(), QAbstractProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

+ Here is the caller graph for this function:

◆ rowsMoved

void QAbstractItemModel::rowsMoved ( const QModelIndex & sourceParent,
int sourceStart,
int sourceEnd,
const QModelIndex & destinationParent,
int destinationRow,
QPrivateSignal  )
signal
Since
4.6

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

{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 QAbstractItemModelTester::QAbstractItemModelTester(), QQmlDelegateModelPrivate::connectToAbstractItemModel(), QQuickTableViewPrivate::connectToModel(), QQmlDelegateModelPrivate::disconnectFromAbstractItemModel(), QQuickTableViewPrivate::disconnectFromModel(), endMoveRows(), QItemSelectionModelPrivate::initModel(), QAbstractItemView::setModel(), QHeaderView::setModel(), QTransposeProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), and QSortFilterProxyModel::setSourceModel().

+ Here is the caller graph for this function:

◆ rowsRemoved

void QAbstractItemModel::rowsRemoved ( const QModelIndex & parent,
int first,
int last,
QPrivateSignal  )
signal

This signal is emitted after rows have been removed from the model.

The removed items are those between first and last inclusive, under the given parent item.

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 QAbstractItemModelTester::QAbstractItemModelTester(), QPdfSearchModel::QPdfSearchModel(), QConcatenateTablesProxyModel::addSourceModel(), QComboBoxPrivate::connectModel(), QQmlDelegateModelPrivate::connectToAbstractItemModel(), QQuickTableViewPrivate::connectToModel(), QQmlDelegateModelPrivate::disconnectFromAbstractItemModel(), QQuickTableViewPrivate::disconnectFromModel(), endRemoveRows(), QStandardItem::removeRows(), QConcatenateTablesProxyModel::removeSourceModel(), QUrlModel::setFileSystemModel(), QAbstractItemView::setModel(), QHeaderView::setModel(), QTableView::setModel(), QTreeView::setModel(), QTransposeProxyModel::setSourceModel(), QAbstractProxyModel::setSourceModel(), QIdentityProxyModel::setSourceModel(), QSortFilterProxyModel::setSourceModel(), and QCompletionModel::setSourceModel().

+ Here is the caller graph for this function:

◆ 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 QListModel, QTableModel, QTreeModel, QQmlTreeModelToTableModel, QQmlTableModel, QAbstractProxyModel, QConcatenateTablesProxyModel, QSortFilterProxyModel, QStringListModel, QFileSystemModel, QStandardItemModel, QSqlTableModel, QUrlModel, TableModel, StringListModel, QQmlListModel, QHeaderDataProxyModel, and QSqlRelationalTableModel.

Definition at line 2037 of file qabstractitemmodel.cpp.

References Q_UNUSED.

Referenced by QDataWidgetMapperPrivate::commit(), QItemDelegate::editorEvent(), QStyledItemDelegate::editorEvent(), QComboMenuDelegate::editorEvent(), main(), QQmlTreeModelToTableModel::setData(), QConcatenateTablesProxyModel::setData(), QSqlTableModel::setData(), setItemData(), SpinBoxDelegate::setModelData(), QItemDelegate::setModelData(), QStyledItemDelegate::setModelData(), QComboBoxDelegate::setSeparator(), QFileDialogComboBox::showPopup(), sql_intro_snippets(), and MainWindow::updateSelection().

+ Here is the caller graph for this function:

◆ 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 QTableModel, QTreeModel, QAbstractProxyModel, QSortFilterProxyModel, QTransposeProxyModel, QStandardItemModel, and QSqlQueryModel.

Definition at line 2713 of file qabstractitemmodel.cpp.

References Q_UNUSED.

Referenced by QHeaderDataProxyModel::setData().

+ Here is the caller graph for this function:

◆ 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 QAbstractProxyModel, QConcatenateTablesProxyModel, QStringListModel, QTransposeProxyModel, QStandardItemModel, and QTableModel.

Definition at line 2082 of file qabstractitemmodel.cpp.

References it, and setData().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sibling()

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

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

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.

This method can optionally be overridden for implementation-specific optimization.

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

Reimplemented in QAbstractTableModel, QAbstractListModel, QAbstractProxyModel, QIdentityProxyModel, QSortFilterProxyModel, QStringListModel, QFileSystemModel, and QHeaderDataProxyModel.

Definition at line 1998 of file qabstractitemmodel.cpp.

References QModelIndex::column(), parent, and QModelIndex::row().

Referenced by QFileSystemModel::sibling().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 QAbstractProxyModel, QConcatenateTablesProxyModel, QSortFilterProxyModel, and QTransposeProxyModel.

Definition at line 2615 of file qabstractitemmodel.cpp.

Referenced by QAbstractItemModelTesterPrivate::nonDestructiveBasicTest().

+ Here is the caller graph for this function:

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

Definition at line 2665 of file qabstractitemmodel.cpp.

Referenced by QTableView::setSelectionModel(), and QTreeView::setSelectionModel().

+ Here is the caller graph for this function:

◆ supportedDragActions()

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

Returns the actions supported by the data in this model.

The default implementation returns supportedDropActions(). Reimplement this function if you wish to support additional actions.

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}

Reimplemented in QAbstractProxyModel.

Definition at line 2263 of file qabstractitemmodel.cpp.

References supportedDropActions().

+ Here is the call graph for this function:

◆ supportedDropActions()

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

Returns the drop actions supported by this model.

The default implementation returns Qt::CopyAction. Reimplement this function if you wish to support additional actions. 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 QAbstractProxyModel, QSortFilterProxyModel, QStringListModel, QFileSystemModel, QStandardItemModel, DragDropListModel, QTableModel, and QTreeModel.

Definition at line 2247 of file qabstractitemmodel.cpp.

References Qt::CopyAction.

Referenced by canDropMimeData(), QAbstractItemModelTesterPrivate::nonDestructiveBasicTest(), supportedDragActions(), and QStringListModel::supportedDropActions().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QAbstractItemViewPrivate

friend class QAbstractItemViewPrivate
friend

Definition at line 238 of file qabstractitemmodel.h.

◆ QAbstractProxyModel

friend class QAbstractProxyModel
friend

Definition at line 239 of file qabstractitemmodel.h.

◆ QPersistentModelIndexData

friend class QPersistentModelIndexData
friend

Definition at line 237 of file qabstractitemmodel.h.

Member Data Documentation

◆ count [1/2]

◆ count [2/2]

Q_INVOKABLE int int QAbstractItemModel::count

Definition at line 280 of file qabstractitemmodel.h.

◆ destinationChild [1/2]

◆ destinationChild [2/2]

Q_INVOKABLE int const QModelIndex int QAbstractItemModel::destinationChild

Definition at line 290 of file qabstractitemmodel.h.

◆ destinationParent [1/2]

◆ destinationParent [2/2]

Q_INVOKABLE int const QModelIndex& QAbstractItemModel::destinationParent

Definition at line 290 of file qabstractitemmodel.h.

◆ order

◆ parent [1/2]

Q_INVOKABLE const QModelIndex & QAbstractItemModel::parent = QModelIndex())

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

If the item has no parent, an invalid QModelIndex is returned.

A common convention used in models that expose tree data structures is that only items in the first column have children. For that case, when reimplementing this 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()

Definition at line 276 of file qabstractitemmodel.h.

Referenced by QTreeModel::QTreeModel(), QTreeModel::QTreeModel(), beginInsertColumns(), QTreeModel::beginInsertItems(), beginInsertRows(), beginRemoveColumns(), QTreeModel::beginRemoveItems(), beginRemoveRows(), canDropMimeData(), QAbstractProxyModel::canDropMimeData(), QConcatenateTablesProxyModel::canDropMimeData(), QAbstractProxyModel::canFetchMore(), QDeclarativeSupportedCategoriesModel::columnCount(), QConcatenateTablesProxyModel::columnCount(), QTransposeProxyModel::columnCount(), QQmlTreeModelToTableModel::columnCount(), QHeaderDataProxyModel::columnCount(), QPdfBookmarkModel::columnCount(), QAbstractItemViewPrivate::columnsAboutToBeRemoved(), decodeData(), dropMimeData(), QAbstractProxyModel::dropMimeData(), QConcatenateTablesProxyModel::dropMimeData(), QTreeModel::dropMimeData(), QTreeModel::ensureSorted(), QAbstractProxyModel::fetchMore(), QTreeModel::hasChildren(), hasChildren(), QAbstractProxyModel::hasChildren(), QCompletionModel::hasChildren(), QHeaderDataProxyModel::hasChildren(), hasIndex(), QCompletionModel::index(), QTreeModel::index(), QDeclarativeSupportedCategoriesModel::index(), QConcatenateTablesProxyModel::index(), QTransposeProxyModel::index(), QUndoModel::index(), QQmlTreeModelToTableModel::index(), QHeaderDataProxyModel::index(), QPdfBookmarkModel::index(), QTreeModel::insertColumns(), QTransposeProxyModel::insertColumns(), QTreeModel::insertRows(), QTransposeProxyModel::insertRows(), QQmlTreeModelToTableModel::lastChildIndex(), QCompletionModel::mapToSource(), match(), QAbstractItemModelTesterPrivate::nonDestructiveBasicTest(), QAbstractItemModelTesterPrivate::parent(), QTreeModel::parent(), QTransposeProxyModel::removeColumns(), QTransposeProxyModel::removeRows(), QTreeModel::removeRows(), QCompletionModel::rowCount(), QTreeModel::rowCount(), QDeclarativeSupportedCategoriesModel::rowCount(), QConcatenateTablesProxyModel::rowCount(), QTransposeProxyModel::rowCount(), QUndoModel::rowCount(), QHeaderDataProxyModel::rowCount(), QPdfBookmarkModel::rowCount(), QQmlTreeModelToTableModel::selectionForRowRange(), sibling(), and QQmlTreeModelToTableModel::testConsistency().

◆ parent [2/2]

Q_INVOKABLE const QModelIndex& QAbstractItemModel::parent = QModelIndex())

Definition at line 285 of file qabstractitemmodel.h.

◆ sourceColumn

◆ sourceRow


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