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

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

#include <Wt/WModelIndex>

List of all members.

Public Member Functions

 WModelIndex ()
 Create an invalid WModelIndex.
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.
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.
WFlags< ItemFlagflags () 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 in a data model.

Indexes are used to indicate a particular item in a WAbstractItemModel. An index points to the item by identifying its row and column location 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. Thus, a model that specifies only a list or table of data (but no hierarchical data) would have as valid indexes only indexes that specify the invalid model index as parent.

Valid indexes are created by the model, within the protected WAbstractItemModel::createIndex() methods. In this way, models can define an 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()).

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

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 for WAbstractItemModel::data().

See also:
WAbstractItemModel::data()

ItemDataRole

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

const WAbstractItemModel* Wt::WModelIndex::model (  )  const [inline]

Returns the model to which this (valid) index is bound.

This returns the model that created the model index.

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.

Topological order follows the order in which the indexes would be displayed in a tree table view, from top to bottom followed by left to right.


Generated on Tue Sep 1 17:51:16 2009 for Wt by doxygen 1.5.6