Wt::WModelIndex Class Reference
[Model/view system]

An index to a data item of a data model. More...

#include <Wt/WModelIndex>

List of all members.

Public Member Functions

 WModelIndex ()
 Create an invalid WModelIndex.
 WModelIndex (const WModelIndex &other)
 Copy constructor.
int column () const
 Returns the column for this model index.
int row () const
 Returns the row for this model index.
void * internalPointer () const
 Returns the internal pointer.
uint64_t internalId () const
 Returns the internal id.
Sha1::Digest internalHashId () const
 Returns a long internal id.
WModelIndex child (int row, int column) const
 Returns a model index for a child item.
WModelIndex parent () const
 Returns an index to the parent.
boost::any data (int role=DisplayRole) const
 Returns data in the model at this index.
int flags () const
 Returns the flags for this item.
bool isValid () const
 Returns whether the index is a real valid index.
const WAbstractItemModelmodel () const
 Returns the model to which this (valid) index is bound.
bool operator== (const WModelIndex &other) const
 Comparison operator.
bool operator!= (const WModelIndex &other) const
 Comparison operator.
bool operator< (const WModelIndex &other) const
 Comparison operator.


Detailed Description

An index to a data item of a data model.

Indexes are used to indicate a particular item in a WAbstractItemModel. It points to the item at a given row and column, within a parent model index.

An index is immutable. The default constructor creates an invalid index, which by convention indicates the parent of top level indexes.

Valid indexes are created by the model, within the protected WAbstractItemModel::createIndex() methods. In this way, models can define the internal pointer or id suitable for identifying items in the model.

Upon the model's choice, model indexes for hierarchical models may have an internal Id represented by a int64_t (internalId()), a pointer (internalPointer()), or an internal hash (internalHashId()). The former are convenient for in-memory models, while the latter is useful for models that keep data out of memory (on disk or in a database).

See also:
WAbstractItemModel

Constructor & Destructor Documentation

Wt::WModelIndex::WModelIndex (  ) 

Create an invalid WModelIndex.

Returns a model index for which isValid() return false.


Member Function Documentation

int Wt::WModelIndex::column (  )  const [inline]

Returns the column for this model index.

See also:
row()

int Wt::WModelIndex::row (  )  const [inline]

Returns the row for this model index.

See also:
column()

void* Wt::WModelIndex::internalPointer (  )  const [inline]

Returns the internal pointer.

The internal pointer is used by the model to retrieve the corresponding data.

This is only defined when the model created the index using WAbstractItemModel::createIndex(int, int, void *) const.

See also:
internalId(), WAbstractItemModel::createIndex(int, int, void *) const

uint64_t Wt::WModelIndex::internalId (  )  const [inline]

Returns the internal id.

The internal id is used by the model to retrieve the corresponding data.

This is only defined when the model created the index using WAbstractItemModel::createIndex(int, int, uint64_t) const.

See also:
internalPointer(), WAbstractItemModel::createIndex(int, int, uint64_t) const

Sha1::Digest Wt::WModelIndex::internalHashId (  )  const [inline]

Returns a long internal id.

A long internal id (20 bytes) may be used by models that do not keep data in memory.

The 20 bytes length has been chosen to be able store SHA-1 hash ids.

WModelIndex Wt::WModelIndex::child ( int  row,
int  column 
) const

Returns a model index for a child item.

This is a convenience method, and is only defined for indexes that are valid().

It has the same function as WAbstractItemModel::index() but is less general because the latter expression may also be used to retrieve top level children, i.e. when index is invalid.

See also:
WAbstractItemModel::index(), isValid()

WModelIndex Wt::WModelIndex::parent (  )  const

Returns an index to the parent.

This is a convenience method for WAbstractItemModel::parent().

For a top level data item, the parent() is an invalid index (see WModelIndex()).

See also:
WAbstractItemModel::parent()

boost::any Wt::WModelIndex::data ( int  role = DisplayRole  )  const

Returns data in the model at this index.

This is a convenience method. It is less general than using WAbstractItemModel::data(), because the latter expression may also be used to retrieve top level children, i.e. when index is invalid.

See also:
WAbstractItemModel::data()

ItemDataRole

int Wt::WModelIndex::flags (  )  const

Returns the flags for this item.

This is a convenience method for WAbstractItemModel::flags().

See also:
WAbstractItemModel::flags()

ItemFlag

bool Wt::WModelIndex::isValid (  )  const [inline]

Returns whether the index is a real valid index.

Returns true when the index points to a valid data item, i.e. at a valid row() and column().

An index may be invalid for two reasons:

  • an operation requested an index that was out of model bounds,
  • or, the index corresponds to the model's top level root item, and is thus the parent index for top level items.

bool Wt::WModelIndex::operator== ( const WModelIndex other  )  const

Comparison operator.

Returns true only if the indexes point at the same data, in the same model.

bool Wt::WModelIndex::operator!= ( const WModelIndex other  )  const

Comparison operator.

See also:
operator==()

bool Wt::WModelIndex::operator< ( const WModelIndex other  )  const

Comparison operator.

Returns true if the index comes topologically before other.


Generated on Mon Jan 26 14:14:08 2009 for Wt by doxygen 1.5.6