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

📄 qabstractitemmodel.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    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()*/void QAbstractItemModel::fetchMore(const QModelIndex &){    // do nothing}/*!  Returns true if there is more data available for \a parent,  otherwise false.  The default implementation always returns false.  \sa fetchMore()*/bool QAbstractItemModel::canFetchMore(const QModelIndex &) const{    return false;}/*!    Returns the item flags for the given \a index.    The base class implementation returns a combination of flags that    enables the item (\c ItemIsEnabled) and allows it to be    selected (\c ItemIsSelectable).    \sa Qt::ItemFlags*/Qt::ItemFlags QAbstractItemModel::flags(const QModelIndex &index) const{    Q_D(const QAbstractItemModel);    if (!d->indexValid(index))        return 0;    return Qt::ItemIsSelectable|Qt::ItemIsEnabled;}/*!    Sorts the model by \a column in the given \a order.    The base class implementation does nothing.*/void QAbstractItemModel::sort(int column, Qt::SortOrder order){    Q_UNUSED(column);    Q_UNUSED(order);    // do nothing}/*!  Returns a model index for the buddy of the item represented by \a index.  When the user wants to edit an item, the view will call this function to  check whether another item in the model should be edited instead, and  construct a delegate using the model index returned by the buddy item.  In the default implementation each item is its own buddy.*/QModelIndex QAbstractItemModel::buddy(const QModelIndex &index) const{    return index;}/*!    Returns a list of indexes for the items in the column of the \a    start index where the data stored under the given \a role matches    the specified \a value. The way the search is performed is defined    by the \a flags given. The list that is returned may be empty.    The search starts from the \a start index, and continues until the    number of matching data items equals \a hits, the search reaches    the last row, or the search reaches \a start again, depending on    whether \c MatchWrap is specified in \a flags. If you want to search    for all matching items, use \a hits = -1.    By default, this function will perform a wrapping, string-based comparison    on all items, searching for items that begin with the search term specified    by \a value.        \note The default implementation of this function only searches columns,    This function can be reimplemented to include other search behavior.*/QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role,                                          const QVariant &value, int hits,                                          Qt::MatchFlags flags) const{    QModelIndexList result;    uint matchType = flags & 0x0F;    Qt::CaseSensitivity cs = flags & Qt::MatchCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;    bool recurse = flags & Qt::MatchRecursive;    bool wrap = flags & Qt::MatchWrap;    bool allHits = (hits == -1);    QString text; // only convert to a string if it is needed    QModelIndex p = parent(start);    int from = start.row();    int to = rowCount(p);    // iterates twice if wrapping    for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {        for (int r = from; (r < to) && (allHits || result.count() < hits); ++r) {            QModelIndex idx = index(r, start.column(), p);            if (!idx.isValid())                 continue;            QVariant v = data(idx, role);            // QVariant based matching            if (matchType == Qt::MatchExactly) {                if (value == v)                    result.append(idx);            } else { // QString based matching                if (text.isEmpty()) // lazy conversion                    text = value.toString();                QString t = v.toString();                switch (matchType) {                case Qt::MatchRegExp:                    if (QRegExp(text, cs).exactMatch(t))                        result.append(idx);                    break;                case Qt::MatchWildcard:                    if (QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t))                        result.append(idx);                    break;                case Qt::MatchStartsWith:                    if (t.startsWith(text, cs))                        result.append(idx);                    break;                case Qt::MatchEndsWith:                    if (t.endsWith(text, cs))                        result.append(idx);                    break;                case Qt::MatchFixedString:                    if (t.compare(text, cs) == 0)                        result.append(idx);                    break;                case Qt::MatchContains:                default:                    if (t.contains(text, cs))                        result.append(idx);                }            }            if (recurse && hasChildren(idx)) { // search the hierarchy                result += match(index(0, idx.column(), idx), role,                                (text.isEmpty() ? value : text),                                (allHits ? -1 : hits - result.count()), flags);            }        }        // prepare for the next iteration        from = 0;        to = start.row();    }    return result;}/*!    Returns the row and column span of the item represented by \a index.    Note: span is not used currently, but will be in the future.*/QSize QAbstractItemModel::span(const QModelIndex &) const{    return QSize(1, 1);}/*!  Called to let the model know that it should submit whatever it has cached  to the permanent storage. Typically used for row editing.  Returns false on error, otherwise true.*/bool QAbstractItemModel::submit(){    return true;}/*!  Called to let the model know that it should discard whatever it has cached.  Typically used for row editing.*/void QAbstractItemModel::revert(){    // do nothing}/*!  Returns the data for the given \a role and \a section in the header  with the specified \a orientation.  \sa Qt::ItemDataRole, setHeaderData(), QHeaderView*/QVariant QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role) const{    Q_UNUSED(orientation);    if (role == Qt::DisplayRole)        return section + 1;    return QVariant();}/*!  Sets the data for the given \a role and \a section in the header with  the specified \a orientation to the \a value supplied.  Returns true if the header's data was updated; otherwise returns false.  Note that the headerDataChanged() signal must be emitted explicitly  when reimplementing this function.  \sa Qt::ItemDataRole, headerData()*/bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation,                                       const QVariant &value, int role){    Q_UNUSED(section);    Q_UNUSED(orientation);    Q_UNUSED(value);    Q_UNUSED(role);    return false;}/*!    \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, void *ptr) const    Creates a model index for the given \a row and \a column with the internal pointer \a ptr.    Note that when you are using a QSortFilterProxyModel its indexes have their own    internal pointer.  It is not advisable to access the internal pointer in the index    outside of the model.  Use the data() function instead.    This function provides a consistent interface that model subclasses must    use to create model indexes.*//*!    \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, int id) const    \obsolete    Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead.*//*!    \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) const    Creates a model index for the given \a row and \a column with the internal    identifier, \a id.    This function provides a consistent interface that model subclasses must    use to create model indexes.*//*!  \internal*/void QAbstractItemModel::encodeData(const QModelIndexList &indexes, QDataStream &stream) const{    QModelIndexList::ConstIterator it = indexes.begin();    for (; it != indexes.end(); ++it)        stream << (*it).row() << (*it).column() << itemData(*it);}/*!  \internal */bool QAbstractItemModel::decodeData(int row, int column, const QModelIndex &parent,                                    QDataStream &stream){    int top = INT_MAX;    int left = INT_MAX;    int bottom = 0;    int right = 0;    QVector<int> rows, columns;    QVector<QMap<int, QVariant> > data;    while (!stream.atEnd()) {        int r, c;        QMap<int, QVariant> v;        stream >> r >> c >> v;        rows.append(r);        columns.append(c);        data.append(v);        top = qMin(r, top);        left = qMin(c, left);        bottom = qMax(r, bottom);        right = qMax(c, right);    }    // insert the dragged items into the table, use a bit array to avoid overwriting items,    // since items from different tables can have the same row and column

⌨️ 快捷键说明

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