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);
1156void QTreeView::scrollTo(
const QModelIndex &index, ScrollHint hint)
1160 if (!d->isIndexValid(index))
1163 d->executePostedLayout();
1164 d->updateScrollBars();
1167 QModelIndex parent = index.parent();
1168 while (parent != d->root && parent.isValid() && state() == NoState && d->itemsExpandable) {
1169 if (!isExpanded(parent))
1171 parent = d->model->parent(parent);
1174 int item = d->viewIndex(index);
1178 QRect area = d->viewport->rect();
1181 if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
1182 int top = verticalScrollBar()->value();
1183 int bottom = top + verticalScrollBar()->pageStep();
1184 if (hint == EnsureVisible && item >= top && item < bottom) {
1186 }
else if (hint == PositionAtTop || (hint == EnsureVisible && item < top)) {
1187 verticalScrollBar()->setValue(item);
1189 const int currentItemHeight = d->itemHeight(item);
1190 int y = (hint == PositionAtCenter
1192 ? area.height() / 2 + currentItemHeight - 1
1195 if (y > currentItemHeight) {
1197 y -= d->itemHeight(item);
1205 verticalScrollBar()->setValue(item);
1208 QRect rect(columnViewportPosition(index.column()),
1209 d->coordinateForItem(item),
1210 columnWidth(index.column()),
1211 d->itemHeight(item));
1213 if (rect.isEmpty()) {
1215 }
else if (hint == EnsureVisible && area.contains(rect)) {
1216 d->viewport->update(rect);
1219 bool above = (hint == EnsureVisible
1220 && (rect.top() < area.top()
1221 || area.height() < rect.height()));
1222 bool below = (hint == EnsureVisible
1223 && rect.bottom() > area.bottom()
1224 && rect.height() < area.height());
1226 int verticalValue = verticalScrollBar()->value();
1227 if (hint == PositionAtTop || above)
1228 verticalValue += rect.top();
1229 else if (hint == PositionAtBottom || below)
1230 verticalValue += rect.bottom() - area.height();
1231 else if (hint == PositionAtCenter)
1232 verticalValue += rect.top() - ((area.height() - rect.height()) / 2);
1233 verticalScrollBar()->setValue(verticalValue);
1237 int viewportWidth = d->viewport->width();
1238 int horizontalOffset = d->header->offset();
1239 int horizontalPosition = d->header->sectionPosition(index.column());
1240 int cellWidth = d->header->sectionSize(index.column());
1242 if (hint == PositionAtCenter) {
1243 horizontalScrollBar()->setValue(horizontalPosition - ((viewportWidth - cellWidth) / 2));
1245 if (horizontalPosition - horizontalOffset < 0 || cellWidth > viewportWidth)
1246 horizontalScrollBar()->setValue(horizontalPosition);
1247 else if (horizontalPosition - horizontalOffset + cellWidth > viewportWidth)
1248 horizontalScrollBar()->setValue(horizontalPosition - viewportWidth + cellWidth);
1424QRect QTreeViewPrivate::intersectedRect(
const QRect rect,
const QModelIndex &topLeft,
const QModelIndex &bottomRight)
const
1426 const auto parentIdx = topLeft.parent();
1427 executePostedLayout();
1429 int left = std::numeric_limits<
int>::max();
1430 int right = std::numeric_limits<
int>::min();
1431 for (
int row = topLeft.row(); row <= bottomRight.row(); ++row) {
1432 const auto idxCol0 = model->index(row, 0, parentIdx);
1433 if (isRowHidden(idxCol0))
1436 if (left != std::numeric_limits<
int>::max()) {
1438 rowRect = visualRect(idxCol0, FullRow);
1439 if (!rowRect.intersects(rect))
1441 rowRect = QRect(left, rowRect.top(), right, rowRect.bottom());
1442 }
else if (!spanningIndexes.isEmpty() && spanningIndexes.contains(idxCol0)) {
1445 rowRect = visualRect(idxCol0, FullRow);
1446 if (!rowRect.intersects(rect))
1449 for (
int col = topLeft.column(); col <= bottomRight.column(); ++col) {
1450 if (header->isSectionHidden(col))
1452 const QModelIndex idx(model->index(row, col, parentIdx));
1453 const QRect idxRect = visualRect(idx, SingleSection);
1454 if (idxRect.isNull())
1457 if (idxRect.top() > rect.bottom() || idxRect.bottom() < rect.top())
1459 if (!idxRect.intersects(rect))
1461 rowRect = rowRect.united(idxRect);
1462 if (rowRect.left() < rect.left() && rowRect.right() > rect.right())
1465 if (rowRect.isValid()) {
1466 left = std::min(left, rowRect.left());
1467 right = std::max(right, rowRect.right());
1470 updateRect = updateRect.united(rowRect);
1471 if (updateRect.contains(rect))
1474 return rect.intersected(updateRect);
1534void QTreeView::drawTree(QPainter *painter,
const QRegion ®ion)
const
1536 Q_D(
const QTreeView);
1538 const QList<QTreeViewItem> &viewItems = d->viewItems;
1540 QStyleOptionViewItem option;
1541 initViewItemOption(&option);
1542 const QStyle::State state = option.state;
1545 if (viewItems.size() == 0 || d->header->count() == 0 || !d->itemDelegate) {
1546 d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1);
1550 int firstVisibleItemOffset = 0;
1551 const int firstVisibleItem = d->firstVisibleItem(&firstVisibleItemOffset);
1552 if (firstVisibleItem < 0) {
1553 d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1);
1557 const int viewportWidth = d->viewport->width();
1559 QPoint hoverPos = d->viewport->mapFromGlobal(QCursor::pos());
1560 d->hoverBranch = d->itemDecorationAt(hoverPos);
1563 bool multipleRects = (region.rectCount() > 1);
1564 for (
const QRect &a : region) {
1565 const QRect area = (multipleRects
1566 ? QRect(0, a.y(), viewportWidth, a.height())
1568 d->leftAndRight = d->startAndEndColumns(area);
1570 int i = firstVisibleItem;
1571 int y = firstVisibleItemOffset;
1574 for (; i < viewItems.size(); ++i) {
1575 const int itemHeight = d->itemHeight(i);
1576 if (y + itemHeight > area.top())
1582 for (; i < viewItems.size() && y <= area.bottom(); ++i) {
1583 const QModelIndex &index = viewItems.at(i).index;
1584 const int itemHeight = d->itemHeight(i);
1585 option.rect = d->visualRect(index, QTreeViewPrivate::FullRow);
1586 option.state = state | (viewItems.at(i).expanded ? QStyle::State_Open : QStyle::State_None)
1587 | (viewItems.at(i).hasChildren ? QStyle::State_Children : QStyle::State_None)
1588 | (viewItems.at(i).hasMoreSiblings ? QStyle::State_Sibling : QStyle::State_None);
1590 d->spanning = viewItems.at(i).spanning;
1591 if (!multipleRects || !drawn.contains(i)) {
1592 drawRow(painter, option, viewItems.at(i).index);
1599 if (y <= area.bottom()) {
1601 d->paintAlternatingRowColors(painter, &option, y, area.bottom());
1616void QTreeViewPrivate::calcLogicalIndices(
1617 QList<
int> *logicalIndices, QList<QStyleOptionViewItem::ViewItemPosition> *itemPositions,
1618 int left,
int right)
const
1620 const int columnCount = header->count();
1622
1623
1624 int logicalIndexBeforeLeft = -1, logicalIndexAfterRight = -1;
1625 for (
int visualIndex = left - 1; visualIndex >= 0; --visualIndex) {
1626 int logicalIndex = header->logicalIndex(visualIndex);
1627 if (!header->isSectionHidden(logicalIndex)) {
1628 logicalIndexBeforeLeft = logicalIndex;
1633 for (
int visualIndex = left; visualIndex < columnCount; ++visualIndex) {
1634 int logicalIndex = header->logicalIndex(visualIndex);
1635 if (!header->isSectionHidden(logicalIndex)) {
1636 if (visualIndex > right) {
1637 logicalIndexAfterRight = logicalIndex;
1640 logicalIndices->append(logicalIndex);
1644 const auto indicesCount = logicalIndices->size();
1645 itemPositions->resize(indicesCount);
1646 for (qsizetype currentLogicalSection = 0; currentLogicalSection < indicesCount; ++currentLogicalSection) {
1648 int nextLogicalSection = currentLogicalSection + 1 >= indicesCount
1649 ? logicalIndexAfterRight
1650 : logicalIndices->at(currentLogicalSection + 1);
1651 int prevLogicalSection = currentLogicalSection - 1 < 0
1652 ? logicalIndexBeforeLeft
1653 : logicalIndices->at(currentLogicalSection - 1);
1654 const int headerSection = logicalIndices->at(currentLogicalSection);
1655 QStyleOptionViewItem::ViewItemPosition pos;
1656 if ((nextLogicalSection == -1 && prevLogicalSection == -1) || spanning) {
1657 pos = QStyleOptionViewItem::OnlyOne;
1658 }
else if ((nextLogicalSection != 0 && prevLogicalSection == -1) || isTreePosition(headerSection))
1659 pos = QStyleOptionViewItem::Beginning;
1660 else if (nextLogicalSection == 0 || nextLogicalSection == -1)
1661 pos = QStyleOptionViewItem::End;
1663 pos = QStyleOptionViewItem::Middle;
1664 (*itemPositions)[currentLogicalSection] = pos;
1694void QTreeView::drawRow(QPainter *painter,
const QStyleOptionViewItem &option,
1695 const QModelIndex &index)
const
1697 Q_D(
const QTreeView);
1698 QStyleOptionViewItem opt = option;
1699 const QPoint offset = d->scrollDelayOffset;
1700 const int y = option.rect.y() + offset.y();
1701 const QModelIndex parent = index.parent();
1702 const QHeaderView *header = d->header;
1703 const QModelIndex current = currentIndex();
1704 const QModelIndex hover = d->hover;
1705 const bool reverse = isRightToLeft();
1706 const QStyle::State state = opt.state;
1707 const bool spanning = d->spanning;
1708 const int left = (spanning ? header->visualIndex(0) : d->leftAndRight.first);
1709 const int right = (spanning ? header->visualIndex(0) : d->leftAndRight.second);
1710 const bool alternate = d->alternatingColors;
1711 const bool enabled = (state & QStyle::State_Enabled) != 0;
1712 const bool allColumnsShowFocus = d->allColumnsShowFocus;
1717 bool indexWidgetHasFocus =
false;
1718 if ((current.row() == index.row()) && !d->editorIndexHash.isEmpty()) {
1719 const int r = index.row();
1720 QWidget *fw = QApplication::focusWidget();
1721 for (
int c = 0; c < header->count(); ++c) {
1722 QModelIndex idx = d->model->index(r, c, parent);
1723 if (QWidget *editor = indexWidget(idx)) {
1724 if (ancestorOf(editor, fw)) {
1725 indexWidgetHasFocus =
true;
1732 const bool widgetHasFocus = hasFocus();
1733 bool currentRowHasFocus =
false;
1734 if (allColumnsShowFocus && widgetHasFocus && current.isValid()) {
1736 const int r = index.row();
1737 for (
int c = 0; c < left && !currentRowHasFocus; ++c) {
1738 QModelIndex idx = d->model->index(r, c, parent);
1739 currentRowHasFocus = (idx == current);
1741 QModelIndex parent = d->model->parent(index);
1742 for (
int c = right; c < header->count() && !currentRowHasFocus; ++c) {
1743 currentRowHasFocus = (d->model->index(r, c, parent) == current);
1752 opt.showDecorationSelected = (d->selectionBehavior & SelectRows)
1753 || option.showDecorationSelected;
1755 int width, height = option.rect.height();
1757 QModelIndex modelIndex;
1758 const bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows
1759 && index.parent() == hover.parent()
1760 && index.row() == hover.row();
1762 QList<
int> logicalIndices;
1763 QList<QStyleOptionViewItem::ViewItemPosition>
1765 d->calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right);
1767 for (
int currentLogicalSection = 0; currentLogicalSection < logicalIndices.size(); ++currentLogicalSection) {
1768 int headerSection = logicalIndices.at(currentLogicalSection);
1769 position = columnViewportPosition(headerSection) + offset.x();
1770 width = header->sectionSize(headerSection);
1773 int lastSection = header->logicalIndex(header->count() - 1);
1775 width = columnViewportPosition(lastSection) + header->sectionSize(lastSection) - position;
1777 width += position - columnViewportPosition(lastSection);
1778 position = columnViewportPosition(lastSection);
1782 modelIndex = d->model->index(index.row(), headerSection, parent);
1783 if (!modelIndex.isValid())
1787 opt.viewItemPosition = viewItemPosList.at(currentLogicalSection);
1790 if (indexWidgetHasFocus)
1791 opt.state |= QStyle::State_Active;
1793 if (d->selectionModel->isSelected(modelIndex))
1794 opt.state |= QStyle::State_Selected;
1795 if (widgetHasFocus && (current == modelIndex)) {
1796 if (allColumnsShowFocus)
1797 currentRowHasFocus =
true;
1799 opt.state |= QStyle::State_HasFocus;
1801 opt.state.setFlag(QStyle::State_MouseOver,
1802 (hoverRow || modelIndex == hover)
1803 && (option.showDecorationSelected || d->hoverBranch == -1));
1806 QPalette::ColorGroup cg;
1807 if ((d->model->flags(modelIndex) & Qt::ItemIsEnabled) == 0) {
1808 opt.state &= ~QStyle::State_Enabled;
1809 cg = QPalette::Disabled;
1810 }
else if (opt.state & QStyle::State_Active) {
1811 cg = QPalette::Active;
1813 cg = QPalette::Inactive;
1815 opt.palette.setCurrentColorGroup(cg);
1819 opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
1821 opt.features &= ~QStyleOptionViewItem::IsDecoratedRootColumn;
1824
1825
1826
1827 if (d->isTreePosition(headerSection)) {
1828 const int i = d->indentationForItem(d->current);
1829 QRect branches(reverse ? position + width - i : position, y, i, height);
1830 const bool setClipRect = branches.width() > width;
1833 painter->setClipRect(QRect(position, y, width, height));
1842 const bool oldShowDecorationSelected = opt.showDecorationSelected;
1843 opt.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected,
1845 opt.rect = branches;
1846 if (opt.rect.width() > 0) {
1848 opt.features |= QStyleOptionViewItem::IsDecoratedRootColumn;
1850 opt.features |= QStyleOptionViewItem::IsDecorationForRootColumn;
1851 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1852 opt.features &= ~QStyleOptionViewItem::IsDecorationForRootColumn;
1857 QStyle::State oldState = opt.state;
1858 opt.state &= ~QStyle::State_Selected;
1859 opt.rect.setRect(reverse ? position : i + position, y, width - i, height);
1860 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1861 opt.state = oldState;
1862 opt.showDecorationSelected = oldShowDecorationSelected;
1865 drawBranches(painter, branches, index);
1869 QStyle::State oldState = opt.state;
1870 opt.state &= ~QStyle::State_Selected;
1871 opt.rect.setRect(position, y, width, height);
1872 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1873 opt.state = oldState;
1876 itemDelegateForIndex(modelIndex)->paint(painter, opt, modelIndex);
1879 if (currentRowHasFocus) {
1880 QStyleOptionFocusRect o;
1881 o.QStyleOption::operator=(option);
1882 o.state |= QStyle::State_KeyboardFocusChange;
1883 QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled)
1884 ? QPalette::Normal : QPalette::Disabled;
1885 o.backgroundColor = option.palette.color(cg, d->selectionModel->isSelected(index)
1886 ? QPalette::Highlight : QPalette::Window);
1888 if (!option.showDecorationSelected)
1889 x = header->sectionPosition(0) + d->indentationForItem(d->current);
1890 QRect focusRect(x - header->offset(), y, header->length() - x, height);
1891 o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), focusRect);
1892 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter);
1895 if (allColumnsShowFocus && !option.showDecorationSelected
1896 && header->sectionsMoved() && (header->visualIndex(0) != 0)) {
1897 QRect sectionRect(0, y, header->sectionPosition(0), height);
1898 o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), sectionRect);
1899 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter);
1909void QTreeView::drawBranches(QPainter *painter,
const QRect &rect,
1910 const QModelIndex &index)
const
1912 Q_D(
const QTreeView);
1913 const bool reverse = isRightToLeft();
1914 const int indent = d->indent;
1915 const int outer = d->rootDecoration ? 0 : 1;
1916 const int item = d->current;
1917 const QTreeViewItem &viewItem = d->viewItems.at(item);
1918 int level = viewItem.level;
1919 QRect primitive(reverse ? rect.left() : rect.right() + 1, rect.top(), indent, rect.height());
1921 QModelIndex parent = index.parent();
1922 QModelIndex current = parent;
1923 QModelIndex ancestor = current.parent();
1925 QStyleOptionViewItem opt;
1926 initViewItemOption(&opt);
1927 QStyle::State extraFlags = QStyle::State_None;
1929 extraFlags |= QStyle::State_Enabled;
1931 extraFlags |= QStyle::State_Active;
1932 QPainterStateGuard psg(painter, QPainterStateGuard::InitialState::NoSave);
1933 if (verticalScrollMode() == QAbstractItemView::ScrollPerPixel) {
1935 painter->setBrushOrigin(QPoint(0, verticalOffset()));
1938 if (d->alternatingColors) {
1939 opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
1944 bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows
1945 && opt.showDecorationSelected
1946 && index.parent() == d->hover.parent()
1947 && index.row() == d->hover.row();
1949 if (d->selectionModel->isSelected(index))
1950 extraFlags |= QStyle::State_Selected;
1952 if (level >= outer) {
1954 primitive.moveLeft(reverse ? primitive.left() : primitive.left() - indent);
1955 opt.rect = primitive;
1957 const bool expanded = viewItem.expanded;
1958 const bool children = viewItem.hasChildren;
1959 bool moreSiblings = viewItem.hasMoreSiblings;
1961 opt.state = QStyle::State_Item | extraFlags
1962 | (moreSiblings ? QStyle::State_Sibling : QStyle::State_None)
1963 | (children ? QStyle::State_Children : QStyle::State_None)
1964 | (expanded ? QStyle::State_Open : QStyle::State_None);
1965 opt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch);
1967 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter,
this);
1970 for (--level; level >= outer; --level) {
1971 primitive.moveLeft(reverse ? primitive.left() + indent : primitive.left() - indent);
1972 opt.rect = primitive;
1973 opt.state = extraFlags;
1974 bool moreSiblings =
false;
1975 if (d->hiddenIndexes.isEmpty()) {
1976 moreSiblings = (d->model->rowCount(ancestor) - 1 > current.row());
1978 int successor = item + viewItem.total + 1;
1979 while (successor < d->viewItems.size()
1980 && d->viewItems.at(successor).level >= uint(level)) {
1981 const QTreeViewItem &successorItem = d->viewItems.at(successor);
1982 if (successorItem.level == uint(level)) {
1983 moreSiblings =
true;
1986 successor += successorItem.total + 1;
1990 opt.state |= QStyle::State_Sibling;
1991 opt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch);
1993 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter,
this);
1995 ancestor = current.parent();
2277QModelIndex QTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
2280 Q_UNUSED(modifiers);
2282 d->executePostedLayout();
2284 QModelIndex current = currentIndex();
2285 if (!current.isValid()) {
2286 int i = d->below(-1);
2288 while (c < d->header->count() && d->header->isSectionHidden(d->header->logicalIndex(c)))
2290 if (i < d->viewItems.size() && c < d->header->count()) {
2291 return d->modelIndex(i, d->header->logicalIndex(c));
2293 return QModelIndex();
2296 const int vi = qMax(0, d->viewIndex(current));
2298 if (isRightToLeft()) {
2299 if (cursorAction == MoveRight)
2300 cursorAction = MoveLeft;
2301 else if (cursorAction == MoveLeft)
2302 cursorAction = MoveRight;
2304 switch (cursorAction) {
2307 return d->modelIndex(d->below(vi), current.column());
2310 return d->modelIndex(d->above(vi), current.column());
2312 QScrollBar *sb = horizontalScrollBar();
2313 if (vi < d->viewItems.size() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) {
2314 d->collapse(vi,
true);
2315 d->moveCursorUpdatedView =
true;
2317 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren,
nullptr,
this);
2319 QModelIndex par = current.parent();
2320 if (par.isValid() && par != rootIndex())
2326 if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2327 int visualColumn = d->header->visualIndex(current.column()) - 1;
2328 while (visualColumn >= 0 && isColumnHidden(d->header->logicalIndex(visualColumn)))
2330 int newColumn = d->header->logicalIndex(visualColumn);
2331 QModelIndex next = current.sibling(current.row(), newColumn);
2336 int oldValue = sb->value();
2337 sb->setValue(sb->value() - sb->singleStep());
2338 if (oldValue != sb->value())
2339 d->moveCursorUpdatedView =
true;
2344 viewport()->update();
2348 if (vi < d->viewItems.size() && !d->viewItems.at(vi).expanded && d->itemsExpandable
2349 && d->hasVisibleChildren(d->viewItems.at(vi).index)) {
2350 d->expand(vi,
true);
2351 d->moveCursorUpdatedView =
true;
2353 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren,
nullptr,
this);
2355 QModelIndex idx = d->modelIndex(d->below(vi));
2356 if (idx.parent() == current)
2362 if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2363 int visualColumn = d->header->visualIndex(current.column()) + 1;
2364 while (visualColumn < d->model->columnCount(current.parent()) && isColumnHidden(d->header->logicalIndex(visualColumn)))
2366 const int newColumn = d->header->logicalIndex(visualColumn);
2367 const QModelIndex next = current.sibling(current.row(), newColumn);
2373 QScrollBar *sb = horizontalScrollBar();
2374 int oldValue = sb->value();
2375 sb->setValue(sb->value() + sb->singleStep());
2376 if (oldValue != sb->value())
2377 d->moveCursorUpdatedView =
true;
2381 viewport()->update();
2384 return d->modelIndex(d->pageUp(vi), current.column());
2386 return d->modelIndex(d->pageDown(vi), current.column());
2388 return d->modelIndex(d->itemForKeyHome(), current.column());
2390 return d->modelIndex(d->itemForKeyEnd(), current.column());
2401void QTreeView::setSelection(
const QRect &rect, QItemSelectionModel::SelectionFlags command)
2404 if (!selectionModel() || rect.isNull())
2407 d->executePostedLayout();
2408 QPoint tl(isRightToLeft() ? qMax(rect.left(), rect.right())
2409 : qMin(rect.left(), rect.right()), qMin(rect.top(), rect.bottom()));
2410 QPoint br(isRightToLeft() ? qMin(rect.left(), rect.right()) :
2411 qMax(rect.left(), rect.right()), qMax(rect.top(), rect.bottom()));
2412 QModelIndex topLeft = indexAt(tl);
2413 QModelIndex bottomRight = indexAt(br);
2414 if (!topLeft.isValid() && !bottomRight.isValid()) {
2415 if (command & QItemSelectionModel::Clear)
2416 selectionModel()->clear();
2419 if (!topLeft.isValid() && !d->viewItems.isEmpty())
2420 topLeft = d->viewItems.constFirst().index;
2421 if (!bottomRight.isValid() && !d->viewItems.isEmpty()) {
2422 const int column = d->header->logicalIndex(d->header->count() - 1);
2423 const QModelIndex index = d->viewItems.constLast().index;
2424 bottomRight = index.sibling(index.row(), column);
2427 if (!d->isIndexEnabled(topLeft) || !d->isIndexEnabled(bottomRight))
2430 d->select(topLeft, bottomRight, command);
2440QRegion QTreeView::visualRegionForSelection(
const QItemSelection &selection)
const
2442 Q_D(
const QTreeView);
2443 if (selection.isEmpty())
2446 QRegion selectionRegion;
2447 const QRect &viewportRect = d->viewport->rect();
2448 for (
const auto &range : selection) {
2449 if (!range.isValid())
2451 QModelIndex parent = range.parent();
2452 QModelIndex leftIndex = range.topLeft();
2453 int columnCount = d->model->columnCount(parent);
2454 while (leftIndex.isValid() && isIndexHidden(leftIndex)) {
2455 if (leftIndex.column() + 1 < columnCount)
2456 leftIndex = d->model->index(leftIndex.row(), leftIndex.column() + 1, parent);
2458 leftIndex = QModelIndex();
2460 if (!leftIndex.isValid())
2462 const QRect leftRect = d->visualRect(leftIndex, QTreeViewPrivate::SingleSection);
2463 int top = leftRect.top();
2464 QModelIndex rightIndex = range.bottomRight();
2465 while (rightIndex.isValid() && isIndexHidden(rightIndex)) {
2466 if (rightIndex.column() - 1 >= 0)
2467 rightIndex = d->model->index(rightIndex.row(), rightIndex.column() - 1, parent);
2469 rightIndex = QModelIndex();
2471 if (!rightIndex.isValid())
2473 const QRect rightRect = d->visualRect(rightIndex, QTreeViewPrivate::SingleSection);
2474 int bottom = rightRect.bottom();
2476 qSwap<
int>(top, bottom);
2477 int height = bottom - top + 1;
2478 if (d->header->sectionsMoved()) {
2479 for (
int c = range.left(); c <= range.right(); ++c) {
2480 const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height);
2481 if (viewportRect.intersects(rangeRect))
2482 selectionRegion += rangeRect;
2485 QRect combined = leftRect|rightRect;
2486 combined.setX(columnViewportPosition(isRightToLeft() ? range.right() : range.left()));
2487 if (viewportRect.intersects(combined))
2488 selectionRegion += combined;
2491 return selectionRegion;
2518void QTreeView::scrollContentsBy(
int dx,
int dy)
2522 d->delayedAutoScroll.stop();
2524 dx = isRightToLeft() ? -dx : dx;
2526 int oldOffset = d->header->offset();
2527 d->header->d_func()->setScrollOffset(horizontalScrollBar(), horizontalScrollMode());
2528 if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) {
2529 int newOffset = d->header->offset();
2530 dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset;
2534 const int itemHeight = d->defaultItemHeight <= 0 ? sizeHintForRow(0) : d->defaultItemHeight;
2535 if (d->viewItems.isEmpty() || itemHeight == 0)
2539 int viewCount = d->viewport->height() / itemHeight;
2540 int maxDeltaY = qMin(d->viewItems.size(), viewCount);
2542 if (qAbs(dy) > qAbs(maxDeltaY) && d->editorIndexHash.isEmpty()) {
2543 verticalScrollBar()->update();
2544 d->viewport->update();
2548 if (dy && verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
2549 int currentScrollbarValue = verticalScrollBar()->value();
2550 int previousScrollbarValue = currentScrollbarValue + dy;
2551 int currentViewIndex = currentScrollbarValue;
2552 int previousViewIndex = previousScrollbarValue;
2554 if (previousViewIndex < currentViewIndex) {
2555 for (
int i = previousViewIndex; i < currentViewIndex; ++i) {
2556 if (i < d->viewItems.size())
2557 dy -= d->itemHeight(i);
2559 }
else if (previousViewIndex > currentViewIndex) {
2560 for (
int i = previousViewIndex - 1; i >= currentViewIndex; --i) {
2561 if (i < d->viewItems.size())
2562 dy += d->itemHeight(i);
2567 d->scrollContentsBy(dx, dy);
2849void QTreeView::expandToDepth(
int depth)
2852 d->viewItems.clear();
2853 QSet<QPersistentModelIndex> old_expandedIndexes;
2854 old_expandedIndexes = d->expandedIndexes;
2855 d->expandedIndexes.clear();
2856 d->interruptDelayedItemsLayout();
2858 for (
int i = 0; i < d->viewItems.size(); ++i) {
2859 if (q20::cmp_less_equal(d->viewItems.at(i).level, depth)) {
2860 d->viewItems[i].expanded =
true;
2862 d->storeExpanded(d->viewItems.at(i).index);
2866 bool someSignalEnabled = isSignalConnected(QMetaMethod::fromSignal(&QTreeView::collapsed));
2867 someSignalEnabled |= isSignalConnected(QMetaMethod::fromSignal(&QTreeView::expanded));
2869 if (!signalsBlocked() && someSignalEnabled) {
2871 QSet<QPersistentModelIndex> collapsedIndexes = old_expandedIndexes - d->expandedIndexes;
2872 QSet<QPersistentModelIndex>::const_iterator i = collapsedIndexes.constBegin();
2873 for (; i != collapsedIndexes.constEnd(); ++i) {
2874 const QPersistentModelIndex &mi = (*i);
2875 if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
2879 QSet<QPersistentModelIndex> expandedIndexs = d->expandedIndexes - old_expandedIndexes;
2880 i = expandedIndexs.constBegin();
2881 for (; i != expandedIndexs.constEnd(); ++i) {
2882 const QPersistentModelIndex &mi = (*i);
2883 if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
2889 d->viewport->update();
2890 d->updateAccessibility();
2948int QTreeView::sizeHintForColumn(
int column)
const
2950 Q_D(
const QTreeView);
2951 d->executePostedLayout();
2952 if (d->viewItems.isEmpty())
2956 QStyleOptionViewItem option;
2957 initViewItemOption(&option);
2958 const QList<QTreeViewItem> viewItems = d->viewItems;
2960 const int maximumProcessRows = d->header->resizeContentsPrecision();
2963 int start = d->firstVisibleItem(&offset);
2964 int end = d->lastVisibleItem(start, offset);
2965 if (start < 0 || end < 0 || end == viewItems.size() - 1) {
2966 end = viewItems.size() - 1;
2967 if (maximumProcessRows < 0) {
2969 }
else if (maximumProcessRows == 0) {
2970 start = qMax(0, end - 1);
2971 int remainingHeight = viewport()->height();
2972 while (start > 0 && remainingHeight > 0) {
2973 remainingHeight -= d->itemHeight(start);
2977 start = qMax(0, end - maximumProcessRows);
2981 int rowsProcessed = 0;
2983 for (
int i = start; i <= end; ++i) {
2984 if (viewItems.at(i).spanning)
2986 QModelIndex index = viewItems.at(i).index;
2987 index = index.sibling(index.row(), column);
2988 w = d->widthHintForIndex(index, w, option, i);
2990 if (rowsProcessed == maximumProcessRows)
2995 int actualBottom = viewItems.size() - 1;
2997 if (maximumProcessRows == 0)
3000 while (rowsProcessed != maximumProcessRows && (start > 0 || end < actualBottom)) {
3003 if ((rowsProcessed % 2 && start > 0) || end == actualBottom) {
3006 if (viewItems.at(start).spanning)
3012 while (end < actualBottom) {
3014 if (viewItems.at(end).spanning)
3023 QModelIndex index = viewItems.at(idx).index;
3024 index = index.sibling(index.row(), column);
3025 w = d->widthHintForIndex(index, w, option, idx);
3036int QTreeView::indexRowSizeHint(
const QModelIndex &index)
const
3038 Q_D(
const QTreeView);
3039 if (!d->isIndexValid(index) || !d->itemDelegate)
3044 int indexRow = index.row();
3045 int count = d->header->count();
3046 bool emptyHeader = (count == 0);
3047 QModelIndex parent = index.parent();
3049 if (count && isVisible()) {
3051 start = d->header->visualIndexAt(0);
3054 count = d->model->columnCount(parent);
3057 if (isRightToLeft()) {
3058 start = (start == -1 ? count - 1 : start);
3061 start = (start == -1 ? 0 : start);
3069 QStyleOptionViewItem option;
3070 initViewItemOption(&option);
3076 option.rect.setWidth(-1);
3078 for (
int column = start; column <= end; ++column) {
3079 int logicalColumn = emptyHeader ? column : d->header->logicalIndex(column);
3080 if (d->header->isSectionHidden(logicalColumn))
3082 QModelIndex idx = d->model->index(indexRow, logicalColumn, parent);
3083 if (idx.isValid()) {
3084 QWidget *editor = d->editorForIndex(idx).widget.data();
3085 if (editor && d->persistent.contains(editor)) {
3086 height = qMax(height, editor->sizeHint().height());
3087 int min = editor->minimumSize().height();
3088 int max = editor->maximumSize().height();
3089 height = qBound(min, height, max);
3091 int hint = itemDelegateForIndex(idx)->sizeHint(option, idx).height();
3092 height = qMax(height, hint);
3418void QTreeViewPrivate::layout(
int i,
bool recursiveExpanding,
bool afterIsUninitialized)
3421 QModelIndex current;
3422 QModelIndex parent = (i < 0) ? (QModelIndex)root : modelIndex(i);
3424 if (i>=0 && !parent.isValid()) {
3431#if QT_CONFIG(accessibility)
3435 const auto resetModelIfNeeded = qScopeGuard([oldViewItemsSize = viewItems.size(),
this]{
3436 pendingAccessibilityUpdate |= oldViewItemsSize != viewItems.size();
3441 if (model->hasChildren(parent)) {
3442 if (model->canFetchMore(parent)) {
3444 model->fetchMore(parent);
3446 const int itemHeight = defaultItemHeight <= 0 ? q->sizeHintForRow(0) : defaultItemHeight;
3447 const int viewCount = itemHeight ? viewport->height() / itemHeight : 0;
3449 while ((count = model->rowCount(parent)) < viewCount &&
3450 count != lastCount && model->canFetchMore(parent)) {
3451 model->fetchMore(parent);
3455 count = model->rowCount(parent);
3459 bool expanding =
true;
3461 if (uniformRowHeights) {
3462 QModelIndex index = model->index(0, 0, parent);
3463 defaultItemHeight = q->indexRowSizeHint(index);
3465 viewItems.resize(count);
3466 afterIsUninitialized =
true;
3467 }
else if (q20::cmp_not_equal(viewItems[i].total, count)) {
3468 if (!afterIsUninitialized)
3469 insertViewItems(i + 1, count, QTreeViewItem());
3471 viewItems.resize(viewItems.size() + count);
3477 int level = (i >= 0 ? viewItems.at(i).level + 1 : 0);
3481 QTreeViewItem *item =
nullptr;
3482 for (
int j = first; j < first + count; ++j) {
3483 current = model->index(j - first, 0, parent);
3484 if (isRowHidden(current)) {
3486 last = j - hidden + children;
3488 last = j - hidden + children;
3490 item->hasMoreSiblings =
true;
3491 item = &viewItems[last];
3492 item->index = current;
3493 item->parentItem = i;
3494 item->level = level;
3496 item->spanning = q->isFirstColumnSpanned(current.row(), parent);
3497 item->expanded =
false;
3499 item->hasMoreSiblings =
false;
3500 if ((recursiveExpanding && !(current.flags() & Qt::ItemNeverHasChildren)) || isIndexExpanded(current)) {
3501 if (recursiveExpanding && storeExpanded(current) && !q->signalsBlocked())
3502 emit q->expanded(current);
3503 item->expanded =
true;
3504 layout(last, recursiveExpanding, afterIsUninitialized);
3505 item = &viewItems[last];
3506 children += item->total;
3507 item->hasChildren = item->total > 0;
3508 last = j - hidden + children;
3510 item->hasChildren = hasVisibleChildren(current);
3517 if (!afterIsUninitialized)
3518 removeViewItems(last + 1, hidden);
3520 viewItems.resize(viewItems.size() - hidden);
3527 viewItems[i].total += count - hidden;
3528 i = viewItems[i].parentItem;
3656int QTreeViewPrivate::itemAtCoordinate(
int coordinate)
const
3658 const int itemCount = viewItems.size();
3661 if (uniformRowHeights && defaultItemHeight <= 0)
3663 if (verticalScrollMode == QAbstractItemView::ScrollPerPixel) {
3664 if (uniformRowHeights) {
3665 const int viewItemIndex = (coordinate + vbar->value()) / defaultItemHeight;
3666 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3669 int viewItemCoordinate = 0;
3670 const int contentsCoordinate = coordinate + vbar->value();
3671 for (
int viewItemIndex = 0; viewItemIndex < viewItems.size(); ++viewItemIndex) {
3672 viewItemCoordinate += itemHeight(viewItemIndex);
3673 if (viewItemCoordinate > contentsCoordinate)
3674 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3677 int topViewItemIndex = vbar->value();
3678 if (uniformRowHeights) {
3680 coordinate -= defaultItemHeight - 1;
3681 const int viewItemIndex = topViewItemIndex + (coordinate / defaultItemHeight);
3682 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3684 if (coordinate >= 0) {
3686 int viewItemCoordinate = 0;
3687 for (
int viewItemIndex = topViewItemIndex; viewItemIndex < viewItems.size(); ++viewItemIndex) {
3688 viewItemCoordinate += itemHeight(viewItemIndex);
3689 if (viewItemCoordinate > coordinate)
3690 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3694 int viewItemCoordinate = 0;
3695 for (
int viewItemIndex = topViewItemIndex; viewItemIndex >= 0; --viewItemIndex) {
3696 if (viewItemCoordinate <= coordinate)
3697 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3698 viewItemCoordinate -= itemHeight(viewItemIndex);
3812void QTreeViewPrivate::updateScrollBars()
3815 QSize viewportSize = viewport->size();
3816 if (!viewportSize.isValid())
3817 viewportSize = QSize(0, 0);
3819 executePostedLayout();
3820 if (viewItems.isEmpty()) {
3824 int itemsInViewport = 0;
3825 if (uniformRowHeights) {
3826 if (defaultItemHeight <= 0)
3827 itemsInViewport = viewItems.size();
3829 itemsInViewport = viewportSize.height() / defaultItemHeight;
3831 const int itemsCount = viewItems.size();
3832 const int viewportHeight = viewportSize.height();
3833 for (
int height = 0, item = itemsCount - 1; item >= 0; --item) {
3834 height += itemHeight(item);
3835 if (height > viewportHeight)
3840 if (verticalScrollMode == QAbstractItemView::ScrollPerItem) {
3841 if (!viewItems.isEmpty())
3842 itemsInViewport = qMax(1, itemsInViewport);
3843 vbar->setRange(0, viewItems.size() - itemsInViewport);
3844 vbar->setPageStep(itemsInViewport);
3845 vbar->setSingleStep(1);
3847 int contentsHeight = 0;
3848 if (uniformRowHeights) {
3849 contentsHeight = defaultItemHeight * viewItems.size();
3851 for (
int i = 0; i < viewItems.size(); ++i)
3852 contentsHeight += itemHeight(i);
3854 vbar->setRange(0, contentsHeight - viewportSize.height());
3855 vbar->setPageStep(viewportSize.height());
3856 vbar->d_func()->itemviewChangeSingleStep(qMax(viewportSize.height() / (itemsInViewport + 1), 2));
3859 const int columnCount = header->count();
3860 const int viewportWidth = viewportSize.width();
3861 int columnsInViewport = 0;
3862 for (
int width = 0, column = columnCount - 1; column >= 0; --column) {
3863 int logical = header->logicalIndex(column);
3864 width += header->sectionSize(logical);
3865 if (width > viewportWidth)
3867 ++columnsInViewport;
3869 if (columnCount > 0)
3870 columnsInViewport = qMax(1, columnsInViewport);
3871 if (horizontalScrollMode == QAbstractItemView::ScrollPerItem) {
3872 hbar->setRange(0, columnCount - columnsInViewport);
3873 hbar->setPageStep(columnsInViewport);
3874 hbar->setSingleStep(1);
3876 const int horizontalLength = header->length();
3877 const QSize maxSize = q->maximumViewportSize();
3878 if (maxSize.width() >= horizontalLength && vbar->maximum() <= 0)
3879 viewportSize = maxSize;
3880 hbar->setPageStep(viewportSize.width());
3881 hbar->setRange(0, qMax(horizontalLength - viewportSize.width(), 0));
3882 hbar->d_func()->itemviewChangeSingleStep(qMax(viewportSize.width() / (columnsInViewport + 1), 2));
3982void QTreeViewPrivate::select(
const QModelIndex &topIndex,
const QModelIndex &bottomIndex,
3983 QItemSelectionModel::SelectionFlags command)
3986 QItemSelection selection;
3987 const int top = viewIndex(topIndex),
3988 bottom = viewIndex(bottomIndex);
3990 const QList<std::pair<
int,
int>> colRanges = columnRanges(topIndex, bottomIndex);
3991 QList<std::pair<
int,
int>>::const_iterator it;
3992 for (it = colRanges.begin(); it != colRanges.end(); ++it) {
3993 const int left = (*it).first,
3994 right = (*it).second;
3996 QModelIndex previous;
3997 QItemSelectionRange currentRange;
3998 QStack<QItemSelectionRange> rangeStack;
3999 for (
int i = top; i <= bottom; ++i) {
4000 QModelIndex index = modelIndex(i);
4001 QModelIndex parent = index.parent();
4002 QModelIndex previousParent = previous.parent();
4003 if (previous.isValid() && parent == previousParent) {
4005 if (qAbs(previous.row() - index.row()) > 1) {
4007 if (currentRange.isValid()) {
4008 selection.append(currentRange);
4011 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4013 QModelIndex tl = model->index(currentRange.top(), currentRange.left(),
4014 currentRange.parent());
4015 currentRange = QItemSelectionRange(tl, index.sibling(index.row(), right));
4017 }
else if (previous.isValid() && parent == model->index(previous.row(), 0, previousParent)) {
4019 rangeStack.push(currentRange);
4020 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4022 if (currentRange.isValid())
4023 selection.append(currentRange);
4024 if (rangeStack.isEmpty()) {
4025 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4027 currentRange = rangeStack.pop();
4028 index = currentRange.bottomRight();
4034 if (currentRange.isValid())
4035 selection.append(currentRange);
4036 for (
int i = 0; i < rangeStack.size(); ++i)
4037 selection.append(rangeStack.at(i));
4039 q->selectionModel()->select(selection, command);