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
ConstructorsModifierConstructorDescriptionCreates 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.protectedWStandardItem(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 TypeMethodDescriptionvoidappendColumn(List<WStandardItem> items) Add a single column of items.voidappendRow(WStandardItem item) Appends a row containing one item.voidappendRow(List<WStandardItem> items) Add a single row of items.voidappendRows(List<WStandardItem> items) Appends multiple rows containing one item.clone()Returns a clone of this item.Returns the item's check state.final WStandardItemgetChild(int row) Returns a child item.getChild(int row, int column) Returns a child item.intReturns the column index.intReturns the column count.final ObjectgetData()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.intgetRow()Returns the row index.intReturns the row count.Returns the item style class.getText()Returns the text.Returns the tool tip.booleanReturns whether the item has any children.voidinsertColumn(int column, List<WStandardItem> items) Inserts a single column of items.voidinsertColumns(int column, int count) Inserts a number of empty columns.voidinsertRow(int row, WStandardItem item) Inserts a row containing one item.voidinsertRow(int row, List<WStandardItem> items) Inserts a single row of items.voidinsertRows(int row, int count) Inserts a number of empty rows.voidinsertRows(int row, List<WStandardItem> items) Inserts multiple rows containing one item.booleanReturns whether the item is checkable.booleanReturns whether the item is checked.booleanReturns whether the item is tri-state checkable.voidremoveColumn(int column) Removes a single column.voidremoveColumns(int column, int count) Removes a number of columns.voidremoveRow(int row) Removes a single row.voidremoveRows(int row, int count) Removes a number of rows.voidsetCheckable(boolean checkable) Makes the item checkable.voidsetChecked(boolean checked) Checks or unchecks the item.voidsetCheckState(CheckState state) Sets the check state.voidsetChild(int row, int column, WStandardItem item) Sets a child item.voidsetChild(int row, WStandardItem item) Sets a child item.voidsetColumnCount(int columns) Sets the column count.final voidSets item data.voidsetData(Object d, ItemDataRole role) Sets item data.final voidSets the flags.voidSets the flags.voidSets the icon url.voidSets a link.protected voidsetModel(WStandardItemModel model) Set the model for thisWStandardItemand its children.voidsetRowCount(int rows) Sets the row count.voidsetStyleClass(CharSequence styleClass) Sets the CSS style class.voidsetText(CharSequence text) Sets the text.voidsetToolTip(CharSequence toolTip) Sets a tool tip.voidsetTristate(boolean tristate) Makes the item tri-state checkable.voidsortChildren(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.- See Also:
-
WStandardItem
public WStandardItem(int rows, int columns) Creates an item with an initial geometry.- See Also:
-
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.Displaydata.The default text is empty ("").
- See Also:
-
getText
Returns the text.- See Also:
-
setIcon
Sets the icon url.The icon is stored as
ItemDataRole.Decorationdata.The default icon url is empty ("").
- See Also:
-
getIcon
Returns the icon url.- See Also:
-
setStyleClass
Sets the CSS style class.The style class is stored as
ItemDataRole.StyleClassdata.The default style class is empty ("").
- See Also:
-
getStyleClass
Returns the item style class.- See Also:
-
setToolTip
Sets a tool tip.The tool tip is stored as
ItemDataRole.ToolTipdata.The default tool tip is empty ("").
- See Also:
-
getToolTip
Returns the tool tip.- See Also:
-
setLink
Sets a link.The link is stored as
ItemDataRole.Linkdata.- 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.PartiallyCheckedstate.- See Also:
-
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.PartiallyCheckedstate when the item is tri-state checkable.The value is stored as ItemDataRole::CheckState data.
- See Also:
-
getCheckState
Returns the item's check state.- See Also:
-
setFlags
Sets the flags.The default flag value is
ItemFlag.Selectable.- See Also:
-
setFlags
Sets the flags. -
getFlags
Returns the flags.- See Also:
-
setCheckable
public void setCheckable(boolean checkable) Makes the item checkable.Adds
ItemFlag.UserCheckableto the item's flags.- See Also:
-
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
tristateistrue, 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
rowsis bigger than the current row count, empty rows are appended.If
rowsis 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
columnsis bigger than the current column count, empty columns are appended.If
columnsis 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));- See Also:
-
insertColumn
Inserts a single column of items.Inserts a single column of
itemsat 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));- See Also:
-
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 benullif 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 settingnullinstead).- 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
columnfrom the model (reducing the column count by one). Is equivalent to:removeColumns(column, 1);- See Also:
-
removeColumns
public void removeColumns(int column, int count) Removes a number of columns.Removes
countcolumns from the model (reducing the column count bycount).- See Also:
-
removeRow
public void removeRow(int row) Removes a single row.Removes the row
rowfrom the model (reducing the row count by one). Is equivalent to:removeRows(row, 1);- See Also:
-
removeRows
public void removeRows(int row, int count) Removes a number of rows.Removes
countrows from the model (reducing the row count bycount).- See Also:
-
getIndex
Returns the model index for this item.- See Also:
-
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.
- See Also:
-
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:
-
setModel
Set the model for thisWStandardItemand its children.You may override this method if you want to change its behaviour.
-