⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qabstractitemmodel.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    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.    \img modelindex-no-parent.png    Every item of data that can be accessed via a model has an associated    model index that is obtained using the index() function. Each index    may have a sibling() index; child items have a parent() index.    Each item has a number of data elements associated with it, and each    of these can be retrieved by specifying a role (see \l Qt::ItemDataRole)    to the model's data() function. Data for all available roles can be    obtained at the same time using the itemData() function.    Data for each role is set using a particular \l Qt::ItemDataRole.    Data for individual roles are set individually with setData(), or they    can be set for all roles with setItemData().    Items can be queried with flags() (see \l Qt::ItemFlag) to see if they    can be selected, dragged, or manipulated in other ways.    If an item has child objects, hasChildren() returns true for the    corresponding index.    The model has a rowCount() and a columnCount() for each level of    the hierarchy. Rows and columns can be inserted and removed with    insertRows(), insertColumns(), removeRows(), and removeColumns().    The model emits signals to indicate changes. For example,    dataChanged() is emitted whenever items of data made available by    the model are changed. Changes to the headers supplied by the model    cause headerDataChanged() to be emitted. If the structure of the    underlying data changes, the model can emit layoutChanged() to    indicate to any attached views that they should redisplay any items    shown, taking the new structure into account.    The items available through the model can be searched for particular    data using the match() function.    If the model is sortable, it can be sorted with sort().    \section1 Subclassing    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    setData(), and reimplement flags() to ensure that \c    ItemIsEditable is returned.  You can also reimplement headerData()    and setHeaderData() to control the way the headers for your model    are presented.    Note that the dataChanged() and headerDataChanged() signals must    be emitted explicitly when reimplementing the setData() and    setHeaderData() functions, respectively.    Custom models need to create model indexes for other components to use.    To do this, call createIndex() with suitable row and column numbers for    the item, and supply a unique identifier for the item, either as a    pointer or as an integer value. Custom models typically use these    unique identifiers in other reimplemented functions to retrieve item    data and access information about the item's parents and children.    See the \l{itemviews/simpletreemodel}{Simple Tree Model} example for    more information about unique identifiers.    It is not necessary to support every role defined in Qt::ItemDataRole.    Depending on the type of data contained within a model, it may only be    useful to implement the data() function to return valid information for    some of the more common roles. Most models provide at least a textual    representation of item data for the Qt::DisplayRole, and well-behaved    models should also provide valid information for the Qt::ToolTipRole    and Qt::WhatsThisRole. Supporting these roles enables models to be used    with standard Qt views. However, for some models that handle    highly-specialized data, it may be appropriate to provide data only for    user-defined roles.    Models that provide interfaces to resizable data structures can    provide implementations of insertRows(), removeRows(), insertColumns(),    and removeColumns(). When implementing these functions, it is    important to notify any connected views about changes to the model's    dimensions both \e before and \e after they occur:    \list    \o An insertRows() implementation must call beginInsertRows()       \e before inserting new rows into the data structure, and it must       call endInsertRows() \e{immediately afterwards}.    \o An insertColumns() implementation must call beginInsertColumns()       \e before inserting new columns into the data structure, and it must       call endInsertColumns() \e{immediately afterwards}.    \o A removeRows() implementation must call beginRemoveRows()       \e before the rows are removed from the data structure, and it must       call endRemoveRows() \e{immediately afterwards}.    \o A removeColumns() implementation must call beginRemoveColumns()       \e before the columns are removed from the data structure, and it must       call endRemoveColumns() \e{immediately afterwards}.    \endlist    The \e private signals that these functions emit give attached components    the chance to take action before any data becomes unavailable. The    encapsulation of the insert and remove operations with these begin and end    functions also enables the model to manage    \l{QPersistentModelIndex}{persistent model indexes} correctly.    \bold{If you want selections to be handled properly, you must ensure that    you call these functions.}    \sa \link model-view-programming.html Model/View Programming\endlink, QModelIndex,        QAbstractItemView, {Using Drag and Drop with Item Views}*//*!    \fn QModelIndex QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const = 0    Returns the index of the item in the model specified by the given \a row,    \a column and \a parent index.*//*!    \fn bool QAbstractItemModel::insertColumn(int column, const QModelIndex &parent)    Inserts a single column before the given \a column in the child items of    the \a parent specified. Returns true if the column is inserted; otherwise    returns false.    \sa insertColumns() insertRow() removeColumn()*//*!    \fn bool QAbstractItemModel::insertRow(int row, const QModelIndex &parent)    Inserts a single row before the given \a row in the child items of the    \a parent specified. Returns true if the row is inserted; otherwise    returns false.    \sa insertRows() insertColumn() removeRow()*//*!    \fn QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const = 0    Returns the parent of the model item with the given \a index.*//*!    \fn bool QAbstractItemModel::removeColumn(int column, const QModelIndex &parent)    Removes the given \a column from the child items of the \a parent specified.    Returns true if the column is removed; otherwise returns false.    \sa removeColumns(), removeRow(), insertColumn()*//*!    \fn bool QAbstractItemModel::removeRow(int row, const QModelIndex &parent)    Removes the given \a row from the child items of the \a parent specified.    Returns true if the row is removed; otherwise returns false.    \sa removeRows(), removeColumn(), insertRow()*//*!    \fn void QAbstractItemModel::headerDataChanged(Qt::Orientation orientation, int first, int last)    This signal is emitted whenever a header is changed. The \a orientation    indicates whether the horizontal or vertical header has changed. The    sections in the header from the \a first to the \a last need to be updated.    Note that this signal must be emitted explicitly when    reimplementing the setHeaderData() function.    If you are changing the number of columns or rows you don't need to emit this signal,    but use the begin/end functions.    \sa headerData(), setHeaderData(), dataChanged()*//*!    \fn void QAbstractItemModel::layoutChanged()    This signal is emitted whenever the layout of items exposed by the model    changes; for example, when the model is sorted. When this signal is    received by a view, it should update the layout of items to reflect this    change.    When subclassing QAbstractItemModel or QAbstractProxyModel, ensure that you    emit this signal if you change the order of items or alter the structure of    the data you expose to views.    \sa dataChanged(), headerDataChanged(), reset()*//*!    Constructs an abstract item model with the given \a parent.*/QAbstractItemModel::QAbstractItemModel(QObject *parent)    : QObject(*new QAbstractItemModelPrivate, parent){}/*!  \internal*/QAbstractItemModel::QAbstractItemModel(QAbstractItemModelPrivate &dd, QObject *parent)    : QObject(dd, parent){}/*!    Destroys the abstract item model.*/QAbstractItemModel::~QAbstractItemModel(){    d_func()->invalidatePersistentIndexes();}/*!    \fn QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const    Returns the sibling at \a row and \a column for the item at \a index, or    an invalid QModelIndex if there is no sibling at that location.    sibling() is just a convenience function that finds the item's parent, and    uses it to retrieve the index of the child item in the specified \a row    and \a column.    \sa index(), QModelIndex::row(), QModelIndex::column()*//*!    \fn int QAbstractItemModel::rowCount(const QModelIndex &parent) const = 0    Returns the number of rows under the given \a parent.*//*!    \fn int QAbstractItemModel::columnCount(const QModelIndex &parent) const = 0;    Returns the number of columns for the given \a parent.*//*!    \fn void QAbstractItemModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)    This signal is emitted whenever the data in an existing item    changes. The affected items are those between \a topLeft and \a    bottomRight inclusive (of the same parent).    Note that this signal must be emitted explicitly when    reimplementing the setData() function.    \sa headerDataChanged(), setData(), layoutChanged()*//*!    \fn void QAbstractItemModel::rowsInserted(const QModelIndex &parent, int start, int end)    This signal is emitted after rows have been inserted into the    model. The new items are those between \a start and \a end    inclusive, under the given \a parent item.    \bold{Note:} Components connected to this signal use it to adapt to changes    in the model's dimensions. It can only be emitted by the QAbstractItemModel    implementation, and cannot be explicitly emitted in subclass code.    \sa insertRows(), beginInsertRows()*//*!    \fn void QAbstractItemModel::rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)    This signal is emitted just before rows are inserted into the    model. The new items will be positioned between \a start and \a end    inclusive, under the given \a parent item.    \bold{Note:} Components connected to this signal use it to adapt to changes    in the model's dimensions. It can only be emitted by the QAbstractItemModel    implementation, and cannot be explicitly emitted in subclass code.    \sa insertRows(), beginInsertRows()*//*!    \fn void QAbstractItemModel::rowsRemoved(const QModelIndex &parent, int start, int end)    This signal is emitted after rows have been removed from the    model. The removed items are those between \a start and \a end    inclusive, under the given \a parent item.    \bold{Note:} Components connected to this signal use it to adapt to changes    in the model's dimensions. It can only be emitted by the QAbstractItemModel    implementation, and cannot be explicitly emitted in subclass code.    \sa removeRows(), beginRemoveRows()*//*!    \fn void QAbstractItemModel::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)    This signal is emitted just before rows are removed from the    model. The items that will be removed are those between \a start and \a end    inclusive, under the given \a parent item.    \bold{Note:} Components connected to this signal use it to adapt to changes    in the model's dimensions. It can only be emitted by the QAbstractItemModel    implementation, and cannot be explicitly emitted in subclass code.    \sa removeRows(), beginRemoveRows()*//*!    \fn void QAbstractItemModel::columnsInserted(const QModelIndex &parent, int start, int end)    This signal is emitted after columns have been inserted into the    model. The new items are those between \a start and \a end    inclusive, under the given \a parent item.    \bold{Note:} Components connected to this signal use it to adapt to changes    in the model's dimensions. It can only be emitted by the QAbstractItemModel    implementation, and cannot be explicitly emitted in subclass code.    \sa insertColumns(), beginInsertColumns()*//*!    \fn void QAbstractItemModel::columnsAboutToBeInserted(const QModelIndex &parent, int start, int end)    This signal is emitted just before columns are inserted into the    model. The new items will be positioned between \a start and \a end    inclusive, under the given \a parent item.    \bold{Note:} Components connected to this signal use it to adapt to changes    in the model's dimensions. It can only be emitted by the QAbstractItemModel    implementation, and cannot be explicitly emitted in subclass code.    \sa insertColumns(), beginInsertColumns()*//*!    \fn void QAbstractItemModel::columnsRemoved(const QModelIndex &parent, int start, int end)    This signal is emitted after columns have been removed from the    model. The removed items are those between \a start and \a end    inclusive, under the given \a parent item.    \bold{Note:} Components connected to this signal use it to adapt to changes    in the model's dimensions. It can only be emitted by the QAbstractItemModel    implementation, and cannot be explicitly emitted in subclass code.    \sa removeColumns(), beginRemoveColumns()*//*!    \fn void QAbstractItemModel::columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)    This signal is emitted just before columns are removed    from the model. The items to be removed are those between \a start and    \a end inclusive, under the given \a parent item.    \bold{Note:} Components connected to this signal use it to adapt to changes    in the model's dimensions. It can only be emitted by the QAbstractItemModel    implementation, and cannot be explicitly emitted in subclass code.    \sa removeColumns(), beginRemoveColumns()*//*!  Returns true if the model returns a valid QModelIndex for \a row and  \a column with \a parent, otherwise returns false.*/bool QAbstractItemModel::hasIndex(int row, int column, const QModelIndex &parent) const{    if (row < 0 || column < 0)        return false;    return row < rowCount(parent) && column < columnCount(parent);}/*!  Returns true if \a parent has any children; otherwise returns false.  Use rowCount() on the parent to find out the number of children.  \sa parent() index()*/bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const{    return (rowCount(parent) > 0) && (columnCount(parent) > 0);}/*!

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -