Wt
4.11.1
|
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< ItemFlag > | flags () 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... | |
WStandardItem * | child (int row, int column=0) const |
Returns a child item. More... | |
std::unique_ptr< WStandardItem > | takeChild (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... | |
WStandardItemModel * | model () const |
Returns the model. More... | |
WStandardItem * | parent () 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< WStandardItem > | clone () 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... | |
WStandardItem & | operator= (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... | |
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<().
Wt::WStandardItem::WStandardItem | ( | const WString & | text | ) |
Creates an item with a text.
Wt::WStandardItem::WStandardItem | ( | const std::string & | iconUri, |
const WString & | text | ||
) |
Wt::WStandardItem::WStandardItem | ( | int | rows, |
int | columns = 1 |
||
) |
Creates an item with an initial geometry.
|
protected |
Create a copy of other.
Copies other's data and flags to this item. This function is useful when reimplementing clone().
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:
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:
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:
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:
CheckState Wt::WStandardItem::checkState | ( | ) | const |
Returns the item's check state.
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.
|
virtual |
Returns a clone of this item.
int Wt::WStandardItem::column | ( | ) | const |
int Wt::WStandardItem::columnCount | ( | ) | const |
Returns the column count.
|
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().
|
virtual |
Returns the flags.
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.
std::string Wt::WStandardItem::icon | ( | ) | const |
Returns the icon url.
WModelIndex Wt::WStandardItem::index | ( | ) | const |
Returns the model index for this item.
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.
void Wt::WStandardItem::insertColumns | ( | int | column, |
int | count | ||
) |
Inserts a number of empty columns.
Inserts count empty columns at position column
.
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:
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.
void Wt::WStandardItem::insertRows | ( | int | row, |
int | count | ||
) |
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:
bool Wt::WStandardItem::isCheckable | ( | ) | const |
Returns whether the item is checkable.
bool Wt::WStandardItem::isChecked | ( | ) | const |
Returns whether the item is checked.
bool Wt::WStandardItem::isTristate | ( | ) | const |
Returns whether the item is tri-state checkable.
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.
|
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().
|
protected |
Assign other to this item.
Assigns others's data and flags to this item. This function is useful when reimplementing clone().
WStandardItem* Wt::WStandardItem::parent | ( | ) | const |
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 Wt::WStandardItem::removeColumns | ( | int | column, |
int | count | ||
) |
Removes a number of columns.
Removes count
columns from the model (reducing the column count by count
).
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 Wt::WStandardItem::removeRows | ( | int | row, |
int | count | ||
) |
Removes a number of rows.
Removes count
rows from the model (reducing the row count by count
).
int Wt::WStandardItem::row | ( | ) | const |
int Wt::WStandardItem::rowCount | ( | ) | const |
Returns the row count.
void Wt::WStandardItem::setCheckable | ( | bool | checkable | ) |
Makes the item checkable.
Adds ItemFlag::UserCheckable to the item's flags.
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.
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.
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.
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:
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.
|
virtual |
Sets the flags.
The default flag value is ItemFlag::Selectable.
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 ("").
void Wt::WStandardItem::setLink | ( | const WLink & | link | ) |
|
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.
rows
> 0, and columnCount() == 0, columnCount is first increased to 1 using setColumnCount(1).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 ("").
void Wt::WStandardItem::setText | ( | const WString & | text | ) |
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 ("").
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())
|
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.
WString Wt::WStandardItem::styleClass | ( | ) | const |
Returns the item style class.
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).
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.
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.
WString Wt::WStandardItem::toolTip | ( | ) | const |
Returns the tool tip.