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#ifdef QT_KEYPAD_NAVIGATION
2303 if (vi == d->viewItems.count()-1 && QApplicationPrivate::keypadNavigationEnabled())
2304 return d->model->index(0, current.column(), d->root);
2306 return d->modelIndex(d->below(vi), current.column());
2309#ifdef QT_KEYPAD_NAVIGATION
2310 if (vi == 0 && QApplicationPrivate::keypadNavigationEnabled())
2311 return d->modelIndex(d->viewItems.count() - 1, current.column());
2313 return d->modelIndex(d->above(vi), current.column());
2315 QScrollBar *sb = horizontalScrollBar();
2316 if (vi < d->viewItems.size() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) {
2317 d->collapse(vi,
true);
2318 d->moveCursorUpdatedView =
true;
2320 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren,
nullptr,
this);
2322 QModelIndex par = current.parent();
2323 if (par.isValid() && par != rootIndex())
2329 if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2330 int visualColumn = d->header->visualIndex(current.column()) - 1;
2331 while (visualColumn >= 0 && isColumnHidden(d->header->logicalIndex(visualColumn)))
2333 int newColumn = d->header->logicalIndex(visualColumn);
2334 QModelIndex next = current.sibling(current.row(), newColumn);
2339 int oldValue = sb->value();
2340 sb->setValue(sb->value() - sb->singleStep());
2341 if (oldValue != sb->value())
2342 d->moveCursorUpdatedView =
true;
2347 viewport()->update();
2351 if (vi < d->viewItems.size() && !d->viewItems.at(vi).expanded && d->itemsExpandable
2352 && d->hasVisibleChildren(d->viewItems.at(vi).index)) {
2353 d->expand(vi,
true);
2354 d->moveCursorUpdatedView =
true;
2356 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren,
nullptr,
this);
2358 QModelIndex idx = d->modelIndex(d->below(vi));
2359 if (idx.parent() == current)
2365 if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2366 int visualColumn = d->header->visualIndex(current.column()) + 1;
2367 while (visualColumn < d->model->columnCount(current.parent()) && isColumnHidden(d->header->logicalIndex(visualColumn)))
2369 const int newColumn = d->header->logicalIndex(visualColumn);
2370 const QModelIndex next = current.sibling(current.row(), newColumn);
2376 QScrollBar *sb = horizontalScrollBar();
2377 int oldValue = sb->value();
2378 sb->setValue(sb->value() + sb->singleStep());
2379 if (oldValue != sb->value())
2380 d->moveCursorUpdatedView =
true;
2384 viewport()->update();
2387 return d->modelIndex(d->pageUp(vi), current.column());
2389 return d->modelIndex(d->pageDown(vi), current.column());
2391 return d->modelIndex(d->itemForKeyHome(), current.column());
2393 return d->modelIndex(d->itemForKeyEnd(), current.column());
2404void QTreeView::setSelection(
const QRect &rect, QItemSelectionModel::SelectionFlags command)
2407 if (!selectionModel() || rect.isNull())
2410 d->executePostedLayout();
2411 QPoint tl(isRightToLeft() ? qMax(rect.left(), rect.right())
2412 : qMin(rect.left(), rect.right()), qMin(rect.top(), rect.bottom()));
2413 QPoint br(isRightToLeft() ? qMin(rect.left(), rect.right()) :
2414 qMax(rect.left(), rect.right()), qMax(rect.top(), rect.bottom()));
2415 QModelIndex topLeft = indexAt(tl);
2416 QModelIndex bottomRight = indexAt(br);
2417 if (!topLeft.isValid() && !bottomRight.isValid()) {
2418 if (command & QItemSelectionModel::Clear)
2419 selectionModel()->clear();
2422 if (!topLeft.isValid() && !d->viewItems.isEmpty())
2423 topLeft = d->viewItems.constFirst().index;
2424 if (!bottomRight.isValid() && !d->viewItems.isEmpty()) {
2425 const int column = d->header->logicalIndex(d->header->count() - 1);
2426 const QModelIndex index = d->viewItems.constLast().index;
2427 bottomRight = index.sibling(index.row(), column);
2430 if (!d->isIndexEnabled(topLeft) || !d->isIndexEnabled(bottomRight))
2433 d->select(topLeft, bottomRight, command);
2443QRegion QTreeView::visualRegionForSelection(
const QItemSelection &selection)
const
2445 Q_D(
const QTreeView);
2446 if (selection.isEmpty())
2449 QRegion selectionRegion;
2450 const QRect &viewportRect = d->viewport->rect();
2451 for (
const auto &range : selection) {
2452 if (!range.isValid())
2454 QModelIndex parent = range.parent();
2455 QModelIndex leftIndex = range.topLeft();
2456 int columnCount = d->model->columnCount(parent);
2457 while (leftIndex.isValid() && isIndexHidden(leftIndex)) {
2458 if (leftIndex.column() + 1 < columnCount)
2459 leftIndex = d->model->index(leftIndex.row(), leftIndex.column() + 1, parent);
2461 leftIndex = QModelIndex();
2463 if (!leftIndex.isValid())
2465 const QRect leftRect = d->visualRect(leftIndex, QTreeViewPrivate::SingleSection);
2466 int top = leftRect.top();
2467 QModelIndex rightIndex = range.bottomRight();
2468 while (rightIndex.isValid() && isIndexHidden(rightIndex)) {
2469 if (rightIndex.column() - 1 >= 0)
2470 rightIndex = d->model->index(rightIndex.row(), rightIndex.column() - 1, parent);
2472 rightIndex = QModelIndex();
2474 if (!rightIndex.isValid())
2476 const QRect rightRect = d->visualRect(rightIndex, QTreeViewPrivate::SingleSection);
2477 int bottom = rightRect.bottom();
2479 qSwap<
int>(top, bottom);
2480 int height = bottom - top + 1;
2481 if (d->header->sectionsMoved()) {
2482 for (
int c = range.left(); c <= range.right(); ++c) {
2483 const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height);
2484 if (viewportRect.intersects(rangeRect))
2485 selectionRegion += rangeRect;
2488 QRect combined = leftRect|rightRect;
2489 combined.setX(columnViewportPosition(isRightToLeft() ? range.right() : range.left()));
2490 if (viewportRect.intersects(combined))
2491 selectionRegion += combined;
2494 return selectionRegion;
2521void QTreeView::scrollContentsBy(
int dx,
int dy)
2525 d->delayedAutoScroll.stop();
2527 dx = isRightToLeft() ? -dx : dx;
2529 int oldOffset = d->header->offset();
2530 d->header->d_func()->setScrollOffset(horizontalScrollBar(), horizontalScrollMode());
2531 if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) {
2532 int newOffset = d->header->offset();
2533 dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset;
2537 const int itemHeight = d->defaultItemHeight <= 0 ? sizeHintForRow(0) : d->defaultItemHeight;
2538 if (d->viewItems.isEmpty() || itemHeight == 0)
2542 int viewCount = d->viewport->height() / itemHeight;
2543 int maxDeltaY = qMin(d->viewItems.size(), viewCount);
2545 if (qAbs(dy) > qAbs(maxDeltaY) && d->editorIndexHash.isEmpty()) {
2546 verticalScrollBar()->update();
2547 d->viewport->update();
2551 if (dy && verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
2552 int currentScrollbarValue = verticalScrollBar()->value();
2553 int previousScrollbarValue = currentScrollbarValue + dy;
2554 int currentViewIndex = currentScrollbarValue;
2555 int previousViewIndex = previousScrollbarValue;
2557 if (previousViewIndex < currentViewIndex) {
2558 for (
int i = previousViewIndex; i < currentViewIndex; ++i) {
2559 if (i < d->viewItems.size())
2560 dy -= d->itemHeight(i);
2562 }
else if (previousViewIndex > currentViewIndex) {
2563 for (
int i = previousViewIndex - 1; i >= currentViewIndex; --i) {
2564 if (i < d->viewItems.size())
2565 dy += d->itemHeight(i);
2570 d->scrollContentsBy(dx, dy);
2852void QTreeView::expandToDepth(
int depth)
2855 d->viewItems.clear();
2856 QSet<QPersistentModelIndex> old_expandedIndexes;
2857 old_expandedIndexes = d->expandedIndexes;
2858 d->expandedIndexes.clear();
2859 d->interruptDelayedItemsLayout();
2861 for (
int i = 0; i < d->viewItems.size(); ++i) {
2862 if (q20::cmp_less_equal(d->viewItems.at(i).level, depth)) {
2863 d->viewItems[i].expanded =
true;
2865 d->storeExpanded(d->viewItems.at(i).index);
2869 bool someSignalEnabled = isSignalConnected(QMetaMethod::fromSignal(&QTreeView::collapsed));
2870 someSignalEnabled |= isSignalConnected(QMetaMethod::fromSignal(&QTreeView::expanded));
2872 if (!signalsBlocked() && someSignalEnabled) {
2874 QSet<QPersistentModelIndex> collapsedIndexes = old_expandedIndexes - d->expandedIndexes;
2875 QSet<QPersistentModelIndex>::const_iterator i = collapsedIndexes.constBegin();
2876 for (; i != collapsedIndexes.constEnd(); ++i) {
2877 const QPersistentModelIndex &mi = (*i);
2878 if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
2882 QSet<QPersistentModelIndex> expandedIndexs = d->expandedIndexes - old_expandedIndexes;
2883 i = expandedIndexs.constBegin();
2884 for (; i != expandedIndexs.constEnd(); ++i) {
2885 const QPersistentModelIndex &mi = (*i);
2886 if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
2892 d->viewport->update();
2893 d->updateAccessibility();
2951int QTreeView::sizeHintForColumn(
int column)
const
2953 Q_D(
const QTreeView);
2954 d->executePostedLayout();
2955 if (d->viewItems.isEmpty())
2959 QStyleOptionViewItem option;
2960 initViewItemOption(&option);
2961 const QList<QTreeViewItem> viewItems = d->viewItems;
2963 const int maximumProcessRows = d->header->resizeContentsPrecision();
2966 int start = d->firstVisibleItem(&offset);
2967 int end = d->lastVisibleItem(start, offset);
2968 if (start < 0 || end < 0 || end == viewItems.size() - 1) {
2969 end = viewItems.size() - 1;
2970 if (maximumProcessRows < 0) {
2972 }
else if (maximumProcessRows == 0) {
2973 start = qMax(0, end - 1);
2974 int remainingHeight = viewport()->height();
2975 while (start > 0 && remainingHeight > 0) {
2976 remainingHeight -= d->itemHeight(start);
2980 start = qMax(0, end - maximumProcessRows);
2984 int rowsProcessed = 0;
2986 for (
int i = start; i <= end; ++i) {
2987 if (viewItems.at(i).spanning)
2989 QModelIndex index = viewItems.at(i).index;
2990 index = index.sibling(index.row(), column);
2991 w = d->widthHintForIndex(index, w, option, i);
2993 if (rowsProcessed == maximumProcessRows)
2998 int actualBottom = viewItems.size() - 1;
3000 if (maximumProcessRows == 0)
3003 while (rowsProcessed != maximumProcessRows && (start > 0 || end < actualBottom)) {
3006 if ((rowsProcessed % 2 && start > 0) || end == actualBottom) {
3009 if (viewItems.at(start).spanning)
3015 while (end < actualBottom) {
3017 if (viewItems.at(end).spanning)
3026 QModelIndex index = viewItems.at(idx).index;
3027 index = index.sibling(index.row(), column);
3028 w = d->widthHintForIndex(index, w, option, idx);
3039int QTreeView::indexRowSizeHint(
const QModelIndex &index)
const
3041 Q_D(
const QTreeView);
3042 if (!d->isIndexValid(index) || !d->itemDelegate)
3047 int indexRow = index.row();
3048 int count = d->header->count();
3049 bool emptyHeader = (count == 0);
3050 QModelIndex parent = index.parent();
3052 if (count && isVisible()) {
3054 start = d->header->visualIndexAt(0);
3057 count = d->model->columnCount(parent);
3060 if (isRightToLeft()) {
3061 start = (start == -1 ? count - 1 : start);
3064 start = (start == -1 ? 0 : start);
3072 QStyleOptionViewItem option;
3073 initViewItemOption(&option);
3079 option.rect.setWidth(-1);
3081 for (
int column = start; column <= end; ++column) {
3082 int logicalColumn = emptyHeader ? column : d->header->logicalIndex(column);
3083 if (d->header->isSectionHidden(logicalColumn))
3085 QModelIndex idx = d->model->index(indexRow, logicalColumn, parent);
3086 if (idx.isValid()) {
3087 QWidget *editor = d->editorForIndex(idx).widget.data();
3088 if (editor && d->persistent.contains(editor)) {
3089 height = qMax(height, editor->sizeHint().height());
3090 int min = editor->minimumSize().height();
3091 int max = editor->maximumSize().height();
3092 height = qBound(min, height, max);
3094 int hint = itemDelegateForIndex(idx)->sizeHint(option, idx).height();
3095 height = qMax(height, hint);
3421void QTreeViewPrivate::layout(
int i,
bool recursiveExpanding,
bool afterIsUninitialized)
3424 QModelIndex current;
3425 QModelIndex parent = (i < 0) ? (QModelIndex)root : modelIndex(i);
3427 if (i>=0 && !parent.isValid()) {
3434#if QT_CONFIG(accessibility)
3438 const auto resetModelIfNeeded = qScopeGuard([oldViewItemsSize = viewItems.size(),
this]{
3439 pendingAccessibilityUpdate |= oldViewItemsSize != viewItems.size();
3444 if (model->hasChildren(parent)) {
3445 if (model->canFetchMore(parent)) {
3447 model->fetchMore(parent);
3449 const int itemHeight = defaultItemHeight <= 0 ? q->sizeHintForRow(0) : defaultItemHeight;
3450 const int viewCount = itemHeight ? viewport->height() / itemHeight : 0;
3452 while ((count = model->rowCount(parent)) < viewCount &&
3453 count != lastCount && model->canFetchMore(parent)) {
3454 model->fetchMore(parent);
3458 count = model->rowCount(parent);
3462 bool expanding =
true;
3464 if (uniformRowHeights) {
3465 QModelIndex index = model->index(0, 0, parent);
3466 defaultItemHeight = q->indexRowSizeHint(index);
3468 viewItems.resize(count);
3469 afterIsUninitialized =
true;
3470 }
else if (q20::cmp_not_equal(viewItems[i].total, count)) {
3471 if (!afterIsUninitialized)
3472 insertViewItems(i + 1, count, QTreeViewItem());
3474 viewItems.resize(viewItems.size() + count);
3480 int level = (i >= 0 ? viewItems.at(i).level + 1 : 0);
3484 QTreeViewItem *item =
nullptr;
3485 for (
int j = first; j < first + count; ++j) {
3486 current = model->index(j - first, 0, parent);
3487 if (isRowHidden(current)) {
3489 last = j - hidden + children;
3491 last = j - hidden + children;
3493 item->hasMoreSiblings =
true;
3494 item = &viewItems[last];
3495 item->index = current;
3496 item->parentItem = i;
3497 item->level = level;
3499 item->spanning = q->isFirstColumnSpanned(current.row(), parent);
3500 item->expanded =
false;
3502 item->hasMoreSiblings =
false;
3503 if ((recursiveExpanding && !(current.flags() & Qt::ItemNeverHasChildren)) || isIndexExpanded(current)) {
3504 if (recursiveExpanding && storeExpanded(current) && !q->signalsBlocked())
3505 emit q->expanded(current);
3506 item->expanded =
true;
3507 layout(last, recursiveExpanding, afterIsUninitialized);
3508 item = &viewItems[last];
3509 children += item->total;
3510 item->hasChildren = item->total > 0;
3511 last = j - hidden + children;
3513 item->hasChildren = hasVisibleChildren(current);
3520 if (!afterIsUninitialized)
3521 removeViewItems(last + 1, hidden);
3523 viewItems.resize(viewItems.size() - hidden);
3530 viewItems[i].total += count - hidden;
3531 i = viewItems[i].parentItem;
3659int QTreeViewPrivate::itemAtCoordinate(
int coordinate)
const
3661 const int itemCount = viewItems.size();
3664 if (uniformRowHeights && defaultItemHeight <= 0)
3666 if (verticalScrollMode == QAbstractItemView::ScrollPerPixel) {
3667 if (uniformRowHeights) {
3668 const int viewItemIndex = (coordinate + vbar->value()) / defaultItemHeight;
3669 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3672 int viewItemCoordinate = 0;
3673 const int contentsCoordinate = coordinate + vbar->value();
3674 for (
int viewItemIndex = 0; viewItemIndex < viewItems.size(); ++viewItemIndex) {
3675 viewItemCoordinate += itemHeight(viewItemIndex);
3676 if (viewItemCoordinate > contentsCoordinate)
3677 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3680 int topViewItemIndex = vbar->value();
3681 if (uniformRowHeights) {
3683 coordinate -= defaultItemHeight - 1;
3684 const int viewItemIndex = topViewItemIndex + (coordinate / defaultItemHeight);
3685 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3687 if (coordinate >= 0) {
3689 int viewItemCoordinate = 0;
3690 for (
int viewItemIndex = topViewItemIndex; viewItemIndex < viewItems.size(); ++viewItemIndex) {
3691 viewItemCoordinate += itemHeight(viewItemIndex);
3692 if (viewItemCoordinate > coordinate)
3693 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3697 int viewItemCoordinate = 0;
3698 for (
int viewItemIndex = topViewItemIndex; viewItemIndex >= 0; --viewItemIndex) {
3699 if (viewItemCoordinate <= coordinate)
3700 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3701 viewItemCoordinate -= itemHeight(viewItemIndex);
3815void QTreeViewPrivate::updateScrollBars()
3818 QSize viewportSize = viewport->size();
3819 if (!viewportSize.isValid())
3820 viewportSize = QSize(0, 0);
3822 executePostedLayout();
3823 if (viewItems.isEmpty()) {
3827 int itemsInViewport = 0;
3828 if (uniformRowHeights) {
3829 if (defaultItemHeight <= 0)
3830 itemsInViewport = viewItems.size();
3832 itemsInViewport = viewportSize.height() / defaultItemHeight;
3834 const int itemsCount = viewItems.size();
3835 const int viewportHeight = viewportSize.height();
3836 for (
int height = 0, item = itemsCount - 1; item >= 0; --item) {
3837 height += itemHeight(item);
3838 if (height > viewportHeight)
3843 if (verticalScrollMode == QAbstractItemView::ScrollPerItem) {
3844 if (!viewItems.isEmpty())
3845 itemsInViewport = qMax(1, itemsInViewport);
3846 vbar->setRange(0, viewItems.size() - itemsInViewport);
3847 vbar->setPageStep(itemsInViewport);
3848 vbar->setSingleStep(1);
3850 int contentsHeight = 0;
3851 if (uniformRowHeights) {
3852 contentsHeight = defaultItemHeight * viewItems.size();
3854 for (
int i = 0; i < viewItems.size(); ++i)
3855 contentsHeight += itemHeight(i);
3857 vbar->setRange(0, contentsHeight - viewportSize.height());
3858 vbar->setPageStep(viewportSize.height());
3859 vbar->d_func()->itemviewChangeSingleStep(qMax(viewportSize.height() / (itemsInViewport + 1), 2));
3862 const int columnCount = header->count();
3863 const int viewportWidth = viewportSize.width();
3864 int columnsInViewport = 0;
3865 for (
int width = 0, column = columnCount - 1; column >= 0; --column) {
3866 int logical = header->logicalIndex(column);
3867 width += header->sectionSize(logical);
3868 if (width > viewportWidth)
3870 ++columnsInViewport;
3872 if (columnCount > 0)
3873 columnsInViewport = qMax(1, columnsInViewport);
3874 if (horizontalScrollMode == QAbstractItemView::ScrollPerItem) {
3875 hbar->setRange(0, columnCount - columnsInViewport);
3876 hbar->setPageStep(columnsInViewport);
3877 hbar->setSingleStep(1);
3879 const int horizontalLength = header->length();
3880 const QSize maxSize = q->maximumViewportSize();
3881 if (maxSize.width() >= horizontalLength && vbar->maximum() <= 0)
3882 viewportSize = maxSize;
3883 hbar->setPageStep(viewportSize.width());
3884 hbar->setRange(0, qMax(horizontalLength - viewportSize.width(), 0));
3885 hbar->d_func()->itemviewChangeSingleStep(qMax(viewportSize.width() / (columnsInViewport + 1), 2));
3985void QTreeViewPrivate::select(
const QModelIndex &topIndex,
const QModelIndex &bottomIndex,
3986 QItemSelectionModel::SelectionFlags command)
3989 QItemSelection selection;
3990 const int top = viewIndex(topIndex),
3991 bottom = viewIndex(bottomIndex);
3993 const QList<std::pair<
int,
int>> colRanges = columnRanges(topIndex, bottomIndex);
3994 QList<std::pair<
int,
int>>::const_iterator it;
3995 for (it = colRanges.begin(); it != colRanges.end(); ++it) {
3996 const int left = (*it).first,
3997 right = (*it).second;
3999 QModelIndex previous;
4000 QItemSelectionRange currentRange;
4001 QStack<QItemSelectionRange> rangeStack;
4002 for (
int i = top; i <= bottom; ++i) {
4003 QModelIndex index = modelIndex(i);
4004 QModelIndex parent = index.parent();
4005 QModelIndex previousParent = previous.parent();
4006 if (previous.isValid() && parent == previousParent) {
4008 if (qAbs(previous.row() - index.row()) > 1) {
4010 if (currentRange.isValid()) {
4011 selection.append(currentRange);
4014 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4016 QModelIndex tl = model->index(currentRange.top(), currentRange.left(),
4017 currentRange.parent());
4018 currentRange = QItemSelectionRange(tl, index.sibling(index.row(), right));
4020 }
else if (previous.isValid() && parent == model->index(previous.row(), 0, previousParent)) {
4022 rangeStack.push(currentRange);
4023 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4025 if (currentRange.isValid())
4026 selection.append(currentRange);
4027 if (rangeStack.isEmpty()) {
4028 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4030 currentRange = rangeStack.pop();
4031 index = currentRange.bottomRight();
4037 if (currentRange.isValid())
4038 selection.append(currentRange);
4039 for (
int i = 0; i < rangeStack.size(); ++i)
4040 selection.append(rangeStack.at(i));
4042 q->selectionModel()->select(selection, command);