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

📄 qtableview.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            if (range.parent() != rootIndex() || !range.isValid())                continue;            for (int r = range.top(); r <= range.bottom(); ++r)                for (int c = range.left(); c <= range.right(); ++c)                    selectionRegion += QRegion(visualRect(d->model->index(r, c, rootIndex())));        }    } else if (horizontalMoved) {        for (int i = 0; i < selection.count(); ++i) {            QItemSelectionRange range = selection.at(i);            if (range.parent() != rootIndex() || !range.isValid())                continue;            int top = rowViewportPosition(range.top());            int bottom = rowViewportPosition(range.bottom()) + rowHeight(range.bottom());            if (top > bottom)                qSwap<int>(top, bottom);            int height = bottom - top;            for (int c = range.left(); c <= range.right(); ++c)                selectionRegion += QRegion(QRect(columnViewportPosition(c), top,                                                 columnWidth(c), height));        }    } else if (verticalMoved) {        for (int i = 0; i < selection.count(); ++i) {            QItemSelectionRange range = selection.at(i);            if (range.parent() != rootIndex() || !range.isValid())                continue;            int left = columnViewportPosition(range.left());            int right = columnViewportPosition(range.right()) + columnWidth(range.right());            if (left > right)                qSwap<int>(left, right);            int width = right - left;            for (int r = range.top(); r <= range.bottom(); ++r)                selectionRegion += QRegion(QRect(left, rowViewportPosition(r),                                                 width, rowHeight(r)));        }    } else { // nothing moved        for (int i = 0; i < selection.count(); ++i) {            QItemSelectionRange range = selection.at(i);            if (range.parent() != rootIndex() || !range.isValid())                continue;            d->trimHiddenSelections(&range);            QRect tl = visualRect(range.topLeft());            QRect br = visualRect(range.bottomRight());            selectionRegion += QRegion(tl|br);        }    }    return selectionRegion;}/*!  \reimp*/QModelIndexList QTableView::selectedIndexes() const{    QModelIndexList viewSelected;    QModelIndexList modelSelected;    if (selectionModel())        modelSelected = selectionModel()->selectedIndexes();    for (int i = 0; i < modelSelected.count(); ++i) {        QModelIndex index = modelSelected.at(i);        if (!isIndexHidden(index) && index.parent() == rootIndex())            viewSelected.append(index);    }    return viewSelected;}/*!    This slot is called whenever rows are added or deleted. The    previous number of rows is specified by \a oldCount, and the new    number of rows is specified by \a newCount.*/void QTableView::rowCountChanged(int /*oldCount*/, int /*newCount*/ ){    updateGeometries();    d_func()->viewport->update();}/*!    This slot is called whenever columns are added or deleted. The    previous number of columns is specified by \a oldCount, and the new    number of columns is specified by \a newCount.*/void QTableView::columnCountChanged(int, int){    updateGeometries();    d_func()->viewport->update();}/*!    \internal*/void QTableView::updateGeometries(){    Q_D(QTableView);    int width = !d->verticalHeader->isHidden() ? d->verticalHeader->sizeHint().width() : 0;    int height = !d->horizontalHeader->isHidden() ? d->horizontalHeader->sizeHint().height() : 0;    bool reverse = isRightToLeft();    setViewportMargins(reverse ? 0 : width, height, reverse ? width : 0, 0);    // update headers    QRect vg = d->viewport->geometry();    int verticalLeft = reverse ? vg.right() : (vg.left() - width);    d->verticalHeader->setGeometry(verticalLeft, vg.top(), width, vg.height());    if (d->verticalHeader->isHidden())        QMetaObject::invokeMethod(d->verticalHeader, "updateGeometries");    d->verticalHeader->setOffset(verticalScrollBar()->value());    int horizontalTop = vg.top() - height;    d->horizontalHeader->setGeometry(vg.left(), horizontalTop, vg.width(), height);    if (d->horizontalHeader->isHidden())        QMetaObject::invokeMethod(d->horizontalHeader, "updateGeometries");    d->horizontalHeader->setOffset(horizontalScrollBar()->value());    // update scrollbars    int horizontalLength = d->horizontalHeader->length();    int verticalLength = d->verticalHeader->length();    QSize vsize = d->viewport->size();    QSize max = maximumViewportSize();    if (max.width() >= horizontalLength && max.height() >= verticalLength)        vsize = max;    verticalScrollBar()->setPageStep(vsize.height());    verticalScrollBar()->setRange(0, verticalLength - vsize.height());    horizontalScrollBar()->setPageStep(vsize.width());    horizontalScrollBar()->setRange(0, horizontalLength - vsize.width());    QAbstractItemView::updateGeometries();}/*!    Returns the size hint for the given \a row's height or -1 if there    is no model.    If you need to set the height of a given row to a fixed value, call    QHeaderView::resizeSection() on the table's vertical header.    If you reimplement this function in a subclass, note that the value you    return is only used when resizeRowToContents() is called. In that case,    if a larger row height is required by either the vertical header or    the item delegate, that width will be used instead.    \sa QWidget::sizeHint, verticalHeader()*/int QTableView::sizeHintForRow(int row) const{    Q_D(const QTableView);    if (!model())        return -1;    int left = qMax(0, columnAt(0));    int right = columnAt(d->viewport->width());    if (right == -1) // the table don't have enought columns to fill the viewport        right = model()->columnCount(rootIndex()) - 1;    QStyleOptionViewItem option = viewOptions();    int hint = 0;    QModelIndex index;    for (int column = left; column <= right; ++column) {        index = d->model->index(row, column, rootIndex());        hint = qMax(hint, itemDelegate()->sizeHint(option, index).height());    }    return d->showGrid ? hint + 1 : hint;}/*!    Returns the size hint for the given \a column's width or -1 if    there is no model.    If you need to set the width of a given column to a fixed value, call    QHeaderView::resizeSection() on the table's horizontal header.    If you reimplement this function in a subclass, note that the value you    return is only used when resizeColumnToContents() is called. In that case,    if a larger column width is required by either the horizontal header or    the item delegate, that width will be used instead.    \sa QWidget::sizeHint, horizontalHeader()*/int QTableView::sizeHintForColumn(int column) const{    Q_D(const QTableView);    if (!model())        return -1;    int top = qMax(0, rowAt(0));    int bottom = rowAt(d->viewport->height());    if (!isVisible() || bottom == -1) // the table don't have enought rows to fill the viewport        bottom = model()->rowCount(rootIndex()) - 1;    QStyleOptionViewItem option = viewOptions();    int hint = 0;    QModelIndex index;    for (int row = top; row <= bottom; ++row) {        index = d->model->index(row, column, rootIndex());        hint = qMax(hint, itemDelegate()->sizeHint(option, index).width());    }    return d->showGrid ? hint + 1 : hint;}/*!    Returns the y-coordinate in contents coordinates of the given \a    row.*/int QTableView::rowViewportPosition(int row) const{    return d_func()->verticalHeader->sectionViewportPosition(row);}/*!    Returns the row in which the given y-coordinate, \a y, in contents    coordinates is located.    \sa columnAt()*/int QTableView::rowAt(int y) const{    return d_func()->verticalHeader->logicalIndexAt(y);}/*!    \since 4.1    Sets the height of the given \a row to be \a height.*/void QTableView::setRowHeight(int row, int height){    d_func()->verticalHeader->resizeSection(row, height);}/*!    Returns the height of the given \a row.    \sa resizeRowToContents(), columnWidth()*/int QTableView::rowHeight(int row) const{    return d_func()->verticalHeader->sectionSize(row);}/*!    Returns the x-coordinate in contents coordinates of the given \a    column.*/int QTableView::columnViewportPosition(int column) const{    return d_func()->horizontalHeader->sectionViewportPosition(column);}/*!    Returns the column in which the given x-coordinate, \a x, in contents    coordinates is located.    \sa rowAt()*/int QTableView::columnAt(int x) const{    return d_func()->horizontalHeader->logicalIndexAt(x);}/*!    \since 4.1    Sets the width of the given \a column to be \a width.*/void QTableView::setColumnWidth(int column, int width){    d_func()->horizontalHeader->resizeSection(column, width);}/*!    Returns the width of the given \a column.    \sa resizeColumnToContents(), rowHeight()*/int QTableView::columnWidth(int column) const{    return d_func()->horizontalHeader->sectionSize(column);}/*!    Returns true if the given \a row is hidden; otherwise returns false.    \sa isColumnHidden()*/bool QTableView::isRowHidden(int row) const{    return d_func()->verticalHeader->isSectionHidden(row);}/*!    If \a hide is true \a row will be hidden, otherwise it will be shown.    \sa setColumnHidden()*/void QTableView::setRowHidden(int row, bool hide){    if (row < 0 || row >= d_func()->verticalHeader->count())        return;    d_func()->verticalHeader->setSectionHidden(row, hide);}/*!    Returns true if the given \a column is hidden; otherwise returns false.    \sa isRowHidden()*/bool QTableView::isColumnHidden(int column) const{    return d_func()->horizontalHeader->isSectionHidden(column);}/*!  If \a hide is true the given \a column will be hidden; otherwise it  will be shown.  \sa setRowHidden()*/void QTableView::setColumnHidden(int column, bool hide){    if (column < 0 || column >= d_func()->horizontalHeader->count())        return;    d_func()->horizontalHeader->setSectionHidden(column, hide);}/*!    \property QTableView::showGrid    \brief whether the grid is shown    If this property is true a grid is drawn for the table; if the    property is false, no grid is drawn. The default value is true.*/bool QTableView::showGrid() const{    return d_func()->showGrid;}void QTableView::setShowGrid(bool show){    if (d_func()->showGrid != show) {        d_func()->showGrid = show;        d_func()->viewport->update();    }}/*!  \property QTableView::gridStyle  \brief  the pen style used to draw the grid.  This property holds the style used when drawing the grid (see \l{showGrid}).*/Qt::PenStyle QTableView::gridStyle() const{    return d_func()->gridStyle;}void QTableView::setGridStyle(Qt::PenStyle style){    if (d_func()->gridStyle != style) {        d_func()->gridStyle = style;        d_func()->viewport->update();    }

⌨️ 快捷键说明

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