Wt  4.11.1
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
Wt::WStandardItem Class Reference

An item in a WStandardItemModel. More...

#include <Wt/WStandardItem.h>

Public Member Functions

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

Protected Member Functions

 WStandardItem (const WStandardItem &other)
 Create a copy of other. More...
 
WStandardItemoperator= (const WStandardItem &other)
 Assign other to this item. More...
 
virtual void setModel (WStandardItemModel *model)
 Set the model for this WStandardItem and its children. More...
 

Private Member Functions

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

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

◆ WStandardItem() [1/4]

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

Creates an item with a text.

See also
setText()

◆ WStandardItem() [2/4]

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

Creates an item with an icon and a text.

See also
setText(), setIcon()

◆ WStandardItem() [3/4]

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

Creates an item with an initial geometry.

See also
setRowCount(), setColumnCount()

◆ WStandardItem() [4/4]

Wt::WStandardItem::WStandardItem ( const WStandardItem other)
protected

Create a copy of other.

Copies other's data and flags to this item. This function is useful when reimplementing clone().

Member Function Documentation

◆ appendColumn()

void Wt::WStandardItem::appendColumn ( std::vector< std::unique_ptr< WStandardItem > >  items)

Add a single column of items.

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

Equivalent to:

insertColumn(columnCount(), std::move(items));
void insertColumn(int column, std::vector< std::unique_ptr< WStandardItem > > items)
Inserts a single column of items.
Definition: WStandardItem.C:395
int columnCount() const
Returns the column count.
Definition: WStandardItem.C:383
See also
insertColumn(), appendRow()

◆ appendRow() [1/2]

void Wt::WStandardItem::appendRow ( std::unique_ptr< 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(), std::move(item));
void insertRow(int row, std::vector< std::unique_ptr< WStandardItem > > items)
Inserts a single row of items.
Definition: WStandardItem.C:440
int rowCount() const
Returns the row count.
Definition: WStandardItem.C:369
See also
insertRow(int, std::unique_ptr<WStandardItem>)

◆ appendRow() [2/2]

void Wt::WStandardItem::appendRow ( std::vector< std::unique_ptr< 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(), std::move(items));
See also
insertRow(), appendColumn()

◆ appendRows()

void Wt::WStandardItem::appendRows ( std::vector< std::unique_ptr< 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(), std::move(items));
void insertRows(int row, int count)
Inserts a number of empty rows.
Definition: WStandardItem.C:497
See also
insertRows(int, const std::vector<WStandardItem *>&)

◆ checkState()

CheckState Wt::WStandardItem::checkState ( ) const

Returns the item's check state.

See also
setCheckState()

◆ child()

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 *).

◆ clone()

std::unique_ptr< WStandardItem > Wt::WStandardItem::clone ( ) const
virtual

Returns a clone of this item.

See also
WStandardItemModel::setItemPrototype()

◆ column()

int Wt::WStandardItem::column ( ) const

Returns the column index.

Returns the column index of this item in the parent.

See also
column()

◆ columnCount()

int Wt::WStandardItem::columnCount ( ) const

Returns the column count.

See also
setRowCount()

◆ compare()

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

◆ data()

cpp17::any Wt::WStandardItem::data ( ItemDataRole  role = ItemDataRole::User) const
virtual

Returns item data.

Returns item data for the given role.

See also
data()

◆ flags()

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

Returns the flags.

See also
setFlags()

◆ hasChildren()

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

◆ icon()

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

Returns the icon url.

See also
setIcon()

◆ index()

WModelIndex Wt::WStandardItem::index ( ) const

Returns the model index for this item.

See also
WStandardItemModel::indexFromItem()

◆ insertColumn()

void Wt::WStandardItem::insertColumn ( int  column,
std::vector< std::unique_ptr< 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()

◆ insertColumns()

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

Inserts a number of empty columns.

Inserts count empty columns at position column.

See also
insertRows()

◆ insertRow() [1/2]

void Wt::WStandardItem::insertRow ( int  row,
std::unique_ptr< 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<std::unique_ptr<WStandardItem>> r;
r.emplace_back(std::move(item));
insertRow(row, std::move(r));
int row() const
Returns the row index.
Definition: WStandardItem.h:576
See also
insertRow(int, const std::vector<WStandardItem *>&)

◆ insertRow() [2/2]

void Wt::WStandardItem::insertRow ( int  row,
std::vector< std::unique_ptr< 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()

◆ insertRows() [1/2]

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

Inserts a number of empty rows.

Inserts count empty rows at position row.

See also
insertColumns()

◆ insertRows() [2/2]

void Wt::WStandardItem::insertRows ( int  row,
std::vector< std::unique_ptr< 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, std::move(items[i]));
See also
insertRow(int, std::unique_ptr<WStandardItem>)

◆ isCheckable()

bool Wt::WStandardItem::isCheckable ( ) const

Returns whether the item is checkable.

See also
setCheckable()

◆ isChecked()

bool Wt::WStandardItem::isChecked ( ) const

Returns whether the item is checked.

See also
setChecked()

◆ isTristate()

bool Wt::WStandardItem::isTristate ( ) const

Returns whether the item is tri-state checkable.

See also
setTristate()

◆ link()

WLink Wt::WStandardItem::link ( ) const

Returns a link.

See also
setLink()

◆ model()

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.

◆ operator<()

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

◆ operator=()

WStandardItem & Wt::WStandardItem::operator= ( const WStandardItem other)
protected

Assign other to this item.

Assigns others's data and flags to this item. This function is useful when reimplementing clone().

◆ parent()

WStandardItem* Wt::WStandardItem::parent ( ) const

Returns the parent item.

Returns the parent item.

See also
setChild()

◆ removeColumn()

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:

void removeColumns(int column, int count)
Removes a number of columns.
Definition: WStandardItem.C:698
int column() const
Returns the column index.
Definition: WStandardItem.h:584
See also
removeColumns(), takeColumn()

◆ removeColumns()

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

◆ removeRow()

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:

void removeRows(int row, int count)
Removes a number of rows.
Definition: WStandardItem.C:720
See also
removeRows(), takeRow()

◆ removeRows()

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

◆ row()

int Wt::WStandardItem::row ( ) const

Returns the row index.

Returns the row index of this item in the parent.

See also
column()

◆ rowCount()

int Wt::WStandardItem::rowCount ( ) const

Returns the row count.

See also
setRowCount()

◆ setCheckable()

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

Makes the item checkable.

Adds ItemFlag::UserCheckable to the item's flags.

See also
setFlags(), setChecked()

◆ setChecked()

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

Checks or unchecks the item.

The value is stored as ItemDataRole::CheckState data.

By default, an item is not checked.

Note: the checkbox will only be enabled if 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::CheckState::PartiallyChecked state.

See also
setCheckable(), setCheckState()

◆ setCheckState()

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

Sets the check state.

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

The value is stored as ItemDataRole::CheckState data.

See also
setCheckable(), setData()

◆ setChild() [1/2]

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

Sets a child item.

Sets a child item item at position (row, column).

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

See also
child().

◆ setChild() [2/2]

void Wt::WStandardItem::setChild ( int  row,
std::unique_ptr< 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, std::move(item));
void setChild(int row, int column, std::unique_ptr< WStandardItem > item)
Sets a child item.
Definition: WStandardItem.C:549
See also
setChild(int, int, WStandardItem *).

◆ setColumnCount()

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

◆ setData()

void Wt::WStandardItem::setData ( const cpp17::any &  data,
ItemDataRole  role = ItemDataRole::User 
)
virtual

Sets item data.

Sets item data for the given role.

See also
data()

◆ setFlags()

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

Sets the flags.

The default flag value is ItemFlag::Selectable.

See also
ItemFlag, flags(), setCheckable()

◆ setIcon()

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

Sets the icon url.

The icon is stored as ItemDataRole::Decoration data.

The default icon url is empty ("").

See also
icon(), setData()

◆ setLink()

void Wt::WStandardItem::setLink ( const WLink link)

Sets a link.

The link is stored as ItemDataRole::Link data.

See also
setData()

◆ setModel()

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.

◆ setRowCount()

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

◆ setStyleClass()

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

Sets the CSS style class.

The style class is stored as ItemDataRole::StyleClass data.

The default style class is empty ("").

See also
styleClass(), setData()

◆ setText()

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

Sets the text.

The text is stored as ItemDataRole::Display data.

The default text is empty ("").

See also
text(), setData()

◆ setToolTip()

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

Sets a tool tip.

The tool tip is stored as ItemDataRole::ToolTip data.

The default tool tip is empty ("").

See also
toolTip(), setData()

◆ setTristate()

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

Makes the item tri-state checkable.

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

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

See also
setCheckable()

◆ sortChildren()

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

◆ styleClass()

WString Wt::WStandardItem::styleClass ( ) const

Returns the item style class.

See also
setStyleClass()

◆ takeChild()

std::unique_ptr< 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).

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

◆ takeColumn()

std::vector< std::unique_ptr< 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()

◆ takeRow()

std::vector< std::unique_ptr< 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()

◆ text()

WString Wt::WStandardItem::text ( ) const

Returns the text.

See also
setText()

◆ toolTip()

WString Wt::WStandardItem::toolTip ( ) const

Returns the tool tip.

See also
setToolTip()