Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
The QAbstractItemModel class provides the abstract interface for item model classes. More...
#include <QAbstractItemModel>
Inherits QObject.
Inherited by QAbstractTableModel, QAbstractListModel, and QDirModel.
The QAbstractItemModel class provides the abstract interface for item model classes.
The QAbstractItemModel class defines the standard interface that item models must use to be able to interoperate with other components in the model/view architecture. It is not supposed to be instantiated directly. Instead, you should subclass it to create new models.
If you need a model to use with a QListView or a QTableView, you should consider subclassing QAbstractListModel or QAbstractTableModel instead of this class.
The underlying data model is exposed to views and delegates as a hierarchy of tables. If you don't make use of the hierarchy, then the model is a simple table of rows and columns. Each item has a unique index specified by a QModelIndex.
Every item has an index(), and possibly a sibling() index; child items have a parent() index. hasChildren() is true for items that have children. Each item has a number of data elements associated with them, each with a particular Role. Data elements are set individually with setData(), or for all roles with setItemData(). Data is retrieved from an item with data() (for a single role), or with itemData() (for every role). Items can be queried with isSelectable() and isEditable(). An item can be searched for using match().
The model has a rowCount() and a columnCount() for each level of the hierarchy. Rows and columns can be inserted and removed with insertRow(), insertColumn(), removeRow(), and removeColumn().
The model emits signals to indicate changes. For example, dataChanged() is emitted whenever the contents of the model are changed; rowsInserted(), columnsInserted(), rowsRemoved(), and columnsRemoved() are emitted when the model's dimensions are changed.
If the model isSortable(), it can be sorted with sort(). To customize sorting and searching, comparison functions can be reimplemented; for example, lessThan(), equal(), and greaterThan().
When subclassing QAbstractItemModel, at the very least you must implement index(), parent(), rowCount(), columnCount(), and data(). To enable editing in your model, you must also implement isEditable() and setData().
See also Model/View Programming, QModelIndex, and QAbstractItemView.
QAbstractItemModel::MatchContains | The value is contained in the item. |
QAbstractItemModel::MatchFromStart | The value matches the start of the item. |
QAbstractItemModel::MatchFromEnd | The value matches the end of the item. |
QAbstractItemModel::MatchExactly | The value matches the item exactly. |
QAbstractItemModel::MatchCase | The search is case sensitive. |
QAbstractItemModel::MatchWrap | The search wraps around. |
QAbstractItemModel::MatchDefault | The default match, which is MatchFromStart|MatchWrap. |
The MatchFlags typedef can store a combination of MatchFlag values.
Each item in the model has a set of data elements associated with it, each with its own role. The roles are used when visualizing and editing the items in the views.
QAbstractItemModel::DisplayRole | The data to be rendered as text. |
QAbstractItemModel::DecorationRole | The data to be rendered as an icon. |
QAbstractItemModel::EditRole | The data in a form suitable for editing in an editor. |
QAbstractItemModel::ToolTipRole | The data displayed in the item's tooltip. |
QAbstractItemModel::StatusTipRole | The data displayed in the status bar. |
QAbstractItemModel::WhatsThisRole | The data displayed for the item in "What's This?" mode. |
QAbstractItemModel::UserRole | The first role that can be used for application-specific purposes. |
Constructs an abstract item model with parent parent.
Destroys the abstract item model.
Returns the 'buddy' of the item represented by index. When the used wants to edit an item that is not editable, the delegate may ask for the item's buddy, and edit that item instead.
See also isEditable().
Returns true if decode() would be able to decode src; otherwise returns false.
Returns the number of columns for the given parent.
This signal is emitted after columns have been inserted into the model. The new items are those between start and end inclusive, under the given parent item.
See also insertColumns().
This signal is emitted just before columns are removed from the model. The removed items are those between start and end inclusive, under the given parent item.
See also removeRows().
Creates a model index for the given row and column that points to the given data and is of the given type.
This function provides a consistent interface that model subclasses must use to create model indices.
Returns the data of role role for the item at index.
This signal is emitted whenever the data in an existing item changes. The affected items are those between topLeft and bottomRight inclusive.
See also rowsInserted(), rowsRemoved(), columnsInserted(), columnsRemoved(), and setData().
Decodes data from e, inserting the data under parent (if possible).
Returns true if the data was successfully decoded and inserted; otherwise returns false.
Returns a pointer to a QDragObject object containing the data associated with the indices from the dragSource.
See also itemData().
Returns true if the data at indexes left and right are equal; otherwise returns false.
See also greaterThan() and lessThan().
Returns true if the data at index left is greater than the data at index right; otherwise returns false.
See also equal() and lessThan().
Returns true if parent has any children; otherwise returns false.
See also parent() and index().
Returns the index of the item in the model specified by the given row, column, parent index, and type.
Inserts count new columns in the model before position column. If column is 0 the columns are prepended to the model, if column is columnCount() the columns are appended to the model. The column will be a child of parent. If parent has no children count columns with at least one row is inserted. Returns true if the columns were successfully inserted; otherwise returns false.
The base class implementation does nothing and returns false. If you want to be able to insert columns you must reimplement this function.
Inserts count rows in the model before position row. If row is 0 the rows are prepended to the model, if row is rowCount() the rows are appended to the model. The row will be a child of parent. If parent has no children count rows with at least one column is inserted. Returns true if the rows were successfully inserted; otherwise returns false.
The base class implementation does nothing and returns false. If you want to be able to insert rows you must reimplement this function.
Returns true if the item at index can be dragged; otherwise returns false.
The base class implementation returns false.
Returns true if other items can be dropped on the item at index; otherwise returns false.
The base class implementation returns false.
Returns true if the item at index is editable; otherwise returns false.
The base class implementation returns false.
Returns true if the item at index is selectable; otherwise returns false.
The base class implementation returns true.
Returns true if the items in the model can be sorted; otherwise returns false.
The base class implementation returns false.
See also sort().
Returns a map with values for all predefined roles in the model for the item at the given index.
This must be reimplemented if you want to extend the model with customized roles.
Returns true if the data at index left is less than the data at index right; otherwise returns false.
See also equal() and greaterThan().
Retuns a list of indexes for the items matching value in role role based on the flags. The list may be empty. The search starts from index start and continues until the number of matching data items equals hits or the search reaches the last row or start, depending on whether MatchWrap is specified in flags or not.
See also QAbstractItemModel::MatchFlag.
Returns the parent of the model item with the given index.
Removes count columns starting with column column under parent parent from the model. Returns true if the columns were successfully removed; otherwise returns false.
The base class implementation does nothing and returns false.
Removes count rows starting with row row under parent parent from the model. Returns true if the rows were successfully removed; otherwise returns false.
The base class implementation does nothing and returns false.
Returns the number of rows under the given parent.
This signal is emitted after rows have been inserted into the model. The new items are those between start and end inclusive, under the given parent item.
See also insertRows().
This signal is emitted just before rows are removed from the model. The removed items are those between start and end inclusive, under the given parent item.
See also removeRows().
Sets the role data for the item at index to value. Returns true if successful; otherwise returns false.
The base class implementation returns false. This function (and data()) must be reimplemented.
See also data() and itemData().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Sets the EditRole role data for the item at index to value. Returns true if successful; otherwise returns false.
See also data() and itemData().
For every Role in roles, sets the role data for the item at index to the associated value in roles. Returns true if successful; otherwise returns false.
See also setData(), data(), and itemData().
Returns the index of the sibling of the item at the given row, column, and index idx.
Sorts the model by column, if it is sortable, in the given order.
The base class implementation does nothing.
See also isSortable().
Copyright © 2004 Trolltech. | Trademarks | Qt 4.0.0-tp1 |