6.0.0-rc4Source

QPersistentModelIndex Class

The QPersistentModelIndex class is used to locate data in a data model, and stays valid when the model changes. More…

Header#include <QPersistentModelIndex>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Functions

QPersistentModelIndex()
QPersistentModelIndex(const QModelIndex &index)
QPersistentModelIndex(const QPersistentModelIndex &other)
QPersistentModelIndex(QPersistentModelIndex &&other)
~QPersistentModelIndex()
QPersistentModelIndex &operator=(const QPersistentModelIndex &other)
QPersistentModelIndex &operator=(QPersistentModelIndex &&other)
QPersistentModelIndex &operator=(const QModelIndex &other)
voidswap(QPersistentModelIndex &other)
operator QModelIndex() const
introw() const
intcolumn() const
void *internalPointer() const
const void *constInternalPointer() const
quintptrinternalId() const
QModelIndexparent() const
QModelIndexsibling(int row, int column) const
QVariantdata(int role = Qt::DisplayRole) const
Qt::ItemFlagsflags() const
const QAbstractItemModel *model() const
boolisValid() const

Detailed Description

A persistent index follows its item when rows and columns are inserted, removed or moved, and becomes invalid when the item is removed or the model is reset. Models that rearrange their items (for example when sorting) update persistent indexes with changePersistentIndex().

See also QModelIndex and QAbstractItemModel.

Differences from Qt

Each persistent index made from a QModelIndex has its own record in the model, which copies share; Qt shares one record per item.

Member Function Documentation

QPersistentModelIndex::QPersistentModelIndex()

Constructs an invalid persistent index.

QPersistentModelIndex::QPersistentModelIndex(const QModelIndex &index)

Constructs a persistent index that follows the item at index.

QPersistentModelIndex::QPersistentModelIndex(const QPersistentModelIndex &other)

Constructs a copy of other, which follows the same item.

QPersistentModelIndex::QPersistentModelIndex(QPersistentModelIndex &&other)

Move-constructs a persistent index from other.

QPersistentModelIndex::~QPersistentModelIndex()

Destroys the persistent index.

int QPersistentModelIndex::column() const

Returns the current column of the item, or -1.

const void * QPersistentModelIndex::constInternalPointer() const

Returns the pointer the model stored in the index, as a pointer to const.

This function was introduced in 6.0.

QVariant QPersistentModelIndex::data(int role = Qt::DisplayRole) const

Returns the data of the item for role.

Qt::ItemFlags QPersistentModelIndex::flags() const

Returns the flags of the item.

quintptr QPersistentModelIndex::internalId() const

Returns the integer the model stored in the index.

void * QPersistentModelIndex::internalPointer() const

Returns the pointer the model stored in the index.

bool QPersistentModelIndex::isValid() const

Returns true if the item still exists; otherwise returns false.

const QAbstractItemModel * QPersistentModelIndex::model() const

Returns the model of the item, or nullptr.

QPersistentModelIndex::operator QModelIndex() const

Returns the current index of the item, or an invalid index.

QPersistentModelIndex & QPersistentModelIndex::operator=(const QPersistentModelIndex &other)

Assigns other to this persistent index and returns a reference to it.

QPersistentModelIndex & QPersistentModelIndex::operator=(QPersistentModelIndex &&other)

Move-assigns other to this persistent index and returns a reference to it.

QPersistentModelIndex & QPersistentModelIndex::operator=(const QModelIndex &other)

Makes this persistent index follow the item at other and returns a reference to it.

QModelIndex QPersistentModelIndex::parent() const

Returns the parent of the item.

int QPersistentModelIndex::row() const

Returns the current row of the item, or -1.

QModelIndex QPersistentModelIndex::sibling(int row, int column) const

Returns the index at row and column under the same parent.

void QPersistentModelIndex::swap(QPersistentModelIndex &other)

Swaps this index with other.