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

📄 qlistview.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
*/void QListView::clearPropertyFlags(){    Q_D(QListView);    d->modeProperties = 0;}/*!  Returns true if the \a row is hidden, otherwise returns false.  \sa setRowHidden*/bool QListView::isRowHidden(int row) const{    Q_D(const QListView);    return d->hiddenRows.contains(row);}/*!  If \a hide is true the \a row will be hidden, otherwise the \a row will be shown.*/void QListView::setRowHidden(int row, bool hide){    Q_D(QListView);    if (hide && !isRowHidden(row))        d->hiddenRows.append(row);    else if (!hide && isRowHidden(row))        d->hiddenRows.remove(d->hiddenRows.indexOf(row));    d->doDelayedItemsLayout();}/*!  \reimp*/QRect QListView::visualRect(const QModelIndex &index) const{    if (!index.isValid() || isIndexHidden(index))        return QRect();    Q_D(const QListView);    d->executePostedLayout();    return d->mapToViewport(rectForIndex(index));}/*!  \reimp*/void QListView::scrollTo(const QModelIndex &index, ScrollHint hint){    Q_D(QListView);    if (index.parent() != rootIndex() || index.column() != d->column)        return;    QRect area = d->viewport->rect();    QRect rect = visualRect(index);    if (hint == EnsureVisible && area.contains(rect)) {        d->setDirtyRegion(rect);        return;    }    // vertical    int vy = verticalScrollBar()->value();    bool above = (hint == EnsureVisible && rect.top() < area.top());    bool below = (hint == EnsureVisible && rect.bottom() > area.bottom());    if (hint == PositionAtTop || above)        verticalScrollBar()->setValue(vy + rect.top());    else if (hint == PositionAtBottom || below)        verticalScrollBar()->setValue(vy + rect.bottom() - viewport()->height());    // horizontal    int vx = horizontalScrollBar()->value();    if (isRightToLeft()) {        if ((rect.left() < area.left()) && (rect.right() < area.right())) // left of            horizontalScrollBar()->setValue(vx - rect.left());        else if (rect.right() > area.right()) // right of            horizontalScrollBar()->setValue(vx - rect.right() + viewport()->width());    } else {        if (rect.left() < area.left()) // left of            horizontalScrollBar()->setValue(vx + rect.left());        else if ((rect.right() > area.right()) && (rect.left() > area.left())) // right of            horizontalScrollBar()->setValue(vx + rect.right() - viewport()->width());    }}/*!  \internal*/void QListView::reset(){    Q_D(QListView);    d->clear();    d->hiddenRows.clear();    QAbstractItemView::reset();}/*!  \internal*/void QListView::setRootIndex(const QModelIndex &index){    Q_D(QListView);    if (model())        d->column = qBound(0, d->column, model()->columnCount(index) - 1);    QAbstractItemView::setRootIndex(index);}/*!    \internal    Scroll the view contents by \a dx and \a dy.*/void QListView::scrollContentsBy(int dx, int dy){    Q_D(QListView);    dx = isRightToLeft() ? -dx : dx;    if (state() == DragSelectingState) {        if (dx > 0) // right            d->elasticBand.moveRight(d->elasticBand.right() + dx);        else if (dx < 0) // left            d->elasticBand.moveLeft(d->elasticBand.left() - dx);        if (dy > 0) // down            d->elasticBand.moveBottom(d->elasticBand.bottom() + dy);        else if (dy < 0) // up            d->elasticBand.moveTop(d->elasticBand.top() - dy);    }    d->scrollContentsBy(dx, dy);    // update the dragged items    if (!d->draggedItems.isEmpty())        d->setDirtyRegion(d->draggedItemsRect().translated(dx, dy));}/*!    \internal    Resize the internal contents to \a width and \a height and set the    scrollbar ranges accordingly.*/void QListView::resizeContents(int width, int height){    Q_D(QListView);    d->contentsSize = QSize(width, height);    horizontalScrollBar()->setRange(0, width - viewport()->width() - 1);    verticalScrollBar()->setRange(0, height - viewport()->height() - 1);}/*!    \internal*/QSize QListView::contentsSize() const{    return d_func()->contentsSize;}/*!  \reimp*/void QListView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight){    Q_D(QListView);    if (d->movement != Static        && d->column >= topLeft.column()        && d->column <= bottomRight.column()) {        QStyleOptionViewItem option = viewOptions();        int bottom = qMin(d->items.count(), bottomRight.row() + 1);        for (int row = topLeft.row(); row < bottom; ++row) {            QModelIndex idx = d->model->index(row, d->column, d->root);            d->items[row].resize(d->itemSize(option, idx));        }    }    QAbstractItemView::dataChanged(topLeft, bottomRight);}/*!  \reimp*/void QListView::rowsInserted(const QModelIndex &parent, int start, int end){    Q_D(QListView);    // if the parent is above rootIndex() in the tree, nothing will happen    if (parent == rootIndex()) {        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*/void QListView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end){    Q_D(QListView);    // if the parent is above rootIndex() in the tree, nothing will happen    QAbstractItemView::rowsAboutToBeRemoved(parent, start, end);    if (parent == rootIndex()) {        int count = (end - start + 1);        for (int i = d->hiddenRows.count() - 1; i >= 0; --i) {            if (d->hiddenRows.at(i) > start) {                if (d->hiddenRows.at(i) < end) {                    d->hiddenRows.remove(i);                } else {                    d->hiddenRows[i] -= count;                }            }        }    }    d->clear();    d->doDelayedItemsLayout();}/*!  \reimp*/void QListView::mouseMoveEvent(QMouseEvent *e){    Q_D(QListView);    QAbstractItemView::mouseMoveEvent(e);    if (d->movement != Static        && state() == DragSelectingState        && d->selectionMode != SingleSelection) {        QRect rect(d->pressedPosition, e->pos() + QPoint(horizontalOffset(), verticalOffset()));        rect = rect.normalized();        d->setDirtyRegion(d->mapToViewport(rect.unite(d->elasticBand)));        d->elasticBand = rect;    }}/*!  \reimp*/void QListView::mouseReleaseEvent(QMouseEvent *e){    Q_D(QListView);    QAbstractItemView::mouseReleaseEvent(e);    if (d->elasticBand.isValid()) {        d->setDirtyRegion(d->mapToViewport(d->elasticBand));        d->elasticBand = QRect();    }}/*!  \reimp*/void QListView::timerEvent(QTimerEvent *e){    Q_D(QListView);    if (e->timerId() == d->delayedLayout.timerId()) {        setState(ExpandingState); // showing the scrollbars will trigger a resize event,        doItemsLayout();          // so we set the state to expanding to avoid        setState(NoState);        // triggering another layout    } else if (e->timerId() == d->batchLayoutTimer.timerId()) {        if (d->doItemsLayout(100)) { // layout is done            d->batchLayoutTimer.stop();            updateGeometries();            d->viewport->update();        }    }    QAbstractItemView::timerEvent(e);}/*!  \reimp*/void QListView::resizeEvent(QResizeEvent *e){    Q_D(QListView);    QAbstractItemView::resizeEvent(e);    if (state() == NoState) {        // if we are in adjust mode, post a delayed layout        if (d->resizeMode == Adjust) {            QSize delta = e->size() - e->oldSize();            if (!d->delayedLayout.isActive()                && ((d->flow == LeftToRight && delta.width() != 0)                    || (d->flow == TopToBottom && delta.height() != 0))) {                d->delayedLayout.start(100, this); // wait 1/10 sec before starting the layout            }        }    }}#ifndef QT_NO_DRAGANDDROP/*!  \reimp*/void QListView::dragMoveEvent(QDragMoveEvent *e){    Q_D(QListView);    if (e->source() == this && d->movement != Static) {        // the ignore by default        e->ignore();        if (d->canDecode(e)) {            // get old dragged items rect            QRect itemsRect = d->itemsRect(d->draggedItems);            d->setDirtyRegion(itemsRect.translated(d->draggedItemsDelta()));            // update position            d->draggedItemsPos = e->pos();            // get new items rect            d->setDirtyRegion(itemsRect.translated(d->draggedItemsDelta()));            // set the item under the cursor to current            QModelIndex index = indexAt(e->pos());            // check if we allow drops here            if (e->source() == this && d->draggedItems.contains(index))                e->accept(); // allow changing item position            else if (model()->flags(index) & Qt::ItemIsDropEnabled)                e->accept(); // allow dropping on dropenabled items            else if (!index.isValid())                e->accept(); // allow dropping in empty areas        }        // do autoscrolling        if (d->shouldAutoScroll(e->pos()))            startAutoScroll();    } else { // not internal        QAbstractItemView::dragMoveEvent(e);    }}/*!  \reimp*/void QListView::dragLeaveEvent(QDragLeaveEvent *e){    Q_D(QListView);    if (d->movement != Static) {        d->viewport->update(d->draggedItemsRect()); // erase the area        d->draggedItemsPos = QPoint(-1, -1); // don't draw the dragged items    }    QAbstractItemView::dragLeaveEvent(e);}/*!  \reimp*/void QListView::dropEvent(QDropEvent *e){    Q_D(QListView);    if (e->source() == this && d->movement != Static)        internalDrop(e);    else        QAbstractItemView::dropEvent(e);}/*!  \reimp*/void QListView::startDrag(Qt::DropActions supportedActions){    Q_D(QListView);    if (d->movement != Static)        internalDrag(supportedActions);    else        QAbstractItemView::startDrag(supportedActions);}/*!    \internal    Called whenever items from the view is dropped on the viewport.    The \a event provides additional information.*/void QListView::internalDrop(QDropEvent *event){    Q_D(QListView);    QPoint offset(horizontalOffset(), verticalOffset());    QPoint end = event->pos() + offset;    QPoint start = d->pressedPosition;    QPoint delta = (d->movement == Snap ?                    d->snapToGrid(end) - d->snapToGrid(start) : end - start);    QList<QModelIndex> indexes = selectionModel()->selectedIndexes();    for (int i = 0; i < indexes.count(); ++i) {        QModelIndex index = indexes.at(i);        QRect rect = rectForIndex(index);        d->setDirtyRegion(d->mapToViewport(rect));        QPoint dest = rect.topLeft() + delta;        if (isRightToLeft())            dest.setX(d->flipX(dest.x()) - rect.width());        d->moveItem(index.row(), dest);        d->setDirtyRegion(visualRect(index));    }    stopAutoScroll();    d->draggedItems.clear();    event->accept(); // we have handled the event}/*!    \internal    Called whenever the user starts dragging items and the items are movable,    enabling internal dragging and dropping of items.*/void QListView::internalDrag(Qt::DropActions supportedActions){    // This function does the same thing as in QAbstractItemView::startDrag(),

⌨️ 快捷键说明

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