Class WStandardItem
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 getChild()
methods.
It is possible to reimplement this class and specialize the methods for data acess (setData()
and getData()
), or provide custom sorting functionality by
reimplementing compare()
.
-
Constructor Summary
ModifierConstructorDescriptionCreates an empty standard item.WStandardItem
(int rows) Creates an item with an initial geometry.WStandardItem
(int rows, int columns) Creates an item with an initial geometry.protected
WStandardItem
(WStandardItem other) Create a copy of other.WStandardItem
(CharSequence text) Creates an item with a text.WStandardItem
(String iconUri, CharSequence text) Creates an item with an icon and a text. -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendColumn
(List<WStandardItem> items) Add a single column of items.void
appendRow
(WStandardItem item) Appends a row containing one item.void
appendRow
(List<WStandardItem> items) Add a single row of items.void
appendRows
(List<WStandardItem> items) Appends multiple rows containing one item.clone()
Returns a clone of this item.Returns the item's check state.final WStandardItem
getChild
(int row) Returns a child item.getChild
(int row, int column) Returns a child item.int
Returns the column index.int
Returns the column count.final Object
getData()
Returns item data.getData
(ItemDataRole role) Returns item data.getFlags()
Returns the flags.getIcon()
Returns the icon url.getIndex()
Returns the model index for this item.getLink()
Returns a link.getModel()
Returns the model.Returns the parent item.int
getRow()
Returns the row index.int
Returns the row count.Returns the item style class.getText()
Returns the text.Returns the tool tip.boolean
Returns whether the item has any children.void
insertColumn
(int column, List<WStandardItem> items) Inserts a single column of items.void
insertColumns
(int column, int count) Inserts a number of empty columns.void
insertRow
(int row, WStandardItem item) Inserts a row containing one item.void
insertRow
(int row, List<WStandardItem> items) Inserts a single row of items.void
insertRows
(int row, int count) Inserts a number of empty rows.void
insertRows
(int row, List<WStandardItem> items) Inserts multiple rows containing one item.boolean
Returns whether the item is checkable.boolean
Returns whether the item is checked.boolean
Returns whether the item is tri-state checkable.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.void
setCheckable
(boolean checkable) Makes the item checkable.void
setChecked
(boolean checked) Checks or unchecks the item.void
setCheckState
(CheckState state) Sets the check state.void
setChild
(int row, int column, WStandardItem item) Sets a child item.void
setChild
(int row, WStandardItem item) Sets a child item.void
setColumnCount
(int columns) Sets the column count.final void
Sets item data.void
setData
(Object d, ItemDataRole role) Sets item data.final void
Sets the flags.void
Sets the flags.void
Sets the icon url.void
Sets a link.protected void
setModel
(WStandardItemModel model) Set the model for thisWStandardItem
and its children.void
setRowCount
(int rows) Sets the row count.void
setStyleClass
(CharSequence styleClass) Sets the CSS style class.void
setText
(CharSequence text) Sets the text.void
setToolTip
(CharSequence toolTip) Sets a tool tip.void
setTristate
(boolean tristate) Makes the item tri-state checkable.void
sortChildren
(int column, SortOrder order) Sorts the children according to a given column and sort order.takeChild
(int row, int column) Takes a child out of the item.takeColumn
(int column) Takes a column of children out of the item.takeRow
(int row) Takes a row of children out of the item.
-
Constructor Details
-
WStandardItem
public WStandardItem()Creates an empty standard item. -
WStandardItem
Creates an item with a text.- See Also:
-
WStandardItem
Creates an item with an icon and a text. -
WStandardItem
public WStandardItem(int rows, int columns) Creates an item with an initial geometry. -
WStandardItem
public WStandardItem(int rows) Creates an item with an initial geometry.Calls
this(rows, 1)
-
WStandardItem
Create a copy of other.Copies other's data and flags to this item. This function is useful when reimplementing
clone()
.
-
-
Method Details
-
setText
Sets the text.The text is stored as
ItemDataRole.Display
data.The default text is empty ("").
-
getText
Returns the text.- See Also:
-
setIcon
Sets the icon url.The icon is stored as
ItemDataRole.Decoration
data.The default icon url is empty ("").
-
getIcon
Returns the icon url.- See Also:
-
setStyleClass
Sets the CSS style class.The style class is stored as
ItemDataRole.StyleClass
data.The default style class is empty ("").
-
getStyleClass
Returns the item style class.- See Also:
-
setToolTip
Sets a tool tip.The tool tip is stored as
ItemDataRole.ToolTip
data.The default tool tip is empty ("").
-
getToolTip
Returns the tool tip.- See Also:
-
setLink
Sets a link.The link is stored as
ItemDataRole.Link
data.- See Also:
-
getLink
Returns a link.- See Also:
-
setChecked
public void setChecked(boolean 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 thirdCheckState.PartiallyChecked
state. -
isChecked
public boolean isChecked()Returns whether the item is checked.- See Also:
-
setCheckState
Sets the check state.Like
setChecked()
, this sets the check state, but allows also setting theCheckState.PartiallyChecked
state when the item is tri-state checkable.The value is stored as ItemDataRole::CheckState data.
-
getCheckState
Returns the item's check state.- See Also:
-
setFlags
Sets the flags.The default flag value is
ItemFlag.Selectable
. -
setFlags
Sets the flags. -
getFlags
Returns the flags.- See Also:
-
setCheckable
public void setCheckable(boolean checkable) Makes the item checkable.Adds
ItemFlag.UserCheckable
to the item's flags. -
isCheckable
public boolean isCheckable()Returns whether the item is checkable.- See Also:
-
setTristate
public void setTristate(boolean tristate) Makes the item tri-state checkable.When
tristate
istrue
, the item is checkable with three states:CheckState.Unchecked
,CheckState.Checked
, andCheckState.PartiallyChecked
.This requires that the item is also checkable (see
setCheckable()
)- See Also:
-
isTristate
public boolean isTristate()Returns whether the item is tri-state checkable.- See Also:
-
setData
Sets item data.Sets item data for the given role.
- See Also:
-
setData
Sets item data. -
getData
Returns item data.Returns item data for the given role.
- See Also:
-
getData
Returns item data.Returns
getData(ItemDataRole.User)
-
hasChildren
public boolean hasChildren()Returns whether the item has any children.This is a convenience method and checks whether
getRowCount()
andgetColumnCount()
differ both from 0.- See Also:
-
setRowCount
public void 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, andgetColumnCount()
== 0, columnCount is first increased to 1 using setColumnCount(1).- See Also:
-
getRowCount
public int getRowCount()Returns the row count.- See Also:
-
setColumnCount
public void 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:
-
getColumnCount
public int getColumnCount()Returns the column count.- See Also:
-
appendColumn
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));
-
insertColumn
Inserts a single column of items.Inserts a single column of
items
at columncolumn
. If necessary, the row count is increased.- See Also:
-
appendRow
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));
-
insertRow
Inserts a single row of items.Inserts a single row of items at row
row
. If necessary, the column count is increased.- See Also:
-
insertColumns
public void insertColumns(int column, int count) Inserts a number of empty columns.Inserts count empty columns at position
column
.- See Also:
-
insertRows
public void insertRows(int row, int count) Inserts a number of empty rows.Inserts count empty rows at position
row
.- See Also:
-
appendRow
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));
- See Also:
-
insertRow
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:
List<WStandardItem> r; r.add(item); insertRow(row, r);
-
appendRows
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));
-
insertRows
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:- See Also:
-
setChild
Sets a child item.Sets a child item item at position (
row
,column
).If necessary, the
getRowCount()
and/or thegetColumnCount()
is increased.- See Also:
-
setChild
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));
-
getChild
Returns a child item.Returns the child item at position (row,
column
). This may benull
if an item was not previously set, or if the position is out of bounds. -
getChild
Returns a child item.Returns
getChild(row, 0)
-
takeChild
Takes a child out of the item.Returns the child item at position (row,
column
), and removes it (by settingnull
instead).- See Also:
-
takeColumn
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
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:
-
removeColumn
public void removeColumn(int column) Removes a single column.Removes the column
column
from the model (reducing the column count by one). Is equivalent to:removeColumns(column, 1);
-
removeColumns
public void removeColumns(int column, int count) Removes a number of columns.Removes
count
columns from the model (reducing the column count bycount
). -
removeRow
public void removeRow(int row) Removes a single row.Removes the row
row
from the model (reducing the row count by one). Is equivalent to:removeRows(row, 1);
-
removeRows
public void removeRows(int row, int count) Removes a number of rows.Removes
count
rows from the model (reducing the row count bycount
). -
getIndex
Returns the model index for this item. -
getModel
Returns the model.This is the model that this item belongs to, or 0 if the item is not associated with a model.
-
getParent
Returns the parent item.Returns the parent item.
-
getRow
public int getRow()Returns the row index.Returns the row index of this item in the parent.
- See Also:
-
getColumn
public int getColumn()Returns the column index.Returns the column index of this item in the parent.
- See Also:
-
clone
Returns a clone of this item. -
sortChildren
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
WAbstractItemModel.layoutAboutToBeChanged()
andWAbstractItemModel.layoutChanged()
signals are emitted before and after the operation so that you get a chance to invalidate or update model indexes.- See Also:
-
compare(WStandardItem other)
WStandardItemModel.setSortRole(ItemDataRole role)
-
setModel
Set the model for thisWStandardItem
and its children.You may override this method if you want to change its behaviour.
-