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

An item in a WStandardItemModel. More...

#include <Wt/WStandardItem>

List of all members.

Public Member Functions

 WStandardItem ()
 Create an empty standard item.
 WStandardItem (const WString &text)
 Create an item with a text.
 WStandardItem (const std::string &iconUri, const WString &text)
 Create an item with an icon and a text.
 WStandardItem (int rows, int columns=1)
 Create an item with an initial geometry.
virtual ~WStandardItem ()
 Destructor.
void setText (const WString &text)
 Set the text.
WString text () const
 Returns the text.
void setIcon (const std::string &uri)
 Set the icon url.
std::string icon () const
 Returns the icon url.
void setStyleClass (const WString &styleClass)
 Set the CSS style class.
WString styleClass () const
 Returns the item style class.
void setToolTip (const WString &toolTip)
 Set a tool tip.
WString toolTip () const
 Returns the tool tip.
void setInternalPath (const std::string &internalpath)
 Set an anchor to an internal path.
std::string internalPath () const
 Returns the anchor to an internal path.
void setUrl (const std::string &url)
 Set an anchor to an external URL.
std::string url () const
 Returns the url referenced by this item.
void setChecked (bool checked)
 Check or uncheck the item.
bool isChecked () const
 Returns whether the item is checked.
void setCheckState (CheckState checked)
 Set the check state.
CheckState checkState () const
 Returns the item's check state.
void setFlags (WFlags< ItemFlag > flags)
 Set the flags.
WFlags< ItemFlagflags () const
 Returns the flags.
void setCheckable (bool checkable)
 Makes the item checkable.
bool isCheckable () const
 Returns whether the item is checkable.
void setTristate (bool tristate)
 Make the item tri-state checkable.
bool isTristate () const
 Returns whether the item is tri-state checkable.
virtual void setData (const boost::any &data, int role=UserRole)
 Set item data.
virtual boost::any data (int role=UserRole) const
 Returns item data.
bool hasChildren () const
 Returns whether the item has any children.
void setRowCount (int rows)
 Change the row count.
int rowCount () const
 Returns the row count.
void setColumnCount (int columns)
 Change the column count.
int columnCount () const
 Returns the column count.
void appendColumn (const std::vector< WStandardItem * > &items)
 Add a single column of items.
void insertColumn (int column, const std::vector< WStandardItem * > &items)
 Insert a single column of items.
void appendRow (const std::vector< WStandardItem * > &items)
 Add a single row of items.
void insertRow (int row, const std::vector< WStandardItem * > &items)
 Insert a single row of items.
void insertColumns (int column, int count)
 Insert a number of empty columns.
void insertRows (int row, int count)
 Insert a number of empty rows.
void appendRow (WStandardItem *item)
 Appends a row containing one item.
void insertRow (int row, WStandardItem *item)
 Inserts a row containing one item.
void appendRows (const std::vector< WStandardItem * > &items)
 Appends multiple rows containing one item.
void insertRows (int row, const std::vector< WStandardItem * > &items)
 Inserts multiple rows containing one item.
void setChild (int row, int column, WStandardItem *item)
 Set a child item.
void setChild (int row, WStandardItem *item)
 Set a child item.
WStandardItemchild (int row, int column=0) const
 Returns a child item.
WStandardItemtakeChild (int row, int column)
 Takes a child out of the item.
std::vector< WStandardItem * > takeColumn (int column)
 Takes a column of children out of the item.
std::vector< WStandardItem * > takeRow (int row)
 Takes a row of children out of the item.
void removeColumn (int column)
 Remove a single column.
void removeColumns (int column, int count)
 Remove a number of columns.
void removeRow (int row)
 Remove a single row.
void removeRows (int row, int count)
 Remove a number of rows.
WModelIndex index () const
 Returns the model index for this item.
WStandardItemModelmodel () const
 Returns the model.
WStandardItemparent () const
 Returns the parent item.
int row () const
 Returns the row index.
int column () const
 Returns the column index.
virtual WStandardItemclone () const
 Returns a clone of this item.
virtual bool operator< (const WStandardItem &other) const
 Compares the item with another item.
virtual void sortChildren (int column, SortOrder order)
 Sorts the children according to a given column and sort order.

Private Member Functions

int compare (const WStandardItem &other) const
 Compares the item with another item.


Detailed Description

An item in a WStandardItemModel.

The item provides access to various data properties: text, icon, CSS style class, tool tip, and check state, and data flags (setFlags() and setCheckable()).

An item may contain a table of children items: the initial geometry may be specified in the constructor, or using the methods setRowCount() and setModelCount(). Unspecified items are 0. You can set or inspect children items using the setChild() and child() methods.

It is possible to reimplement this class and specialize the methods for data acess (setData() and data()), or provide custom sorting functionality by reimplementing

operator<().


Constructor & Destructor Documentation

Wt::WStandardItem::WStandardItem ( const WString text  ) 

Create an item with a text.

See also:
setText()

Wt::WStandardItem::WStandardItem ( const std::string &  iconUri,
const WString text 
)

Create an item with an icon and a text.

See also:
setText(), setIcon()

Wt::WStandardItem::WStandardItem ( int  rows,
int  columns = 1 
)

Create an item with an initial geometry.

See also:
setRowCount(), setColumnCount()


Member Function Documentation

void Wt::WStandardItem::setText ( const WString text  ) 

Set the text.

The text is stored as DisplayRole data.

The default text is empty ("").

See also:
text(), setData()

WString Wt::WStandardItem::text (  )  const

Returns the text.

See also:
setText()

void Wt::WStandardItem::setIcon ( const std::string &  uri  ) 

Set the icon url.

The icon is stored as DecorationRole data.

The default icon url is empty ("").

See also:
icon(), setData()

std::string Wt::WStandardItem::icon (  )  const

Returns the icon url.

See also:
setIcon()

void Wt::WStandardItem::setStyleClass ( const WString styleClass  ) 

Set the CSS style class.

The style class is stored as StyleClassRole data.

The default style class is empty ("").

See also:
styleClass(), setData()

WString Wt::WStandardItem::styleClass (  )  const

Returns the item style class.

See also:
setStyleClass()

void Wt::WStandardItem::setToolTip ( const WString toolTip  ) 

Set a tool tip.

The tool tip is stored as ToolTipRole data.

The default tool tip is empty ("").

See also:
toolTip(), setData()

WString Wt::WStandardItem::toolTip (  )  const

Returns the tool tip.

See also:
setToolTip()

void Wt::WStandardItem::setInternalPath ( const std::string &  internalpath  ) 

Set an anchor to an internal path.

The internal path is stored as InternalPathRole data.

See also:
internalPath(), setData()

std::string Wt::WStandardItem::internalPath (  )  const

Returns the anchor to an internal path.

See also:
setInternalPath(), setData()

void Wt::WStandardItem::setUrl ( const std::string &  url  ) 

Set an anchor to an external URL.

The anchor Url is stored as UrlRole data.

See also:
setInternalPath(), setData()

std::string Wt::WStandardItem::url (  )  const

Returns the url referenced by this item.

See also:
setUrl(), setData()

void Wt::WStandardItem::setChecked ( bool  checked  ) 

Check or uncheck the item.

The value is stored as CheckStateRole data.

By default, an item is not checked.

Note: this requires that the item is checkable (see setCheckable()).

If the item is tri-state, you may consider using setCheckState() instead which supports also setting the third Wt::PartiallyChecked state.

See also:
setCheckable(), setCheckState()

bool Wt::WStandardItem::isChecked (  )  const

Returns whether the item is checked.

See also:
setChecked()

void Wt::WStandardItem::setCheckState ( CheckState  checked  ) 

Set the check state.

Like setChecked(), this sets the check state, but allows also setting the Wt::PartiallyChecked state when the item is tri-state checkable.

The value is stored as CheckStateRole data.

See also:
setCheckable(), setData()

CheckState Wt::WStandardItem::checkState (  )  const

Returns the item's check state.

See also:
setCheckState()

void Wt::WStandardItem::setFlags ( WFlags< ItemFlag flags  ) 

Set the flags.

The default flag value is ItemIsSelectable.

See also:
ItemFlag, flags(), setCheckable()

WFlags< ItemFlag > Wt::WStandardItem::flags (  )  const

Returns the flags.

See also:
setFlags()

void Wt::WStandardItem::setCheckable ( bool  checkable  ) 

Makes the item checkable.

Adds ItemIsUserCheckable to the item's flags.

See also:
setFlags(), setChecked()

bool Wt::WStandardItem::isCheckable (  )  const

Returns whether the item is checkable.

See also:
setCheckable()

void Wt::WStandardItem::setTristate ( bool  tristate  ) 

Make the item tri-state checkable.

When tristate is true, the item is checkable with three states: Wt::Unchecked, Wt::Checked, and Wt::PartiallyChecked.

This requires that the item is also checkable (see setCheckable())

See also:
setCheckable()

bool Wt::WStandardItem::isTristate (  )  const

Returns whether the item is tri-state checkable.

See also:
setTristate()

void Wt::WStandardItem::setData ( const boost::any &  data,
int  role = UserRole 
) [virtual]

Set item data.

Sets item data for the given role.

See also:
data()

boost::any Wt::WStandardItem::data ( int  role = UserRole  )  const [virtual]

Returns item data.

Returns item data for the given role.

See also:
data()

bool Wt::WStandardItem::hasChildren (  )  const

Returns whether the item has any children.

This is a convenience method and checks whether rowCount() and columnCount() differ both from 0.

See also:
rowCount(), columnCount()

void Wt::WStandardItem::setRowCount ( int  rows  ) 

Change the row count.

If rows is bigger than the current row count, empty rows are appended.

If rows is smaller than the current row count, rows are deleted at the end.

Note:
If rows > 0, and columnCount() == 0, columnCount is first increased to 1 using setColumnCount(1).
See also:
setColumnCount(), rowCount()

int Wt::WStandardItem::rowCount (  )  const

Returns the row count.

See also:
setRowCount()

void Wt::WStandardItem::setColumnCount ( int  columns  ) 

Change the column count.

If columns is bigger than the current column count, empty columns are appended.

If columns is smaller than the current column count, columns are deleted at the end.

See also:
setRowCount(), columnCount()

int Wt::WStandardItem::columnCount (  )  const

Returns the column count.

See also:
setRowCount()

void Wt::WStandardItem::appendColumn ( const std::vector< WStandardItem * > &  items  ) 

Add a single column of items.

Appends a single column of items. If necessary, the row count is increased.

Equivalent to:

See also:
insertColumn(), appendRow()

void Wt::WStandardItem::insertColumn ( int  column,
const std::vector< WStandardItem * > &  items 
)

Insert a single column of items.

Inserts a single column of items at column column. If necessary, the row count is increased.

See also:
WStandardItem::insertRow()

void Wt::WStandardItem::appendRow ( const std::vector< WStandardItem * > &  items  ) 

Add a single row of items.

Appends a single row of items. If necessary, the column count is increased.

Equivalent to:

 insertRow(rowCount(), items);

See also:
insertRow(), appendColumn()

void Wt::WStandardItem::insertRow ( int  row,
const std::vector< WStandardItem * > &  items 
)

Insert a single row of items.

Inserts a single row of items at row row. If necessary, the column count is increased.

See also:
insertColumn()

void Wt::WStandardItem::insertColumns ( int  column,
int  count 
)

Insert a number of empty columns.

Inserts count empty columns at position column.

See also:
insertRows()

void Wt::WStandardItem::insertRows ( int  row,
int  count 
)

Insert a number of empty rows.

Inserts count empty rows at position row.

See also:
insertColumns()

void Wt::WStandardItem::appendRow ( WStandardItem item  ) 

Appends a row containing one item.

This is a convenience method for nodes with a single column (for example for tree nodes). This adds a row with a single item, and is equivalent to:

 insertRow(rowCount(), item);

See also:
insertRow(int, WStandardItem *)

void Wt::WStandardItem::insertRow ( int  row,
WStandardItem item 
)

Inserts a row containing one item.

This is a convenience method for nodes with a single column (for example for tree nodes). This inserts a row with a single item, and is equivalent to:

 std::vector<WStandardItem *> r;
 r.push_back(item);
 insertRow(row, r);

See also:
insertRow(int, const std::vector<WStandardItem *>&)

void Wt::WStandardItem::appendRows ( const std::vector< WStandardItem * > &  items  ) 

Appends multiple rows containing one item.

This is a convenience method for nodes with a single column (for example for tree nodes). This adds a number of rows, each containing a single item, and is equivalent to:

 insertRows(rowCount(), items);

See also:
insertRows(int, const std::vector<WStandardItem *>&)

void Wt::WStandardItem::insertRows ( int  row,
const std::vector< WStandardItem * > &  items 
)

Inserts multiple rows containing one item.

This is a convenience method for nodes with a single column (for example for tree nodes). This inserts a number of rows at row row, each containing a single item, and is equivalent to:

 for (unsigned i = 0; i < items.size(); ++i)
   insertRow(row + i, items[i]);

See also:
insertRow(int, WStandardItem *)

void Wt::WStandardItem::setChild ( int  row,
int  column,
WStandardItem item 
)

Set a child item.

Sets a child item item at position (row, column). If an item was previously set, it is deleted first.

If necessary, the rowCount() and/or the columnCount() is increased.

See also:
child().

void Wt::WStandardItem::setChild ( int  row,
WStandardItem item 
)

Set a child item.

This is a convenience method for nodes with a single column (e.g. tree nodes), and is equivalent to:

 setChild(row, 0, item);

See also:
setChild(int, int, WStandardItem *).

WStandardItem * Wt::WStandardItem::child ( int  row,
int  column = 0 
) const

Returns a child item.

Returns the child item at position (row, column). This may be 0 if an item was not previously set, or if the position is out of bounds.

See also:
setChild(int, int, WStandardItem *).

WStandardItem * Wt::WStandardItem::takeChild ( int  row,
int  column 
)

Takes a child out of the item.

Returns the child item at position (row, column), and removes it (by setting 0 instead). Ownership of the item is transferred to the caller.

See also:
child(), setChild(int, int, WStandardItem *)

std::vector< WStandardItem * > Wt::WStandardItem::takeColumn ( int  column  ) 

Takes a column of children out of the item.

Returns the column column, and removes the column from the model (reducing the column count by one). Ownership of all items is transferred to the caller.

See also:
takeRow(), removeColumn()

std::vector< WStandardItem * > Wt::WStandardItem::takeRow ( int  row  ) 

Takes a row of children out of the item.

Returns the row row, and removes the row from the model (reducing the row count by one). Ownership of all items is transferred to the caller.

See also:
takeColumn(), removeRow()

void Wt::WStandardItem::removeColumn ( int  column  ) 

Remove a single column.

Removes the column column from the model (reducing the column count by one). Is equivalent to:

See also:
removeColumns(), takeColumn()

void Wt::WStandardItem::removeColumns ( int  column,
int  count 
)

Remove a number of columns.

Removes count columns from the model (reducing the column count by count).

See also:
removeColumn(), removeRows()

void Wt::WStandardItem::removeRow ( int  row  ) 

Remove a single row.

Removes the row row from the model (reducing the row count by one). Is equivalent to:

See also:
removeRows(), takeRow()

void Wt::WStandardItem::removeRows ( int  row,
int  count 
)

Remove a number of rows.

Removes count rows from the model (reducing the row count by count).

See also:
removeRow(), removeColumns()

WModelIndex Wt::WStandardItem::index (  )  const

Returns the model index for this item.

See also:
WStandardItemModel::indexFromItem()

WStandardItemModel* Wt::WStandardItem::model (  )  const [inline]

Returns the model.

This is the model that this item belongs to, or 0 if the item is not associated with a model.

WStandardItem* Wt::WStandardItem::parent (  )  const [inline]

Returns the parent item.

Returns the parent item.

See also:
setChild()

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

Returns the row index.

Returns the row index of this item in the parent.

See also:
column()

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

Returns the column index.

Returns the column index of this item in the parent.

See also:
column()

WStandardItem * Wt::WStandardItem::clone (  )  const [virtual]

Returns a clone of this item.

See also:
WStandardItemModel::setItemPrototype()

bool Wt::WStandardItem::operator< ( const WStandardItem other  )  const [virtual]

Compares the item with another item.

This is used during sorting (from sortChildren()), and returns which of the two items is the lesser, based on their data.

The default implementation compares the data based on the value corresponding to the WStandardItemModel::sortRole().

See also:
sortChildren(), WStandardItemModel::setSortRole()

void Wt::WStandardItem::sortChildren ( int  column,
SortOrder  order 
) [virtual]

Sorts the children according to a given column and sort order.

Children of this item, and all children items are sorted recursively. Existing model indexes will be invalidated by the operation (will point to other items).

The WStandardItemModel::layoutAboutToBeChanged and WStandardItemModel::layoutChanged signals are emitted before and after the operation so that you get a chance to invalidate or update model indexes.

See also:
operator<(), WStandardItemModel::setSortRole()

int Wt::WStandardItem::compare ( const WStandardItem other  )  const [private]

Compares the item with another item.

This is used during sorting (from sortChildren()), and returns which of the two items is the lesser, based on their data.

The default implementation compares the data based on the value corresponding to the WStandardItemModel::sortRole().

See also:
sortChildren(), WStandardItemModel::setSortRole()


Generated on Tue Nov 3 15:34:33 2009 for Wt by doxygen 1.5.6