Qt 4.8
Public Functions | Properties | Friends | List of all members
QPersistentModelIndex Class Reference

The QPersistentModelIndex class is used to locate data in a data model. More...

#include <qabstractitemmodel.h>

Public Functions

QModelIndex child (int row, int column) const
 Returns the child of the model index that is stored in the given row and column. More...
 
int column () const
 Returns the column this persistent model index refers to. More...
 
QVariant data (int role=Qt::DisplayRole) const
 Returns the data for the given role for the item referred to by the index. More...
 
Qt::ItemFlags flags () const
 Returns the flags for the item referred to by the index. More...
 
qint64 internalId () const
 
void * internalPointer () const
 
bool isValid () const
 Returns true if this persistent model index is valid; otherwise returns false. More...
 
const QAbstractItemModelmodel () const
 Returns the model that the index belongs to. More...
 
 operator const QModelIndex & () const
 Cast operator that returns a const QModelIndex&. More...
 
bool operator!= (const QPersistentModelIndex &other) const
 Returns true if this persistent model index is not equal to the other persistent model index; otherwise returns false. More...
 
bool operator!= (const QModelIndex &other) const
 Returns true if this persistent model index does not refer to the same location as the other model index; otherwise returns false. More...
 
bool operator< (const QPersistentModelIndex &other) const
 Returns true if this persistent model index is smaller than the other persistent model index; otherwise returns false. More...
 
QPersistentModelIndexoperator= (const QPersistentModelIndex &other)
 Sets the persistent model index to refer to the same item in a model as the other persistent model index. More...
 
QPersistentModelIndexoperator= (const QModelIndex &other)
 Sets the persistent model index to refer to the same item in a model as the other model index. More...
 
bool operator== (const QPersistentModelIndex &other) const
 Returns true if this persistent model index is equal to the other persistent model index; otherwise returns false. More...
 
bool operator== (const QModelIndex &other) const
 Returns true if this persistent model index refers to the same location as the other model index; otherwise returns false. More...
 
QModelIndex parent () const
 Returns the parent QModelIndex for this persistent index, or an invalid QModelIndex if it has no parent. More...
 
 QPersistentModelIndex ()
 
 QPersistentModelIndex (const QModelIndex &index)
 Creates a new QPersistentModelIndex that is a copy of the model index. More...
 
 QPersistentModelIndex (const QPersistentModelIndex &other)
 Creates a new QPersistentModelIndex that is a copy of the other persistent model index. More...
 
int row () const
 Returns the row this persistent model index refers to. More...
 
QModelIndex sibling (int row, int column) const
 Returns the sibling at row and column or an invalid QModelIndex if there is no sibling at this position. More...
 
 ~QPersistentModelIndex ()
 

Properties

QPersistentModelIndexDatad
 

Friends

Q_CORE_EXPORT QDebug operator<< (QDebug, const QPersistentModelIndex &)
 
uint qHash (const QPersistentModelIndex &)
 

Detailed Description

The QPersistentModelIndex class is used to locate data in a data model.

A QPersistentModelIndex is a model index that can be stored by an application, and later used to access information in a model. Unlike the QModelIndex class, it is safe to store a QPersistentModelIndex since the model will ensure that references to items will continue to be valid as long as they can be accessed by the model.

It is good practice to check that persistent model indexes are valid before using them.

See also
{Model/View Programming}, QModelIndex, QAbstractItemModel

Definition at line 107 of file qabstractitemmodel.h.

Constructors and Destructors

◆ QPersistentModelIndex() [1/3]

QPersistentModelIndex::QPersistentModelIndex ( )
Warning
This function is not part of the public interface.

Definition at line 118 of file qabstractitemmodel.cpp.

119  : d(0)
120 {
121 }
QPersistentModelIndexData * d

◆ QPersistentModelIndex() [2/3]

QPersistentModelIndex::QPersistentModelIndex ( const QModelIndex index)

Creates a new QPersistentModelIndex that is a copy of the model index.

Definition at line 143 of file qabstractitemmodel.cpp.

144  : d(0)
145 {
146  if (index.isValid()) {
148  d->ref.ref();
149  }
150 }
bool ref()
Atomically increments the value of this QAtomicInt.
static QPersistentModelIndexData * create(const QModelIndex &index)
QPersistentModelIndexData * d
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ QPersistentModelIndex() [3/3]

QPersistentModelIndex::QPersistentModelIndex ( const QPersistentModelIndex other)

Creates a new QPersistentModelIndex that is a copy of the other persistent model index.

Definition at line 133 of file qabstractitemmodel.cpp.

134  : d(other.d)
135 {
136  if (d) d->ref.ref();
137 }
bool ref()
Atomically increments the value of this QAtomicInt.
QPersistentModelIndexData * d

◆ ~QPersistentModelIndex()

QPersistentModelIndex::~QPersistentModelIndex ( )
Warning
This function is not part of the public interface.

Definition at line 158 of file qabstractitemmodel.cpp.

159 {
160  if (d && !d->ref.deref()) {
162  d = 0;
163  }
164 }
static void destroy(QPersistentModelIndexData *data)
bool deref()
Atomically decrements the value of this QAtomicInt.
QPersistentModelIndexData * d

Functions

◆ child()

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

Returns the child of the model index that is stored in the given row and column.

See also
parent() sibling()

Definition at line 399 of file qabstractitemmodel.cpp.

400 {
401  if (d)
402  return d->index.child(row, column);
403  return QModelIndex();
404 }
int row() const
Returns the row this persistent model index refers to.
int column() const
Returns the column this persistent model index refers to.
QPersistentModelIndexData * d
QModelIndex child(int row, int column) const
Returns the child of the model index that is stored in the given row and column.
The QModelIndex class is used to locate data in a data model.

◆ column()

int QPersistentModelIndex::column ( ) const

Returns the column this persistent model index refers to.

Definition at line 326 of file qabstractitemmodel.cpp.

Referenced by QDataWidgetMapperPrivate::currentIdx(), QAbstractItemModelPrivate::movePersistentIndexes(), QItemSelectionRange::operator<(), and QItemSelectionModel::setCurrentIndex().

327 {
328  if (d)
329  return d->index.column();
330  return -1;
331 }
QPersistentModelIndexData * d
int column() const
Returns the column this model index refers to.

◆ data()

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

◆ flags()

Qt::ItemFlags QPersistentModelIndex::flags ( ) const

Returns the flags for the item referred to by the index.

Since
4.2

Definition at line 427 of file qabstractitemmodel.cpp.

Referenced by QAccessibleItemRow::state().

428 {
429  if (d)
430  return d->index.flags();
431  return 0;
432 }
QPersistentModelIndexData * d
Qt::ItemFlags flags() const
Returns the flags for the item referred to by the index.

◆ internalId()

qint64 QPersistentModelIndex::internalId ( ) const
Warning
This function is not part of the public interface.

Returns a qint64 used by the model to associate the index with the internal data structure.

Definition at line 358 of file qabstractitemmodel.cpp.

359 {
360  if (d)
361  return d->index.internalId();
362  return 0;
363 }
qint64 internalId() const
Returns a qint64 used by the model to associate the index with the internal data structure.
QPersistentModelIndexData * d

◆ internalPointer()

void * QPersistentModelIndex::internalPointer ( ) const
Warning
This function is not part of the public interface.

Returns a void * pointer used by the model to associate the index with the internal data structure.

Definition at line 342 of file qabstractitemmodel.cpp.

343 {
344  if (d)
345  return d->index.internalPointer();
346  return 0;
347 }
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
QPersistentModelIndexData * d

◆ isValid()

bool QPersistentModelIndex::isValid ( ) const

Returns true if this persistent model index is valid; otherwise returns false.

A valid index belongs to a model, and has non-negative row and column numbers.

See also
model(), row(), column()

Definition at line 459 of file qabstractitemmodel.cpp.

Referenced by QListWidgetPrivate::_q_emitCurrentItemChanged(), QAbstractItemViewPrivate::checkMouseMove(), QDataWidgetMapperPrivate::commit(), QAccessibleItemRow::isValid(), QAbstractItemView::keyPressEvent(), QTreeView::mouseDoubleClickEvent(), QAbstractItemView::mouseMoveEvent(), QAbstractItemView::mousePressEvent(), QAbstractItemView::mouseReleaseEvent(), and QAccessibleItemRow::rect().

460 {
461  return d && d->index.isValid();
462 }
QPersistentModelIndexData * d
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ model()

const QAbstractItemModel * QPersistentModelIndex::model ( ) const

Returns the model that the index belongs to.

Definition at line 437 of file qabstractitemmodel.cpp.

Referenced by QAccessibleItemRow::children(), QItemSelectionRange::operator<(), and QAccessibleItemRow::rect().

438 {
439  if (d)
440  return d->index.model();
441  return 0;
442 }
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
QPersistentModelIndexData * d

◆ operator const QModelIndex &()

QPersistentModelIndex::operator const QModelIndex & ( ) const

Cast operator that returns a const QModelIndex&.

Definition at line 256 of file qabstractitemmodel.cpp.

257 {
258  static const QModelIndex invalid;
259  if (d)
260  return d->index;
261  return invalid;
262 }
QPersistentModelIndexData * d
The QModelIndex class is used to locate data in a data model.

◆ operator!=() [1/2]

bool QPersistentModelIndex::operator!= ( const QPersistentModelIndex other) const
inline

Returns true if this persistent model index is not equal to the other persistent model index; otherwise returns false.

Since
4.2

Definition at line 116 of file qabstractitemmodel.h.

117  { return !operator==(other); }
bool operator==(const QPersistentModelIndex &other) const
Returns true if this persistent model index is equal to the other persistent model index; otherwise r...

◆ operator!=() [2/2]

bool QPersistentModelIndex::operator!= ( const QModelIndex other) const

Returns true if this persistent model index does not refer to the same location as the other model index; otherwise returns false.

Definition at line 294 of file qabstractitemmodel.cpp.

295 {
296  if (d)
297  return d->index != other;
298  return other.isValid();
299 }
QPersistentModelIndexData * d
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ operator<()

bool QPersistentModelIndex::operator< ( const QPersistentModelIndex other) const

Returns true if this persistent model index is smaller than the other persistent model index; otherwise returns false.

Since
4.1

All values in the persistent model index are used when comparing with another persistent model index.

Definition at line 194 of file qabstractitemmodel.cpp.

195 {
196  if (d && other.d)
197  return d->index < other.d->index;
198 
199  return d < other.d;
200 }
QPersistentModelIndexData * d

◆ operator=() [1/2]

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

Sets the persistent model index to refer to the same item in a model as the other persistent model index.

Definition at line 218 of file qabstractitemmodel.cpp.

219 {
220  if (d == other.d)
221  return *this;
222  if (d && !d->ref.deref())
224  d = other.d;
225  if (d) d->ref.ref();
226  return *this;
227 }
static void destroy(QPersistentModelIndexData *data)
bool ref()
Atomically increments the value of this QAtomicInt.
bool deref()
Atomically decrements the value of this QAtomicInt.
QPersistentModelIndexData * d

◆ operator=() [2/2]

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

Sets the persistent model index to refer to the same item in a model as the other model index.

Definition at line 234 of file qabstractitemmodel.cpp.

235 {
236  if (d && !d->ref.deref())
238  if (other.isValid()) {
240  if (d) d->ref.ref();
241  } else {
242  d = 0;
243  }
244  return *this;
245 }
static void destroy(QPersistentModelIndexData *data)
bool ref()
Atomically increments the value of this QAtomicInt.
static QPersistentModelIndexData * create(const QModelIndex &index)
bool deref()
Atomically decrements the value of this QAtomicInt.
QPersistentModelIndexData * d
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ operator==() [1/2]

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

Returns true if this persistent model index is equal to the other persistent model index; otherwise returns false.

All values in the persistent model index are used when comparing with another persistent model index.

Definition at line 174 of file qabstractitemmodel.cpp.

175 {
176  if (d && other.d)
177  return d->index == other.d->index;
178  return d == other.d;
179 }
QPersistentModelIndexData * d

◆ operator==() [2/2]

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

Returns true if this persistent model index refers to the same location as the other model index; otherwise returns false.

All values in the persistent model index are used when comparing with another model index.

Definition at line 277 of file qabstractitemmodel.cpp.

278 {
279  if (d)
280  return d->index == other;
281  return !other.isValid();
282 }
QPersistentModelIndexData * d
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ parent()

QModelIndex QPersistentModelIndex::parent ( ) const

◆ row()

int QPersistentModelIndex::row ( ) const

◆ sibling()

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

Returns the sibling at row and column or an invalid QModelIndex if there is no sibling at this position.

See also
parent() child()

Definition at line 385 of file qabstractitemmodel.cpp.

Referenced by QAccessibleItemRow::text().

386 {
387  if (d)
388  return d->index.sibling(row, column);
389  return QModelIndex();
390 }
int row() const
Returns the row this persistent model index refers to.
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
int column() const
Returns the column this persistent model index refers to.
QPersistentModelIndexData * d
The QModelIndex class is used to locate data in a data model.

Friends and Related Functions

◆ operator<<

Q_CORE_EXPORT QDebug operator<< ( QDebug  ,
const QPersistentModelIndex  
)
friend

Definition at line 478 of file qabstractitemmodel.cpp.

479 {
480  if (idx.d)
481  dbg << idx.d->index;
482  else
483  dbg << QModelIndex();
484  return dbg;
485 }
QPersistentModelIndexData * d
The QModelIndex class is used to locate data in a data model.

◆ qHash

uint qHash ( const QPersistentModelIndex index)
friend

Definition at line 143 of file qabstractitemmodel.h.

144 { return qHash(index.d); }
QPersistentModelIndexData * d
friend uint qHash(const QPersistentModelIndex &)

Properties

◆ d

QPersistentModelIndexData* QPersistentModelIndex::d
private

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