Wt
4.11.0
|
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. | |
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 | 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< ItemFlag > | flags () 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 cpp17::any &data, ItemDataRole role=ItemDataRole::User) |
Sets item data. | |
virtual cpp17::any | data (ItemDataRole role=ItemDataRole::User) 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 (std::vector< std::unique_ptr< WStandardItem > > items) |
Add a single column of items. | |
void | insertColumn (int column, std::vector< std::unique_ptr< WStandardItem > > items) |
Inserts a single column of items. | |
void | appendRow (std::vector< std::unique_ptr< WStandardItem > > items) |
Add a single row of items. | |
void | insertRow (int row, std::vector< std::unique_ptr< 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 (std::unique_ptr< WStandardItem > item) |
Appends a row containing one item. | |
void | insertRow (int row, std::unique_ptr< WStandardItem > item) |
Inserts a row containing one item. | |
void | appendRows (std::vector< std::unique_ptr< WStandardItem > > items) |
Appends multiple rows containing one item. | |
void | insertRows (int row, std::vector< std::unique_ptr< WStandardItem > > items) |
Inserts multiple rows containing one item. | |
void | setChild (int row, int column, std::unique_ptr< WStandardItem > item) |
Sets a child item. | |
void | setChild (int row, std::unique_ptr< WStandardItem > item) |
Sets a child item. | |
WStandardItem * | child (int row, int column=0) const |
Returns a child item. | |
std::unique_ptr< WStandardItem > | takeChild (int row, int column) |
Takes a child out of the item. | |
std::vector< std::unique_ptr< WStandardItem > > | takeColumn (int column) |
Takes a column of children out of the item. | |
std::vector< std::unique_ptr< 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. | |
WStandardItemModel * | model () const |
Returns the model. | |
WStandardItem * | parent () const |
Returns the parent item. | |
int | row () const |
Returns the row index. | |
int | column () const |
Returns the column index. | |
virtual std::unique_ptr< WStandardItem > | clone () 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 | |
WStandardItem (const WStandardItem &other) | |
Create a copy of other. | |
WStandardItem & | operator= (const WStandardItem &other) |
Assign other to this item. | |
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. | |
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<().
Creates an item with a text.
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.
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, |
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 |
Removes a single column.
Removes the column column
from the model (reducing the column count by one). Is equivalent to:
Removes a number of columns.
Removes count
columns from the model (reducing the column count by count
).
Removes a single row.
Removes the row row
from the model (reducing the row count by one). Is equivalent to:
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.
Makes the item checkable.
Adds ItemFlag::UserCheckable to the item's flags.
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:
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.
Sets the icon url.
The icon is stored as ItemDataRole::Decoration data.
The default icon url is empty ("").
|
protectedvirtual |
Set the model for this WStandardItem and its children.
You may override this method if you want to change its behaviour.
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).Sets the CSS style class.
The style class is stored as ItemDataRole::StyleClass data.
The default style class is empty ("").
Sets a tool tip.
The tool tip is stored as ItemDataRole::ToolTip data.
The default tool tip is empty ("").
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())
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.