22#if QT_CONFIG(whatsthis)
25#include <private/qheaderview_p.h>
26#include <private/qabstractitemmodel_p.h>
27#include <private/qabstractitemdelegate_p.h>
29#ifndef QT_NO_DATASTREAM
35#ifndef QT_NO_DATASTREAM
310 d->viewport->setMouseTracking(
true);
313 delete d->itemDelegate;
324 d->layoutChangePersistentSections.clear();
408 return d->orientation;
435 if (
d->offset == (
int)newOffset)
437 int ndelta =
d->offset - newOffset;
438 d->offset = newOffset;
440 d->viewport->scroll(isRightToLeft() ? -ndelta : ndelta, 0);
442 d->viewport->scroll(0, ndelta);
449 d->firstPos += ndelta;
450 d->lastPos += ndelta;
465 if (visualSectionNumber > -1 && visualSectionNumber < d->sectionCount()) {
466 int position =
d->headerSectionPosition(
d->adjustedVisualIndex(visualSectionNumber));
494 d->executePostedLayout();
495 d->executePostedResize();
509 if (
d->cachedSizeHint.isValid())
510 return d->cachedSizeHint;
511 d->cachedSizeHint =
QSize(0, 0);
512 const int sectionCount =
count();
516 for (
int checked = 0; checked < 100 &&
i < sectionCount; ++
i) {
521 d->cachedSizeHint =
d->cachedSizeHint.expandedTo(
hint);
524 i =
qMax(
i, sectionCount - 100 );
525 for (
int j = sectionCount - 1, checked = 0;
j >=
i && checked < 100; --
j) {
530 d->cachedSizeHint =
d->cachedSizeHint.expandedTo(
hint);
532 return d->cachedSizeHint;
542 QAbstractItemView::setVisible(
v);
544 QAbstractScrollArea *
parent = qobject_cast<QAbstractScrollArea*>(parentWidget());
563 if (logicalIndex < 0 || logicalIndex >=
count())
586 d->executePostedLayout();
587 d->executePostedResize();
588 const int count =
d->sectionCount();
593 vposition =
d->viewport->width() - vposition - 1;
594 vposition +=
d->offset;
596 if (vposition >
d->length)
598 int visual =
d->headerVisualIndexAt(vposition);
602 while (
d->isVisualIndexHidden(visual)){
636 if (logicalIndex < 0 || logicalIndex >=
count())
641 d->executePostedResize();
642 return d->headerSectionSize(visual);
664 d->executePostedResize();
665 return d->headerSectionPosition(visual);
684 int offsetPosition =
position -
d->offset;
687 return offsetPosition;
708template<
typename Container>
710 typename Container::size_type rangeStart,
711 typename Container::size_type rangeEnd,
712 typename Container::size_type targetPosition)
715 Q_ASSERT(targetPosition < rangeStart || targetPosition >= rangeEnd);
717 const bool forwardMove = targetPosition > rangeStart;
718 typename Container::size_type
first = std::min(rangeStart, targetPosition);
719 typename Container::size_type mid = forwardMove ? rangeEnd : rangeStart;
720 typename Container::size_type last = forwardMove ? targetPosition + 1 : rangeEnd;
721 std::rotate(
c.begin() +
first,
c.begin() + mid,
c.begin() + last);
734 d->executePostedLayout();
735 if (from < 0 || from >=
d->sectionCount() || to < 0 || to >=
d->sectionCount())
745 d->initializeIndexMapping();
747 int *visualIndices =
d->visualIndices.data();
748 int *logicalIndices =
d->logicalIndices.data();
749 int logical = logicalIndices[from];
753 while (visual < to) {
754 visualIndices[logicalIndices[visual + 1]] = visual;
755 logicalIndices[visual] = logicalIndices[visual + 1];
759 while (visual > to) {
760 visualIndices[logicalIndices[visual - 1]] = visual;
761 logicalIndices[visual] = logicalIndices[visual - 1];
765 visualIndices[logical] = to;
766 logicalIndices[to] = logical;
770 d->sectionStartposRecalc =
true;
772 if (
d->hasAutoResizeSections())
773 d->doDelayedResizeSections();
774 d->viewport->update();
779 const int lastSectionVisualIdx =
visualIndex(
d->lastSectionLogicalIdx);
780 if (from >= lastSectionVisualIdx || to >= lastSectionVisualIdx)
781 d->maybeRestorePrevLastSectionAndStretchLast();
798 d->executePostedLayout();
799 if (first < 0 || first >=
d->sectionCount() || second < 0 || second >=
d->sectionCount())
802 int firstSize =
d->headerSectionSize(
first);
804 int firstLogical =
d->logicalIndex(
first);
806 int secondSize =
d->headerSectionSize(second);
807 ResizeMode secondMode =
d->headerSectionResizeMode(second);
808 int secondLogical =
d->logicalIndex(second);
811 d->preventCursorChangeInSetOffset =
true;
813 d->createSectionItems(second, second, firstSize, firstMode);
814 d->createSectionItems(
first,
first, secondSize, secondMode);
816 d->initializeIndexMapping();
818 d->visualIndices[firstLogical] = second;
819 d->logicalIndices[second] = firstLogical;
821 d->visualIndices[secondLogical] =
first;
822 d->logicalIndices[
first] = secondLogical;
824 if (!
d->hiddenSectionSize.isEmpty()) {
825 bool firstHidden =
d->isVisualIndexHidden(
first);
826 bool secondHidden =
d->isVisualIndexHidden(second);
827 d->setVisualIndexHidden(
first, secondHidden);
828 d->setVisualIndexHidden(second, firstHidden);
831 d->viewport->update();
836 const int lastSectionVisualIdx =
visualIndex(
d->lastSectionLogicalIdx);
837 if (
first >= lastSectionVisualIdx || second >= lastSectionVisualIdx)
838 d->maybeRestorePrevLastSectionAndStretchLast();
864 d->hiddenSectionSize.insert(logical,
size);
873 d->preventCursorChangeInSetOffset =
true;
875 int oldSize =
d->headerSectionSize(visual);
879 d->executePostedLayout();
880 d->invalidateCachedSizeHint();
883 d->lastSectionSize =
size;
885 d->createSectionItems(visual, visual,
size,
d->headerSectionResizeMode(visual));
887 if (!updatesEnabled()) {
888 if (
d->hasAutoResizeSections())
889 d->doDelayedResizeSections();
894 int w =
d->viewport->width();
895 int h =
d->viewport->height();
906 if (
d->hasAutoResizeSections()) {
907 d->doDelayedResizeSections();
908 r =
d->viewport->rect();
918 QAbstractScrollArea *
parent = qobject_cast<QAbstractScrollArea *>(parentWidget());
919 if (
parent &&
parent->sizeAdjustPolicy() == QAbstractScrollArea::AdjustToContents)
922 d->viewport->update(
r.normalized());
936 d->resizeSections(
mode,
true);
965 d->executePostedLayout();
966 if (
d->hiddenSectionSize.isEmpty() || logicalIndex < 0 || logicalIndex >=
d->sectionCount())
970 return d->isVisualIndexHidden(visual);
983 return d->hiddenSectionSize.size();
996 if (logicalIndex < 0 || logicalIndex >=
count())
999 d->executePostedLayout();
1002 if (
hide ==
d->isVisualIndexHidden(visual))
1006 if (isHidingLastSection)
1007 d->restoreSizeOnPrevLastSection();
1008 int size =
d->headerSectionSize(visual);
1009 if (!
d->hasAutoResizeSections())
1012 d->setVisualIndexHidden(visual,
true);
1013 if (isHidingLastSection)
1014 d->setNewLastSection(
d->lastVisibleVisualIndex());
1015 if (
d->hasAutoResizeSections())
1016 d->doDelayedResizeSections();
1020 d->setVisualIndexHidden(visual,
false);
1024 if (newLastSection) {
1025 d->restoreSizeOnPrevLastSection();
1026 d->setNewLastSection(visual);
1042 d->executePostedLayout();
1043 return d->sectionCount();
1060 d->executePostedLayout();
1061 if (
d->visualIndices.isEmpty()) {
1062 if (logicalIndex < d->sectionCount())
1064 }
else if (logicalIndex < d->visualIndices.size()) {
1066 Q_ASSERT(visual < d->sectionCount());
1084 if (visualIndex < 0 || visualIndex >=
d->sectionCount())
1106 d->movableSections = movable;
1124 return d->movableSections;
1154 d->allowUserMoveOfSection0 = movable;
1160 return d->allowUserMoveOfSection0;
1175 d->clickableSections = clickable;
1191 return d->clickableSections;
1197 d->highlightSelected = highlight;
1203 return d->highlightSelected;
1221 d->setGlobalHeaderResizeMode(
mode);
1222 if (
d->hasAutoResizeSections())
1223 d->doDelayedResizeSections();
1246 ResizeMode old =
d->headerSectionResizeMode(visual);
1247 d->setHeaderSectionResizeMode(visual,
mode);
1250 ++
d->stretchSections;
1252 ++
d->contentsSections;
1254 --
d->stretchSections;
1256 --
d->contentsSections;
1259 d->doDelayedResizeSections();
1277 return d->headerSectionResizeMode(visual);
1319 return d->resizeContentsPrecision;
1335 return d->stretchSections;
1350 if (
d->sortIndicatorShown ==
show)
1353 d->sortIndicatorShown =
show;
1361 d->viewport->update();
1367 return d->sortIndicatorShown;
1387 int old =
d->sortIndicatorSection;
1391 d->sortIndicatorOrder =
order;
1402 d->viewport->update();
1423 return d->sortIndicatorSection;
1436 return d->sortIndicatorOrder;
1462 if (
d->sortIndicatorClearable == clearable)
1464 d->sortIndicatorClearable = clearable;
1471 return d->sortIndicatorClearable;
1492 return d->stretchLastSection;
1498 if (
d->stretchLastSection == stretch)
1500 d->stretchLastSection = stretch;
1504 d->setNewLastSection(
d->lastVisibleVisualIndex());
1507 d->restoreSizeOnPrevLastSection();
1528 return d->cascadingResizing;
1534 d->cascadingResizing =
enable;
1554 return d->defaultSectionSize;
1562 d->setDefaultSectionSize(
size);
1568 if (
d->customDefaultSectionSize) {
1569 d->updateDefaultSectionSizeFromStyle();
1570 d->customDefaultSectionSize =
false;
1590 if (
d->minimumSectionSize == -1) {
1596 return d->minimumSectionSize;
1605 const bool needSizeCheck =
size >
d->minimumSectionSize;
1606 d->minimumSectionSize =
size;
1610 if (needSizeCheck) {
1611 if (
d->hasAutoResizeSections()) {
1612 d->doDelayedResizeSections();
1614 for (
int visual = 0; visual <
d->sectionCount(); ++visual) {
1615 if (
d->isVisualIndexHidden(visual))
1617 if (
d->headerSectionSize(visual) <
d->minimumSectionSize)
1642 if (
d->maximumSectionSize == -1)
1644 return d->maximumSectionSize;
1657 d->minimumSectionSize =
size;
1660 const bool needSizeCheck =
size <
d->maximumSectionSize;
1661 d->maximumSectionSize =
size;
1663 if (needSizeCheck) {
1664 if (
d->hasAutoResizeSections()) {
1665 d->doDelayedResizeSections();
1667 for (
int visual = 0; visual <
d->sectionCount(); ++visual) {
1668 if (
d->isVisualIndexHidden(visual))
1670 if (
d->headerSectionSize(visual) >
d->maximumSectionSize)
1687 return d->defaultAlignment;
1697 d->viewport->update();
1718 return !
d->visualIndices.isEmpty();
1732 return !
d->hiddenSectionSize.isEmpty();
1735#ifndef QT_NO_DATASTREAM
1768 if (
state.isEmpty())
1775 stream.setVersion(dataStreamVersion);
1788 d->viewport->update();
1807 d->invalidateCachedSizeHint();
1820 if (logicalFirst < 0 || logicalLast < 0 || logicalFirst >=
count() || logicalLast >=
count())
1823 d->invalidateCachedSizeHint();
1825 int firstVisualIndex = INT_MAX, lastVisualIndex = -1;
1827 for (
int section = logicalFirst; section <= logicalLast; ++section) {
1829 firstVisualIndex =
qMin(firstVisualIndex, visual);
1830 lastVisualIndex =
qMax(lastVisualIndex, visual);
1833 d->executePostedResize();
1834 const int first =
d->headerSectionPosition(firstVisualIndex),
1835 last =
d->headerSectionPosition(lastVisualIndex)
1836 +
d->headerSectionSize(lastVisualIndex);
1839 d->viewport->update(
first, 0, last -
first,
d->viewport->height());
1841 d->viewport->update(0,
first,
d->viewport->width(), last -
first);
1871 if (
d->hasAutoResizeSections())
1885 int logicalFirst,
int logicalLast)
1889 if (
parent !=
d->root ||
d->modelSectionCount() ==
d->sectionCount())
1891 int oldCount =
d->sectionCount();
1893 d->invalidateCachedSizeHint();
1896 d->preventCursorChangeInSetOffset =
true;
1899 int insertAt = logicalFirst;
1900 int insertCount = logicalLast - logicalFirst + 1;
1902 bool lastSectionActualChange =
false;
1905 int visualIndexForStretch =
d->lastSectionLogicalIdx;
1906 if (
d->lastSectionLogicalIdx >= 0 &&
d->lastSectionLogicalIdx <
d->visualIndices.size())
1907 visualIndexForStretch =
d->visualIndices[
d->lastSectionLogicalIdx];
1910 if (
d->lastSectionLogicalIdx < 0 || insertAt >= visualIndexForStretch)
1911 lastSectionActualChange =
true;
1913 if (
d->lastSectionLogicalIdx >= logicalFirst)
1914 d->lastSectionLogicalIdx += insertCount;
1918 d->sectionStartposRecalc =
true;
1920 if (
d->sectionItems.isEmpty() || insertAt >=
d->sectionItems.size()) {
1921 int insertLength =
d->defaultSectionSize * insertCount;
1922 d->length += insertLength;
1923 d->sectionItems.insert(
d->sectionItems.size(), insertCount, section);
1926 int insertLength =
d->defaultSectionSize * insertCount;
1927 d->length += insertLength;
1928 d->sectionItems.insert(insertAt, insertCount, section);
1932 if (
d->sortIndicatorSection >= logicalFirst)
1933 d->sortIndicatorSection += insertCount;
1936 if (
d->globalResizeMode ==
Stretch)
1937 d->stretchSections =
d->sectionCount();
1939 d->contentsSections =
d->sectionCount();
1942 d->sectionSelected.clear();
1945 if (!
d->visualIndices.isEmpty() && !
d->logicalIndices.isEmpty()) {
1946 Q_ASSERT(
d->visualIndices.size() ==
d->logicalIndices.size());
1947 int mappingCount =
d->visualIndices.size();
1948 for (
int i = 0;
i < mappingCount; ++
i) {
1949 if (
d->visualIndices.at(
i) >= logicalFirst)
1950 d->visualIndices[
i] += insertCount;
1951 if (
d->logicalIndices.at(
i) >= logicalFirst)
1952 d->logicalIndices[
i] += insertCount;
1954 for (
int j = logicalFirst;
j <= logicalLast; ++
j) {
1955 d->visualIndices.insert(
j,
j);
1956 d->logicalIndices.insert(
j,
j);
1963 end =
d->hiddenSectionSize.cend();
it !=
end; ++
it) {
1964 const int oldIndex =
it.key();
1965 const int newIndex = (oldIndex < logicalFirst) ? oldIndex : oldIndex + insertCount;
1966 newHiddenSectionSize[newIndex] =
it.value();
1968 d->hiddenSectionSize.swap(newHiddenSectionSize);
1970 d->doDelayedResizeSections();
1973 if (lastSectionActualChange)
1974 d->maybeRestorePrevLastSectionAndStretchLast();
1977 if (!
d->hasAutoResizeSections())
1978 d->viewport->update();
1990 int logicalFirst,
int logicalLast)
2000 const int changeCount = logicalLast - logicalFirst + 1;
2004 for (
int i = 0;
i < logicalFirst; ++
i)
2005 if (
q->isSectionHidden(
i))
2008 if (
q->isSectionHidden(
j))
2014 int logicalFirst,
int logicalLast)
2019 if (
qMin(logicalFirst, logicalLast) < 0
2022 int oldCount =
q->count();
2023 int changeCount = logicalLast - logicalFirst + 1;
2034 if (logicalFirst == logicalLast) {
2035 int l = logicalFirst;
2064 if (logindex > logicalFirst)
2065 logindex -= changeCount;
2066 visual_data[logindex] =
w;
2067 logical_data[
w] = logindex;
2085 emit q->sectionCountChanged(oldCount,
q->count());
2087 if (
q->stretchLastSection()) {
2089 if (lastSectionRemoved)
2101 if (sourceParent !=
root || destinationParent !=
root)
2111 if (sourceParent !=
root || destinationParent !=
root)
2180 if (newCount == 0) {
2183 emit q->sectionCountChanged(oldCount, 0);
2187 bool hasPersistantIndexes =
false;
2188 for (
const auto &
item : oldPersistentSections) {
2189 if (
item.index.isValid()) {
2190 hasPersistantIndexes =
true;
2205 if (!hasPersistantIndexes) {
2206 if (oldCount != newCount)
2207 q->initializeSections();
2212 if (newCount != oldCount) {
2213 const int min =
qBound(0, oldCount, newCount - 1);
2214 q->initializeSections(min, newCount - 1);
2222 for (
const auto &
item : oldPersistentSections) {
2224 if (!
index.isValid())
2231 const int newVisualIndex =
visualIndex(newLogicalIndex);
2234 newSection =
item.section;
2236 if (newSection.isHidden) {
2238 newSection.isHidden =
false;
2239 q->setSectionHidden(newLogicalIndex,
true);
2261 const int oldCount =
d->sectionCount();
2262 const int newCount =
d->modelSectionCount();
2263 if (newCount <= 0) {
2266 }
else if (newCount != oldCount) {
2267 const int min =
qBound(0, oldCount, newCount - 1);
2270 d->maybeRestorePrevLastSectionAndStretchLast();
2274 if (newCount < oldCount)
2275 d->updateHiddenSections(newCount, oldCount);
2290 d->invalidateCachedSizeHint();
2291 int oldCount =
d->sectionCount();
2293 if (
end + 1 <
d->sectionCount()) {
2294 int newCount =
end + 1;
2295 d->removeSectionsFromSectionItems(newCount,
d->sectionCount() - 1);
2296 if (!
d->hiddenSectionSize.isEmpty()) {
2297 if (oldCount - newCount >
d->hiddenSectionSize.size()) {
2298 for (
int i =
end + 1;
i <
d->sectionCount(); ++
i)
2299 d->hiddenSectionSize.remove(
i);
2302 while (
it !=
d->hiddenSectionSize.end()) {
2304 it =
d->hiddenSectionSize.erase(
it);
2312 int newSectionCount =
end + 1;
2314 if (!
d->logicalIndices.isEmpty()) {
2315 if (oldCount <= newSectionCount) {
2316 d->logicalIndices.resize(newSectionCount);
2317 d->visualIndices.resize(newSectionCount);
2318 for (
int i = oldCount;
i < newSectionCount; ++
i) {
2319 d->logicalIndices[
i] =
i;
2320 d->visualIndices[
i] =
i;
2324 for (
int i = 0;
i < oldCount; ++
i) {
2325 int v =
d->logicalIndices.at(
i);
2326 if (
v < newSectionCount) {
2327 d->logicalIndices[
j] =
v;
2328 d->visualIndices[
v] =
j;
2332 d->logicalIndices.resize(newSectionCount);
2333 d->visualIndices.resize(newSectionCount);
2337 if (
d->globalResizeMode ==
Stretch)
2338 d->stretchSections = newSectionCount;
2340 d->contentsSections = newSectionCount;
2342 if (newSectionCount > oldCount)
2343 d->createSectionItems(
start,
end,
d->defaultSectionSize,
d->globalResizeMode);
2346 if (
d->sectionCount() != oldCount)
2348 d->viewport->update();
2384 switch (
e->type()) {
2399 int oldHover =
d->hover;
2401 if (
d->hover != oldHover) {
2410 if (te->
timerId() ==
d->delayedResize.timerId()) {
2411 d->delayedResize.stop();
2416 if (!
d->customDefaultSectionSize)
2417 d->updateDefaultSectionSizeFromStyle();
2438 QRect translatedEventRect =
e->rect();
2463 d->prepareSectionSelected();
2465 QRect currentSectionRect;
2466 const int width =
d->viewport->width();
2467 const int height =
d->viewport->height();
2468 const int rtlHorizontalOffset =
d->reverse() ? 1 : 0;
2470 if (
d->isVisualIndexHidden(
i))
2498 if (currentSectionRect.
left() > translatedEventRect.
left()) {
2503 }
else if (currentSectionRect.
right() < translatedEventRect.
right()) {
2509 }
else if (currentSectionRect.
bottom() < translatedEventRect.
bottom()) {
2519 for (
int a = 0,
i = 0;
i <
d->sectionItems.count(); ++
i) {
2520 QColor color((
i & 4 ? 255 : 0), (
i & 2 ? 255 : 0), (
i & 1 ? 255 : 0));
2525 a +=
d->sectionItems.at(
i).size;
2540 int pos =
d->orientation ==
Qt::Horizontal ?
e->position().toPoint().x() :
e->position().toPoint().y();
2542 d->originalSize = -1;
2545 if (
d->clickableSections)
2548 bool acceptMoveSection =
d->movableSections;
2549 if (acceptMoveSection &&
d->pressed == 0 && !
d->allowUserMoveOfSection0)
2550 acceptMoveSection =
false;
2552 if (acceptMoveSection) {
2554 d->section =
d->pressed;
2555 if (
d->section == -1)
2558 d->setupSectionIndicator(
d->section,
pos);
2559 }
else if (
d->clickableSections &&
d->pressed != -1) {
2567 d->preventCursorChangeInSetOffset =
false;
2573 d->clearCascadingSections();
2583 const int pos =
d->orientation ==
Qt::Horizontal ?
e->position().toPoint().x() :
e->position().toPoint().y();
2593 d->firstPressed =
d->pressed = -1;
2598 if (
d->cascadingResizing) {
2599 int delta =
d->reverse() ?
d->lastPos -
pos :
pos -
d->lastPos;
2601 d->cascadingResize(visual,
d->headerSectionSize(visual) + delta);
2603 int delta =
d->reverse() ?
d->firstPos -
pos :
pos -
d->firstPos;
2611 if (
d->shouldAutoScroll(
e->position().toPoint())) {
2612 d->draggedPosition =
e->pos();
2613 d->startAutoScroll();
2617 || !
d->sectionIndicator->isHidden()
2623 if (visual == 0 &&
logicalIndex(0) == 0 && !
d->allowUserMoveOfSection0)
2626 const int posThreshold =
d->headerSectionPosition(visual) -
d->offset +
d->headerSectionSize(visual) / 2;
2627 const int checkPos =
d->reverse() ?
d->viewport->width() -
pos :
pos;
2629 int oldTarget =
d->target;
2630 if (visual < moving) {
2631 if (checkPos < posThreshold)
2632 d->target =
d->logicalIndex(visual);
2634 d->target =
d->logicalIndex(visual + 1);
2635 }
else if (visual > moving) {
2636 if (checkPos > posThreshold)
2637 d->target =
d->logicalIndex(visual);
2639 d->target =
d->logicalIndex(visual - 1);
2641 d->target =
d->section;
2643 if (oldTarget !=
d->target || oldTarget == -1)
2644 d->updateSectionsBeforeAfter(
d->target);
2645 d->updateSectionIndicator(
d->section,
pos);
2651 if (logical == -1 &&
pos > 0)
2653 if (logical ==
d->pressed)
2655 else if (
d->pressed != -1)
2657 d->pressed = logical;
2658 if (
d->clickableSections && logical != -1) {
2674#ifndef QT_NO_STATUSTIP
2679 if (
d->shouldClearStatusTip || !statusTip.
isEmpty()) {
2682 d->shouldClearStatusTip = !statusTip.
isEmpty();
2701 int pos =
d->orientation ==
Qt::Horizontal ?
e->position().toPoint().x() :
e->position().toPoint().y();
2706 && !
d->sectionIndicator->isHidden()
2714 d->section =
d->target = -1;
2715 d->updateSectionIndicator(
d->section,
pos);
2717 d->updateSectionsBeforeAfter(from);
2722 if (!
d->clickableSections) {
2728 if (
d->clickableSections) {
2730 if (section != -1 && section ==
d->firstPressed) {
2731 QRect firstPressedSectionRect;
2732 switch (
d->orientation) {
2737 d->viewport->height());
2740 firstPressedSectionRect.
setRect(0,
2742 d->viewport->width(),
2747 if (firstPressedSectionRect.
contains(
e->position().toPoint())) {
2748 d->flipSortIndicator(section);
2752 if (
d->pressed != -1)
2757 d->originalSize = -1;
2758 d->clearCascadingSections();
2764 d->firstPressed =
d->pressed = -1;
2774 int pos =
d->orientation ==
Qt::Horizontal ?
e->position().toPoint().x() :
e->position().toPoint().y();
2781 if (
cursor().shape() == splitCursor) {
2800 switch (
e->type()) {
2801#if QT_CONFIG(tooltip)
2805 if (logical != -1) {
2814#if QT_CONFIG(whatsthis)
2825 if (logical != -1) {
2826 QVariant whatsthis =
d->model->headerData(logical,
d->orientation,
2835#if QT_CONFIG(statustip)
2839 if (logical != -1) {
2840 QString statustip =
d->model->headerData(logical,
d->orientation,
2843 setStatusTip(statustip);
2850 d->invalidateCachedSizeHint();
2854 QAbstractScrollArea *
parent = qobject_cast<QAbstractScrollArea *>(parentWidget());
2861 d->pressed =
d->section =
d->target = -1;
2862 d->updateSectionIndicator(
d->section, -1);
2865 QAbstractScrollArea *asa = qobject_cast<QAbstractScrollArea *>(parentWidget());
2896 if (
window()->isActiveWindow())
2898 if (
d->clickableSections) {
2903 else if (
d->highlightSelected) {
2920 ? QtPrivate::legacyFlagValueFromModelData<Qt::Alignment>(textAlignment)
2921 :
d->defaultAlignment;
2955 bool first =
d->isFirstVisibleSection(visual);
2956 bool last =
d->isLastVisibleSection(visual);
2965 opt.orientation =
d->orientation;
2967 bool previousSelected =
d->isSectionSelected(this->
logicalIndex(visual - 1));
2968 bool nextSelected =
d->isSectionSelected(this->
logicalIndex(visual + 1));
2969 if (previousSelected && nextSelected)
2971 else if (previousSelected)
2973 else if (nextSelected)
2990 if (!
rect.isValid())
3009 if (oBrushButton != nBrushButton || oBrushWindow != nBrushWindow) {
3035 return qvariant_cast<QSize>(
variant);
3045 fnt = qvariant_cast<QFont>(
var);
3099 d->layoutChildren();
3100 if (
d->hasAutoResizeSections())
3101 d->doDelayedResizeSections();
3112 d->scrollDirtyRegion(dx, dy);
3124 const auto doesRoleAffectSize = [](
int role) ->
bool {
3136 if (std::none_of(roles.
begin(), roles.
end(), doesRoleAffectSize))
3139 d->invalidateCachedSizeHint();
3140 if (
d->hasAutoResizeSections()) {
3144 for (
int i =
first;
i <= last && !resizeRequired; ++
i)
3147 d->doDelayedResizeSections();
3243 const int max =
d->modelSectionCount();
3246 int logicalLeft = max;
3247 int logicalRight = 0;
3249 if (
d->visualIndices.empty()) {
3252 if (
r.parent().isValid() || !
r.isValid())
3254 if (
r.left() < logicalLeft)
3255 logicalLeft =
r.left();
3256 if (
r.right() > logicalRight)
3257 logicalRight =
r.right();
3263 if (
r.parent().isValid() || !
r.isValid())
3265 for (
int k =
r.left(); k <=
r.right(); ++k) {
3279 if (logicalLeft < 0 || logicalLeft >=
count() ||
3280 logicalRight < 0 || logicalRight >=
count())
3286 return QRect(leftPos, 0, rightPos - leftPos,
height());
3289 int logicalTop = max;
3290 int logicalBottom = 0;
3292 if (
d->visualIndices.empty()) {
3295 if (
r.parent().isValid() || !
r.isValid())
3297 if (
r.top() < logicalTop)
3298 logicalTop =
r.top();
3299 if (
r.bottom() > logicalBottom)
3300 logicalBottom =
r.bottom();
3307 if (
r.parent().isValid() || !
r.isValid())
3309 for (
int k =
r.top(); k <=
r.bottom(); ++k) {
3324 if (logicalTop < 0 || logicalTop >=
count() ||
3325 logicalBottom < 0 || logicalBottom >=
count())
3331 return QRect(0, topPos,
width(), bottomPos - topPos);
3340 int visual =
q->visualIndexAt(
position);
3344 int pos =
q->sectionViewportPosition(log);
3348 bool atRight = (
position >
pos +
q->sectionSize(log) - grip);
3350 qSwap(atLeft, atRight);
3354 while(visual > -1) {
3355 int logical =
q->logicalIndex(--visual);
3356 if (!
q->isSectionHidden(logical))
3359 }
else if (atRight) {
3370 if (!sectionIndicator) {
3376 int p =
q->sectionViewportPosition(
section);
3385 sectionIndicator->resize(
w,
h);
3388 const qreal pixmapDevicePixelRatio =
q->devicePixelRatio();
3398 const QFont sectionFont = qvariant_cast<QFont>(
variant);
3409 sectionIndicator->setPixmap(pm);
3417 if (!sectionIndicator)
3421 sectionIndicator->hide();
3430 sectionIndicator->show();
3446 option->orientation =
d->orientation;
3483 return item.size > 0 &&
item.calculated_startpos == 0;
3501 for (
int visual =
q->count()-1; visual >= 0; --visual) {
3502 if (!
q->isSectionHidden(
q->logicalIndex(visual)))
3532 if (!
q->stretchLastSection())
3577 int stretchSection = -1;
3579 stretchSection = lastSectionVisualIdx;
3583 int numberOfStretchedSections = 0;
3590 if (useGlobalMode && (
i != stretchSection))
3591 resizeMode = globalMode;
3596 ++numberOfStretchedSections;
3602 int sectionSize = 0;
3610 sectionSize =
qBound(
q->minimumSectionSize(),
3612 q->maximumSectionSize());
3614 section_sizes.
append(sectionSize);
3615 lengthToStretch -= sectionSize;
3619 int stretchSectionLength = -1;
3620 int pixelReminder = 0;
3621 if (numberOfStretchedSections > 0 && lengthToStretch > 0) {
3622 int hintLengthForEveryStretchedSection = lengthToStretch / numberOfStretchedSections;
3623 stretchSectionLength =
qMax(hintLengthForEveryStretchedSection,
q->minimumSectionSize());
3624 pixelReminder = lengthToStretch % numberOfStretchedSections;
3628 int spanStartSection = 0;
3629 int previousSectionLength = 0;
3636 int newSectionLength = -1;
3640 newSectionLength = 0;
3644 resizeMode = globalMode;
3646 resizeMode = (
i == stretchSection
3648 : newSectionResizeMode);
3650 if (
i == lastSectionVisualIdx)
3653 newSectionLength = stretchSectionLength;
3654 if (pixelReminder > 0) {
3655 newSectionLength += 1;
3660 newSectionLength = section_sizes.
takeFirst();
3665 if ((previousSectionResizeMode != newSectionResizeMode
3666 || previousSectionLength != newSectionLength) &&
i > 0) {
3667 createSectionItems(spanStartSection,
i - 1, previousSectionLength, previousSectionResizeMode);
3669 spanStartSection =
i;
3672 if (newSectionLength != oldSectionLength)
3675 previousSectionLength = newSectionLength;
3676 previousSectionResizeMode = newSectionResizeMode;
3680 previousSectionLength, previousSectionResizeMode);
3696 sectiondata[
i].
size = sizePerSection;
3705 int removedlength = 0;
3756 q->setSortIndicator(
section, sortOrder);
3762 if (
value.canConvert<
int>())
3770 const int minimumSize =
q->minimumSectionSize();
3772 int delta = newSize - oldSize;
3775 bool sectionResized =
false;
3782 if (currentSectionSize < originalSectionSize) {
3783 int newSectionSize = currentSectionSize + delta;
3785 if (newSectionSize >= originalSectionSize &&
false)
3787 sectionResized =
true;
3795 if (!sectionResized) {
3796 newSize =
qMax(newSize, minimumSize);
3797 if (oldSize != newSize)
3808 if (currentSectionSize <= minimumSize)
3810 int newSectionSize =
qMax(currentSectionSize - delta, minimumSize);
3813 delta = delta - (currentSectionSize - newSectionSize);
3818 bool sectionResized =
false;
3826 if (currentSectionSize >= originalSectionSize)
3828 int newSectionSize = currentSectionSize - delta;
3830 if (newSectionSize >= originalSectionSize &&
false) {
3833 sectionResized =
true;
3841 if (delta < 0 && newSize < minimumSize) {
3842 for (
int i = visual - 1;
i >= 0; --
i) {
3848 if (sectionSize <= minimumSize)
3857 if (!sectionResized) {
3864 int newSectionSize =
qMax(currentSectionSize - delta, minimumSize);
3890 const int newSize =
size;
3891 if (newSize !=
section.size) {
3893 const int oldSectionSize =
section.sectionSize();
3920 i.calculated_startpos = pixelpos;
3957 while (startidx <= endidx) {
3958 int middle = (endidx + startidx) / 2;
3960 endidx = middle - 1;
3963 startidx = middle + 1;
3995 ?
view->sizeHintForColumn(logical)
3996 :
view->sizeHintForRow(logical));
4005 int currentVisualIndex = 0;
4010 ++currentVisualIndex;
4024 q->setOffsetToLastSection();
4041 std::swap(from, to);
4042 updateRect =
QRect(
QPoint(
q->sectionViewportPosition(from), 0),
4045 updateRect =
QRect(
QPoint(0,
q->sectionViewportPosition(from)),
4051#ifndef QT_NO_DATASTREAM
4091 int sortIndicatorSectionIn;
4092 bool sortIndicatorShownIn;
4097 bool movableSectionsIn;
4098 bool clickableSectionsIn;
4099 bool highlightSelectedIn;
4100 bool stretchLastSectionIn;
4101 bool cascadingResizingIn;
4102 int stretchSectionsIn;
4103 int contentsSectionsIn;
4104 int defaultSectionSizeIn;
4105 int minimumSectionSizeIn;
4111 in >> sortIndicatorSectionIn;
4112 in >> sortIndicatorShownIn;
4114 in >> visualIndicesIn;
4115 in >> logicalIndicesIn;
4118 in >> sectionHidden;
4119 in >> hiddenSectionSizeIn;
4122 int unusedSectionCount;
4123 in >> unusedSectionCount;
4128 in >> movableSectionsIn;
4129 in >> clickableSectionsIn;
4130 in >> highlightSelectedIn;
4131 in >> stretchLastSectionIn;
4132 in >> cascadingResizingIn;
4133 in >> stretchSectionsIn;
4134 in >> contentsSectionsIn;
4135 in >> defaultSectionSizeIn;
4136 in >> minimumSectionSizeIn;
4151 in >> sectionItemsIn;
4156 for (
int u = 0; u < sectionItemsIn.
size(); ++u) {
4157 int count = sectionItemsIn.
at(u).tmpDataStreamSectionCount;
4161 newSectionItems.
append(sectionItemsIn[u]);
4164 int sectionItemsLengthTotal = 0;
4166 sectionItemsLengthTotal +=
section.size;
4167 if (sectionItemsLengthTotal != lengthIn)
4171 if (newSectionItems.
size() < currentCount) {
4174 for (
int i = newSectionItems.
size();
i < currentCount; ++
i) {
4179 const int insertCount = currentCount - newSectionItems.
size();
4180 const int insertLength = defaultSectionSizeIn * insertCount;
4181 lengthIn += insertLength;
4226 int inLastSectionSize;
4227 in >> inLastSectionSize;
4237 int inSortIndicatorClearable;
4238 in >> inSortIndicatorClearable;
4249#include "moc_qheaderview.cpp"
static QAbstractItemModel * staticEmptyModel()
LayoutChangeHint
This enum describes the way the model changes layout.
virtual Q_INVOKABLE QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns the data for the given role and section in the header with the specified orientation.
virtual Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
virtual Q_INVOKABLE int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
virtual Q_INVOKABLE QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index.
QPersistentModelIndex root
QAbstractItemModel * model
void executePostedLayout() const
The QAbstractItemView class provides the basic functionality for item view classes.
QAbstractItemModel * model() const
Returns the model that this view is presenting.
bool event(QEvent *event) override
\reimp
State state() const
Returns the item view's state.
virtual void reset()
Reset the internal state of the view.
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This slot is called when items with the given roles are changed in the model.
bool viewportEvent(QEvent *event) override
This function is used to handle tool tips, and What's This? mode, if the given event is a QEvent::Too...
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
This slot is called when rows are about to be removed.
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
virtual void doItemsLayout()
CursorAction
This enum describes the different ways to navigate between items,.
virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
This slot is called when a new item becomes the current item.
ScrollHint
\value EnsureVisible Scroll to ensure that the item is visible.
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
This slot is called when rows are inserted.
int value
the slider's current value
int maximum
the slider's maximum value
int startDragDistance
the minimum distance required for a drag and drop operation to start.
void stop()
Stops the timer.
void clear()
Clears the contents of the bit array and makes it empty.
bool testBit(qsizetype i) const
Returns true if the bit at index position i is 1; otherwise returns false.
void setBit(qsizetype i)
Sets the bit at index position i to 1.
qsizetype size() const
Returns the number of bits stored in the bit array.
The QColor class provides colors based on RGB, HSV or CMYK values.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static void setPos(int x, int y)
Moves the cursor (hot spot) of the primary screen to the global screen position (x,...
static QPoint pos()
Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates.
\inmodule QtCore\reentrant
\reentrant \inmodule QtGui
void setBold(bool)
If enable is true sets the font's weight to \l{Weight}{QFont::Bold}; otherwise sets the weight to \l{...
virtual void initStyleOption(QStyleOptionFrame *option) const
bool remove(const Key &key)
Removes the item that has the key from the hash.
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
T value(const Key &key) const noexcept
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
bool isEmpty() const noexcept
Returns true if the hash contains no items; otherwise returns false.
The QHelpEvent class provides an event that is used to request helpful information about a particular...
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
const QPoint & pos() const
Returns the mouse cursor position when the event was generated, relative to the widget to which the e...
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
The QLabel widget provides a text or image display.
qsizetype size() const noexcept
void removeFirst() noexcept
bool isEmpty() const noexcept
iterator insert(qsizetype i, parameter_type t)
const_reference at(qsizetype i) const noexcept
void remove(qsizetype i, qsizetype n=1)
void resize(qsizetype size)
void append(parameter_type t)
constexpr int row() const noexcept
Returns the row this model index refers to.
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
constexpr int column() const noexcept
Returns the column this model index refers to.
constexpr bool isValid() const noexcept
Returns {true} if this model index is valid; otherwise returns {false}.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
The QPaintEvent class contains event parameters for paint events.
The QPainter class performs low-level painting on widgets and other paint devices.
void setBrushOrigin(int x, int y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void restore()
Restores the current painter state (pops a saved state off the stack).
void setOpacity(qreal opacity)
void save()
Saves the current painter state (pushes the state onto a stack).
void setFont(const QFont &f)
Sets the painter's font to the given font.
QPoint brushOrigin() const
Returns the currently set brush origin.
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
void setDevicePixelRatio(qreal scaleFactor)
Sets the device pixel ratio for the pixmap.
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
\inmodule QtCore\reentrant
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
\inmodule QtCore\reentrant
constexpr int x() const noexcept
Returns the x coordinate of this point.
constexpr int y() const noexcept
Returns the y coordinate of this point.
\inmodule QtCore\reentrant
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr void setRect(int x, int y, int w, int h) noexcept
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given widt...
constexpr void translate(int dx, int dy) noexcept
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position.
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
The QRegion class specifies a clip region for a painter.
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
The QStatusTipEvent class provides an event that is used to show messages in a status bar.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
\variable QStyleOptionFocusRect::backgroundColor
The QStyleOption class stores the parameters used by QStyle functions.
void initFrom(const QWidget *w)
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
@ PM_HeaderDefaultSectionSizeHorizontal
@ PM_HeaderDefaultSectionSizeVertical
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
bool canConvert(QMetaType targetType) const
static void showText(const QPoint &pos, const QString &text, QWidget *w=nullptr)
Shows text as a "What's This?" window, at global position pos.
QSet< QString >::iterator it
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static void unsetCursor(QWindow *w)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qBound(const T &min, const T &val, const T &max)
constexpr const T & qMax(const T &a, const T &b)
constexpr T qAbs(const T &t)
GLsizei const GLfloat * v
[13]
GLuint64 GLenum void * handle
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLuint GLsizei const GLchar * label
[43]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q
GLfixed GLfixed GLint GLint order
GLenum GLint GLint * precision
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define QT_CONFIG(feature)
QSqlQueryModel * model
[16]
QTextStream out(stdout)
[7]
item setCursor(Qt::IBeamCursor)
[1]
view viewport() -> scroll(dx, dy, deviceRect)
QItemSelection * selection
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent