An index to a data item in a data model. More...
#include <Wt/WModelIndex>
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< ItemFlag > | flags () const |
Returns the flags for this item. | |
bool | isValid () const |
Returns whether the index is a real valid index. | |
const WAbstractItemModel * | model () 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. |
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()).
Wt::WModelIndex::WModelIndex | ( | ) |
Create an invalid WModelIndex.
Returns a model index for which isValid() return false
.
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.
int Wt::WModelIndex::column | ( | ) | const [inline] |
Returns the column for this model index.
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().
WFlags< ItemFlag > Wt::WModelIndex::flags | ( | ) | const |
Returns the flags for this item.
This is a convenience method for WAbstractItemModel::flags().
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.
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.
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:
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.
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.
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.
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()).
int Wt::WModelIndex::row | ( | ) | const [inline] |
Returns the row for this model index.