Class WStandardItemModel


  • public class WStandardItemModel
    extends WAbstractItemModel
    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.