17#include <private/qscrollbar_p.h>
18#if QT_CONFIG(accessibility)
22#include <private/qapplication_p.h>
23#include <private/qtreeview_p.h>
24#include <private/qheaderview_p.h>
189 if (
d->selectionModel) {
191 d->model,
SLOT(submit()));
196 d->viewItems.clear();
197 d->expandedIndexes.clear();
198 d->hiddenIndexes.clear();
199 d->geometryRecursionBlock =
true;
200 d->header->setModel(
model);
201 d->geometryRecursionBlock =
false;
209 d->header,
SLOT(_q_layoutChanged()));
216 if (
d->sortingEnabled)
217 d->_q_sortIndicatorChanged(
header()->sortIndicatorSection(),
header()->sortIndicatorOrder());
226 d->header->setRootIndex(
index);
237 if (
d->selectionModel) {
240 d->model,
SLOT(submit()));
246 if (
d->selectionModel) {
249 d->model,
SLOT(submit()));
277 if (
d->header &&
d->header->parent() ==
this)
280 d->header->setParent(
this);
281 d->header->setFirstSectionMovable(
false);
283 if (!
d->header->model()) {
284 d->header->setModel(
d->model);
285 if (
d->selectionModel)
286 d->header->setSelectionModel(
d->selectionModel);
318 return d->autoExpandDelay;
324 d->autoExpandDelay = delay;
349 if (!
d->customIndent || (
i !=
d->indent)) {
351 d->customIndent =
true;
352 d->viewport->update();
359 if (
d->customIndent) {
360 d->updateIndentationFromStyle();
361 d->customIndent =
false;
379 return d->rootDecoration;
385 if (
show !=
d->rootDecoration) {
386 d->rootDecoration =
show;
387 d->viewport->update();
410 return d->uniformRowHeights;
416 d->uniformRowHeights = uniform;
432 return d->itemsExpandable;
454 return d->expandsOnDoubleClick;
460 d->expandsOnDoubleClick =
enable;
469 return d->header->sectionViewportPosition(
column);
480 return d->header->sectionSize(
column);
503 return d->header->logicalIndexAt(
x);
514 return d->header->isSectionHidden(
column);
525 if (column < 0 || column >=
d->header->count())
543 return d->header->isHidden();
549 d->header->setHidden(
hide);
563 return d->isRowHidden(
d->model->index(
row, 0,
parent));
577 if (!
index.isValid())
581 d->hiddenIndexes.insert(
index);
582 }
else if (
d->isPersistent(
index)) {
583 d->hiddenIndexes.remove(
index);
586 d->doDelayedItemsLayout();
600 if (
d->spanningIndexes.isEmpty() || !
d->model)
603 return d->spanningIndexes.contains(
index);
621 if (!
index.isValid())
625 d->spanningIndexes.insert(
index);
627 d->spanningIndexes.remove(
index);
629 d->executePostedLayout();
632 d->viewItems[
i].spanning =
span;
634 d->viewport->update();
646 if (
d->delayedPendingLayout)
652 bool sizeChanged =
false;
653 int topViewIndex =
d->viewIndex(topLeft);
654 if (topViewIndex == 0) {
656 sizeChanged =
d->defaultItemHeight != newDefaultItemHeight;
657 d->defaultItemHeight = newDefaultItemHeight;
660 if (topViewIndex != -1) {
661 if (topLeft.
row() == bottomRight.
row()) {
662 int oldHeight =
d->itemHeight(topViewIndex);
663 d->invalidateHeightCache(topViewIndex);
664 sizeChanged |= (oldHeight !=
d->itemHeight(topViewIndex));
665 if (topLeft.
column() == 0)
666 d->viewItems[topViewIndex].hasChildren =
d->hasVisibleChildren(topLeft);
668 int bottomViewIndex =
d->viewIndex(bottomRight);
669 for (
int i = topViewIndex;
i <= bottomViewIndex; ++
i) {
670 int oldHeight =
d->itemHeight(
i);
671 d->invalidateHeightCache(
i);
672 sizeChanged |= (oldHeight !=
d->itemHeight(
i));
673 if (topLeft.
column() == 0)
674 d->viewItems[
i].hasChildren =
d->hasVisibleChildren(
d->viewItems.at(
i).index);
680 d->updateScrollBars();
681 d->viewport->update();
698 if (
d->header->isSectionHidden(
column))
700 d->header->hideSection(
column);
712 if (!
d->header->isSectionHidden(
column))
714 d->header->showSection(
column);
728 if (!
d->isIndexValid(
index))
732 if (
d->isIndexExpanded(
index))
734 if (
d->delayedPendingLayout) {
736 if (
d->storeExpanded(
index))
744 if (!
d->isAnimating()) {
746 d->viewport->update();
748 }
else if (
d->storeExpanded(
index)) {
763 if (!
d->isIndexValid(
index))
765 if (!
d->isIndexExpanded(
index))
768 d->delayedAutoScroll.stop();
770 if (
d->delayedPendingLayout) {
772 if (
d->isPersistent(
index) &&
d->expandedIndexes.remove(
index))
778 d->collapse(
i,
true);
779 if (!
d->isAnimating()) {
784 if (
d->isPersistent(
index) &&
d->expandedIndexes.remove(
index))
800 return d->isIndexExpanded(
index);
854 return d->sortingEnabled;
873 d->animationsEnabled = animate;
879 return d->animationsEnabled;
896 if (
d->allColumnsShowFocus ==
enable)
898 d->allColumnsShowFocus =
enable;
899 d->viewport->update();
905 return d->allColumnsShowFocus;
924 if (
d->wrapItemText == on)
926 d->wrapItemText = on;
927 d->doDelayedItemsLayout();
933 return d->wrapItemText;
949 d->viewport->update();
964 return d->treePosition;
973 if (!
d->model->rowCount(
d->root) || !
d->model->columnCount(
d->root))
977 d->executePostedLayout();
978 if (
d->viewItems.isEmpty())
985 start =
d->viewItems.at(0).index;
987 bool skipRow =
false;
988 bool keyboardTimeWasValid =
d->keyboardInputTime.isValid();
989 qint64 keyboardInputTimeElapsed;
990 if (keyboardTimeWasValid)
991 keyboardInputTimeElapsed =
d->keyboardInputTime.restart();
993 d->keyboardInputTime.start();
994 if (search.
isEmpty() || !keyboardTimeWasValid
996 d->keyboardInput = search;
999 d->keyboardInput += search;
1003 bool sameKey =
false;
1004 if (
d->keyboardInput.size() > 1) {
1005 int c =
d->keyboardInput.count(
d->keyboardInput.at(
d->keyboardInput.size() - 1));
1006 sameKey = (
c ==
d->keyboardInput.size());
1016 const int origCol =
start.column();
1017 start =
d->viewItems.at(0).index;
1018 if (origCol !=
start.column())
1023 int startIndex =
d->viewIndex(
start);
1024 if (startIndex <= -1)
1027 int previousLevel = -1;
1030 QString searchString = sameKey ?
QString(
d->keyboardInput.at(0)) :
d->keyboardInput;
1031 for (
int i = 0;
i <
d->viewItems.size(); ++
i) {
1032 if ((
int)
d->viewItems.at(
i).level > previousLevel) {
1034 if (
start.column() > 0)
1040 int hitIndex =
d->viewIndex(
match.at(0));
1041 if (hitIndex >= 0 && hitIndex < startIndex)
1042 bestAbove = bestAbove == -1 ? hitIndex :
qMin(hitIndex, bestAbove);
1043 else if (hitIndex >= startIndex)
1044 bestBelow = bestBelow == -1 ? hitIndex :
qMin(hitIndex, bestBelow);
1047 previousLevel =
d->viewItems.at(
i).level;
1052 index =
d->viewItems.at(bestBelow).index;
1053 else if (bestAbove > -1)
1054 index =
d->viewItems.at(bestAbove).index;
1056 if (
start.column() > 0)
1059 if (
index.isValid())
1074 d->executePostedLayout();
1076 int vi =
d->viewIndex(
index);
1080 bool spanning =
d->viewItems.at(vi).spanning;
1086 if (
d->isTreePosition(
index.column())) {
1087 int i =
d->indentationForItem(vi);
1089 if (!isRightToLeft())
1093 int y =
d->coordinateForItem(vi);
1094 int h =
d->itemHeight(vi);
1111 if (!
d->isIndexValid(
index))
1114 d->executePostedLayout();
1115 d->updateScrollBars();
1133 int top = verticalScrollBar()->value();
1134 int bottom =
top + verticalScrollBar()->pageStep();
1138 verticalScrollBar()->setValue(
item);
1140 const int currentItemHeight =
d->itemHeight(
item);
1143 ?
area.height() / 2 + currentItemHeight - 1
1146 if (
y > currentItemHeight) {
1148 y -=
d->itemHeight(
item);
1156 verticalScrollBar()->setValue(
item);
1160 d->coordinateForItem(
item),
1162 d->itemHeight(
item));
1164 if (
rect.isEmpty()) {
1167 d->viewport->update(
rect);
1172 ||
area.height() <
rect.height()));
1177 int verticalValue = verticalScrollBar()->value();
1179 verticalValue +=
rect.top();
1181 verticalValue +=
rect.bottom() -
area.height();
1183 verticalValue +=
rect.top() - ((
area.height() -
rect.height()) / 2);
1184 verticalScrollBar()->setValue(verticalValue);
1188 int viewportWidth =
d->viewport->width();
1190 int horizontalPosition =
d->header->sectionPosition(
index.column());
1191 int cellWidth =
d->header->sectionSize(
index.column());
1194 horizontalScrollBar()->setValue(horizontalPosition - ((viewportWidth - cellWidth) / 2));
1196 if (horizontalPosition - horizontalOffset < 0 || cellWidth > viewportWidth)
1197 horizontalScrollBar()->setValue(horizontalPosition);
1198 else if (horizontalPosition -
horizontalOffset + cellWidth > viewportWidth)
1199 horizontalScrollBar()->setValue(horizontalPosition - viewportWidth + cellWidth);
1210 if (!
d->customIndent) {
1213 d->updateIndentationFromStyle();
1216 QAbstractItemView::changeEvent(
event);
1225 if (
event->timerId() ==
d->columnResizeTimerID) {
1227 killTimer(
d->columnResizeTimerID);
1228 d->columnResizeTimerID = 0;
1230 int viewportHeight =
d->viewport->height();
1231 int viewportWidth =
d->viewport->width();
1232 for (
int i =
d->columnsToUpdate.size() - 1;
i >= 0; --
i) {
1233 int column =
d->columnsToUpdate.at(
i);
1235 if (isRightToLeft())
1238 rect |=
QRect(
x, 0, viewportWidth -
x, viewportHeight);
1240 d->viewport->update(
rect.normalized());
1241 d->columnsToUpdate.clear();
1242 }
else if (
event->timerId() ==
d->openTimer.timerId()) {
1245 &&
d->viewport->rect().contains(
pos)) {
1249 d->openTimer.stop();
1258#if QT_CONFIG(draganddrop)
1259void QTreeView::dragMoveEvent(QDragMoveEvent *
event)
1262 if (
d->autoExpandDelay >= 0)
1263 d->openTimer.start(
d->autoExpandDelay,
this);
1264 QAbstractItemView::dragMoveEvent(
event);
1274 switch (
event->type()) {
1279 int oldBranch =
d->hoverBranch;
1282 if (
d->hover != newIndex ||
d->hoverBranch != oldBranch) {
1303 d->executePostedLayout();
1305#if QT_CONFIG(animation)
1306 if (
d->isAnimating()) {
1308 d->drawAnimatedOperation(&
painter);
1313#if QT_CONFIG(draganddrop)
1333 if (rowHeight <= 0) {
1340 option->features.setFlag(QStyleOptionViewItem::Alternate,
current & 1);
1363 q->updateGeometries();
1383 const auto parentIdx = topLeft.
parent();
1386 for (
int r = topLeft.
row();
r <= bottomRight.
row(); ++
r) {
1391 updateRect |=
q->visualRect(idx);
1394 return rect.intersected(updateRect);
1410 if (idx.column() > 0 &&
q->isFirstColumnSpanned(idx.row(), idx.parent()))
1425 ||
option->showDecorationSelected;
1437 const int visualIndex = logicalIndices.
indexOf(
current.column());
1438 option->viewItemPosition = viewItemPosList.
at(visualIndex);
1455 QStyleOptionViewItem
option;
1460 if (viewItems.
size() == 0 ||
d->header->count() == 0 || !
d->itemDelegate) {
1465 int firstVisibleItemOffset = 0;
1466 const int firstVisibleItem =
d->firstVisibleItem(&firstVisibleItemOffset);
1467 if (firstVisibleItem < 0) {
1472 const int viewportWidth =
d->viewport->width();
1475 d->hoverBranch =
d->itemDecorationAt(hoverPos);
1478 bool multipleRects = (region.
rectCount() > 1);
1479 for (
const QRect &
a : region) {
1481 ?
QRect(0,
a.y(), viewportWidth,
a.height())
1483 d->leftAndRight =
d->startAndEndColumns(
area);
1485 int i = firstVisibleItem;
1486 int y = firstVisibleItemOffset;
1489 for (;
i < viewItems.
size(); ++
i) {
1490 const int itemHeight =
d->itemHeight(
i);
1491 if (
y + itemHeight >
area.top())
1497 for (;
i < viewItems.
size() &&
y <=
area.bottom(); ++
i) {
1498 const int itemHeight =
d->itemHeight(
i);
1499 option.rect.setRect(0,
y, viewportWidth, itemHeight);
1504 d->spanning = viewItems.
at(
i).spanning;
1505 if (!multipleRects || !drawn.
contains(
i)) {
1513 if (
y <=
area.bottom()) {
1538 int logicalIndexBeforeLeft = -1, logicalIndexAfterRight = -1;
1539 for (
int visualIndex =
left - 1; visualIndex >= 0; --visualIndex) {
1542 logicalIndexBeforeLeft = logicalIndex;
1547 for (
int visualIndex =
left; visualIndex < columnCount; ++visualIndex) {
1550 if (visualIndex >
right) {
1551 logicalIndexAfterRight = logicalIndex;
1554 logicalIndices->
append(logicalIndex);
1558 itemPositions->
resize(logicalIndices->
size());
1559 for (
int currentLogicalSection = 0; currentLogicalSection < logicalIndices->
size(); ++currentLogicalSection) {
1560 const int headerSection = logicalIndices->
at(currentLogicalSection);
1562 int nextLogicalSection = currentLogicalSection + 1 >= logicalIndices->
size()
1563 ? logicalIndexAfterRight
1564 : logicalIndices->
at(currentLogicalSection + 1);
1565 int prevLogicalSection = currentLogicalSection - 1 < 0
1566 ? logicalIndexBeforeLeft
1567 : logicalIndices->
at(currentLogicalSection - 1);
1568 QStyleOptionViewItem::ViewItemPosition
pos;
1569 if (columnCount == 1 || (nextLogicalSection == 0 && prevLogicalSection == -1)
1570 || (headerSection == 0 && nextLogicalSection == -1) ||
spanning)
1571 pos = QStyleOptionViewItem::OnlyOne;
1572 else if (
isTreePosition(headerSection) || (nextLogicalSection != 0 && prevLogicalSection == -1))
1573 pos = QStyleOptionViewItem::Beginning;
1574 else if (nextLogicalSection == 0 || nextLogicalSection == -1)
1575 pos = QStyleOptionViewItem::End;
1577 pos = QStyleOptionViewItem::Middle;
1578 (*itemPositions)[currentLogicalSection] =
pos;
1619 const bool reverse = isRightToLeft();
1621 const bool spanning =
d->spanning;
1624 const bool alternate =
d->alternatingColors;
1631 bool indexWidgetHasFocus =
false;
1632 if ((current.
row() ==
index.row()) && !
d->editorIndexHash.isEmpty()) {
1633 const int r =
index.row();
1639 indexWidgetHasFocus =
true;
1646 const bool widgetHasFocus = hasFocus();
1647 bool currentRowHasFocus =
false;
1650 const int r =
index.row();
1651 for (
int c = 0;
c <
left && !currentRowHasFocus; ++
c) {
1653 currentRowHasFocus = (idx == current);
1657 currentRowHasFocus = (
d->model->index(
r,
c,
parent) == current);
1667 ||
option.showDecorationSelected;
1679 d->calcLogicalIndices(&logicalIndices, &viewItemPosList,
left,
right);
1681 for (
int currentLogicalSection = 0; currentLogicalSection < logicalIndices.
size(); ++currentLogicalSection) {
1682 int headerSection = logicalIndices.
at(currentLogicalSection);
1696 modelIndex =
d->model->index(
index.row(), headerSection,
parent);
1701 opt.viewItemPosition = viewItemPosList.
at(currentLogicalSection);
1704 if (indexWidgetHasFocus)
1707 if (
d->selectionModel->isSelected(modelIndex))
1709 if (widgetHasFocus && (current == modelIndex)) {
1711 currentRowHasFocus =
true;
1716 (hoverRow || modelIndex == hover)
1717 && (
option.showDecorationSelected ||
d->hoverBranch == -1));
1733 opt.
features.setFlag(QStyleOptionViewItem::Alternate,
d->current & 1);
1740 if (
d->isTreePosition(headerSection)) {
1741 const int i =
d->indentationForItem(
d->current);
1743 const bool setClipRect = branches.
width() >
width;
1756 const bool oldShowDecorationSelected =
opt.showDecorationSelected;
1763 QStyle::State oldState =
opt.
state;
1768 opt.showDecorationSelected = oldShowDecorationSelected;
1775 QStyle::State oldState =
opt.
state;
1785 if (currentRowHasFocus) {
1787 o.QStyleOption::operator=(
option);
1791 o.backgroundColor =
option.palette.color(cg,
d->selectionModel->isSelected(
index)
1794 if (!
option.showDecorationSelected)
1797 o.rect = style()->visualRect(layoutDirection(),
d->viewport->rect(), focusRect);
1804 o.rect = style()->visualRect(layoutDirection(),
d->viewport->rect(), sectionRect);
1819 const bool reverse = isRightToLeft();
1820 const int indent =
d->indent;
1821 const int outer =
d->rootDecoration ? 0 : 1;
1822 const int item =
d->current;
1831 QStyleOptionViewItem
opt;
1842 if (
d->alternatingColors) {
1843 opt.
features.setFlag(QStyleOptionViewItem::Alternate,
d->current & 1);
1849 &&
opt.showDecorationSelected
1850 &&
index.parent() ==
d->hover.parent()
1851 &&
index.row() ==
d->hover.row();
1853 if (
d->selectionModel->isSelected(
index))
1856 if (
level >= outer) {
1858 primitive.moveLeft(reverse ? primitive.left() : primitive.left() - indent);
1875 primitive.moveLeft(reverse ? primitive.left() + indent : primitive.left() - indent);
1878 bool moreSiblings =
false;
1879 if (
d->hiddenIndexes.isEmpty()) {
1880 moreSiblings = (
d->model->rowCount(ancestor) - 1 > current.
row());
1882 int successor =
item + viewItem.
total + 1;
1883 while (successor < d->viewItems.size()
1884 &&
d->viewItems.at(successor).level >=
uint(
level)) {
1887 moreSiblings =
true;
1890 successor += successorItem.
total + 1;
1899 ancestor = current.
parent();
1910 bool handled =
false;
1912 handled =
d->expandOrCollapseItemAtPos(
event->position().toPoint());
1913 if (!handled &&
d->itemDecorationAt(
event->position().toPoint()) == -1)
1925 if (
d->itemDecorationAt(
event->position().toPoint()) == -1) {
1931 d->expandOrCollapseItemAtPos(
event->position().toPoint());
1941 if (
state() !=
NoState || !
d->viewport->rect().contains(
event->position().toPoint()))
1944 int i =
d->itemDecorationAt(
event->position().toPoint());
1946 i =
d->itemAtCoordinate(
event->position().toPoint().y());
1953 if (
d->pressedIndex != persistent) {
1970 d->releaseFromDoubleClick =
true;
1971 d->executePostedLayout();
1972 if (
d->itemsExpandable
1973 &&
d->expandsOnDoubleClick
1974 &&
d->hasVisibleChildren(persistent)) {
1975 if (!((i < d->viewItems.size()) && (
d->viewItems.at(
i).index == firstColumnIndex))) {
1977 for (
i = 0;
i <
d->viewItems.size(); ++
i) {
1978 if (
d->viewItems.at(
i).index == firstColumnIndex)
1981 if (
i ==
d->viewItems.size())
1984 if (
d->viewItems.at(
i).expanded)
1985 d->collapse(
i,
true);
2000 if (
d->itemDecorationAt(
event->position().toPoint()) == -1)
2012 if (
d->isIndexValid(current) &&
d->model &&
d->itemsExpandable) {
2013 switch (
event->key()) {
2035 d->executePostedLayout();
2037 int visualIndex =
d->itemAtCoordinate(point.
y());
2042 if (
d->viewItems.at(visualIndex).spanning)
2045 int column =
d->columnAt(point.
x());
2059 if (!
d->isIndexValid(
index))
2061 d->executePostedLayout();
2065 const QModelIndex firstColumnIndex =
d->viewItems.at(
i).index;
2066 return firstColumnIndex.
sibling(firstColumnIndex.
row(),
index.column());
2075 if (!
d->isIndexValid(
index))
2077 d->executePostedLayout();
2079 if (++
i >=
d->viewItems.size())
2081 const QModelIndex firstColumnIndex =
d->viewItems.at(
i).index;
2082 return firstColumnIndex.
sibling(firstColumnIndex.
row(),
index.column());
2093 if (
d->hasRemovedItems) {
2095 d->hasRemovedItems =
false;
2097 while (
it !=
d->expandedIndexes.end()) {
2099 it =
d->expandedIndexes.erase(
it);
2103 it =
d->hiddenIndexes.begin();
2104 while (
it !=
d->hiddenIndexes.end()) {
2106 it =
d->hiddenIndexes.erase(
it);
2111 d->viewItems.clear();
2113 if (
d->model->hasChildren(
parent)) {
2117 d->header->doItemsLayout();
2126 d->expandedIndexes.clear();
2127 d->hiddenIndexes.clear();
2128 d->spanningIndexes.clear();
2129 d->viewItems.clear();
2144 return d->header->offset();
2156 if (
d->uniformRowHeights)
2157 return verticalScrollBar()->value() *
d->defaultItemHeight;
2161 d->executePostedLayout();
2163 const int cnt =
qMin(
d->viewItems.size(), verticalScrollBar()->
value());
2164 for (
int i = 0;
i < cnt; ++
i)
2169 return verticalScrollBar()->value();
2181 d->executePostedLayout();
2185 int i =
d->below(-1);
2187 while (c < d->
header->
count() &&
d->header->isSectionHidden(
d->header->logicalIndex(
c)))
2189 if (i < d->viewItems.size() && c < d->
header->
count()) {
2190 return d->modelIndex(
i,
d->header->logicalIndex(
c));
2195 const int vi =
qMax(0,
d->viewIndex(current));
2197 if (isRightToLeft()) {
2203 switch (cursorAction) {
2206#ifdef QT_KEYPAD_NAVIGATION
2207 if (vi ==
d->viewItems.count()-1 && QApplicationPrivate::keypadNavigationEnabled())
2208 return d->model->index(0, current.
column(),
d->root);
2210 return d->modelIndex(
d->below(vi), current.
column());
2213#ifdef QT_KEYPAD_NAVIGATION
2214 if (vi == 0 && QApplicationPrivate::keypadNavigationEnabled())
2215 return d->modelIndex(
d->viewItems.count() - 1, current.
column());
2217 return d->modelIndex(
d->above(vi), current.
column());
2220 if (vi < d->viewItems.size() &&
d->viewItems.at(vi).expanded &&
d->itemsExpandable && sb->
value() == sb->
minimum()) {
2221 d->collapse(vi,
true);
2222 d->moveCursorUpdatedView =
true;
2234 int visualColumn =
d->header->visualIndex(current.
column()) - 1;
2235 while (visualColumn >= 0 &&
isColumnHidden(
d->header->logicalIndex(visualColumn)))
2237 int newColumn =
d->header->logicalIndex(visualColumn);
2243 int oldValue = sb->
value();
2245 if (oldValue != sb->
value())
2246 d->moveCursorUpdatedView =
true;
2255 if (vi < d->viewItems.size() && !
d->viewItems.at(vi).expanded &&
d->itemsExpandable
2256 &&
d->hasVisibleChildren(
d->viewItems.at(vi).index)) {
2257 d->expand(vi,
true);
2258 d->moveCursorUpdatedView =
true;
2263 if (idx.
parent() == current)
2270 int visualColumn =
d->header->visualIndex(current.
column()) + 1;
2273 const int newColumn =
d->header->logicalIndex(visualColumn);
2281 int oldValue = sb->
value();
2283 if (oldValue != sb->
value())
2284 d->moveCursorUpdatedView =
true;
2291 return d->modelIndex(
d->pageUp(vi), current.
column());
2293 return d->modelIndex(
d->pageDown(vi), current.
column());
2295 return d->modelIndex(
d->itemForKeyHome(), current.
column());
2297 return d->modelIndex(
d->itemForKeyEnd(), current.
column());
2314 d->executePostedLayout();
2321 if (!topLeft.isValid() && !bottomRight.
isValid()) {
2326 if (!topLeft.isValid() && !
d->viewItems.isEmpty())
2327 topLeft =
d->viewItems.constFirst().index;
2328 if (!bottomRight.
isValid() && !
d->viewItems.isEmpty()) {
2329 const int column =
d->header->logicalIndex(
d->header->count() - 1);
2334 if (!
d->isIndexEnabled(topLeft) || !
d->isIndexEnabled(bottomRight))
2337 d->select(topLeft, bottomRight, command);
2354 const QRect &viewportRect =
d->viewport->rect();
2356 if (!
range.isValid())
2360 int columnCount =
d->model->columnCount(
parent);
2362 if (leftIndex.
column() + 1 < columnCount)
2363 leftIndex =
d->model->index(leftIndex.
row(), leftIndex.
column() + 1,
parent);
2370 int top = leftRect.
top();
2373 if (rightIndex.
column() - 1 >= 0)
2374 rightIndex =
d->model->index(rightIndex.
row(), rightIndex.
column() - 1,
parent);
2385 if (
d->header->sectionsMoved()) {
2389 selectionRegion += rangeRect;
2392 QRect combined = leftRect|rightRect;
2395 selectionRegion += combined;
2398 return selectionRegion;
2410 for (
int i = 0;
i < modelSelected.
size(); ++
i) {
2415 if (
index.isValid())
2417 viewSelected.
append(modelSelected.
at(
i));
2419 return viewSelected;
2429 d->delayedAutoScroll.stop();
2431 dx = isRightToLeft() ? -dx : dx;
2433 int oldOffset =
d->header->offset();
2436 int newOffset =
d->header->offset();
2437 dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset;
2441 const int itemHeight =
d->defaultItemHeight <= 0 ?
sizeHintForRow(0) :
d->defaultItemHeight;
2442 if (
d->viewItems.isEmpty() || itemHeight == 0)
2446 int viewCount =
d->viewport->height() / itemHeight;
2447 int maxDeltaY =
qMin(
d->viewItems.size(), viewCount);
2449 if (
qAbs(dy) >
qAbs(maxDeltaY) &&
d->editorIndexHash.isEmpty()) {
2450 verticalScrollBar()->update();
2451 d->viewport->update();
2456 int currentScrollbarValue = verticalScrollBar()->value();
2457 int previousScrollbarValue = currentScrollbarValue + dy;
2458 int currentViewIndex = currentScrollbarValue;
2459 int previousViewIndex = previousScrollbarValue;
2461 if (previousViewIndex < currentViewIndex) {
2462 for (
int i = previousViewIndex;
i < currentViewIndex; ++
i) {
2463 if (i < d->viewItems.size())
2464 dy -=
d->itemHeight(
i);
2466 }
else if (previousViewIndex > currentViewIndex) {
2467 for (
int i = previousViewIndex - 1;
i >= currentViewIndex; --
i) {
2468 if (i < d->viewItems.size())
2469 dy +=
d->itemHeight(
i);
2474 d->scrollContentsBy(dx, dy);
2484 d->viewport->update();
2503 if (
d->delayedPendingLayout) {
2514 const int parentRowCount =
d->model->rowCount(
parent);
2516 if (
parent !=
d->root && !
d->isIndexExpanded(
parent) && parentRowCount > delta) {
2521 const int parentItem =
d->viewIndex(
parent);
2522 if (((parentItem != -1) &&
d->viewItems.at(parentItem).expanded)
2524 d->doDelayedItemsLayout();
2525 }
else if (parentItem != -1 && parentRowCount == delta) {
2527 d->viewItems[parentItem].hasChildren =
true;
2541 d->viewItems.clear();
2553 d->viewItems.clear();
2554 d->doDelayedItemsLayout();
2555 d->hasRemovedItems =
true;
2566 if (oldCount == 0 && newCount > 0) {
2568 d->doDelayedItemsLayout();
2584 d->executePostedLayout();
2585 if (column < 0 || column >=
d->header->count())
2588 int header =
d->header->isHidden() ? 0 :
d->header->sectionSizeHint(
column);
2611 if (!
d->sortingEnabled ||
2612 (
d->header->sortIndicatorSection() ==
column &&
d->header->sortIndicatorOrder() ==
order))
2625 d->executePostedLayout();
2627 const QModelIndex &idx =
d->viewItems.constLast().index;
2629 d->select(
d->viewItems.constFirst().index, lastItemIndex,
2641 d->executePostedLayout();
2643 if (
d->viewItems.size() == 0)
2655 result +=
QSize(0,
d->header->isHidden() ? 0 :
d->header->height());
2675 d->viewItems.clear();
2676 d->interruptDelayedItemsLayout();
2677 d->layout(-1,
true);
2679 d->viewport->update();
2704 d->doDelayedItemsLayout();
2713 const int curDepth = elem.second;
2714 const int rowCount =
d->model->rowCount(
parent);
2715 for (
int row = 0;
row < rowCount; ++
row) {
2717 if (!
d->isIndexValid(
child))
2721 if (
d->isIndexExpanded(
child))
2723 if (
d->storeExpanded(
child))
2740 old_expandedIndexes =
d->expandedIndexes;
2741 d->expandedIndexes.clear();
2744 for (;
i != old_expandedIndexes.
constEnd(); ++
i) {
2765 d->viewItems.clear();
2767 old_expandedIndexes =
d->expandedIndexes;
2768 d->expandedIndexes.clear();
2769 d->interruptDelayedItemsLayout();
2771 for (
int i = 0;
i <
d->viewItems.size(); ++
i) {
2773 d->viewItems[
i].expanded =
true;
2775 d->storeExpanded(
d->viewItems.at(
i).index);
2782 if (!signalsBlocked() && someSignalEnabled) {
2786 for (;
i != collapsedIndexes.
constEnd(); ++
i) {
2794 for (;
i != expandedIndexs.
constEnd(); ++
i) {
2802 d->viewport->update();
2815 d->columnsToUpdate.append(
column);
2816 if (
d->columnResizeTimerID == 0)
2817 d->columnResizeTimerID = startTimer(0);
2827 if (
d->geometryRecursionBlock)
2829 d->geometryRecursionBlock =
true;
2831 if (!
d->header->isHidden()) {
2832 height =
qMax(
d->header->minimumHeight(),
d->header->sizeHint().height());
2835 setViewportMargins(0,
height, 0, 0);
2836 QRect vg =
d->viewport->geometry();
2838 d->header->setGeometry(geometryRect);
2840 d->updateScrollBars();
2841 d->geometryRecursionBlock =
false;
2863 d->executePostedLayout();
2864 if (
d->viewItems.isEmpty())
2868 QStyleOptionViewItem
option;
2872 const int maximumProcessRows =
d->header->resizeContentsPrecision();
2879 if (maximumProcessRows < 0) {
2881 }
else if (maximumProcessRows == 0) {
2883 int remainingHeight =
viewport()->height();
2884 while (
start > 0 && remainingHeight > 0) {
2885 remainingHeight -=
d->itemHeight(
start);
2893 int rowsProcessed = 0;
2896 if (viewItems.
at(
i).spanning)
2902 if (rowsProcessed == maximumProcessRows)
2907 int actualBottom = viewItems.
size() - 1;
2909 if (maximumProcessRows == 0)
2912 while (rowsProcessed != maximumProcessRows && (
start > 0 ||
end < actualBottom)) {
2915 if ((rowsProcessed % 2 &&
start > 0) ||
end == actualBottom) {
2918 if (viewItems.
at(
start).spanning)
2924 while (
end < actualBottom) {
2926 if (viewItems.
at(
end).spanning)
2951 if (!
d->isIndexValid(
index) || !
d->itemDelegate)
2956 int indexRow =
index.row();
2957 int count =
d->header->count();
2958 bool emptyHeader = (
count == 0);
2963 start =
d->header->visualIndexAt(0);
2969 if (isRightToLeft()) {
2981 QStyleOptionViewItem
option;
2988 option.rect.setWidth(-1);
2991 int logicalColumn = emptyHeader ?
column :
d->header->logicalIndex(
column);
2992 if (
d->header->isSectionHidden(logicalColumn))
2996 QWidget *editor =
d->editorForIndex(idx).widget.data();
2997 if (editor &&
d->persistent.contains(editor)) {
2999 int min = editor->minimumSize().height();
3000 int max = editor->maximumSize().height();
3019 d->executePostedLayout();
3023 return d->itemHeight(
i);
3050 updateStyledFrameWidths();
3061#if QT_CONFIG(animation)
3077#if QT_CONFIG(animation)
3094#if QT_CONFIG(animation)
3096 beginAnimatedOperation();
3120bool QTreeViewPrivate::checkViewItems()
const
3152#if QT_CONFIG(animation)
3164 while (
index > -1) {
3173#if QT_CONFIG(animation)
3175 beginAnimatedOperation();
3180#if QT_CONFIG(animation)
3183 animatedOperation.item =
item;
3184 animatedOperation.viewport =
viewport;
3185 animatedOperation.setDirection(
direction);
3197 animatedOperation.setEndValue(
top +
h);
3199 animatedOperation.setStartValue(
top);
3200 animatedOperation.before = renderTreeToPixmapForAnimation(
rect);
3203void QTreeViewPrivate::beginAnimatedOperation()
3208 rect.setTop(animatedOperation.top());
3212 int c = animatedOperation.item +
viewItems.
at(animatedOperation.item).
total + 1;
3213 for (
int i = animatedOperation.item + 1;
i <
c &&
h <
limit; ++
i)
3216 animatedOperation.setEndValue(animatedOperation.top() +
h);
3219 if (!
rect.isEmpty()) {
3220 animatedOperation.after = renderTreeToPixmapForAnimation(
rect);
3223 animatedOperation.start();
3229 const int start = animatedOperation.startValue().toInt(),
3230 end = animatedOperation.endValue().toInt(),
3231 current = animatedOperation.currentValue().toInt();
3233 const QPixmap top = collapsing ? animatedOperation.before : animatedOperation.after;
3235 const QPixmap bottom = collapsing ? animatedOperation.after : animatedOperation.before;
3239QPixmap QTreeViewPrivate::renderTreeToPixmapForAnimation(
const QRect &
rect)
const
3243 pixmap.setDevicePixelRatio(
q->devicePixelRatio());
3244 if (
rect.size().isEmpty())
3254 QStyleOptionViewItem
option;
3255 q->initViewItemOption(&
option);
3260 if (
option.rect.isValid()) {
3279void QTreeViewPrivate::_q_endAnimatedOperation()
3283 q->updateGeometries();
3320 if (
i>=0 && !
parent.isValid()) {
3327#if QT_CONFIG(accessibility)
3332 if (oldViewItemsSize != viewItems.size() && QAccessible::isActive()) {
3333 QAccessibleTableModelChangeEvent event(q, QAccessibleTableModelChangeEvent::ModelReset);
3334 QAccessible::updateAccessibility(&event);
3345 const int itemHeight = defaultItemHeight <= 0 ?
q->sizeHintForRow(0) : defaultItemHeight;
3346 const int viewCount = itemHeight ?
viewport->height() / itemHeight : 0;
3358 bool expanding =
true;
3360 if (uniformRowHeights) {
3362 defaultItemHeight =
q->indexRowSizeHint(
index);
3364 viewItems.resize(
count);
3365 afterIsUninitialized =
true;
3366 }
else if (viewItems[
i].total != (
uint)
count) {
3367 if (!afterIsUninitialized)
3370 viewItems.resize(viewItems.size() +
count);
3376 int level = (
i >= 0 ? viewItems.at(
i).level + 1 : 0);
3383 if (isRowHidden(current)) {
3385 last =
j - hidden + children;
3387 last =
j - hidden + children;
3389 item->hasMoreSiblings =
true;
3390 item = &viewItems[last];
3391 item->index = current;
3395 item->spanning =
q->isFirstColumnSpanned(current.row(),
parent);
3396 item->expanded =
false;
3398 item->hasMoreSiblings =
false;
3400 if (recursiveExpanding && storeExpanded(current) && !
q->signalsBlocked())
3401 emit q->expanded(current);
3402 item->expanded =
true;
3403 layout(last, recursiveExpanding, afterIsUninitialized);
3404 item = &viewItems[last];
3405 children +=
item->total;
3406 item->hasChildren =
item->total > 0;
3407 last =
j - hidden + children;
3409 item->hasChildren = hasVisibleChildren(current);
3416 if (!afterIsUninitialized)
3417 removeViewItems(last + 1, hidden);
3419 viewItems.resize(viewItems.size() - hidden);
3426 viewItems[
i].total +=
count - hidden;
3427 i = viewItems[
i].parentItem;
3489 if (!
index.isValid())
3513 return y - vbar->value();
3517 int topViewItemIndex = vbar->value();
3520 if (
item >= topViewItemIndex) {
3523 int viewItemCoordinate = 0;
3524 int viewItemIndex = topViewItemIndex;
3526 if (viewItemIndex ==
item)
3527 return viewItemCoordinate;
3528 viewItemCoordinate +=
itemHeight(viewItemIndex);
3533 return viewItemCoordinate;
3536 int viewItemCoordinate = 0;
3537 for (
int viewItemIndex = topViewItemIndex; viewItemIndex > 0; --viewItemIndex) {
3538 if (viewItemIndex ==
item)
3539 return viewItemCoordinate;
3540 viewItemCoordinate -=
itemHeight(viewItemIndex - 1);
3542 return viewItemCoordinate;
3565 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3568 int viewItemCoordinate = 0;
3569 const int contentsCoordinate = coordinate + vbar->value();
3570 for (
int viewItemIndex = 0; viewItemIndex <
viewItems.
size(); ++viewItemIndex) {
3571 viewItemCoordinate +=
itemHeight(viewItemIndex);
3572 if (viewItemCoordinate > contentsCoordinate)
3573 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3576 int topViewItemIndex = vbar->value();
3581 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3583 if (coordinate >= 0) {
3585 int viewItemCoordinate = 0;
3586 for (
int viewItemIndex = topViewItemIndex; viewItemIndex <
viewItems.
size(); ++viewItemIndex) {
3587 viewItemCoordinate +=
itemHeight(viewItemIndex);
3588 if (viewItemCoordinate > coordinate)
3589 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3593 int viewItemCoordinate = 0;
3594 for (
int viewItemIndex = topViewItemIndex; viewItemIndex >= 0; --viewItemIndex) {
3595 if (viewItemCoordinate <= coordinate)
3596 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3597 viewItemCoordinate -=
itemHeight(viewItemIndex);
3616 for (
int i = 0;
i < localCount; ++
i) {
3661 const int value = vbar->value();
3690 if (firstVisual < 0 ||
offset < 0) {
3692 if (firstVisual < 0)
3716 viewportSize =
QSize(0, 0);
3723 int itemsInViewport = 0;
3731 const int viewportHeight = viewportSize.
height();
3734 if (
height > viewportHeight)
3741 itemsInViewport =
qMax(1, itemsInViewport);
3743 vbar->setPageStep(itemsInViewport);
3744 vbar->setSingleStep(1);
3746 int contentsHeight = 0;
3753 vbar->setRange(0, contentsHeight - viewportSize.
height());
3754 vbar->setPageStep(viewportSize.
height());
3755 vbar->d_func()->itemviewChangeSingleStep(
qMax(viewportSize.
height() / (itemsInViewport + 1), 2));
3759 const int viewportWidth = viewportSize.
width();
3760 int columnsInViewport = 0;
3764 if (
width > viewportWidth)
3766 ++columnsInViewport;
3768 if (columnCount > 0)
3769 columnsInViewport =
qMax(1, columnsInViewport);
3771 hbar->setRange(0, columnCount - columnsInViewport);
3772 hbar->setPageStep(columnsInViewport);
3773 hbar->setSingleStep(1);
3776 const QSize maxSize =
q->maximumViewportSize();
3777 if (maxSize.
width() >= horizontalLength && vbar->maximum() <= 0)
3778 viewportSize = maxSize;
3779 hbar->setPageStep(viewportSize.
width());
3780 hbar->setRange(0,
qMax(horizontalLength - viewportSize.
width(), 0));
3781 hbar->d_func()->itemviewChangeSingleStep(
qMax(viewportSize.
width() / (columnsInViewport + 1), 2));
3789 bool spanned =
false;
3792 if (
index.isValid())
3793 spanned =
q->isFirstColumnSpanned(
index.row(),
index.parent());
3804 return viewItemIndex;
3822 if (
q->isRightToLeft())
3840 const int start =
qMin(topVisual, bottomVisual);
3841 const int end =
qMax(topVisual, bottomVisual);
3849 logicalIndexes << logical;
3853 std::sort(logicalIndexes.
begin(), logicalIndexes.
end());
3859 for(
int i = 0;
i < logicalIndexes.
size(); ++
i) {
3860 const int logicalColumn = logicalIndexes.
at(
i);
3861 if (
current.second + 1 != logicalColumn) {
3882 QItemSelectionModel::SelectionFlags command)
3892 const int left = (*it).first,
3893 right = (*it).second;
3918 rangeStack.
push(currentRange);
3926 currentRange = rangeStack.
pop();
3935 for (
int i = 0;
i < rangeStack.
size(); ++
i)
3938 q->selectionModel()->select(
selection, command);
3946 if (
q->isRightToLeft()) {
3967 for (
int i = 0;
i < rowCount; ++
i) {
3987 return (
q->visualIndex(
index) + (
q->header() ? 1 : 0)) *
index.model()->columnCount() +
index.column();
4006 previousRect.
setX(0);
4012 currentRect.
setX(0);
4017#if QT_CONFIG(accessibility)
4018 if (QAccessible::isActive() && current.
isValid()) {
4021 QAccessibleEvent
event(
this, QAccessible::Focus);
4022 event.setChild(
d->accessibleTree2Index(current));
4023 QAccessible::updateAccessibility(&
event);
4035#if QT_CONFIG(accessibility)
4036 if (QAccessible::isActive()) {
4042 int entry =
d->accessibleTree2Index(sel);
4044 QAccessibleEvent
event(
this, QAccessible::SelectionAdd);
4045 event.setChild(
entry);
4046 QAccessible::updateAccessibility(&
event);
4050 int entry =
d->accessibleTree2Index(desel);
4052 QAccessibleEvent
event(
this, QAccessible::SelectionRemove);
4053 event.setChild(
entry);
4054 QAccessible::updateAccessibility(&
event);
4063 d->executePostedLayout();
4064 return d->viewIndex(
index);
4074 if (!
d->viewItems.isEmpty() &&
value == verticalScrollBar()->maximum()) {
4077 while (
ret.isValid()) {
4079 d->model->fetchMore(
ret);
4090#include "moc_qtreeview.cpp"
Direction
This enum describes the direction of the animation when in \l Running state.
The QAbstractItemDelegate class is used to display and edit data items from a model.
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const =0
This pure abstract function must be reimplemented if you want to provide custom rendering.
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const =0
This pure abstract function must be reimplemented if you want to provide custom rendering.
static QAbstractItemModel * staticEmptyModel()
virtual Q_INVOKABLE bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Returns {true} if parent has any children; otherwise returns {false}.
virtual Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
virtual Q_INVOKABLE void fetchMore(const QModelIndex &parent)
Fetches any available data for the items with the parent specified by the parent index.
virtual Q_INVOKABLE bool canFetchMore(const QModelIndex &parent) const
Returns {true} if there is more data available for parent; otherwise returns {false}.
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.
const QEditorInfo & editorForIndex(const QModelIndex &index) const
virtual void _q_modelDestroyed()
virtual QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const
void doDelayedItemsLayout(int delay=0)
QBasicTimer delayedAutoScroll
QSet< QWidget * > persistent
QPointer< QAbstractItemDelegate > itemDelegate
QAbstractItemView::ScrollMode horizontalScrollMode
virtual void _q_columnsRemoved(const QModelIndex &parent, int start, int end)
QAbstractItemView::State state
bool isPersistent(const QModelIndex &index) const
QAbstractItemView::State stateBeforeAnimation
QPersistentModelIndex root
QAbstractItemModel * model
virtual void _q_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
void executePostedLayout() const
QWidget * editor(const QModelIndex &index, const QStyleOptionViewItem &options)
QEditorIndexHash editorIndexHash
QAbstractItemView::SelectionBehavior selectionBehavior
QAbstractItemView::ScrollMode verticalScrollMode
The QAbstractItemView class provides the basic functionality for item view classes.
SelectionMode
This enum indicates how the view responds to user selections:
QWidget * indexWidget(const QModelIndex &index) const
void activated(const QModelIndex &index)
This signal is emitted when the item specified by index is activated by the user.
QAbstractItemModel * model() const
Returns the model that this view is presenting.
void setCurrentIndex(const QModelIndex &index)
Sets the current item to be the item at index.
void doubleClicked(const QModelIndex &index)
This signal is emitted when a mouse button is double-clicked.
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
Sets the current selection model to the given selectionModel.
void timerEvent(QTimerEvent *event) override
This function is called with the given event when a timer event is sent to the widget.
ScrollMode verticalScrollMode
how the view scrolls its contents in the vertical direction
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This slot is called when the selection is changed.
State state() const
Returns the item view's state.
virtual void reset()
Reset the internal state of the view.
void mouseReleaseEvent(QMouseEvent *event) override
This function is called with the given event when a mouse button is released, after a mouse press eve...
virtual QAbstractItemDelegate * itemDelegateForIndex(const QModelIndex &index) const
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.
QModelIndex currentIndex() const
Returns the model index of the current item.
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.
ScrollMode horizontalScrollMode
how the view scrolls its contents in the horizontal direction
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
virtual void initViewItemOption(QStyleOptionViewItem *option) const
virtual void doItemsLayout()
void keyPressEvent(QKeyEvent *event) override
This function is called with the given event when a key event is sent to the widget.
QModelIndex rootIndex() const
Returns the model index of the model's root item.
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.
void mousePressEvent(QMouseEvent *event) override
This function is called with the given event when a mouse button is pressed while the cursor is insid...
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
This slot is called when rows are inserted.
virtual void updateEditorGeometries()
void edit(const QModelIndex &index)
Starts editing the item corresponding to the given index if it is editable.
void setState(State state)
Sets the item view's state to the given state.
void mouseMoveEvent(QMouseEvent *event) override
This function is called with the given event when a mouse move event is sent to the widget.
QItemSelectionModel * selectionModel() const
Returns the current selection model.
virtual void verticalScrollbarValueChanged(int value)
virtual void updateGeometries()
SelectionBehavior selectionBehavior
which selection behavior the view uses
QSize viewportSizeHint() const override
virtual void horizontalScrollbarAction(int action)
virtual int sizeHintForRow(int row) const
Returns the height size hint for the specified row or -1 if there is no model.
int value
the slider's current value
int singleStep
the single step.
int minimum
the sliders's minimum value
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the index of the data in row and column with parent.
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this ap...
int keyboardInputInterval
the time limit in milliseconds that distinguishes a key press from two consecutive key presses
void stop()
Stops the timer.
static QPoint pos()
Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates.
QGraphicsItem * parentItem() const
Returns a pointer to this item's parent item.
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
const_iterator constBegin() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
friend class const_iterator
QModelIndexList selectedIndexes
virtual void clear()
Clears the selection model.
int top() const
Returns the row index corresponding to the uppermost selected row in the selection range.
const QPersistentModelIndex & bottomRight() const
Returns the index for the item located at the bottom-right corner of the selection range.
QModelIndex parent() const
Returns the parent model item index of the items in the selection range.
int left() const
Returns the column index corresponding to the leftmost selected column in the selection range.
bool isValid() const
Returns true if the selection range is valid; otherwise returns false.
Q_CORE_EXPORT QModelIndexList indexes() const
Returns a list of model indexes that correspond to the selected items.
The QKeyEvent class describes a key event.
qsizetype size() const noexcept
bool isEmpty() const noexcept
iterator insert(qsizetype i, parameter_type t)
const_reference at(qsizetype i) const noexcept
T value(qsizetype i) const
void remove(qsizetype i, qsizetype n=1)
qsizetype count() const noexcept
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}.
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
constexpr quintptr internalId() const noexcept
Returns a {quintptr} used by the model to associate the index with the internal data structure.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
The QPaintEvent class contains event parameters for paint events.
The QPainter class performs low-level painting on widgets and other paint devices.
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation.
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 save()
Saves the current painter state (pushes the state onto a stack).
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
QPoint brushOrigin() const
Returns the currently set brush origin.
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
void setCurrentColorGroup(ColorGroup cg)
Set the palette's current color group to cg.
ColorGroup
\value Disabled \value Active \value Inactive \value Normal synonym for Active
bool isValid() const
Returns {true} if this persistent model index is valid; otherwise returns {false}.
Qt::ItemFlags flags() const
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
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
bool intersects(const QRect &r) const noexcept
Returns true if this rectangle intersects with the given rectangle (i.e., there is at least one pixel...
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
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 setWidth(int w) noexcept
Sets the width of the rectangle to the given width.
constexpr void setX(int x) noexcept
Sets the left edge of the rectangle to the given x coordinate.
constexpr int width() const noexcept
Returns the width of the rectangle.
The QRegion class specifies a clip region for a painter.
QRect boundingRect() const noexcept
Returns the bounding rectangle of this region.
int rectCount() const noexcept
const_iterator constBegin() const noexcept
const_iterator constEnd() const noexcept
iterator erase(const_iterator i)
iterator find(const T &value)
bool contains(const T &value) const
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool canFetchMore(const QModelIndex &parent=QModelIndex()) const override
void fetchMore(const QModelIndex &parent=QModelIndex()) override
T pop()
Removes the top item from the stack and returns it.
void push(const T &t)
Adds element t to the top of the stack.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
\variable QStyleOption::palette
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.
@ State_KeyboardFocusChange
@ SH_ItemView_PaintAlternatingRowColorsForEmptyArea
@ SH_ItemView_ArrowKeysNavigateIntoChildren
@ SH_Widget_Animation_Duration
@ SH_ListViewExpand_SelectMouseType
@ SH_ItemView_ActivateItemOnSingleClick
@ SH_ItemView_ShowDecorationSelected
@ SE_TreeViewDisclosureItem
int itemForKeyEnd() const
int widthHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option, int i) const
int accessibleTree2Index(const QModelIndex &index) const
bool isRowHidden(const QModelIndex &idx) const
int logicalIndexForTree() const
bool isItemHiddenOrDisabled(int i) const
void _q_sortIndicatorChanged(int column, Qt::SortOrder order)
int itemHeight(int item) const
void collapse(int item, bool emitSignal)
void calcLogicalIndices(QList< int > *logicalIndices, QList< QStyleOptionViewItem::ViewItemPosition > *itemPositions, int left, int right) const
void layout(int item, bool recusiveExpanding=false, bool afterIsUninitialized=false)
QModelIndex modelIndex(int i, int column=0) const
bool storeExpanded(const QPersistentModelIndex &idx)
QList< QPair< int, int > > columnRanges(const QModelIndex &topIndex, const QModelIndex &bottomIndex) const
void removeViewItems(int pos, int count)
bool isTreePosition(int logicalIndex) const
QRect intersectedRect(const QRect rect, const QModelIndex &topLeft, const QModelIndex &bottomRight) const override
int firstVisibleItem(int *offset=nullptr) const
QRect itemDecorationRect(const QModelIndex &index) const
void insertViewItems(int pos, int count, const QTreeViewItem &viewItem)
QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const override
\reimp
void _q_columnsRemoved(const QModelIndex &, int, int) override
void select(const QModelIndex &start, const QModelIndex &stop, QItemSelectionModel::SelectionFlags command)
void paintAlternatingRowColors(QPainter *painter, QStyleOptionViewItem *option, int y, int bottom) const
void _q_modelDestroyed() override
QList< QTreeViewItem > viewItems
int pageUp(int item) const
int viewIndex(const QModelIndex &index) const
int itemDecorationAt(const QPoint &pos) const
int pageDown(int item) const
QSet< QPersistentModelIndex > hiddenIndexes
int lastVisibleItem(int firstVisual=-1, int offset=-1) const
int columnAt(int x) const
int itemAtCoordinate(int coordinate) const
QSet< QPersistentModelIndex > spanningIndexes
void _q_columnsAboutToBeRemoved(const QModelIndex &, int, int) override
int itemForKeyHome() const
int indentationForItem(int item) const
void updateIndentationFromStyle()
QSet< QPersistentModelIndex > expandedIndexes
bool expandOrCollapseItemAtPos(const QPoint &pos)
void adjustViewOptionsForIndex(QStyleOptionViewItem *option, const QModelIndex ¤t) const override
int coordinateForItem(int item) const
void _q_modelAboutToBeReset()
void expand(int item, bool emitSignal)
QPair< int, int > startAndEndColumns(const QRect &rect) const
bool hasVisibleChildren(const QModelIndex &parent) const
The QTreeView class provides a default model/view implementation of a tree view.
void setItemsExpandable(bool enable)
bool isSortingEnabled() const
bool isIndexHidden(const QModelIndex &index) const override
\reimp
void expand(const QModelIndex &index)
Expands the model item specified by the index.
bool itemsExpandable
whether the items are expandable by the user.
QRegion visualRegionForSelection(const QItemSelection &selection) const override
Returns the rectangle from the viewport of the items in the given selection.
void setWordWrap(bool on)
void setSelectionModel(QItemSelectionModel *selectionModel) override
\reimp
bool isHeaderHidden() const
virtual void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
Draws the branches in the tree view on the same row as the model item index, using the painter given.
void collapse(const QModelIndex &index)
Collapses the model item specified by the index.
void setModel(QAbstractItemModel *model) override
\reimp
QModelIndex indexBelow(const QModelIndex &index) const
Returns the model index of the item below index.
int indexRowSizeHint(const QModelIndex &index) const
Returns the size hint for the row indicated by index.
void reset() override
\reimp
void doItemsLayout() override
int rowHeight(const QModelIndex &index) const
bool isExpanded(const QModelIndex &index) const
Returns true if the model item index is expanded; otherwise returns false.
void changeEvent(QEvent *event) override
\reimp
QSize viewportSizeHint() const override
\reimp
int columnViewportPosition(int column) const
Returns the horizontal position of the column in the viewport.
void columnCountChanged(int oldCount, int newCount)
Informs the tree view that the number of columns in the tree view has changed from oldCount to newCou...
void setColumnHidden(int column, bool hide)
If hide is true the column is hidden, otherwise the column is shown.
QHeaderView * header() const
Returns the header for the tree view.
void setColumnWidth(int column, int width)
void keyPressEvent(QKeyEvent *event) override
\reimp
void setTreePosition(int logicalIndex)
void setExpandsOnDoubleClick(bool enable)
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override
Move the cursor in the way described by cursorAction, using the information provided by the button mo...
void verticalScrollbarValueChanged(int value) override
bool wordWrap
the item text word-wrapping policy
int columnAt(int x) const
Returns the column in the tree view whose header covers the x coordinate given.
virtual void drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const
Draws the row in the tree view that contains the model item index, using the painter given.
void selectAll() override
\reimp
void setExpanded(const QModelIndex &index, bool expand)
Sets the item referred to by index to either collapse or expanded, depending on the value of expanded...
void updateGeometries() override
\reimp
void mousePressEvent(QMouseEvent *event) override
\reimp
void timerEvent(QTimerEvent *event) override
\reimp
~QTreeView()
Destroys the tree view.
QModelIndex indexAt(const QPoint &p) const override
\reimp
int sizeHintForColumn(int column) const override
Returns the size hint for the column's width or -1 if there is no model.
void setHeaderHidden(bool hide)
QModelIndex indexAbove(const QModelIndex &index) const
Returns the model index of the item above index.
bool viewportEvent(QEvent *event) override
\reimp
void drawTree(QPainter *painter, const QRegion ®ion) const
void columnMoved()
This slot is called whenever a column has been moved.
bool uniformRowHeights
whether all items in the treeview have the same height
void expandToDepth(int depth)
void setUniformRowHeights(bool uniform)
void showColumn(int column)
Shows the given column in the tree view.
void setHeader(QHeaderView *header)
Sets the header for the tree view, to the given header.
QTreeView(QWidget *parent=nullptr)
Constructs a tree view with a parent to represent a model's data.
void setRootIsDecorated(bool show)
void setIndentation(int i)
int indentation
indentation of the items in the tree view.
void setAllColumnsShowFocus(bool enable)
void columnResized(int column, int oldSize, int newSize)
This function is called whenever {column}'s size is changed in the header.
void mouseReleaseEvent(QMouseEvent *event) override
\reimp
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override
Applies the selection command to the items in or touched by the rectangle, rect.
bool allColumnsShowFocus
whether items should show keyboard focus using all columns
void paintEvent(QPaintEvent *event) override
\reimp
void resizeColumnToContents(int column)
Resizes the column given to the size of its contents.
void setFirstColumnSpanned(int row, const QModelIndex &parent, bool span)
int autoExpandDelay
The delay time before items in a tree are opened during a drag and drop operation.
void mouseDoubleClickEvent(QMouseEvent *event) override
\reimp
void setAutoExpandDelay(int delay)
QModelIndexList selectedIndexes() const override
\reimp
void keyboardSearch(const QString &search) override
\reimp
void collapsed(const QModelIndex &index)
This signal is emitted when the item specified by index is collapsed.
void mouseMoveEvent(QMouseEvent *event) override
\reimp
void sortByColumn(int column, Qt::SortOrder order)
bool isColumnHidden(int column) const
Returns true if the column is hidden; otherwise returns false.
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible) override
Scroll the contents of the tree view until the given model item index is visible.
void rowsRemoved(const QModelIndex &parent, int first, int last)
bool rootIsDecorated
whether to show controls for expanding and collapsing top-level items
bool expandsOnDoubleClick
whether the items can be expanded by double-clicking.
void setRowHidden(int row, const QModelIndex &parent, bool hide)
If hide is true the row with the given parent is hidden, otherwise the row is shown.
bool isRowHidden(int row, const QModelIndex &parent) const
Returns true if the item in the given row of the parent is hidden; otherwise returns false.
QRect visualRect(const QModelIndex &index) const override
Returns the rectangle on the viewport occupied by the item at index.
int horizontalOffset() const override
Returns the horizontal offset of the items in the treeview.
void setSortingEnabled(bool enable)
int columnWidth(int column) const
Returns the width of the column.
void hideColumn(int column)
Hides the column given.
bool isFirstColumnSpanned(int row, const QModelIndex &parent) const
void setAnimated(bool enable)
void expanded(const QModelIndex &index)
This signal is emitted when the item specified by index is expanded.
int verticalOffset() const override
Returns the vertical offset of the items in the tree view.
void expandRecursively(const QModelIndex &index, int depth=-1)
void scrollContentsBy(int dx, int dy) override
Scrolls the contents of the tree view by (dx, dy).
EGLImageKHR int int EGLuint64KHR * modifiers
QSet< QString >::iterator it
Combined button and popup list for selecting options.
std::pair< T1, T2 > QPair
static QString header(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static int area(const QSize &s)
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)
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
GLenum GLuint GLint level
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum GLuint GLintptr offset
GLfloat GLfloat GLfloat GLfloat h
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
GLenum GLenum GLsizei void GLsizei void void * span
GLfixed GLfixed GLint GLint order
constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
static bool ancestorOf(QObject *widget, QObject *other)
QSqlQueryModel * model
[16]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
myObject disconnect()
[26]
view viewport() -> scroll(dx, dy, deviceRect)
QItemSelection * selection
[0]
QPointer< QWidget > widget
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
bool contains(const AT &t) const noexcept
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent