?? qabstractitemmodel.cpp
字號:
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);}/*! Returns a map with values for all predefined roles in the model for the item at the given \a index. Reimplemented this function if you want to extend the default behavior of this function to include custom roles in the map. \sa Qt::ItemDataRole, data()*/QMap<int, QVariant> QAbstractItemModel::itemData(const QModelIndex &index) const{ QMap<int, QVariant> roles; for (int i = 0; i < Qt::UserRole; ++i) { QVariant variantData = data(index, i); if (variantData.type() != QVariant::Invalid) roles.insert(i, variantData); } return roles;}/*! Sets the \a role data for the item at \a index to \a value. Returns true if successful; otherwise returns false. The dataChanged() signal should be emitted if the data was successfully set. The base class implementation returns false. This function and data() must be reimplemented for editable models. Note that the dataChanged() signal must be emitted explicitly when reimplementing this function. \sa Qt::ItemDataRole, data(), itemData()*/bool QAbstractItemModel::setData(const QModelIndex &index, const QVariant &value, int role){ Q_UNUSED(index); Q_UNUSED(value); Q_UNUSED(role); return false;}/*! \fn QVariant QAbstractItemModel::data(const QModelIndex &index, int role) const = 0 Returns the data stored under the given \a role for the item referred to by the \a index. \sa Qt::ItemDataRole, setData(), headerData()*//*! For every Qt::ItemDataRole in \a roles, sets the role data for the item at \a index to the associated value in \a roles. Returns true if successful; otherwise returns false. \sa setData() data() itemData()*/bool QAbstractItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles){ bool b = true; for (QMap<int, QVariant>::ConstIterator it = roles.begin(); it != roles.end(); ++it) b = b && setData(index, it.value(), it.key()); return b;}/*! Returns a list of MIME types that can be used to describe a list of model indexes. \sa mimeData()*/QStringList QAbstractItemModel::mimeTypes() const{ QStringList types; types << QLatin1String("application/x-qabstractitemmodeldatalist"); return types;}/*! Returns an object that contains serialized items of data corresponding to the list of \a indexes specified. The formats used to describe the encoded data is obtained from the mimeTypes() function. If the list of indexes is empty, or there are no supported MIME types, 0 is returned rather than a serialized empty list. \sa mimeTypes(), dropMimeData()*/QMimeData *QAbstractItemModel::mimeData(const QModelIndexList &indexes) const{ if (indexes.count() <= 0) return 0; QStringList types = mimeTypes(); if (types.isEmpty()) return 0; QMimeData *data = new QMimeData(); QString format = types.at(0); QByteArray encoded; QDataStream stream(&encoded, QIODevice::WriteOnly); encodeData(indexes, stream); data->setData(format, encoded); return data;}/*! Handles the \a data supplied by a drag and drop operation that ended with the given \a action. Although the specified \a row, \a column and \a parent indicate the location of an item in the model where the operation ended, it is the responsibility of the view to provide a suitable location for where the data should be inserted. For instance, a drop action on an item in a QTreeView can result in new items either being inserted as children of the item specified by \a row, \a column, and \a parent, or as siblings of the item. \sa supportedDropActions(), {Using Drag and Drop with Item Views}*/bool QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent){ // check if the action is supported if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction)) return false; // check if the format is supported QStringList types = mimeTypes(); if (types.isEmpty()) return false; QString format = types.at(0); if (!data->hasFormat(format)) return false; if (row > rowCount(parent)) row = rowCount(parent); if (row == -1) row = rowCount(parent); if (column == -1) column = 0; // decode and insert QByteArray encoded = data->data(format); QDataStream stream(&encoded, QIODevice::ReadOnly); return decodeData(row, column, parent, stream);}/*! \since 4.2 Returns the drop actions supported by this model. The default implementation returns Qt::CopyAction. Reimplement this function if you wish to support additional actions. Note that you must also reimplement the dropMimeData() function to handle the additional operations. \sa dropMimeData(), Qt::DropActions, {Using Drag and Drop with Item Views}*/Qt::DropActions QAbstractItemModel::supportedDropActions() const{ return Qt::CopyAction;}/*! Returns the actions supported by the data in this model. The default implementation returns supportedDropActions() unless specific values have been set with setSupportedDragActions(). supportedDragActions() is used by QAbstractItemView::startDrag() as the default values when a drag occurs. \sa Qt::DropActions, {Using Drag and Drop with Item Views}*/Qt::DropActions QAbstractItemModel::supportedDragActions() const{ // ### Qt 5: make this virtual or these properties Q_D(const QAbstractItemModel); if (d->supportedDragActions != -1) return d->supportedDragActions; return supportedDropActions();}/*! \since 4.2 Sets the supported drag \a actions for the items in the model. \sa supportedDragActions(), {Using Drag and Drop with Item Views}*/void QAbstractItemModel::setSupportedDragActions(Qt::DropActions actions){ Q_D(QAbstractItemModel); d->supportedDragActions = actions;}/*! On models that support this, inserts \a count rows into the model before the given \a row. The items in the new row will be children of the item represented by the \a parent model index. If \a row is 0, the rows are prepended to any existing rows in the parent. If \a row is rowCount(), the rows are appended to any existing rows in the parent. If \a parent has no children, a single column with \a count rows is inserted. Returns true if the rows were successfully inserted; otherwise returns false. The base class implementation does nothing and returns false. If you implement your own model, you can reimplement this function if you want to support insertions. Alternatively, you can provide you own API for altering the data. \sa insertColumns(), removeRows(), beginInsertRows(), endInsertRows()*/bool QAbstractItemModel::insertRows(int, int, const QModelIndex &){ return false;}/*! On models that support this, inserts \a count new columns into the model before the given \a column. The items in each new column will be children of the item represented by the \a parent model index. If \a column is 0, the columns are prepended to any existing columns. If \a column is columnCount(), the columns are appended to any existing columns. If \a parent has no children, a single row with \a count columns is inserted. Returns true if the columns were successfully inserted; otherwise returns false. The base class implementation does nothing and returns false. If you implement your own model, you can reimplement this function if you want to support insertions. Alternatively, you can provide you own API for altering the data. \sa insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns()*/bool QAbstractItemModel::insertColumns(int, int, const QModelIndex &){ return false;}/*! On models that support this, removes \a count rows starting with the given \a row under parent \a parent from the model. Returns true if the rows were successfully removed; otherwise returns false. The base class implementation does nothing and returns false. If you implement your own model, you can reimplement this function if you want to support removing. Alternatively, you can provide you own API for altering the data. \sa removeRow(), removeColumns(), insertColumns(), beginRemoveRows(), endRemoveRows()*/bool QAbstractItemModel::removeRows(int, int, const QModelIndex &){ return false;}/*! On models that support this, removes \a count columns starting with the given \a column under parent \a parent from the model. Returns true if the columns were successfully removed; otherwise returns false. The base class implementation does nothing and returns false. If you implement your own model, you can reimplement this function if you want to support removing. Alternatively, you can provide you own API for altering the data. \sa removeColumn(), removeRows(), insertColumns(), beginRemoveColumns(), endRemoveColumns()*/bool QAbstractItemModel::removeColumns(int, int, const QModelIndex &){ return false;}/*! Fetches any available data for the items with the parent specified by the \a parent index. Reimplement this if you have incremental data. The default implementation does nothing. \sa canFetchMore()*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -