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

📄 qheaderview.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
bool QHeaderView::isClickable() const{    Q_D(const QHeaderView);    return d->clickableSections;}void QHeaderView::setHighlightSections(bool highlight){    Q_D(QHeaderView);    d->highlightSelected = highlight;}bool QHeaderView::highlightSections() const{    Q_D(const QHeaderView);    return d->highlightSelected;}/*!    Sets the constraints on how the header can be resized to those    described by the given \a mode.    \sa resizeMode(), length(), sectionResized(), sectionAutoResize()*/void QHeaderView::setResizeMode(ResizeMode mode){    Q_D(QHeaderView);    initializeSections();    QHeaderViewPrivate::HeaderSection *sections = d->sections.data();    for (int i = 0; i < d->sections.count(); ++i)        sections[i].mode = mode;    d->stretchSections = (mode == Stretch ? count() : 0);    d->customSections =  (mode == Custom ? count() : 0);    d->globalResizeMode = mode;    if (d->hasAutoResizeSections())        resizeSections(); // section sizes may change as a result of the new mode}/*!    \overload    Sets the constraints on how the section specified by \a logicalIndex    in the header can be resized to those described by the given \a mode.*/void QHeaderView::setResizeMode(int logicalIndex, ResizeMode mode){    Q_D(QHeaderView);    int visual = visualIndex(logicalIndex);    Q_ASSERT(visual != -1);    ResizeMode old = d->sections[visual].mode;    d->sections[visual].mode = mode;    if (mode == Stretch && old != Stretch)        ++d->stretchSections;    else if (mode == Custom && old != Custom)        ++d->customSections;    else if (mode != Stretch && old == Stretch)        --d->stretchSections;    else if (mode != Custom && old == Custom)        --d->customSections;    if (d->hasAutoResizeSections())        resizeSections(); // section sizes may change as a result of the new mode}/*!    Returns the resize mode that applies to the section specified by the given \a logicalIndex.    \sa setResizeMode()*/QHeaderView::ResizeMode QHeaderView::resizeMode(int logicalIndex) const{    Q_D(const QHeaderView);    int visual = visualIndex(logicalIndex);    Q_ASSERT(visual != -1);    return d->sections.at(visual).mode;}/*!    \since 4.1    Returns the number of sections that are set to resize mode stretch.    In views this can be used to see if the headerview needs to resize the sections when the view geometry changes.    \sa stretchLastSection, resizeMode()*/int QHeaderView::stretchSectionCount() const{    Q_D(const QHeaderView);    return d->stretchSections;}/*!  \property QHeaderView::showSortIndicator  \brief whether the sort indicator is shown  \sa setClickable()*/void QHeaderView::setSortIndicatorShown(bool show){    Q_D(QHeaderView);    d->sortIndicatorShown = show;    if (sortIndicatorSection() < 0 || sortIndicatorSection() > count())        return;    if (d->sections.size() > sortIndicatorSection()        && d->sections.at(sortIndicatorSection()).mode == Custom) {        resizeSections();        d->viewport->update();    }}bool QHeaderView::isSortIndicatorShown() const{    Q_D(const QHeaderView);    return d->sortIndicatorShown;}/*!    Sets the sort indicator for the section specified by the given \a logicalIndex in the direction    specified by \a order, and removes the sort indicator from any    other section that was showing it.    \sa sortIndicatorSection() sortIndicatorOrder()*/void QHeaderView::setSortIndicator(int logicalIndex, Qt::SortOrder order){    Q_D(QHeaderView);    Q_ASSERT(logicalIndex >= 0);    // This is so that people can set the position of the sort indicator before the fill the model    int old = d->sortIndicatorSection;    d->sortIndicatorSection = logicalIndex;    d->sortIndicatorOrder = order;    if (logicalIndex >= d->sections.count() - 1)        return; // nothing to do    if (old != logicalIndex && resizeMode(logicalIndex) == Custom) {        resizeSections();        d->viewport->update();    } else {        if (old != logicalIndex)            updateSection(old);        updateSection(logicalIndex);    }}/*!    Returns the logical index of the section that has a sort    indicator. By default this is section 0.    \sa setSortIndicator() sortIndicatorOrder() setSortIndicatorShown()*/int QHeaderView::sortIndicatorSection() const{    Q_D(const QHeaderView);    return d->sortIndicatorSection;}/*!    Returns the order for the sort indicator. If no section has a sort    indicator the return value of this function is undefined.    \sa setSortIndicator() sortIndicatorSection()*/Qt::SortOrder QHeaderView::sortIndicatorOrder() const{    Q_D(const QHeaderView);    return d->sortIndicatorOrder;}/*!    \property QHeaderView::stretchLastSection    \brief whether the last visible section in the header takes up all the available space.  The default value is false.    \sa setResizeMode()*/bool QHeaderView::stretchLastSection() const{    Q_D(const QHeaderView);    return d->stretchLastSection;}void QHeaderView::setStretchLastSection(bool stretch){    Q_D(QHeaderView);    d->stretchLastSection = stretch;    if (stretch)        resizeSections();    else if (count())        resizeSection(count() - 1, d->defaultSectionSize);}/*!    \property QHeaderView::defaultSectionSize    \brief the default size of the header sections before resizing.*/int QHeaderView::defaultSectionSize() const{    Q_D(const QHeaderView);    return d->defaultSectionSize;}void QHeaderView::setDefaultSectionSize(int size){    Q_D(QHeaderView);    d->defaultSectionSize = size;}Qt::Alignment QHeaderView::defaultAlignment() const{    Q_D(const QHeaderView);    return d->defaultAlignment;}/*!    \since 4.1    \property QHeaderView::defaultAlignment    \brief the default alignment of the text in each header section*/void QHeaderView::setDefaultAlignment(Qt::Alignment alignment){    Q_D(QHeaderView);    d->defaultAlignment = alignment;}/*!    \internal*/void QHeaderView::doItemsLayout(){    initializeSections();    QAbstractItemView::doItemsLayout();}/*!  Returns true if sections in the header has been moved;  otherwise returns false;  \sa moveSection()*/bool QHeaderView::sectionsMoved() const{    Q_D(const QHeaderView);    return !d->visualIndices.isEmpty();}/*!    \since 4.1    Returns true if sections in the header has been hidden;    otherwise returns false;    \sa setSectionHidden()*/bool QHeaderView::sectionsHidden() const{    Q_D(const QHeaderView);    return !d->hiddenSectionSize.isEmpty();}/*!  Updates the changed header sections with the given \a orientation, from  \a logicalFirst to \a logicalLast inclusive.*/void QHeaderView::headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast){    Q_D(QHeaderView);    if (d->orientation != orientation)        return;    // Before initilization the size isn't set    if (count() == 0)        return;    Q_ASSERT(logicalFirst >= 0);    Q_ASSERT(logicalLast >= 0);    Q_ASSERT(logicalFirst < count());    Q_ASSERT(logicalLast < count());    d->invalidateCachedSizeHint();    if (orientation == Qt::Horizontal) {        int left = sectionViewportPosition(logicalFirst);        int right = sectionViewportPosition(logicalLast);        right += sectionSize(logicalLast);        d->viewport->update(left, 0, right - left, d->viewport->height());    } else {        int top = sectionViewportPosition(logicalFirst);        int bottom = sectionViewportPosition(logicalLast);        bottom += sectionSize(logicalLast);        d->viewport->update(0, top, d->viewport->width(), bottom - top);    }}/*!    \internal    Updates the section specified by the given \a logicalIndex.*/void QHeaderView::updateSection(int logicalIndex){    Q_D(QHeaderView);    if (orientation() == Qt::Horizontal)        d->viewport->update(QRect(sectionViewportPosition(logicalIndex),                                  0, sectionSize(logicalIndex), d->viewport->height()));    else        d->viewport->update(QRect(0, sectionViewportPosition(logicalIndex),                                  d->viewport->width(), sectionSize(logicalIndex)));}/*!    \internal    Resizes the sections according to their size hints. You should not    normally need to call this function.*/void QHeaderView::resizeSections(){    Q_D(QHeaderView);    if (d->hasAutoResizeSections())        d->resizeSections(Interactive, false); // no global resize mode}/*!    This slot is called when sections are inserted into the \a parent,    \a logicalFirst and \a logicalLast indexes signify where the new    sections are inserted.    \a logicalFirst and \a logicalLast will be the same if just one    section is inserted.*/void QHeaderView::sectionsInserted(const QModelIndex &parent, int logicalFirst, int){    Q_D(QHeaderView);    if (parent != rootIndex() || !d->model)        return; // we only handle changes in the top level    if (d->orientation == Qt::Horizontal)        initializeSections(logicalFirst, qMax(d->model->columnCount(rootIndex())-1, 0));    else        initializeSections(logicalFirst, qMax(d->model->rowCount(rootIndex())-1, 0));    d->invalidateCachedSizeHint();}/*!    This slot is called when sections are removed from the \a parent,    \a logicalFirst and \a logicalLast signify where the sections are removed    from. (\a logicalFirst and \a logicalLast will be the same if just one section    is removed.)*/void QHeaderView::sectionsAboutToBeRemoved(const QModelIndex &parent,                                           int logicalFirst, int logicalLast){    Q_UNUSED(parent);    Q_UNUSED(logicalFirst);    Q_UNUSED(logicalLast);}void QHeaderViewPrivate::_q_sectionsRemoved(const QModelIndex &parent,                                           int logicalFirst, int logicalLast){    Q_Q(QHeaderView);    if (parent != q->rootIndex() || !model)        return; // we only handle changes in the top level    if (qMin(logicalFirst, logicalLast) < 0        || qMax(logicalLast, logicalFirst) >= sections.count() - 1)        return; // should could assert here, but since models could emit signals with strange args, we are a bit forgiving    int oldCount = q->count();    int changeCount = logicalLast - logicalFirst + 1;    if (visualIndices.isEmpty() && logicalIndices.isEmpty()) {        int delta = sections.at(logicalLast + 1).position                    - sections.at(logicalFirst).position;        for (int i = logicalLast + 1; i < sections.count(); ++i)            sections[i].position -= delta;        sections.remove(logicalFirst, changeCount);        for (int i = logicalFirst; i <= changeCount+logicalFirst; ++i)            hiddenSectionSize.remove(i);    } else {        for (int l = logicalLast; l >= logicalFirst; --l) {            int visual = visualIndices.at(l);            int size = sections.at(visual + 1).position - sections.at(visual).position;            for (int v = 0; v < sections.count(); ++v) {                if (logicalIndex(v) > l)                    --(logicalIndices[v]);                if (v > visual) {                    sections[v].position -= size;                    int logical = logicalIndex(v);                    --(visualIndices[logical]);                }            }            sections.remove(visual);            hiddenSectionSize.remove(l);            logicalIndices.remove(visual);            visualIndices.remove(l);        }    }    // if we only have the last section (the "end" position) left, the header is empty    if (sections.count() == 1)        clear();    invalidateCachedSizeHint();    emit q->sectionCountChanged(oldCount, q->count());    viewport->update();}/*!  \internal*/void QHeaderView::initializeSections(){    Q_D(QHeaderView);    if (!model())        return;    if (d->orientation == Qt::Horizontal) {        int c = model()->columnCount(rootIndex());        if (c == 0) {            int oldCount = count();            d->clear();

⌨️ 快捷键说明

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