Wt  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Public Member Functions | Protected Member Functions | Private Member Functions
Wt::WStandardItem Class Reference

An item in a WStandardItemModel. More...

#include <Wt/WStandardItem>

List of all members.

Public Member Functions

 WStandardItem ()
 Creates an empty standard item.
 WStandardItem (const WString &text)
 Creates an item with a text.
 WStandardItem (const std::string &iconUri, const WString &text)
 Creates an item with an icon and a text.
 WStandardItem (int rows, int columns=1)
 Creates an item with an initial geometry.
virtual ~WStandardItem ()
 Destructor.
void setText (const WString &text)
 Sets the text.
WString text () const
 Returns the text.
void setIcon (const std::string &uri)
 Sets the icon url.
std::string icon () const
 Returns the icon url.
void setStyleClass (const WString &styleClass)
 Sets the CSS style class.
WString styleClass () const
 Returns the item style class.
void setToolTip (const WString &toolTip)
 Sets a tool tip.
WString toolTip () const
 Returns the tool tip.
void setLink (const WLink &link)
 Sets a link.
WLink link () const
 Returns a link.
void setInternalPath (const std::string &internalpath)
 Sets a link to an internal path (deprecated).
std::string internalPath () const
 Returns the link to an internal path (deprecated).
void setUrl (const std::string &url)
 Sets a link to a URL (deprecated).
std::string url () const
 Returns the linked URL (deprecated).
void setChecked (bool checked)
 Checks or unchecks the item.
bool isChecked () const
 Returns whether the item is checked.
void setCheckState (CheckState checked)
 Sets the check state.
CheckState checkState () const
 Returns the item's check state.
void setFlags (WFlags< ItemFlag > flags)
 Sets 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)
 Makes 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)
 Sets 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)
 Sets the row count.
int rowCount () const
 Returns the row count.
void setColumnCount (int columns)
 Sets 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)
 Inserts 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)
 Inserts a single row of items.
void insertColumns (int column, int count)
 Inserts a number of empty columns.
void insertRows (int row, int count)
 Inserts 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)
 Sets a child item.
void setChild (int row, WStandardItem *item)
 Sets 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)
 Removes a single column.
void removeColumns (int column, int count)
 Removes a number of columns.
void removeRow (int row)
 Removes a single row.
void removeRows (int row, int count)
 Removes 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.

Protected Member Functions

virtual void setModel (WStandardItemModel *model)
 Set the model for this WStandardItem and its children.

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)

Creates an item with a text.

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

Creates an item with an icon and a text.

See also:
setText(), setIcon()
Wt::WStandardItem::WStandardItem ( int  rows,
int  columns = 1 
)

Creates an item with an initial geometry.

See also:
setRowCount(), setColumnCount()

Member Function Documentation

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::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::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::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 *>&)
CheckState Wt::WStandardItem::checkState ( ) const

Returns the item's check state.

See also:
setCheckState()
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::clone ( ) const
virtual

Returns a clone of this item.

See also:
WStandardItemModel::setItemPrototype()
int Wt::WStandardItem::column ( ) const

Returns the column index.

Returns the column index of this item in the parent.

See also:
column()
int Wt::WStandardItem::columnCount ( ) const

Returns the column count.

See also:
setRowCount()
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()
boost::any Wt::WStandardItem::data ( int  role = UserRole) const
virtual

Returns item data.

Returns item data for the given role.

See also:
data()
WFlags< ItemFlag > Wt::WStandardItem::flags ( ) const

Returns the flags.

See also:
setFlags()
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()
std::string Wt::WStandardItem::icon ( ) const

Returns the icon url.

See also:
setIcon()
WModelIndex Wt::WStandardItem::index ( ) const

Returns the model index for this item.

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

Inserts 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::insertColumns ( int  column,
int  count 
)

Inserts a number of empty columns.

Inserts count empty columns at position column.

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

Inserts 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::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);
See also:
insertRow(int, const std::vector<WStandardItem *>&)
void Wt::WStandardItem::insertRows ( int  row,
int  count 
)

Inserts a number of empty rows.

Inserts count empty rows at position row.

See also:
insertColumns()
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 *)
std::string Wt::WStandardItem::internalPath ( ) const

Returns the link to an internal path (deprecated).

See also:
setInternalPath()
Deprecated:
Use link() instead.
bool Wt::WStandardItem::isCheckable ( ) const

Returns whether the item is checkable.

See also:
setCheckable()
bool Wt::WStandardItem::isChecked ( ) const

Returns whether the item is checked.

See also:
setChecked()
bool Wt::WStandardItem::isTristate ( ) const

Returns whether the item is tri-state checkable.

See also:
setTristate()
WLink Wt::WStandardItem::link ( ) const

Returns a link.

See also:
setLink()
WStandardItemModel* Wt::WStandardItem::model ( ) const

Returns the model.

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

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()
WStandardItem* Wt::WStandardItem::parent ( ) const

Returns the parent item.

Returns the parent item.

See also:
setChild()
void Wt::WStandardItem::removeColumn ( int  column)

Removes 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 
)

Removes 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)

Removes 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 
)

Removes a number of rows.

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

See also:
removeRow(), removeColumns()
int Wt::WStandardItem::row ( ) const

Returns the row index.

Returns the row index of this item in the parent.

See also:
column()
int Wt::WStandardItem::rowCount ( ) const

Returns the row count.

See also:
setRowCount()
void Wt::WStandardItem::setCheckable ( bool  checkable)

Makes the item checkable.

Adds ItemIsUserCheckable to the item's flags.

See also:
setFlags(), setChecked()
void Wt::WStandardItem::setChecked ( bool  checked)

Checks or unchecks 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()
void Wt::WStandardItem::setCheckState ( CheckState  checked)

Sets 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()
void Wt::WStandardItem::setChild ( int  row,
int  column,
WStandardItem item 
)

Sets 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 
)

Sets 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 *).
void Wt::WStandardItem::setColumnCount ( int  columns)

Sets 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()
void Wt::WStandardItem::setData ( const boost::any &  data,
int  role = UserRole 
)
virtual

Sets item data.

Sets item data for the given role.

See also:
data()
void Wt::WStandardItem::setFlags ( WFlags< ItemFlag flags)

Sets the flags.

The default flag value is ItemIsSelectable.

See also:
ItemFlag, flags(), setCheckable()
void Wt::WStandardItem::setIcon ( const std::string &  uri)

Sets the icon url.

The icon is stored as DecorationRole data.

The default icon url is empty ("").

See also:
icon(), setData()
void Wt::WStandardItem::setInternalPath ( const std::string &  internalpath)

Sets a link to an internal path (deprecated).

The internal path is stored as LinkRole data..

Deprecated:
Use setLink() instead.
void Wt::WStandardItem::setLink ( const WLink link)

Sets a link.

The link is stored as LinkRole data.

See also:
setData()
void Wt::WStandardItem::setModel ( WStandardItemModel model)
protectedvirtual

Set the model for this WStandardItem and its children.

You may override this method if you want to change its behaviour.

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

Sets 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()
void Wt::WStandardItem::setStyleClass ( const WString styleClass)

Sets the CSS style class.

The style class is stored as StyleClassRole data.

The default style class is empty ("").

See also:
styleClass(), setData()
void Wt::WStandardItem::setText ( const WString text)

Sets the text.

The text is stored as DisplayRole data.

The default text is empty ("").

See also:
text(), setData()
void Wt::WStandardItem::setToolTip ( const WString toolTip)

Sets a tool tip.

The tool tip is stored as ToolTipRole data.

The default tool tip is empty ("").

See also:
toolTip(), setData()
void Wt::WStandardItem::setTristate ( bool  tristate)

Makes 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()
void Wt::WStandardItem::setUrl ( const std::string &  url)

Sets a link to a URL (deprecated).

The URL is stored as LinkRole data.

Deprecated:
Use setLink() instead.
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()
WString Wt::WStandardItem::styleClass ( ) const

Returns the item style class.

See also:
setStyleClass()
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()
WString Wt::WStandardItem::text ( ) const

Returns the text.

See also:
setText()
WString Wt::WStandardItem::toolTip ( ) const

Returns the tool tip.

See also:
setToolTip()
std::string Wt::WStandardItem::url ( ) const

Returns the linked URL (deprecated).

See also:
setUrl()
Deprecated:
Use link() instead.

Generated on Sun May 27 2012 for the C++ Web Toolkit (Wt) by doxygen 1.8.1