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

📄 qabstractitemview.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
*/void QAbstractItemView::horizontalScrollbarAction(int){    //do nothing}/*!    Closes the given \a editor, and releases it. The \a hint is    used to specify how the view should respond to the end of the editing    operation. For example, the hint may indicate that the next item in    the view should be opened for editing.    \sa edit()*/void QAbstractItemView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint){    Q_D(QAbstractItemView);    // Close the editor    if (editor && !d->persistent.contains(editor)) {        setState(NoState);        d->removeEditor(editor);        d->releaseEditor(editor);    }    // The EndEditHint part    QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::ClearAndSelect        |d->selectionBehaviorFlags();    switch (hint) {    case QAbstractItemDelegate::EditNextItem: {        QModelIndex index = moveCursor(MoveNext, Qt::NoModifier);        if (index.isValid()) {            QPersistentModelIndex persistent(index);            selectionModel()->setCurrentIndex(persistent, flags);            // currentChanged signal would have already started editing            if (!(editTriggers() & QAbstractItemView::CurrentChanged))                edit(persistent);        } break; }    case QAbstractItemDelegate::EditPreviousItem: {        QModelIndex index = moveCursor(MovePrevious, Qt::NoModifier);        if (index.isValid()) {            QPersistentModelIndex persistent(index);            selectionModel()->setCurrentIndex(persistent, flags);            // currentChanged signal would have already started editing            if (!(editTriggers() & QAbstractItemView::CurrentChanged))                edit(persistent);        } break; }    case QAbstractItemDelegate::SubmitModelCache:        model()->submit();        break;    case QAbstractItemDelegate::RevertModelCache:        model()->revert();        break;    default:        break;    }}/*!  Commit the data in the \a editor to the model.  \sa closeEditor()*/void QAbstractItemView::commitData(QWidget *editor){    if (!model() || !editor)        return;    editor->removeEventFilter(d_func()->delegate);    QModelIndex index = d_func()->indexForEditor(editor);    itemDelegate()->setModelData(editor, model(), index);    editor->installEventFilter(d_func()->delegate);}/*!  Remove the editor \a editor from the map.*/void QAbstractItemView::editorDestroyed(QObject *editor){    Q_D(QAbstractItemView);    QWidget *w = ::qobject_cast<QWidget*>(editor);    d->removeEditor(w);    d->persistent.removeAll(w);    if (state() == EditingState)        setState(NoState);}/*!    Sets the horizontal scrollbar's steps per item to \a steps.    This is the number of steps used by the horizontal scrollbar to    represent the width of an item.    Note that if the view has a horizontal header, the item steps    will be ignored and the header section size will be used instead.    \sa horizontalStepsPerItem() setVerticalStepsPerItem()*/void QAbstractItemView::setHorizontalStepsPerItem(int steps){    d_func()->horizontalStepsPerItem = steps;    horizontalScrollBar()->setSingleStep(steps);}/*!    Returns the horizontal scrollbar's steps per item.    \sa setHorizontalStepsPerItem() verticalStepsPerItem()*/int QAbstractItemView::horizontalStepsPerItem() const{    return d_func()->horizontalStepsPerItem;}/*!    Sets the vertical scrollbar's steps per item to \a steps.    This is the number of steps used by the vertical scrollbar to    represent the height of an item.    Note that if the view has a vertical header, the item steps    will be ignored and the header section size will be used instead.    \sa verticalStepsPerItem() setHorizontalStepsPerItem()*/void QAbstractItemView::setVerticalStepsPerItem(int steps){    d_func()->verticalStepsPerItem = steps;    verticalScrollBar()->setSingleStep(steps);}/*!    Returns the vertical scrollbar's steps per item.    \sa setVerticalStepsPerItem() horizontalStepsPerItem()*/int QAbstractItemView::verticalStepsPerItem() const{    return d_func()->verticalStepsPerItem;}/*!  Moves to and selects the item best matching the string \a search.  If no item is found nothing happens.*/void QAbstractItemView::keyboardSearch(const QString &search){    Q_D(QAbstractItemView);    if (!model() || !model()->rowCount(rootIndex()) || !model()->columnCount(rootIndex()))        return;    QModelIndex start = currentIndex().isValid() ? currentIndex()                        : model()->index(0, 0, rootIndex());    QTime now(QTime::currentTime());    bool skipRow = false;    if (d->keyboardInputTime.msecsTo(now) > QApplication::keyboardInputInterval()) {        d->keyboardInput = search;        skipRow = true;    } else {        d->keyboardInput += search;    }    d->keyboardInputTime = now;    // special case for searches with same key like 'aaaaa'    bool sameKey = false;    if (d->keyboardInput.length() > 1) {        int c = d->keyboardInput.count(d->keyboardInput.at(d->keyboardInput.length() - 1));        sameKey = (c == d->keyboardInput.length());        if (sameKey)            skipRow = true;    }    // skip if we are searching for the same key or a new search started    if (skipRow) {        QModelIndex parent = start.parent();        int newRow = (start.row() < model()->rowCount(parent) - 1) ? start.row() + 1 : 0;        start = model()->index(newRow, start.column(), parent);    }    // search from start with wraparound    QString searchString = sameKey ? QString(d->keyboardInput.at(0)) : d->keyboardInput;    QModelIndexList match;    match = model()->match(start, Qt::DisplayRole, searchString);    if (!match.isEmpty() && match.at(0).isValid()) {        selectionModel()->setCurrentIndex(match.at(0),            (d->selectionMode == SingleSelection             ? QItemSelectionModel::SelectionFlags(QItemSelectionModel::ClearAndSelect                                                   | d->selectionBehaviorFlags())             : QItemSelectionModel::SelectionFlags(QItemSelectionModel::NoUpdate)));    }}/*!    Returns the size hint for the item with the specified \a index or    an invalid size for invalid indexes.*/QSize QAbstractItemView::sizeHintForIndex(const QModelIndex &index) const{    if (!index.isValid())        return QSize();    return itemDelegate()->sizeHint(viewOptions(), index);}/*!    Returns the height size hint for the specified \a row or -1 if    there is no model.    This function is used in views with a vertical header to find the size hint for    a header section based on the contents of the given \a row.    \sa sizeHintForColumn()*/int QAbstractItemView::sizeHintForRow(int row) const{    Q_D(const QAbstractItemView);    Q_ASSERT(row >= 0);    if(!model() || row >= model()->rowCount())        return -1;    QStyleOptionViewItem option = viewOptions();    QAbstractItemDelegate *delegate = itemDelegate();    Q_ASSERT(delegate);    int height = 0;    int colCount = model()->columnCount(rootIndex());    QModelIndex index;    for (int c = 0; c < colCount; ++c) {        index = model()->index(row, c, rootIndex());        if (QWidget *editor = d->editorForIndex(index))            height = qMax(height, editor->size().height());        height = qMax(height, delegate->sizeHint(option, index).height());    }    return height;}/*!    Returns the width size hint for the specified \a column or -1 if there is no model.    This function is used in views with a horizontal header to find the size hint for    a header section based on the contents of the given \a column.    \sa sizeHintForRow()*/int QAbstractItemView::sizeHintForColumn(int column) const{    Q_D(const QAbstractItemView);    Q_ASSERT(column >= 0);    if(!model() || column >= model()->columnCount())        return -1;    QStyleOptionViewItem option = viewOptions();    QAbstractItemDelegate *delegate = itemDelegate();    Q_ASSERT(delegate);    int width = 0;    int rows = model()->rowCount(rootIndex());    QModelIndex index;    for (int r = 0; r < rows; ++r) {        index = model()->index(r, column, rootIndex());        if (QWidget *editor = d->editorForIndex(index))            width = qMax(width, editor->sizeHint().width());        width = qMax(width, delegate->sizeHint(option, index).width());    }    return width;}/*!    Opens a persistent editor on the item at the given \a index.    If no editor exists, the delegate will create a new editor.*/void QAbstractItemView::openPersistentEditor(const QModelIndex &index){    Q_D(QAbstractItemView);    QStyleOptionViewItem options = viewOptions();    options.rect = visualRect(index);    options.state |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);    QWidget *editor = d->editor(index, options);    if (editor) {        editor->show();        d->persistent.append(editor);    }}/*!  Closes the persistent editor for the item at the given \a index.*/void QAbstractItemView::closePersistentEditor(const QModelIndex &index){    Q_D(QAbstractItemView);    QWidget *editor = d->editorForIndex(index);    if (editor) {        d->persistent.removeAll(editor);        d->releaseEditor(editor);    }    d->removeEditor(editor);}/*!    \since 4.1    Sets the given \a widget on the item at the given \a index.    This function should only be used to display static content within the visible    area corresponding to an item of data. If you want to display custom dynamic    content or implement a custom editor widget, subclass QItemDelegate instead.    Note: the viewport takes ownership of the widget.    \sa {Delegate Classes}*/void QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget){    Q_D(QAbstractItemView);    Q_ASSERT(widget);    Q_ASSERT(index.isValid());    if (QWidget *oldWidget = indexWidget(index)) {        d->removeEditor(oldWidget);        oldWidget->deleteLater();    }    widget->setParent(viewport());    widget->setGeometry(visualRect(index));    d->persistent.append(widget);    d->addEditor(index, widget);    widget->show();}/*!    \since 4.1    Returns the widget for the item at the given \a index.*/QWidget* QAbstractItemView::indexWidget(const QModelIndex &index) const{    Q_ASSERT(index.isValid());    return d_func()->editorForIndex(index);}/*!    \since 4.1    Scrolls the view to the top.*/void QAbstractItemView::scrollToTop(){    verticalScrollBar()->setValue(verticalScrollBar()->minimum());}/*!    \since 4.1    Scrolls the view to the bottom.*/void QAbstractItemView::scrollToBottom(){    verticalScrollBar()->setValue(verticalScrollBar()->maximum());}/*!    This slot is called when items are changed in the model. The    changed items are those from \a topLeft to \a bottomRight    inclusive. If just one item is changed \a topLeft == \a    bottomRight.*/void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight){    // Single item changed    Q_D(QAbstractItemView);    if (topLeft == bottomRight && topLeft.isValid()) {        if (d->hasEditor(topLeft))            itemDelegate()->setEditorData(d->editorForIndex(topLeft), topLeft);        else if (isVisible() && !d->delayedLayout.isActive()) // otherwise the items will be update later anyway            d->viewport->update(visualRect(topLeft));        return;    }    updateEditorData(); // we are counting on having relatively few editors    if (!isVisible() || d->delayedLayout.isActive())        return; // no need to update    d->viewport->update();}/*!    This slot is called when rows are inserted. The new rows are those    under the given \a parent from \a start to \a end inclusive. The    base class implementation calls fetchMore() on the model to check    for more data.    \sa rowsAboutToBeRemoved()*/void QAbstractItemView::rowsInserted(const QModelIndex &, int, int){    if (!isVisible())        d_func()->fetchMore();}/*!    This slot is called when rows are about to be removed. The deleted rows are    those under the given \a parent from \a start to \a end inclusive.    \sa rowsInserted()*/void QAbstractItemView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end){    Q_D(QAbstractItemView);    setState(CollapsingState);    // Ensure one selected item in single selection mode.    QModelIndex current = currentIndex();    if (selectionMode() == SingleSelection && current.isValid() &&        current.row() >= start 

⌨️ 快捷键说明

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