186void QTreeView::setModel(QAbstractItemModel *model)
189 if (model == d->model)
191 if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
192 for (QMetaObject::Connection &connection : d->modelConnections)
193 QObject::disconnect(connection);
196 if (d->selectionModel) {
197 QObject::disconnect(d->selectionmodelConnection);
199 d->viewItems.clear();
200 d->expandedIndexes.clear();
201 d->hiddenIndexes.clear();
202 d->geometryRecursionBlock =
true;
203 d->header->setModel(model);
204 d->geometryRecursionBlock =
false;
205 QAbstractItemView::setModel(model);
209 QObjectPrivate::disconnect(d->model, &QAbstractItemModel::rowsRemoved,
210 d, &QAbstractItemViewPrivate::rowsRemoved);
212 QObjectPrivate::disconnect(d->model, &QAbstractItemModel::layoutChanged,
213 d->header->d_func(), &QAbstractItemViewPrivate::layoutChanged);
215 d->modelConnections = {
217 QObject::connect(d->model, &QAbstractItemModel::rowsRemoved,
218 this, &QTreeView::rowsRemoved),
219 QObjectPrivate::connect(d->model, &QAbstractItemModel::modelAboutToBeReset,
220 d, &QTreeViewPrivate::modelAboutToBeReset)
223 if (d->sortingEnabled)
224 d->sortIndicatorChanged(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
279void QTreeView::setHeader(QHeaderView *header)
282 if (header == d->header || !header)
284 if (d->header && d->header->parent() ==
this)
287 d->header->setParent(
this);
288 d->header->setFirstSectionMovable(
false);
290 if (!d->header->model()) {
291 d->header->setModel(d->model);
292 if (d->selectionModel)
293 d->header->setSelectionModel(d->selectionModel);
296 d->headerConnections = {
297 connect(d->header, &QHeaderView::sectionResized,
298 this, &QTreeView::columnResized),
299 connect(d->header, &QHeaderView::sectionMoved,
300 this, &QTreeView::columnMoved),
301 connect(d->header, &QHeaderView::sectionCountChanged,
302 this, &QTreeView::columnCountChanged),
303 connect(d->header, &QHeaderView::sectionHandleDoubleClicked,
304 this, &QTreeView::resizeColumnToContents),
305 connect(d->header, &QHeaderView::geometriesChanged,
306 this, &QTreeView::updateGeometries)
309 setSortingEnabled(d->sortingEnabled);
967void QTreeView::keyboardSearch(
const QString &search)
970 if (!d->model->rowCount(d->root) || !d->model->columnCount(d->root))
974 d->executePostedLayout();
975 if (d->viewItems.isEmpty())
979 if (currentIndex().isValid())
980 start = currentIndex();
982 start = d->viewItems.at(0).index;
984 bool skipRow =
false;
985 bool keyboardTimeWasValid = d->keyboardInputTime.isValid();
986 qint64 keyboardInputTimeElapsed;
987 if (keyboardTimeWasValid)
988 keyboardInputTimeElapsed = d->keyboardInputTime.restart();
990 d->keyboardInputTime.start();
991 if (search.isEmpty() || !keyboardTimeWasValid
992 || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) {
993 d->keyboardInput = search;
994 skipRow = currentIndex().isValid();
996 d->keyboardInput += search;
1000 bool sameKey =
false;
1001 if (d->keyboardInput.size() > 1) {
1002 int c = d->keyboardInput.count(d->keyboardInput.at(d->keyboardInput.size() - 1));
1003 sameKey = (c == d->keyboardInput.size());
1010 if (indexBelow(start).isValid()) {
1011 start = indexBelow(start);
1013 const int origCol = start.column();
1014 start = d->viewItems.at(0).index;
1015 if (origCol != start.column())
1016 start = start.sibling(start.row(), origCol);
1020 int startIndex = d->viewIndex(start);
1021 if (startIndex <= -1)
1024 int previousLevel = -1;
1027 QString searchString = sameKey ? QString(d->keyboardInput.at(0)) : d->keyboardInput;
1028 for (
int i = 0; i < d->viewItems.size(); ++i) {
1029 if ((
int)d->viewItems.at(i).level > previousLevel) {
1030 QModelIndex searchFrom = d->viewItems.at(i).index;
1031 if (start.column() > 0)
1032 searchFrom = searchFrom.sibling(searchFrom.row(), start.column());
1033 if (searchFrom.parent() == start.parent())
1035 QModelIndexList match = d->model->match(searchFrom, Qt::DisplayRole, searchString, 1,
1036 keyboardSearchFlags());
1038 int hitIndex = d->viewIndex(match.at(0));
1039 if (hitIndex >= 0 && hitIndex < startIndex)
1040 bestAbove = bestAbove == -1 ? hitIndex : qMin(hitIndex, bestAbove);
1041 else if (hitIndex >= startIndex)
1042 bestBelow = bestBelow == -1 ? hitIndex : qMin(hitIndex, bestBelow);
1045 previousLevel = d->viewItems.at(i).level;
1050 index = d->viewItems.at(bestBelow).index;
1051 else if (bestAbove > -1)
1052 index = d->viewItems.at(bestAbove).index;
1054 if (start.column() > 0)
1055 index = index.sibling(index.row(), start.column());
1057 if (index.isValid())
1058 setCurrentIndex(index);
1151void QTreeView::scrollTo(
const QModelIndex &index, ScrollHint hint)
1155 if (!d->isIndexValid(index))
1158 d->executePostedLayout();
1159 d->updateScrollBars();
1162 QModelIndex parent = index.parent();
1163 while (parent != d->root && parent.isValid() && state() == NoState && d->itemsExpandable) {
1164 if (!isExpanded(parent))
1166 parent = d->model->parent(parent);
1169 int item = d->viewIndex(index);
1173 QRect area = d->viewport->rect();
1176 if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
1177 int top = verticalScrollBar()->value();
1178 int bottom = top + verticalScrollBar()->pageStep();
1179 if (hint == EnsureVisible && item >= top && item < bottom) {
1181 }
else if (hint == PositionAtTop || (hint == EnsureVisible && item < top)) {
1182 verticalScrollBar()->setValue(item);
1184 const int currentItemHeight = d->itemHeight(item);
1185 int y = (hint == PositionAtCenter
1187 ? area.height() / 2 + currentItemHeight - 1
1190 if (y > currentItemHeight) {
1192 y -= d->itemHeight(item);
1200 verticalScrollBar()->setValue(item);
1203 QRect rect(columnViewportPosition(index.column()),
1204 d->coordinateForItem(item),
1205 columnWidth(index.column()),
1206 d->itemHeight(item));
1208 if (rect.isEmpty()) {
1210 }
else if (hint == EnsureVisible && area.contains(rect)) {
1211 d->viewport->update(rect);
1214 bool above = (hint == EnsureVisible
1215 && (rect.top() < area.top()
1216 || area.height() < rect.height()));
1217 bool below = (hint == EnsureVisible
1218 && rect.bottom() > area.bottom()
1219 && rect.height() < area.height());
1221 int verticalValue = verticalScrollBar()->value();
1222 if (hint == PositionAtTop || above)
1223 verticalValue += rect.top();
1224 else if (hint == PositionAtBottom || below)
1225 verticalValue += rect.bottom() - area.height();
1226 else if (hint == PositionAtCenter)
1227 verticalValue += rect.top() - ((area.height() - rect.height()) / 2);
1228 verticalScrollBar()->setValue(verticalValue);
1232 int viewportWidth = d->viewport->width();
1233 int horizontalOffset = d->header->offset();
1234 int horizontalPosition = d->header->sectionPosition(index.column());
1235 int cellWidth = d->header->sectionSize(index.column());
1237 if (hint == PositionAtCenter) {
1238 horizontalScrollBar()->setValue(horizontalPosition - ((viewportWidth - cellWidth) / 2));
1240 if (horizontalPosition - horizontalOffset < 0 || cellWidth > viewportWidth)
1241 horizontalScrollBar()->setValue(horizontalPosition);
1242 else if (horizontalPosition - horizontalOffset + cellWidth > viewportWidth)
1243 horizontalScrollBar()->setValue(horizontalPosition - viewportWidth + cellWidth);
1419QRect QTreeViewPrivate::intersectedRect(
const QRect rect,
const QModelIndex &topLeft,
const QModelIndex &bottomRight)
const
1421 const auto parentIdx = topLeft.parent();
1422 executePostedLayout();
1424 int left = std::numeric_limits<
int>::max();
1425 int right = std::numeric_limits<
int>::min();
1426 for (
int row = topLeft.row(); row <= bottomRight.row(); ++row) {
1427 const auto idxCol0 = model->index(row, 0, parentIdx);
1428 if (isRowHidden(idxCol0))
1431 if (left != std::numeric_limits<
int>::max()) {
1433 rowRect = visualRect(idxCol0, FullRow);
1434 if (!rowRect.intersects(rect))
1436 rowRect = QRect(left, rowRect.top(), right, rowRect.bottom());
1437 }
else if (!spanningIndexes.isEmpty() && spanningIndexes.contains(idxCol0)) {
1440 rowRect = visualRect(idxCol0, FullRow);
1441 if (!rowRect.intersects(rect))
1444 for (
int col = topLeft.column(); col <= bottomRight.column(); ++col) {
1445 if (header->isSectionHidden(col))
1447 const QModelIndex idx(model->index(row, col, parentIdx));
1448 const QRect idxRect = visualRect(idx, SingleSection);
1449 if (idxRect.isNull())
1452 if (idxRect.top() > rect.bottom() || idxRect.bottom() < rect.top())
1454 if (!idxRect.intersects(rect))
1456 rowRect = rowRect.united(idxRect);
1457 if (rowRect.left() < rect.left() && rowRect.right() > rect.right())
1460 if (rowRect.isValid()) {
1461 left = std::min(left, rowRect.left());
1462 right = std::max(right, rowRect.right());
1465 updateRect = updateRect.united(rowRect);
1466 if (updateRect.contains(rect))
1469 return rect.intersected(updateRect);
1529void QTreeView::drawTree(QPainter *painter,
const QRegion ®ion)
const
1531 Q_D(
const QTreeView);
1533 const QList<QTreeViewItem> &viewItems = d->viewItems;
1535 QStyleOptionViewItem option;
1536 initViewItemOption(&option);
1537 const QStyle::State state = option.state;
1540 if (viewItems.size() == 0 || d->header->count() == 0 || !d->itemDelegate) {
1541 d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1);
1545 int firstVisibleItemOffset = 0;
1546 const int firstVisibleItem = d->firstVisibleItem(&firstVisibleItemOffset);
1547 if (firstVisibleItem < 0) {
1548 d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1);
1552 const int viewportWidth = d->viewport->width();
1554 QPoint hoverPos = d->viewport->mapFromGlobal(QCursor::pos());
1555 d->hoverBranch = d->itemDecorationAt(hoverPos);
1558 bool multipleRects = (region.rectCount() > 1);
1559 for (
const QRect &a : region) {
1560 const QRect area = (multipleRects
1561 ? QRect(0, a.y(), viewportWidth, a.height())
1563 d->leftAndRight = d->startAndEndColumns(area);
1565 int i = firstVisibleItem;
1566 int y = firstVisibleItemOffset;
1569 for (; i < viewItems.size(); ++i) {
1570 const int itemHeight = d->itemHeight(i);
1571 if (y + itemHeight > area.top())
1577 for (; i < viewItems.size() && y <= area.bottom(); ++i) {
1578 const QModelIndex &index = viewItems.at(i).index;
1579 const int itemHeight = d->itemHeight(i);
1580 option.rect = d->visualRect(index, QTreeViewPrivate::FullRow);
1581 option.state = state | (viewItems.at(i).expanded ? QStyle::State_Open : QStyle::State_None)
1582 | (viewItems.at(i).hasChildren ? QStyle::State_Children : QStyle::State_None)
1583 | (viewItems.at(i).hasMoreSiblings ? QStyle::State_Sibling : QStyle::State_None);
1585 d->spanning = viewItems.at(i).spanning;
1586 if (!multipleRects || !drawn.contains(i)) {
1587 drawRow(painter, option, viewItems.at(i).index);
1594 if (y <= area.bottom()) {
1596 d->paintAlternatingRowColors(painter, &option, y, area.bottom());
1611void QTreeViewPrivate::calcLogicalIndices(
1612 QList<
int> *logicalIndices, QList<QStyleOptionViewItem::ViewItemPosition> *itemPositions,
1613 int left,
int right)
const
1615 const int columnCount = header->count();
1617
1618
1619 int logicalIndexBeforeLeft = -1, logicalIndexAfterRight = -1;
1620 for (
int visualIndex = left - 1; visualIndex >= 0; --visualIndex) {
1621 int logicalIndex = header->logicalIndex(visualIndex);
1622 if (!header->isSectionHidden(logicalIndex)) {
1623 logicalIndexBeforeLeft = logicalIndex;
1628 for (
int visualIndex = left; visualIndex < columnCount; ++visualIndex) {
1629 int logicalIndex = header->logicalIndex(visualIndex);
1630 if (!header->isSectionHidden(logicalIndex)) {
1631 if (visualIndex > right) {
1632 logicalIndexAfterRight = logicalIndex;
1635 logicalIndices->append(logicalIndex);
1639 const auto indicesCount = logicalIndices->size();
1640 itemPositions->resize(indicesCount);
1641 for (qsizetype currentLogicalSection = 0; currentLogicalSection < indicesCount; ++currentLogicalSection) {
1643 int nextLogicalSection = currentLogicalSection + 1 >= indicesCount
1644 ? logicalIndexAfterRight
1645 : logicalIndices->at(currentLogicalSection + 1);
1646 int prevLogicalSection = currentLogicalSection - 1 < 0
1647 ? logicalIndexBeforeLeft
1648 : logicalIndices->at(currentLogicalSection - 1);
1649 const int headerSection = logicalIndices->at(currentLogicalSection);
1650 QStyleOptionViewItem::ViewItemPosition pos;
1651 if ((nextLogicalSection == -1 && prevLogicalSection == -1) || spanning) {
1652 pos = QStyleOptionViewItem::OnlyOne;
1653 }
else if ((nextLogicalSection != 0 && prevLogicalSection == -1) || isTreePosition(headerSection))
1654 pos = QStyleOptionViewItem::Beginning;
1655 else if (nextLogicalSection == 0 || nextLogicalSection == -1)
1656 pos = QStyleOptionViewItem::End;
1658 pos = QStyleOptionViewItem::Middle;
1659 (*itemPositions)[currentLogicalSection] = pos;
1689void QTreeView::drawRow(QPainter *painter,
const QStyleOptionViewItem &option,
1690 const QModelIndex &index)
const
1692 Q_D(
const QTreeView);
1693 QStyleOptionViewItem opt = option;
1694 const QPoint offset = d->scrollDelayOffset;
1695 const int y = option.rect.y() + offset.y();
1696 const QModelIndex parent = index.parent();
1697 const QHeaderView *header = d->header;
1698 const QModelIndex current = currentIndex();
1699 const QModelIndex hover = d->hover;
1700 const bool reverse = isRightToLeft();
1701 const QStyle::State state = opt.state;
1702 const bool spanning = d->spanning;
1703 const int left = (spanning ? header->visualIndex(0) : d->leftAndRight.first);
1704 const int right = (spanning ? header->visualIndex(0) : d->leftAndRight.second);
1705 const bool alternate = d->alternatingColors;
1706 const bool enabled = (state & QStyle::State_Enabled) != 0;
1707 const bool allColumnsShowFocus = d->allColumnsShowFocus;
1712 bool indexWidgetHasFocus =
false;
1713 if ((current.row() == index.row()) && !d->editorIndexHash.isEmpty()) {
1714 const int r = index.row();
1715 QWidget *fw = QApplication::focusWidget();
1716 for (
int c = 0; c < header->count(); ++c) {
1717 QModelIndex idx = d->model->index(r, c, parent);
1718 if (QWidget *editor = indexWidget(idx)) {
1719 if (ancestorOf(editor, fw)) {
1720 indexWidgetHasFocus =
true;
1727 const bool widgetHasFocus = hasFocus();
1728 bool currentRowHasFocus =
false;
1729 if (allColumnsShowFocus && widgetHasFocus && current.isValid()) {
1731 const int r = index.row();
1732 for (
int c = 0; c < left && !currentRowHasFocus; ++c) {
1733 QModelIndex idx = d->model->index(r, c, parent);
1734 currentRowHasFocus = (idx == current);
1736 QModelIndex parent = d->model->parent(index);
1737 for (
int c = right; c < header->count() && !currentRowHasFocus; ++c) {
1738 currentRowHasFocus = (d->model->index(r, c, parent) == current);
1747 opt.showDecorationSelected = (d->selectionBehavior & SelectRows)
1748 || option.showDecorationSelected;
1750 int width, height = option.rect.height();
1752 QModelIndex modelIndex;
1753 const bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows
1754 && index.parent() == hover.parent()
1755 && index.row() == hover.row();
1757 QList<
int> logicalIndices;
1758 QList<QStyleOptionViewItem::ViewItemPosition>
1760 d->calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right);
1762 for (
int currentLogicalSection = 0; currentLogicalSection < logicalIndices.size(); ++currentLogicalSection) {
1763 int headerSection = logicalIndices.at(currentLogicalSection);
1764 position = columnViewportPosition(headerSection) + offset.x();
1765 width = header->sectionSize(headerSection);
1768 int lastSection = header->logicalIndex(header->count() - 1);
1770 width = columnViewportPosition(lastSection) + header->sectionSize(lastSection) - position;
1772 width += position - columnViewportPosition(lastSection);
1773 position = columnViewportPosition(lastSection);
1777 modelIndex = d->model->index(index.row(), headerSection, parent);
1778 if (!modelIndex.isValid())
1782 opt.viewItemPosition = viewItemPosList.at(currentLogicalSection);
1785 if (indexWidgetHasFocus)
1786 opt.state |= QStyle::State_Active;
1788 if (d->selectionModel->isSelected(modelIndex))
1789 opt.state |= QStyle::State_Selected;
1790 if (widgetHasFocus && (current == modelIndex)) {
1791 if (allColumnsShowFocus)
1792 currentRowHasFocus =
true;
1794 opt.state |= QStyle::State_HasFocus;
1796 opt.state.setFlag(QStyle::State_MouseOver,
1797 (hoverRow || modelIndex == hover)
1798 && (option.showDecorationSelected || d->hoverBranch == -1));
1801 QPalette::ColorGroup cg;
1802 if ((d->model->flags(modelIndex) & Qt::ItemIsEnabled) == 0) {
1803 opt.state &= ~QStyle::State_Enabled;
1804 cg = QPalette::Disabled;
1805 }
else if (opt.state & QStyle::State_Active) {
1806 cg = QPalette::Active;
1808 cg = QPalette::Inactive;
1810 opt.palette.setCurrentColorGroup(cg);
1814 opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
1816 opt.features &= ~QStyleOptionViewItem::IsDecoratedRootColumn;
1819
1820
1821
1822 if (d->isTreePosition(headerSection)) {
1823 const int i = d->indentationForItem(d->current);
1824 QRect branches(reverse ? position + width - i : position, y, i, height);
1825 const bool setClipRect = branches.width() > width;
1828 painter->setClipRect(QRect(position, y, width, height));
1837 const bool oldShowDecorationSelected = opt.showDecorationSelected;
1838 opt.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected,
1840 opt.rect = branches;
1841 if (opt.rect.width() > 0) {
1843 opt.features |= QStyleOptionViewItem::IsDecoratedRootColumn;
1845 opt.features |= QStyleOptionViewItem::IsDecorationForRootColumn;
1846 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1847 opt.features &= ~QStyleOptionViewItem::IsDecorationForRootColumn;
1852 QStyle::State oldState = opt.state;
1853 opt.state &= ~QStyle::State_Selected;
1854 opt.rect.setRect(reverse ? position : i + position, y, width - i, height);
1855 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1856 opt.state = oldState;
1857 opt.showDecorationSelected = oldShowDecorationSelected;
1860 drawBranches(painter, branches, index);
1864 QStyle::State oldState = opt.state;
1865 opt.state &= ~QStyle::State_Selected;
1866 opt.rect.setRect(position, y, width, height);
1867 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1868 opt.state = oldState;
1871 itemDelegateForIndex(modelIndex)->paint(painter, opt, modelIndex);
1874 if (currentRowHasFocus) {
1875 QStyleOptionFocusRect o;
1876 o.QStyleOption::operator=(option);
1877 o.state |= QStyle::State_KeyboardFocusChange;
1878 QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled)
1879 ? QPalette::Normal : QPalette::Disabled;
1880 o.backgroundColor = option.palette.color(cg, d->selectionModel->isSelected(index)
1881 ? QPalette::Highlight : QPalette::Window);
1883 if (!option.showDecorationSelected)
1884 x = header->sectionPosition(0) + d->indentationForItem(d->current);
1885 QRect focusRect(x - header->offset(), y, header->length() - x, height);
1886 o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), focusRect);
1887 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter);
1890 if (allColumnsShowFocus && !option.showDecorationSelected
1891 && header->sectionsMoved() && (header->visualIndex(0) != 0)) {
1892 QRect sectionRect(0, y, header->sectionPosition(0), height);
1893 o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), sectionRect);
1894 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter);
1904void QTreeView::drawBranches(QPainter *painter,
const QRect &rect,
1905 const QModelIndex &index)
const
1907 Q_D(
const QTreeView);
1908 const bool reverse = isRightToLeft();
1909 const int indent = d->indent;
1910 const int outer = d->rootDecoration ? 0 : 1;
1911 const int item = d->current;
1912 const QTreeViewItem &viewItem = d->viewItems.at(item);
1913 int level = viewItem.level;
1914 QRect primitive(reverse ? rect.left() : rect.right() + 1, rect.top(), indent, rect.height());
1916 QModelIndex parent = index.parent();
1917 QModelIndex current = parent;
1918 QModelIndex ancestor = current.parent();
1920 QStyleOptionViewItem opt;
1921 initViewItemOption(&opt);
1922 QStyle::State extraFlags = QStyle::State_None;
1924 extraFlags |= QStyle::State_Enabled;
1926 extraFlags |= QStyle::State_Active;
1927 QPainterStateGuard psg(painter, QPainterStateGuard::InitialState::NoSave);
1928 if (verticalScrollMode() == QAbstractItemView::ScrollPerPixel) {
1930 painter->setBrushOrigin(QPoint(0, verticalOffset()));
1933 if (d->alternatingColors) {
1934 opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
1939 bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows
1940 && opt.showDecorationSelected
1941 && index.parent() == d->hover.parent()
1942 && index.row() == d->hover.row();
1944 if (d->selectionModel->isSelected(index))
1945 extraFlags |= QStyle::State_Selected;
1947 if (level >= outer) {
1949 primitive.moveLeft(reverse ? primitive.left() : primitive.left() - indent);
1950 opt.rect = primitive;
1952 const bool expanded = viewItem.expanded;
1953 const bool children = viewItem.hasChildren;
1954 bool moreSiblings = viewItem.hasMoreSiblings;
1956 opt.state = QStyle::State_Item | extraFlags
1957 | (moreSiblings ? QStyle::State_Sibling : QStyle::State_None)
1958 | (children ? QStyle::State_Children : QStyle::State_None)
1959 | (expanded ? QStyle::State_Open : QStyle::State_None);
1960 opt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch);
1962 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter,
this);
1965 for (--level; level >= outer; --level) {
1966 primitive.moveLeft(reverse ? primitive.left() + indent : primitive.left() - indent);
1967 opt.rect = primitive;
1968 opt.state = extraFlags;
1969 bool moreSiblings =
false;
1970 if (d->hiddenIndexes.isEmpty()) {
1971 moreSiblings = (d->model->rowCount(ancestor) - 1 > current.row());
1973 int successor = item + viewItem.total + 1;
1974 while (successor < d->viewItems.size()
1975 && d->viewItems.at(successor).level >= uint(level)) {
1976 const QTreeViewItem &successorItem = d->viewItems.at(successor);
1977 if (successorItem.level == uint(level)) {
1978 moreSiblings =
true;
1981 successor += successorItem.total + 1;
1985 opt.state |= QStyle::State_Sibling;
1986 opt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch);
1988 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter,
this);
1990 ancestor = current.parent();
2272QModelIndex QTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
2275 Q_UNUSED(modifiers);
2277 d->executePostedLayout();
2279 QModelIndex current = currentIndex();
2280 if (!current.isValid()) {
2281 int i = d->below(-1);
2283 while (c < d->header->count() && d->header->isSectionHidden(d->header->logicalIndex(c)))
2285 if (i < d->viewItems.size() && c < d->header->count()) {
2286 return d->modelIndex(i, d->header->logicalIndex(c));
2288 return QModelIndex();
2291 const int vi = qMax(0, d->viewIndex(current));
2293 if (isRightToLeft()) {
2294 if (cursorAction == MoveRight)
2295 cursorAction = MoveLeft;
2296 else if (cursorAction == MoveLeft)
2297 cursorAction = MoveRight;
2299 switch (cursorAction) {
2302 return d->modelIndex(d->below(vi), current.column());
2305 return d->modelIndex(d->above(vi), current.column());
2307 QScrollBar *sb = horizontalScrollBar();
2308 if (vi < d->viewItems.size() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) {
2309 d->collapse(vi,
true);
2310 d->moveCursorUpdatedView =
true;
2312 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren,
nullptr,
this);
2314 QModelIndex par = current.parent();
2315 if (par.isValid() && par != rootIndex())
2321 if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2322 int visualColumn = d->header->visualIndex(current.column()) - 1;
2323 while (visualColumn >= 0 && isColumnHidden(d->header->logicalIndex(visualColumn)))
2325 int newColumn = d->header->logicalIndex(visualColumn);
2326 QModelIndex next = current.sibling(current.row(), newColumn);
2331 int oldValue = sb->value();
2332 sb->setValue(sb->value() - sb->singleStep());
2333 if (oldValue != sb->value())
2334 d->moveCursorUpdatedView =
true;
2339 viewport()->update();
2343 if (vi < d->viewItems.size() && !d->viewItems.at(vi).expanded && d->itemsExpandable
2344 && d->hasVisibleChildren(d->viewItems.at(vi).index)) {
2345 d->expand(vi,
true);
2346 d->moveCursorUpdatedView =
true;
2348 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren,
nullptr,
this);
2350 QModelIndex idx = d->modelIndex(d->below(vi));
2351 if (idx.parent() == current)
2357 if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2358 int visualColumn = d->header->visualIndex(current.column()) + 1;
2359 while (visualColumn < d->model->columnCount(current.parent()) && isColumnHidden(d->header->logicalIndex(visualColumn)))
2361 const int newColumn = d->header->logicalIndex(visualColumn);
2362 const QModelIndex next = current.sibling(current.row(), newColumn);
2368 QScrollBar *sb = horizontalScrollBar();
2369 int oldValue = sb->value();
2370 sb->setValue(sb->value() + sb->singleStep());
2371 if (oldValue != sb->value())
2372 d->moveCursorUpdatedView =
true;
2376 viewport()->update();
2379 return d->modelIndex(d->pageUp(vi), current.column());
2381 return d->modelIndex(d->pageDown(vi), current.column());
2383 return d->modelIndex(d->itemForKeyHome(), current.column());
2385 return d->modelIndex(d->itemForKeyEnd(), current.column());
2396void QTreeView::setSelection(
const QRect &rect, QItemSelectionModel::SelectionFlags command)
2399 if (!selectionModel() || rect.isNull())
2402 d->executePostedLayout();
2403 QPoint tl(isRightToLeft() ? qMax(rect.left(), rect.right())
2404 : qMin(rect.left(), rect.right()), qMin(rect.top(), rect.bottom()));
2405 QPoint br(isRightToLeft() ? qMin(rect.left(), rect.right()) :
2406 qMax(rect.left(), rect.right()), qMax(rect.top(), rect.bottom()));
2407 QModelIndex topLeft = indexAt(tl);
2408 QModelIndex bottomRight = indexAt(br);
2409 if (!topLeft.isValid() && !bottomRight.isValid()) {
2410 if (command & QItemSelectionModel::Clear)
2411 selectionModel()->clear();
2414 if (!topLeft.isValid() && !d->viewItems.isEmpty())
2415 topLeft = d->viewItems.constFirst().index;
2416 if (!bottomRight.isValid() && !d->viewItems.isEmpty()) {
2417 const int column = d->header->logicalIndex(d->header->count() - 1);
2418 const QModelIndex index = d->viewItems.constLast().index;
2419 bottomRight = index.sibling(index.row(), column);
2422 if (!d->isIndexEnabled(topLeft) || !d->isIndexEnabled(bottomRight))
2425 d->select(topLeft, bottomRight, command);
2435QRegion QTreeView::visualRegionForSelection(
const QItemSelection &selection)
const
2437 Q_D(
const QTreeView);
2438 if (selection.isEmpty())
2441 QRegion selectionRegion;
2442 const QRect &viewportRect = d->viewport->rect();
2443 for (
const auto &range : selection) {
2444 if (!range.isValid())
2446 QModelIndex parent = range.parent();
2447 QModelIndex leftIndex = range.topLeft();
2448 int columnCount = d->model->columnCount(parent);
2449 while (leftIndex.isValid() && isIndexHidden(leftIndex)) {
2450 if (leftIndex.column() + 1 < columnCount)
2451 leftIndex = d->model->index(leftIndex.row(), leftIndex.column() + 1, parent);
2453 leftIndex = QModelIndex();
2455 if (!leftIndex.isValid())
2457 const QRect leftRect = d->visualRect(leftIndex, QTreeViewPrivate::SingleSection);
2458 int top = leftRect.top();
2459 QModelIndex rightIndex = range.bottomRight();
2460 while (rightIndex.isValid() && isIndexHidden(rightIndex)) {
2461 if (rightIndex.column() - 1 >= 0)
2462 rightIndex = d->model->index(rightIndex.row(), rightIndex.column() - 1, parent);
2464 rightIndex = QModelIndex();
2466 if (!rightIndex.isValid())
2468 const QRect rightRect = d->visualRect(rightIndex, QTreeViewPrivate::SingleSection);
2469 int bottom = rightRect.bottom();
2471 qSwap<
int>(top, bottom);
2472 int height = bottom - top + 1;
2473 if (d->header->sectionsMoved()) {
2474 for (
int c = range.left(); c <= range.right(); ++c) {
2475 const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height);
2476 if (viewportRect.intersects(rangeRect))
2477 selectionRegion += rangeRect;
2480 QRect combined = leftRect|rightRect;
2481 combined.setX(columnViewportPosition(isRightToLeft() ? range.right() : range.left()));
2482 if (viewportRect.intersects(combined))
2483 selectionRegion += combined;
2486 return selectionRegion;
2513void QTreeView::scrollContentsBy(
int dx,
int dy)
2517 d->delayedAutoScroll.stop();
2519 dx = isRightToLeft() ? -dx : dx;
2521 int oldOffset = d->header->offset();
2522 d->header->d_func()->setScrollOffset(horizontalScrollBar(), horizontalScrollMode());
2523 if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) {
2524 int newOffset = d->header->offset();
2525 dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset;
2529 const int itemHeight = d->defaultItemHeight <= 0 ? sizeHintForRow(0) : d->defaultItemHeight;
2530 if (d->viewItems.isEmpty() || itemHeight == 0)
2534 int viewCount = d->viewport->height() / itemHeight;
2535 int maxDeltaY = qMin(d->viewItems.size(), viewCount);
2537 if (qAbs(dy) > qAbs(maxDeltaY) && d->editorIndexHash.isEmpty()) {
2538 verticalScrollBar()->update();
2539 d->viewport->update();
2543 if (dy && verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
2544 int currentScrollbarValue = verticalScrollBar()->value();
2545 int previousScrollbarValue = currentScrollbarValue + dy;
2546 int currentViewIndex = currentScrollbarValue;
2547 int previousViewIndex = previousScrollbarValue;
2549 if (previousViewIndex < currentViewIndex) {
2550 for (
int i = previousViewIndex; i < currentViewIndex; ++i) {
2551 if (i < d->viewItems.size())
2552 dy -= d->itemHeight(i);
2554 }
else if (previousViewIndex > currentViewIndex) {
2555 for (
int i = previousViewIndex - 1; i >= currentViewIndex; --i) {
2556 if (i < d->viewItems.size())
2557 dy += d->itemHeight(i);
2562 d->scrollContentsBy(dx, dy);
2844void QTreeView::expandToDepth(
int depth)
2847 d->viewItems.clear();
2848 QSet<QPersistentModelIndex> old_expandedIndexes;
2849 old_expandedIndexes = d->expandedIndexes;
2850 d->expandedIndexes.clear();
2851 d->interruptDelayedItemsLayout();
2853 for (
int i = 0; i < d->viewItems.size(); ++i) {
2854 if (q20::cmp_less_equal(d->viewItems.at(i).level, depth)) {
2855 d->viewItems[i].expanded =
true;
2857 d->storeExpanded(d->viewItems.at(i).index);
2861 bool someSignalEnabled = isSignalConnected(QMetaMethod::fromSignal(&QTreeView::collapsed));
2862 someSignalEnabled |= isSignalConnected(QMetaMethod::fromSignal(&QTreeView::expanded));
2864 if (!signalsBlocked() && someSignalEnabled) {
2866 QSet<QPersistentModelIndex> collapsedIndexes = old_expandedIndexes - d->expandedIndexes;
2867 QSet<QPersistentModelIndex>::const_iterator i = collapsedIndexes.constBegin();
2868 for (; i != collapsedIndexes.constEnd(); ++i) {
2869 const QPersistentModelIndex &mi = (*i);
2870 if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
2874 QSet<QPersistentModelIndex> expandedIndexs = d->expandedIndexes - old_expandedIndexes;
2875 i = expandedIndexs.constBegin();
2876 for (; i != expandedIndexs.constEnd(); ++i) {
2877 const QPersistentModelIndex &mi = (*i);
2878 if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
2884 d->viewport->update();
2885 d->updateAccessibility();
2943int QTreeView::sizeHintForColumn(
int column)
const
2945 Q_D(
const QTreeView);
2946 d->executePostedLayout();
2947 if (d->viewItems.isEmpty())
2951 QStyleOptionViewItem option;
2952 initViewItemOption(&option);
2953 const QList<QTreeViewItem> viewItems = d->viewItems;
2955 const int maximumProcessRows = d->header->resizeContentsPrecision();
2958 int start = d->firstVisibleItem(&offset);
2959 int end = d->lastVisibleItem(start, offset);
2960 if (start < 0 || end < 0 || end == viewItems.size() - 1) {
2961 end = viewItems.size() - 1;
2962 if (maximumProcessRows < 0) {
2964 }
else if (maximumProcessRows == 0) {
2965 start = qMax(0, end - 1);
2966 int remainingHeight = viewport()->height();
2967 while (start > 0 && remainingHeight > 0) {
2968 remainingHeight -= d->itemHeight(start);
2972 start = qMax(0, end - maximumProcessRows);
2976 int rowsProcessed = 0;
2978 for (
int i = start; i <= end; ++i) {
2979 if (viewItems.at(i).spanning)
2981 QModelIndex index = viewItems.at(i).index;
2982 index = index.sibling(index.row(), column);
2983 w = d->widthHintForIndex(index, w, option, i);
2985 if (rowsProcessed == maximumProcessRows)
2990 int actualBottom = viewItems.size() - 1;
2992 if (maximumProcessRows == 0)
2995 while (rowsProcessed != maximumProcessRows && (start > 0 || end < actualBottom)) {
2998 if ((rowsProcessed % 2 && start > 0) || end == actualBottom) {
3001 if (viewItems.at(start).spanning)
3007 while (end < actualBottom) {
3009 if (viewItems.at(end).spanning)
3018 QModelIndex index = viewItems.at(idx).index;
3019 index = index.sibling(index.row(), column);
3020 w = d->widthHintForIndex(index, w, option, idx);
3031int QTreeView::indexRowSizeHint(
const QModelIndex &index)
const
3033 Q_D(
const QTreeView);
3034 if (!d->isIndexValid(index) || !d->itemDelegate)
3039 int indexRow = index.row();
3040 int count = d->header->count();
3041 bool emptyHeader = (count == 0);
3042 QModelIndex parent = index.parent();
3044 if (count && isVisible()) {
3046 start = d->header->visualIndexAt(0);
3049 count = d->model->columnCount(parent);
3052 if (isRightToLeft()) {
3053 start = (start == -1 ? count - 1 : start);
3056 start = (start == -1 ? 0 : start);
3064 QStyleOptionViewItem option;
3065 initViewItemOption(&option);
3071 option.rect.setWidth(-1);
3073 for (
int column = start; column <= end; ++column) {
3074 int logicalColumn = emptyHeader ? column : d->header->logicalIndex(column);
3075 if (d->header->isSectionHidden(logicalColumn))
3077 QModelIndex idx = d->model->index(indexRow, logicalColumn, parent);
3078 if (idx.isValid()) {
3079 QWidget *editor = d->editorForIndex(idx).widget.data();
3080 if (editor && d->persistent.contains(editor)) {
3081 height = qMax(height, editor->sizeHint().height());
3082 int min = editor->minimumSize().height();
3083 int max = editor->maximumSize().height();
3084 height = qBound(min, height, max);
3086 int hint = itemDelegateForIndex(idx)->sizeHint(option, idx).height();
3087 height = qMax(height, hint);
3413void QTreeViewPrivate::layout(
int i,
bool recursiveExpanding,
bool afterIsUninitialized)
3416 QModelIndex current;
3417 QModelIndex parent = (i < 0) ? (QModelIndex)root : modelIndex(i);
3419 if (i>=0 && !parent.isValid()) {
3426#if QT_CONFIG(accessibility)
3430 const auto resetModelIfNeeded = qScopeGuard([oldViewItemsSize = viewItems.size(),
this]{
3431 pendingAccessibilityUpdate |= oldViewItemsSize != viewItems.size();
3436 if (model->hasChildren(parent)) {
3437 if (model->canFetchMore(parent)) {
3439 model->fetchMore(parent);
3441 const int itemHeight = defaultItemHeight <= 0 ? q->sizeHintForRow(0) : defaultItemHeight;
3442 const int viewCount = itemHeight ? viewport->height() / itemHeight : 0;
3444 while ((count = model->rowCount(parent)) < viewCount &&
3445 count != lastCount && model->canFetchMore(parent)) {
3446 model->fetchMore(parent);
3450 count = model->rowCount(parent);
3454 bool expanding =
true;
3456 if (uniformRowHeights) {
3457 QModelIndex index = model->index(0, 0, parent);
3458 defaultItemHeight = q->indexRowSizeHint(index);
3460 viewItems.resize(count);
3461 afterIsUninitialized =
true;
3462 }
else if (q20::cmp_not_equal(viewItems[i].total, count)) {
3463 if (!afterIsUninitialized)
3464 insertViewItems(i + 1, count, QTreeViewItem());
3466 viewItems.resize(viewItems.size() + count);
3472 int level = (i >= 0 ? viewItems.at(i).level + 1 : 0);
3476 QTreeViewItem *item =
nullptr;
3477 for (
int j = first; j < first + count; ++j) {
3478 current = model->index(j - first, 0, parent);
3479 if (isRowHidden(current)) {
3481 last = j - hidden + children;
3483 last = j - hidden + children;
3485 item->hasMoreSiblings =
true;
3486 item = &viewItems[last];
3487 item->index = current;
3488 item->parentItem = i;
3489 item->level = level;
3491 item->spanning = q->isFirstColumnSpanned(current.row(), parent);
3492 item->expanded =
false;
3494 item->hasMoreSiblings =
false;
3495 if ((recursiveExpanding && !(current.flags() & Qt::ItemNeverHasChildren)) || isIndexExpanded(current)) {
3496 if (recursiveExpanding && storeExpanded(current) && !q->signalsBlocked())
3497 emit q->expanded(current);
3498 item->expanded =
true;
3499 layout(last, recursiveExpanding, afterIsUninitialized);
3500 item = &viewItems[last];
3501 children += item->total;
3502 item->hasChildren = item->total > 0;
3503 last = j - hidden + children;
3505 item->hasChildren = hasVisibleChildren(current);
3512 if (!afterIsUninitialized)
3513 removeViewItems(last + 1, hidden);
3515 viewItems.resize(viewItems.size() - hidden);
3522 viewItems[i].total += count - hidden;
3523 i = viewItems[i].parentItem;
3651int QTreeViewPrivate::itemAtCoordinate(
int coordinate)
const
3653 const int itemCount = viewItems.size();
3656 if (uniformRowHeights && defaultItemHeight <= 0)
3658 if (verticalScrollMode == QAbstractItemView::ScrollPerPixel) {
3659 if (uniformRowHeights) {
3660 const int viewItemIndex = (coordinate + vbar->value()) / defaultItemHeight;
3661 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3664 int viewItemCoordinate = 0;
3665 const int contentsCoordinate = coordinate + vbar->value();
3666 for (
int viewItemIndex = 0; viewItemIndex < viewItems.size(); ++viewItemIndex) {
3667 viewItemCoordinate += itemHeight(viewItemIndex);
3668 if (viewItemCoordinate > contentsCoordinate)
3669 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3672 int topViewItemIndex = vbar->value();
3673 if (uniformRowHeights) {
3675 coordinate -= defaultItemHeight - 1;
3676 const int viewItemIndex = topViewItemIndex + (coordinate / defaultItemHeight);
3677 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3679 if (coordinate >= 0) {
3681 int viewItemCoordinate = 0;
3682 for (
int viewItemIndex = topViewItemIndex; viewItemIndex < viewItems.size(); ++viewItemIndex) {
3683 viewItemCoordinate += itemHeight(viewItemIndex);
3684 if (viewItemCoordinate > coordinate)
3685 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3689 int viewItemCoordinate = 0;
3690 for (
int viewItemIndex = topViewItemIndex; viewItemIndex >= 0; --viewItemIndex) {
3691 if (viewItemCoordinate <= coordinate)
3692 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3693 viewItemCoordinate -= itemHeight(viewItemIndex);
3807void QTreeViewPrivate::updateScrollBars()
3810 QSize viewportSize = viewport->size();
3811 if (!viewportSize.isValid())
3812 viewportSize = QSize(0, 0);
3814 executePostedLayout();
3815 if (viewItems.isEmpty()) {
3819 int itemsInViewport = 0;
3820 if (uniformRowHeights) {
3821 if (defaultItemHeight <= 0)
3822 itemsInViewport = viewItems.size();
3824 itemsInViewport = viewportSize.height() / defaultItemHeight;
3826 const int itemsCount = viewItems.size();
3827 const int viewportHeight = viewportSize.height();
3828 for (
int height = 0, item = itemsCount - 1; item >= 0; --item) {
3829 height += itemHeight(item);
3830 if (height > viewportHeight)
3835 if (verticalScrollMode == QAbstractItemView::ScrollPerItem) {
3836 if (!viewItems.isEmpty())
3837 itemsInViewport = qMax(1, itemsInViewport);
3838 vbar->setRange(0, viewItems.size() - itemsInViewport);
3839 vbar->setPageStep(itemsInViewport);
3840 vbar->setSingleStep(1);
3842 int contentsHeight = 0;
3843 if (uniformRowHeights) {
3844 contentsHeight = defaultItemHeight * viewItems.size();
3846 for (
int i = 0; i < viewItems.size(); ++i)
3847 contentsHeight += itemHeight(i);
3849 vbar->setRange(0, contentsHeight - viewportSize.height());
3850 vbar->setPageStep(viewportSize.height());
3851 vbar->d_func()->itemviewChangeSingleStep(qMax(viewportSize.height() / (itemsInViewport + 1), 2));
3854 const int columnCount = header->count();
3855 const int viewportWidth = viewportSize.width();
3856 int columnsInViewport = 0;
3857 for (
int width = 0, column = columnCount - 1; column >= 0; --column) {
3858 int logical = header->logicalIndex(column);
3859 width += header->sectionSize(logical);
3860 if (width > viewportWidth)
3862 ++columnsInViewport;
3864 if (columnCount > 0)
3865 columnsInViewport = qMax(1, columnsInViewport);
3866 if (horizontalScrollMode == QAbstractItemView::ScrollPerItem) {
3867 hbar->setRange(0, columnCount - columnsInViewport);
3868 hbar->setPageStep(columnsInViewport);
3869 hbar->setSingleStep(1);
3871 const int horizontalLength = header->length();
3872 const QSize maxSize = q->maximumViewportSize();
3873 if (maxSize.width() >= horizontalLength && vbar->maximum() <= 0)
3874 viewportSize = maxSize;
3875 hbar->setPageStep(viewportSize.width());
3876 hbar->setRange(0, qMax(horizontalLength - viewportSize.width(), 0));
3877 hbar->d_func()->itemviewChangeSingleStep(qMax(viewportSize.width() / (columnsInViewport + 1), 2));
3977void QTreeViewPrivate::select(
const QModelIndex &topIndex,
const QModelIndex &bottomIndex,
3978 QItemSelectionModel::SelectionFlags command)
3981 QItemSelection selection;
3982 const int top = viewIndex(topIndex),
3983 bottom = viewIndex(bottomIndex);
3985 const QList<std::pair<
int,
int>> colRanges = columnRanges(topIndex, bottomIndex);
3986 QList<std::pair<
int,
int>>::const_iterator it;
3987 for (it = colRanges.begin(); it != colRanges.end(); ++it) {
3988 const int left = (*it).first,
3989 right = (*it).second;
3991 QModelIndex previous;
3992 QItemSelectionRange currentRange;
3993 QStack<QItemSelectionRange> rangeStack;
3994 for (
int i = top; i <= bottom; ++i) {
3995 QModelIndex index = modelIndex(i);
3996 QModelIndex parent = index.parent();
3997 QModelIndex previousParent = previous.parent();
3998 if (previous.isValid() && parent == previousParent) {
4000 if (qAbs(previous.row() - index.row()) > 1) {
4002 if (currentRange.isValid()) {
4003 selection.append(currentRange);
4006 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4008 QModelIndex tl = model->index(currentRange.top(), currentRange.left(),
4009 currentRange.parent());
4010 currentRange = QItemSelectionRange(tl, index.sibling(index.row(), right));
4012 }
else if (previous.isValid() && parent == model->index(previous.row(), 0, previousParent)) {
4014 rangeStack.push(currentRange);
4015 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4017 if (currentRange.isValid())
4018 selection.append(currentRange);
4019 if (rangeStack.isEmpty()) {
4020 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4022 currentRange = rangeStack.pop();
4023 index = currentRange.bottomRight();
4029 if (currentRange.isValid())
4030 selection.append(currentRange);
4031 for (
int i = 0; i < rangeStack.size(); ++i)
4032 selection.append(rangeStack.at(i));
4034 q->selectionModel()->select(selection, command);