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

📄 qlistview.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    Q_D(QListView);    if (batchSize <= 0) {        qWarning("Invalid batchSize (%d)", batchSize);        return;    }    d->batchSize = batchSize;}int QListView::batchSize() const{    Q_D(const QListView);    return d->batchSize;}/*!    \property QListView::gridSize    \brief the size of the layout grid    This property is the size of the grid in which the items are laid    out. The default is an empty size which means that there is no    grid and the layout is not done in a grid. Setting this property    to a non-empty size switches on the grid layout. (When a grid    layout is in force the \l spacing property is ignored.)    Setting this property when the view is visible will cause the    items to be laid out again.    \sa viewMode*/void QListView::setGridSize(const QSize &size){    Q_D(QListView);    d->modeProperties |= uint(QListViewPrivate::GridSize);    d->setGridSize(size);    d->doDelayedItemsLayout();}QSize QListView::gridSize() const{    Q_D(const QListView);    return d->gridSize();}/*!    \property QListView::viewMode    \brief the view mode of the QListView.    This property will change the other unset properties to conform    with the set view mode. QListView-specific properties that have already been set    will not be changed, unless clearPropertyFlags() has been called.    Setting the view mode will enable or disable drag and drop based on the    selected movement. For ListMode, the default movement is \l Static    (drag and drop disabled); for IconMode, the default movement is    \l Free (drag and drop enabled).    \sa isWrapping, spacing, gridSize, flow, movement, resizeMode*/void QListView::setViewMode(ViewMode mode){    Q_D(QListView);    d->viewMode = mode;    if (mode == ListMode) {        delete d->dynamicListView;        d->dynamicListView = 0;        if (!d->staticListView)            d->staticListView = new QStaticListViewBase(this, d);        if (!(d->modeProperties & QListViewPrivate::Wrap))            d->setWrapping(false);        if (!(d->modeProperties & QListViewPrivate::Spacing))            d->setSpacing(0);        if (!(d->modeProperties & QListViewPrivate::GridSize))            d->setGridSize(QSize());        if (!(d->modeProperties & QListViewPrivate::Flow))            d->flow = TopToBottom;        if (!(d->modeProperties & QListViewPrivate::Movement))            d->movement = Static;        if (!(d->modeProperties & QListViewPrivate::ResizeMode))            d->resizeMode = Fixed;        if (!(d->modeProperties & QListViewPrivate::SelectionRectVisible))            d->showElasticBand = false;    } else {        delete d->staticListView;        d->staticListView = 0;        if (!d->dynamicListView)            d->dynamicListView = new QDynamicListViewBase(this, d);        if (!(d->modeProperties & QListViewPrivate::Wrap))            d->setWrapping(true);        if (!(d->modeProperties & QListViewPrivate::Spacing))            d->setSpacing(0);        if (!(d->modeProperties & QListViewPrivate::GridSize))            d->setGridSize(QSize());        if (!(d->modeProperties & QListViewPrivate::Flow))            d->flow = LeftToRight;        if (!(d->modeProperties & QListViewPrivate::Movement))            d->movement = Free;        if (!(d->modeProperties & QListViewPrivate::ResizeMode))            d->resizeMode = Fixed;        if (!(d->modeProperties & QListViewPrivate::SelectionRectVisible))            d->showElasticBand = true;    }#ifndef QT_NO_DRAGANDDROP    bool movable = (d->movement != Static);    setDragEnabled(movable);    setAcceptDrops(movable);#endif    d->clear();    d->doDelayedItemsLayout();}QListView::ViewMode QListView::viewMode() const{    Q_D(const QListView);    return d->viewMode;}/*!    Clears the QListView-specific property flags. See \l{viewMode}.    Properties inherited from QAbstractItemView are not covered by the    property flags. Specifically, \l{dragEnabled} and \l{acceptDrops} are    computed by QListView when calling setMovement() or setViewMode().*/void QListView::clearPropertyFlags(){    Q_D(QListView);    d->modeProperties = 0;}/*!    Returns true if the \a row is hidden; otherwise returns false.*/bool QListView::isRowHidden(int row) const{    Q_D(const QListView);    return d->hiddenRows.contains(row);}/*!    If \a hide is true, the given \a row will be hidden; otherwise    the \a row will be shown.*/void QListView::setRowHidden(int row, bool hide){    Q_D(QListView);    const bool hidden = d->hiddenRows.contains(row);    if (d->viewMode == ListMode) {        if (hide && !hidden)            d->hiddenRows.append(row);        else if (!hide && hidden)            d->hiddenRows.remove(d->hiddenRows.indexOf(row));        d->doDelayedItemsLayout();    } else {        if (hide && !hidden) {            d->dynamicListView->removeItem(row);            d->hiddenRows.append(row);        } else if (!hide && hidden) {            d->hiddenRows.remove(d->hiddenRows.indexOf(row));            d->dynamicListView->insertItem(row);        }        if (d->resizeMode == Adjust)            d->doDelayedItemsLayout();        d->viewport->update();    }}/*!  \reimp*/QRect QListView::visualRect(const QModelIndex &index) const{    Q_D(const QListView);    return d->mapToViewport(rectForIndex(index), d->viewMode == QListView::ListMode);}/*!  \reimp*/void QListView::scrollTo(const QModelIndex &index, ScrollHint hint){    Q_D(QListView);    if (index.parent() != d->root || index.column() != d->column)        return;    const QRect rect = visualRect(index);    if (hint == EnsureVisible && d->viewport->rect().contains(rect)) {        d->setDirtyRegion(rect);        return;    }    if (d->flow == QListView::TopToBottom || d->isWrapping()) // vertical        verticalScrollBar()->setValue(d->verticalScrollToValue(index, rect, hint));    if (d->flow == QListView::LeftToRight || d->isWrapping()) // horizontal        horizontalScrollBar()->setValue(d->horizontalScrollToValue(index, rect, hint));}int QListViewPrivate::horizontalScrollToValue(const QModelIndex &index, const QRect &rect,                                              QListView::ScrollHint hint) const{    Q_Q(const QListView);    const QRect area = viewport->rect();    const bool leftOf = q->isRightToLeft()                        ? (rect.left() < area.left()) && (rect.right() < area.right())                        : rect.left() < area.left();    const bool rightOf = q->isRightToLeft()                         ? rect.right() > area.right()                         : (rect.right() > area.right()) && (rect.left() > area.left());    int horizontalValue = q->horizontalScrollBar()->value();    // ScrollPerItem    if (q->horizontalScrollMode() == QAbstractItemView::ScrollPerItem && viewMode == QListView::ListMode) {        const QListViewItem item = indexToListViewItem(index);        const QRect rect = q->visualRect(index);        horizontalValue = staticListView->horizontalPerItemValue(itemIndex(item),                                                                horizontalValue, area.width(),                                                                leftOf, rightOf, isWrapping(), hint, rect.width());    } else { // ScrollPerPixel        if (q->isRightToLeft()) {            if (hint == QListView::PositionAtCenter) {                horizontalValue += ((area.width() - rect.width()) / 2) - rect.left();            } else {                if (leftOf)                    horizontalValue -= rect.left();                else if (rightOf)                    horizontalValue += qMin(rect.left(), area.width() - rect.right());            }       } else {            if (hint == QListView::PositionAtCenter) {                horizontalValue += rect.left() - ((area.width()- rect.width()) / 2);            } else {                if (leftOf)                    horizontalValue += rect.left();                else if (rightOf)                    horizontalValue += qMin(rect.left(), rect.right() - area.width());            }        }    }    return horizontalValue;}int QListViewPrivate::verticalScrollToValue(const QModelIndex &index, const QRect &rect,                                            QListView::ScrollHint hint) const{    Q_Q(const QListView);    const QRect area = viewport->rect();    const bool above = (hint == QListView::EnsureVisible && rect.top() < area.top());    const bool below = (hint == QListView::EnsureVisible && rect.bottom() > area.bottom());    int verticalValue = q->verticalScrollBar()->value();    // ScrollPerItem    if (q->verticalScrollMode() == QAbstractItemView::ScrollPerItem && viewMode == QListView::ListMode) {        const QListViewItem item = indexToListViewItem(index);        const QRect rect = q->visualRect(index);        verticalValue = staticListView->verticalPerItemValue(itemIndex(item),                                                             verticalValue, area.height(),                                                             above, below, isWrapping(), hint, rect.height());    } else { // ScrollPerPixel        if (hint == QListView::PositionAtTop || above)            verticalValue += rect.top();        else if (hint == QListView::PositionAtBottom || below)            verticalValue +=  qMin(rect.top(), rect.bottom() - area.height());        else if (hint == QListView::PositionAtCenter)            verticalValue += rect.top() - ((area.height() - rect.height()) / 2);    }    return verticalValue;}/*!  \internal*/void QListView::reset(){    Q_D(QListView);    d->clear();    d->hiddenRows.clear();    QAbstractItemView::reset();}/*!  \internal*/void QListView::setRootIndex(const QModelIndex &index){    Q_D(QListView);    d->column = qBound(0, d->column, d->model->columnCount(index) - 1);    QAbstractItemView::setRootIndex(index);    // sometimes we get an update before reset() is called    d->clear();    d->hiddenRows.clear();}/*!    \internal    Scroll the view contents by \a dx and \a dy.*/void QListView::scrollContentsBy(int dx, int dy){    Q_D(QListView);    d->delayedAutoScroll.stop(); // auto scroll was canceled by the user scrolling    if (d->viewMode == ListMode)        d->staticListView->scrollContentsBy(dx, dy);    else if (state() == DragSelectingState)        d->scrollElasticBandBy(isRightToLeft() ? -dx : dx, dy);    d->scrollContentsBy(isRightToLeft() ? -dx : dx, dy);    // update the dragged items    if (d->viewMode == IconMode) // ### move to dynamic class    if (!d->dynamicListView->draggedItems.isEmpty())        d->setDirtyRegion(d->dynamicListView->draggedItemsRect().translated(dx, dy));}/*!    \internal    Resize the internal contents to \a width and \a height and set the    scroll bar ranges accordingly.*/void QListView::resizeContents(int width, int height){    Q_D(QListView);    d->setContentsSize(width, height);}/*!    \internal*/QSize QListView::contentsSize() const{    Q_D(const QListView);    return d->contentsSize();}/*!  \reimp*/void QListView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight){    Q_D(QListView);    if (d->viewMode == IconMode)        d->dynamicListView->dataChanged(topLeft, bottomRight);    QAbstractItemView::dataChanged(topLeft, bottomRight);}/*!  \reimp*/void QListView::rowsInserted(const QModelIndex &parent, int start, int end){    Q_D(QListView);    // ### be smarter about inserted items    // if the parent is above d->root in the tree, nothing will happen    if (parent == d->root) {        int count = (end - start + 1);        for (int i = d->hiddenRows.count() - 1; i >= 0; --i)            if (d->hiddenRows.at(i) >= start)                d->hiddenRows[i] += count;    }    d->clear();    d->doDelayedItemsLayout();    QAbstractItemView::rowsInserted(parent, start, end);}/*!  \reimp*/

⌨️ 快捷键说明

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