|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecteu.webtoolkit.jwt.WObject
eu.webtoolkit.jwt.WAbstractItemModel
eu.webtoolkit.jwt.WStandardItemModel
public class WStandardItemModel
A standard data model, which stores its data in memory.
The standard item model supports all features of WAbstractItemModel,
and can thus be used to represent tables, trees and tree tables.
The data itself are organized in WStandardItem objects. There is one
invisible root object (getInvisibleRootItem()) that holds the toplevel data. Most methods in this
class that access or manipulate data internally operate on this root item.
If you want to use the model as a table, then you can use
WStandardItemModel() to set the initial table size, and use the
getItem() and
setItem() methods to set data. You can change the geometry by inserting rows
(insertRow()) or
columns (insertColumn()) or removing rows (
WAbstractItemModel#removeRow()) or columns (
WAbstractItemModel#removeColumn()).
If you want to use the model as a tree (or tree table), then you can use the
default constructor to start with an empty tree, and use the
WStandardItem API on
getInvisibleRootItem() to
manipulate the tree root. When you are building a tree, the column count at
each node is 1. When you are building a tree table, you can add additional
columns of data for each internal node. Only the items in the first column
have children that result in a hierarchical tree structure.
When using the model with a view class, you can use the
getItemFromIndex() and
indexFromItem()
models to translate between model indexes (that are used by the view class)
and standard items.
| Constructor Summary | |
|---|---|
WStandardItemModel()
Creates a new standard item model. |
|
WStandardItemModel(int rows,
int columns)
Creates a new standard item model with an initial geometry. |
|
WStandardItemModel(int rows,
int columns,
WObject parent)
Creates a new standard item model with an initial geometry. |
|
WStandardItemModel(WObject parent)
Creates a new standard item model. |
|
| Method Summary | |
|---|---|
void |
appendColumn(java.util.List<WStandardItem> items)
Adds a single column of top level items. |
void |
appendRow(java.util.List<WStandardItem> items)
Adds a single row of top level items. |
void |
appendRow(WStandardItem item)
Appends a single row containing a single item. |
protected void |
beginInsertColumns(WModelIndex parent,
int first,
int last)
Method to be called before inserting columns. |
protected void |
beginInsertRows(WModelIndex parent,
int first,
int last)
Method to be called before inserting rows. |
protected void |
beginRemoveColumns(WModelIndex parent,
int first,
int last)
Method to be called before removing columns. |
protected void |
beginRemoveRows(WModelIndex parent,
int first,
int last)
Method to be called before removing rows. |
void |
clear()
Erases all data in the model. |
WModelIndex |
fromRawIndex(java.lang.Object rawIndex)
Converts a raw pointer to a model index. |
int |
getColumnCount(WModelIndex parent)
Returns the number of columns. |
java.lang.Object |
getData(WModelIndex index,
int role)
Returns data at a specific model index. |
java.util.EnumSet<ItemFlag> |
getFlags(WModelIndex index)
Returns the flags for an item. |
java.lang.Object |
getHeaderData(int section,
Orientation orientation,
int role)
Returns the row or column header data. |
java.util.EnumSet<HeaderFlag> |
getHeaderFlags(int section,
Orientation orientation)
Returns the flags for a header. |
WModelIndex |
getIndex(int row,
int column,
WModelIndex parent)
Returns the child index for the given row and column. |
WStandardItem |
getInvisibleRootItem()
Returns the invisible root item. |
WStandardItem |
getItem(int row)
Returns a toplevel item. |
WStandardItem |
getItem(int row,
int column)
Returns a toplevel item. |
WStandardItem |
getItemFromIndex(WModelIndex index)
Returns the standard item that corresponds to a model index. |
WStandardItem |
getItemPrototype()
Returns the item prototype. |
WModelIndex |
getParent(WModelIndex index)
Returns the parent for a model index. |
int |
getRowCount(WModelIndex parent)
Returns the number of rows. |
int |
getSortRole()
Returns the role used to sort the model. |
WModelIndex |
indexFromItem(WStandardItem item)
Returns the model index for a particular item. |
void |
insertColumn(int column,
java.util.List<WStandardItem> items)
Inserts a single column of top level items. |
boolean |
insertColumns(int column,
int count,
WModelIndex parent)
Inserts one or more columns. |
void |
insertRow(int row,
java.util.List<WStandardItem> items)
Inserts a single row of top level items. |
void |
insertRow(int row,
WStandardItem item)
Inserts a single row containing a single item. |
boolean |
insertRows(int row,
int count,
WModelIndex parent)
Inserts one or more rows. |
Signal1<WStandardItem> |
itemChanged()
Signal emitted when an item is changed. |
boolean |
removeColumns(int column,
int count,
WModelIndex parent)
Removes columns. |
boolean |
removeRows(int row,
int count,
WModelIndex parent)
Removes rows. |
boolean |
setData(WModelIndex index,
java.lang.Object value,
int role)
Sets data at the given model index. |
boolean |
setHeaderData(int section,
Orientation orientation,
java.lang.Object value,
int role)
Sets header data for a column or row. |
void |
setHeaderFlags(int section,
Orientation orientation,
java.util.EnumSet<HeaderFlag> flags)
Sets header flags. |
void |
setHeaderFlags(int section,
Orientation orientation,
HeaderFlag flag,
HeaderFlag... flags)
Sets header flags. |
void |
setItem(int row,
int column,
WStandardItem item)
Sets a toplevel item. |
void |
setItemPrototype(WStandardItem item)
Sets the item prototype. |
void |
setSortRole(int role)
Set the role used to sort the model. |
void |
sort(int column,
SortOrder order)
Sorts the model according to a particular column. |
java.util.List<WStandardItem> |
takeColumn(int column)
Takes a column out of the model. |
WStandardItem |
takeItem(int row)
Takes an item out of the model. |
WStandardItem |
takeItem(int row,
int column)
Takes an item out of the model. |
java.util.List<WStandardItem> |
takeRow(int row)
Takes a row out of the model. |
java.lang.Object |
toRawIndex(WModelIndex index)
Converts a model index to a raw pointer that remains valid while the model's layout is changed. |
| Methods inherited from class eu.webtoolkit.jwt.WObject |
|---|
addChild, getId, getObjectName, remove, setObjectName, tr |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WStandardItemModel(WObject parent)
public WStandardItemModel()
Calls this((WObject)null)
public WStandardItemModel(int rows,
int columns,
WObject parent)
Creates a standard item model with a geometry of rows x
columns. All items are set to null.
public WStandardItemModel(int rows,
int columns)
Calls this(rows, columns, (WObject)null)
| Method Detail |
|---|
public void clear()
After clearing the model,
WAbstractItemModel#getRowCount() and
WAbstractItemModel#getColumnCount() are 0.
public WStandardItem getInvisibleRootItem()
The invisible root item is a special item that is not rendered itself, but holds the top level data.
public WModelIndex indexFromItem(WStandardItem item)
If the item is the
getInvisibleRootItem(),
then an invalid index is returned.
getItemFromIndex(WModelIndex index)public WStandardItem getItemFromIndex(WModelIndex index)
If the index is an invalid index, then the
getInvisibleRootItem()
is returned.
indexFromItem(WStandardItem item)public void appendColumn(java.util.List<WStandardItem> items)
Appends a single column of top level items. If necessary,
the row count is increased.
Equivalent to:
insertColumn(columnCount(), items);
insertColumn(int column, List items),
appendRow(List items)
public void insertColumn(int column,
java.util.List<WStandardItem> items)
Inserts a single column of top level items at column
column. If necessary, the row count is increased.
Equivalent to:
invisibleRootItem().insertColumn(column, items);
WStandardItem.insertColumn(int column, List items)public void appendRow(java.util.List<WStandardItem> items)
Appends a single row of top level items. If necessary, the
column count is increased.
Equivalent to:
insertRow(rowCount(), items);
insertRow(int row, List items),
appendColumn(List items)
public void insertRow(int row,
java.util.List<WStandardItem> items)
Inserts a single row of top level items at row
row. If necessary, the column count is increased.
Equivalent to:
invisibleRootItem().insertRow(row, items);
WStandardItem.insertRow(int row, List items)public void appendRow(WStandardItem item)
Appends a single toplevel row, with a single item.
Equivalent to:
insertRow(rowCount(), item);
WStandardItem.insertRow(int row, WStandardItem item)
public void insertRow(int row,
WStandardItem item)
Inserts a single toplevel row, with a single item.
Equivalent to:
invisibleRootItem().insertRow(row, item);
WStandardItem.insertRow(int row, WStandardItem item)
public WStandardItem getItem(int row,
int column)
Returns the top level at at (row, column). This may
be 0 if no item was set previously at that position, or if the indicated
position is out of bounds.
Equivalent to:
invisibleRootItem().child(row, column);
WStandardItem.getChild(int row, int column)public final WStandardItem getItem(int row)
Returns getItem(row, 0)
public void setItem(int row,
int column,
WStandardItem item)
Sets the top level at at (row, column). If necessary,
the number of rows or columns is increased.
If an item was previously set for that position, it is deleted first.
Equivalent to:
invisibleRootItem().setChild(row, column, item);
WStandardItem.setChild(int row, int column, WStandardItem item)public WStandardItem getItemPrototype()
setItemPrototype(WStandardItem item)public void setItemPrototype(WStandardItem item)
Set the item that is cloned when an item needs to be created because the
model is manipulated through its WAbstractItemModel API. For
example, this may be needed when a view sets data at a position for which
no item was previously set and thus created.
The new item is created based on this prototype by using
WStandardItem#clone().
The default prototype is WStandardItem().
setItemPrototype(WStandardItem item)public java.util.List<WStandardItem> takeColumn(int column)
Removes a column from the model, and returns the items that it contained. Ownership of the items is transferred out of the model.
Equivalent to:
invisibleRootItem().takeColumn(column);
WStandardItem.takeColumn(int column),
WStandardItem.takeRow(int row)public java.util.List<WStandardItem> takeRow(int row)
Removes a row from the model, and returns the items that it contained. Ownership of the items is transferred out of the model.
Equivalent to:
invisibleRootItem().takeRow(row);
WStandardItem.takeRow(int row),
takeColumn(int column)
public WStandardItem takeItem(int row,
int column)
Removes an item from the model, and returns it. Ownership of the item is transferred out of the model.
Equivalent to:
invisibleRootItem().takeItem(row, column);
takeItem(int row, int column),
WStandardItem.takeRow(int row),
WStandardItem.takeColumn(int column)public final WStandardItem takeItem(int row)
Returns takeItem(row, 0)
public void setHeaderFlags(int section,
Orientation orientation,
java.util.EnumSet<HeaderFlag> flags)
By default, no flags are set.
public final void setHeaderFlags(int section,
Orientation orientation,
HeaderFlag flag,
HeaderFlag... flags)
Calls
setHeaderFlags(section, orientation, EnumSet.of(flag, flags))
public java.util.EnumSet<HeaderFlag> getHeaderFlags(int section,
Orientation orientation)
WAbstractItemModelThe default implementation returns no flags set.
getHeaderFlags in class WAbstractItemModelHeaderFlagpublic java.util.EnumSet<ItemFlag> getFlags(WModelIndex index)
WAbstractItemModel
The default implementation returns ItemIsSelectable.
getFlags in class WAbstractItemModelItemFlagpublic WModelIndex getParent(WModelIndex index)
WAbstractItemModel
An implementation should use
createIndex() to create a model index that corresponds to the parent of
a given index.
Note that the index itself may be stale (referencing a row/column within
the parent that is outside the model geometry), but its parent
(identified by the WModelIndex#getInternalPointer()) is referencing an existing parent. A
stale index can only be used while the model geometry is being updated,
i.e. during the emission of the corresponding
[rows/columns](Being)[Removed/Inserted]() signals.
getParent in class WAbstractItemModelWAbstractItemModel.getIndex(int row, int column, WModelIndex parent)
public java.lang.Object getData(WModelIndex index,
int role)
WAbstractItemModelReturn data for a given role at a given index.
You should check the role to decide what data to return.
Usually a View class will ask for data for several roles which affect not
only the contents (ItemDataRole.DisplayRole) but also icons (
ItemDataRole.DecorationRole), URLs (ItemDataRole.LinkRole
), and other visual aspects. If your item does not specify data for a
particular role, it should simply return a boost::any().
getData in class WAbstractItemModelWAbstractItemModel.getFlags(WModelIndex index),
WAbstractItemModel.getHeaderData(int section, Orientation
orientation, int role),
WAbstractItemModel.setData(WModelIndex index, Object value, int
role)
public java.lang.Object getHeaderData(int section,
Orientation orientation,
int role)
WAbstractItemModel
When orientation is Horizontal, section is a column number, when
orientation is Vertical,
section is a row number.
getHeaderData in class WAbstractItemModelWAbstractItemModel.getData(WModelIndex index, int role),
WAbstractItemModel.setHeaderData(int section, Orientation
orientation, Object value, int role)
public WModelIndex getIndex(int row,
int column,
WModelIndex parent)
WAbstractItemModel
When implementing this method, you can use
createIndex() to create an index that corresponds to the item at
row and column within parent.
If the location is invalid (out of bounds at the parent), then an invalid index must be returned.
getIndex in class WAbstractItemModelWAbstractItemModel.getParent(WModelIndex index)public int getColumnCount(WModelIndex parent)
WAbstractItemModel
This returns the number of columns at index parent.
getColumnCount in class WAbstractItemModelWAbstractItemModel.getRowCount(WModelIndex parent)public int getRowCount(WModelIndex parent)
WAbstractItemModel
This returns the number of rows at index parent.
getRowCount in class WAbstractItemModelWAbstractItemModel.getColumnCount(WModelIndex parent)
public boolean insertColumns(int column,
int count,
WModelIndex parent)
WAbstractItemModel
In models that support column insertion, this inserts count
columns, starting at column, and returns true
if the operation was successful. The new columns are inserted under
parent.
The default implementation returns false.
The model implementation must call
beginInsertColumns() and endInsertColumns() before and after the operation whenever its geometry
is changed by inserting columns. This emits signals for views to properly
react to these changes.
insertColumns in class WAbstractItemModelWAbstractItemModel.insertRows(int row, int count, WModelIndex
parent),
WAbstractItemModel.removeColumns(int column, int count, WModelIndex
parent),
WAbstractItemModel.beginInsertColumns(WModelIndex parent, int first,
int last),
WAbstractItemModel.endInsertColumns()
public boolean insertRows(int row,
int count,
WModelIndex parent)
WAbstractItemModel
In models that support row insertion, this inserts count
rows, starting at row, and returns true if the
operation was successful. The new rows are inserted under
parent.
If parent had no children, then a single column is added with
count rows.
The default implementation returns false.
The model implementation must call
beginInsertRows() and endInsertRows() before and after the operation whenever its geometry is
changed by inserting rows. This emits signals for views to properly react
to these changes.
insertRows in class WAbstractItemModelWAbstractItemModel.insertColumns(int column, int count, WModelIndex
parent),
WAbstractItemModel.removeRows(int row, int count, WModelIndex
parent),
WAbstractItemModel.beginInsertRows(WModelIndex parent, int first,
int last),
WAbstractItemModel.endInsertRows()
public boolean removeColumns(int column,
int count,
WModelIndex parent)
WAbstractItemModel
Returns true if the operation was successful.
The default implementation returns false.
The model implementation must call
beginRemoveColumns() and endRemoveColumns() before and after the operation whenever its geometry
is changed by removing columns. This emits signals for views to properly
react to these changes.
removeColumns in class WAbstractItemModelWAbstractItemModel.removeRows(int row, int count, WModelIndex
parent),
WAbstractItemModel.insertColumns(int column, int count, WModelIndex
parent),
WAbstractItemModel.beginRemoveColumns(WModelIndex parent, int first,
int last),
WAbstractItemModel.endRemoveColumns()
public boolean removeRows(int row,
int count,
WModelIndex parent)
WAbstractItemModel
Returns true if the operation was successful.
The default implementation returns false.
The model implementation must call
beginRemoveRows() and endRemoveRows() before and after the operation whenever its geometry is
changed by removing rows. This emits signals for views to properly react
to these changes.
removeRows in class WAbstractItemModelWAbstractItemModel.removeColumns(int column, int count, WModelIndex
parent),
WAbstractItemModel.insertRows(int row, int count, WModelIndex
parent),
WAbstractItemModel.beginRemoveRows(WModelIndex parent, int first,
int last),
WAbstractItemModel.endRemoveRows()
public boolean setData(WModelIndex index,
java.lang.Object value,
int role)
WAbstractItemModel
Returns true if the operation was successful.
The default implementation returns false.
The model implementation must emit the
dataChanged() signal after data
was changed.
setData in class WAbstractItemModelWAbstractItemModel.getData(WModelIndex index, int role)
public boolean setHeaderData(int section,
Orientation orientation,
java.lang.Object value,
int role)
WAbstractItemModel
Returns true if the operation was successful.
setHeaderData in class WAbstractItemModelWAbstractItemModel.getHeaderData(int section, Orientation
orientation, int role)public java.lang.Object toRawIndex(WModelIndex index)
WAbstractItemModelUse this method to temporarily save model indexes while the model's layout is changed by for example a sorting operation.
The default implementation returns null, which indicates
that the index cannot be converted to a raw pointer. If you reimplement
this method, you also need to reimplemnt
fromRawIndex().
toRawIndex in class WAbstractItemModelWAbstractItemModel.layoutAboutToBeChanged(),
WAbstractItemModel.sort(int column, SortOrder order),
WAbstractItemModel.fromRawIndex(Object rawIndex)public WModelIndex fromRawIndex(java.lang.Object rawIndex)
WAbstractItemModel
Use this method to create model index from temporary raw pointers. It is
the reciproce method of
toRawIndex().
You can return an invalid modelindex if the rawIndex no longer points to a valid item because of the layout change.
fromRawIndex in class WAbstractItemModelWAbstractItemModel.toRawIndex(WModelIndex index)public void setSortRole(int role)
The default role is DisplayRole.
sort(int column, SortOrder order)public int getSortRole()
setSortRole(int role)
public void sort(int column,
SortOrder order)
WAbstractItemModel
If the model supports sorting, then it should emit the
layoutAboutToBeChanged() signal, rearrange its items, and afterwards
emit the layoutChanged()
signal.
sort in class WAbstractItemModelWAbstractItemModel.layoutAboutToBeChanged(),
WAbstractItemModel.layoutChanged()public Signal1<WStandardItem> itemChanged()
This signal is emitted whenever data for an item has changed. The item that has changed is passed as the first parameter.
WStandardItem.setData(Object d, int role)
protected void beginInsertColumns(WModelIndex parent,
int first,
int last)
WAbstractItemModel
If your model supports insertion of columns, then you should call this
method before inserting one or more columns, and
endInsertColumns()
afterwards. These methods emit the necessary signals to allow view
classes to update themselves.
beginInsertColumns in class WAbstractItemModelWAbstractItemModel.endInsertColumns(),
WAbstractItemModel.insertColumns(int column, int count, WModelIndex
parent),
WAbstractItemModel.columnsAboutToBeInserted()
protected void beginInsertRows(WModelIndex parent,
int first,
int last)
WAbstractItemModel
If your model supports insertion of rows, then you should call this
method before inserting one or more rows, and
endInsertRows() afterwards.
These methods emit the necessary signals to allow view classes to update
themselves.
beginInsertRows in class WAbstractItemModelWAbstractItemModel.endInsertRows(),
WAbstractItemModel.insertRows(int row, int count, WModelIndex
parent),
WAbstractItemModel.rowsAboutToBeInserted()
protected void beginRemoveColumns(WModelIndex parent,
int first,
int last)
WAbstractItemModel
If your model supports removal of columns, then you should call this
method before removing one or more columns, and
endRemoveColumns()
afterwards. These methods emit the necessary signals to allow view
classes to update themselves.
beginRemoveColumns in class WAbstractItemModelWAbstractItemModel.endRemoveColumns(),
WAbstractItemModel.removeColumns(int column, int count, WModelIndex
parent),
WAbstractItemModel.columnsAboutToBeRemoved()
protected void beginRemoveRows(WModelIndex parent,
int first,
int last)
WAbstractItemModel
If your model supports removal of rows, then you should call this method
before removing one or more rows, and
endRemoveRows() afterwards.
These methods emit the necessary signals to allow view classes to update
themselves.
beginRemoveRows in class WAbstractItemModelWAbstractItemModel.endRemoveRows(),
WAbstractItemModel.removeRows(int row, int count, WModelIndex
parent),
WAbstractItemModel.rowsAboutToBeRemoved()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||