

The functions provide the following features: It is used to hold a list of QVariants, containing column data, and information about its position in the tree structure. It does not inherit from QObject or provide signals and slots. The ShortcutEditorModelItem class is defined as follows: With the appropriate data structure in place, we can create a tree model with a minimal amount of extra code to supply model indexes and data to other components. This makes writing the model easier and ensures that all model indexes that refer to the same item have the same internal data pointer. The use of a pointer-based tree structure means that, when passing a model index to a view, we can record the address of the corresponding item in the index (see QAbstractItemModel::createIndex()) and retrieve it later with QModelIndex::internalPointer().


For simplicity, we will use a list of QVariant objects to store the data for each column in the item. Since each item in a tree view usually contains several columns of data (a name and a shortcut in this example), it is natural to store this information in each item. Having this information readily available makes implementing the model easier. However, the root item in the tree structure has no parent item and it is never referenced outside the model.Įach ShortcutEditorModelItem contains information about its place in the tree structure it can return its parent item and its row number. Generally, each ShortcutEditorModelItem has a parent item, and can have a number of child items. The data is stored internally in the model using ShortcutEditorModelItem objects that are linked together in a pointer-based tree structure.
