184void QTreeView::setModel(QAbstractItemModel *model)
187 if (model == d->model)
189 if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
190 for (QMetaObject::Connection &connection : d->modelConnections)
191 QObject::disconnect(connection);
194 if (d->selectionModel) {
195 QObject::disconnect(d->selectionmodelConnection);
197 d->viewItems.clear();
198 d->expandedIndexes.clear();
199 d->hiddenIndexes.clear();
200 d->geometryRecursionBlock =
true;
201 d->header->setModel(model);
202 d->geometryRecursionBlock =
false;
203 QAbstractItemView::setModel(model);
207 QObjectPrivate::disconnect(d->model, &QAbstractItemModel::rowsRemoved,
208 d, &QAbstractItemViewPrivate::rowsRemoved);
210 QObjectPrivate::disconnect(d->model, &QAbstractItemModel::layoutChanged,
211 d->header->d_func(), &QAbstractItemViewPrivate::layoutChanged);
213 d->modelConnections = {
215 QObject::connect(d->model, &QAbstractItemModel::rowsRemoved,
216 this, &QTreeView::rowsRemoved),
217 QObjectPrivate::connect(d->model, &QAbstractItemModel::modelAboutToBeReset,
218 d, &QTreeViewPrivate::modelAboutToBeReset)
221 if (d->sortingEnabled)
222 d->sortIndicatorChanged(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
277void QTreeView::setHeader(QHeaderView *header)
280 if (header == d->header || !header)
282 if (d->header && d->header->parent() ==
this)
285 d->header->setParent(
this);
286 d->header->setFirstSectionMovable(
false);
288 if (!d->header->model()) {
289 d->header->setModel(d->model);
290 if (d->selectionModel)
291 d->header->setSelectionModel(d->selectionModel);
294 d->headerConnections = {
295 connect(d->header, &QHeaderView::sectionResized,
296 this, &QTreeView::columnResized),
297 connect(d->header, &QHeaderView::sectionMoved,
298 this, &QTreeView::columnMoved),
299 connect(d->header, &QHeaderView::sectionCountChanged,
300 this, &QTreeView::columnCountChanged),
301 connect(d->header, &QHeaderView::sectionHandleDoubleClicked,
302 this, &QTreeView::resizeColumnToContents),
303 connect(d->header, &QHeaderView::geometriesChanged,
304 this, &QTreeView::updateGeometries)
307 setSortingEnabled(d->sortingEnabled);
965void QTreeView::keyboardSearch(
const QString &search)
968 if (!d->model->rowCount(d->root) || !d->model->columnCount(d->root))
972 d->executePostedLayout();
973 if (d->viewItems.isEmpty())
977 if (currentIndex().isValid())
978 start = currentIndex();
980 start = d->viewItems.at(0).index;
982 bool skipRow =
false;
983 bool keyboardTimeWasValid = d->keyboardInputTime.isValid();
984 qint64 keyboardInputTimeElapsed;
985 if (keyboardTimeWasValid)
986 keyboardInputTimeElapsed = d->keyboardInputTime.restart();
988 d->keyboardInputTime.start();
989 if (search.isEmpty() || !keyboardTimeWasValid
990 || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) {
991 d->keyboardInput = search;
992 skipRow = currentIndex().isValid();
994 d->keyboardInput += search;
998 bool sameKey =
false;
999 if (d->keyboardInput.size() > 1) {
1000 int c = d->keyboardInput.count(d->keyboardInput.at(d->keyboardInput.size() - 1));
1001 sameKey = (c == d->keyboardInput.size());
1008 if (indexBelow(start).isValid()) {
1009 start = indexBelow(start);
1011 const int origCol = start.column();
1012 start = d->viewItems.at(0).index;
1013 if (origCol != start.column())
1014 start = start.sibling(start.row(), origCol);
1018 int startIndex = d->viewIndex(start);
1019 if (startIndex <= -1)
1022 int previousLevel = -1;
1025 QString searchString = sameKey ? QString(d->keyboardInput.at(0)) : d->keyboardInput;
1026 for (
int i = 0; i < d->viewItems.size(); ++i) {
1027 if ((
int)d->viewItems.at(i).level > previousLevel) {
1028 QModelIndex searchFrom = d->viewItems.at(i).index;
1029 if (start.column() > 0)
1030 searchFrom = searchFrom.sibling(searchFrom.row(), start.column());
1031 if (searchFrom.parent() == start.parent())
1033 QModelIndexList match = d->model->match(searchFrom, Qt::DisplayRole, searchString, 1,
1034 keyboardSearchFlags());
1036 int hitIndex = d->viewIndex(match.at(0));
1037 if (hitIndex >= 0 && hitIndex < startIndex)
1038 bestAbove = bestAbove == -1 ? hitIndex : qMin(hitIndex, bestAbove);
1039 else if (hitIndex >= startIndex)
1040 bestBelow = bestBelow == -1 ? hitIndex : qMin(hitIndex, bestBelow);
1043 previousLevel = d->viewItems.at(i).level;
1048 index = d->viewItems.at(bestBelow).index;
1049 else if (bestAbove > -1)
1050 index = d->viewItems.at(bestAbove).index;
1052 if (start.column() > 0)
1053 index = index.sibling(index.row(), start.column());
1055 if (index.isValid())
1056 setCurrentIndex(index);
1149void QTreeView::scrollTo(
const QModelIndex &index, ScrollHint hint)
1153 if (!d->isIndexValid(index))
1156 d->executePostedLayout();
1157 d->updateScrollBars();
1160 QModelIndex parent = index.parent();
1161 while (parent != d->root && parent.isValid() && state() == NoState && d->itemsExpandable) {
1162 if (!isExpanded(parent))
1164 parent = d->model->parent(parent);
1167 int item = d->viewIndex(index);
1171 QRect area = d->viewport->rect();
1174 if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
1175 int top = verticalScrollBar()->value();
1176 int bottom = top + verticalScrollBar()->pageStep();
1177 if (hint == EnsureVisible && item >= top && item < bottom) {
1179 }
else if (hint == PositionAtTop || (hint == EnsureVisible && item < top)) {
1180 verticalScrollBar()->setValue(item);
1182 const int currentItemHeight = d->itemHeight(item);
1183 int y = (hint == PositionAtCenter
1185 ? area.height() / 2 + currentItemHeight - 1
1188 if (y > currentItemHeight) {
1190 y -= d->itemHeight(item);
1198 verticalScrollBar()->setValue(item);
1201 QRect rect(columnViewportPosition(index.column()),
1202 d->coordinateForItem(item),
1203 columnWidth(index.column()),
1204 d->itemHeight(item));
1206 if (rect.isEmpty()) {
1208 }
else if (hint == EnsureVisible && area.contains(rect)) {
1209 d->viewport->update(rect);
1212 bool above = (hint == EnsureVisible
1213 && (rect.top() < area.top()
1214 || area.height() < rect.height()));
1215 bool below = (hint == EnsureVisible
1216 && rect.bottom() > area.bottom()
1217 && rect.height() < area.height());
1219 int verticalValue = verticalScrollBar()->value();
1220 if (hint == PositionAtTop || above)
1221 verticalValue += rect.top();
1222 else if (hint == PositionAtBottom || below)
1223 verticalValue += rect.bottom() - area.height();
1224 else if (hint == PositionAtCenter)
1225 verticalValue += rect.top() - ((area.height() - rect.height()) / 2);
1226 verticalScrollBar()->setValue(verticalValue);
1230 int viewportWidth = d->viewport->width();
1231 int horizontalOffset = d->header->offset();
1232 int horizontalPosition = d->header->sectionPosition(index.column());
1233 int cellWidth = d->header->sectionSize(index.column());
1235 if (hint == PositionAtCenter) {
1236 horizontalScrollBar()->setValue(horizontalPosition - ((viewportWidth - cellWidth) / 2));
1238 if (horizontalPosition - horizontalOffset < 0 || cellWidth > viewportWidth)
1239 horizontalScrollBar()->setValue(horizontalPosition);
1240 else if (horizontalPosition - horizontalOffset + cellWidth > viewportWidth)
1241 horizontalScrollBar()->setValue(horizontalPosition - viewportWidth + cellWidth);
1417QRect QTreeViewPrivate::intersectedRect(
const QRect rect,
const QModelIndex &topLeft,
const QModelIndex &bottomRight)
const
1419 const auto parentIdx = topLeft.parent();
1420 executePostedLayout();
1422 int left = std::numeric_limits<
int>::max();
1423 int right = std::numeric_limits<
int>::min();
1424 for (
int row = topLeft.row(); row <= bottomRight.row(); ++row) {
1425 const auto idxCol0 = model->index(row, 0, parentIdx);
1426 if (isRowHidden(idxCol0))
1429 if (left != std::numeric_limits<
int>::max()) {
1431 rowRect = visualRect(idxCol0, FullRow);
1432 if (!rowRect.intersects(rect))
1434 rowRect = QRect(left, rowRect.top(), right, rowRect.bottom());
1435 }
else if (!spanningIndexes.isEmpty() && spanningIndexes.contains(idxCol0)) {
1438 rowRect = visualRect(idxCol0, FullRow);
1439 if (!rowRect.intersects(rect))
1442 for (
int col = topLeft.column(); col <= bottomRight.column(); ++col) {
1443 if (header->isSectionHidden(col))
1445 const QModelIndex idx(model->index(row, col, parentIdx));
1446 const QRect idxRect = visualRect(idx, SingleSection);
1447 if (idxRect.isNull())
1450 if (idxRect.top() > rect.bottom() || idxRect.bottom() < rect.top())
1452 if (!idxRect.intersects(rect))
1454 rowRect = rowRect.united(idxRect);
1455 if (rowRect.left() < rect.left() && rowRect.right() > rect.right())
1458 if (rowRect.isValid()) {
1459 left = std::min(left, rowRect.left());
1460 right = std::max(right, rowRect.right());
1463 updateRect = updateRect.united(rowRect);
1464 if (updateRect.contains(rect))
1467 return rect.intersected(updateRect);
1527void QTreeView::drawTree(QPainter *painter,
const QRegion ®ion)
const
1529 Q_D(
const QTreeView);
1531 const QList<QTreeViewItem> &viewItems = d->viewItems;
1533 QStyleOptionViewItem option;
1534 initViewItemOption(&option);
1535 const QStyle::State state = option.state;
1538 if (viewItems.size() == 0 || d->header->count() == 0 || !d->itemDelegate) {
1539 d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1);
1543 int firstVisibleItemOffset = 0;
1544 const int firstVisibleItem = d->firstVisibleItem(&firstVisibleItemOffset);
1545 if (firstVisibleItem < 0) {
1546 d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1);
1550 const int viewportWidth = d->viewport->width();
1552 QPoint hoverPos = d->viewport->mapFromGlobal(QCursor::pos());
1553 d->hoverBranch = d->itemDecorationAt(hoverPos);
1556 bool multipleRects = (region.rectCount() > 1);
1557 for (
const QRect &a : region) {
1558 const QRect area = (multipleRects
1559 ? QRect(0, a.y(), viewportWidth, a.height())
1561 d->leftAndRight = d->startAndEndColumns(area);
1563 int i = firstVisibleItem;
1564 int y = firstVisibleItemOffset;
1567 for (; i < viewItems.size(); ++i) {
1568 const int itemHeight = d->itemHeight(i);
1569 if (y + itemHeight > area.top())
1575 for (; i < viewItems.size() && y <= area.bottom(); ++i) {
1576 const QModelIndex &index = viewItems.at(i).index;
1577 const int itemHeight = d->itemHeight(i);
1578 option.rect = d->visualRect(index, QTreeViewPrivate::FullRow);
1579 option.state = state | (viewItems.at(i).expanded ? QStyle::State_Open : QStyle::State_None)
1580 | (viewItems.at(i).hasChildren ? QStyle::State_Children : QStyle::State_None)
1581 | (viewItems.at(i).hasMoreSiblings ? QStyle::State_Sibling : QStyle::State_None);
1583 d->spanning = viewItems.at(i).spanning;
1584 if (!multipleRects || !drawn.contains(i)) {
1585 drawRow(painter, option, viewItems.at(i).index);
1592 if (y <= area.bottom()) {
1594 d->paintAlternatingRowColors(painter, &option, y, area.bottom());
1609void QTreeViewPrivate::calcLogicalIndices(
1610 QList<
int> *logicalIndices, QList<QStyleOptionViewItem::ViewItemPosition> *itemPositions,
1611 int left,
int right)
const
1613 const int columnCount = header->count();
1615
1616
1617 int logicalIndexBeforeLeft = -1, logicalIndexAfterRight = -1;
1618 for (
int visualIndex = left - 1; visualIndex >= 0; --visualIndex) {
1619 int logicalIndex = header->logicalIndex(visualIndex);
1620 if (!header->isSectionHidden(logicalIndex)) {
1621 logicalIndexBeforeLeft = logicalIndex;
1626 for (
int visualIndex = left; visualIndex < columnCount; ++visualIndex) {
1627 int logicalIndex = header->logicalIndex(visualIndex);
1628 if (!header->isSectionHidden(logicalIndex)) {
1629 if (visualIndex > right) {
1630 logicalIndexAfterRight = logicalIndex;
1633 logicalIndices->append(logicalIndex);
1637 const auto indicesCount = logicalIndices->size();
1638 itemPositions->resize(indicesCount);
1639 for (qsizetype currentLogicalSection = 0; currentLogicalSection < indicesCount; ++currentLogicalSection) {
1641 int nextLogicalSection = currentLogicalSection + 1 >= indicesCount
1642 ? logicalIndexAfterRight
1643 : logicalIndices->at(currentLogicalSection + 1);
1644 int prevLogicalSection = currentLogicalSection - 1 < 0
1645 ? logicalIndexBeforeLeft
1646 : logicalIndices->at(currentLogicalSection - 1);
1647 const int headerSection = logicalIndices->at(currentLogicalSection);
1648 QStyleOptionViewItem::ViewItemPosition pos;
1649 if ((nextLogicalSection == -1 && prevLogicalSection == -1) || spanning) {
1650 pos = QStyleOptionViewItem::OnlyOne;
1651 }
else if ((nextLogicalSection != 0 && prevLogicalSection == -1) || isTreePosition(headerSection))
1652 pos = QStyleOptionViewItem::Beginning;
1653 else if (nextLogicalSection == 0 || nextLogicalSection == -1)
1654 pos = QStyleOptionViewItem::End;
1656 pos = QStyleOptionViewItem::Middle;
1657 (*itemPositions)[currentLogicalSection] = pos;
1687void QTreeView::drawRow(QPainter *painter,
const QStyleOptionViewItem &option,
1688 const QModelIndex &index)
const
1690 Q_D(
const QTreeView);
1691 QStyleOptionViewItem opt = option;
1692 const QPoint offset = d->scrollDelayOffset;
1693 const int y = option.rect.y() + offset.y();
1694 const QModelIndex parent = index.parent();
1695 const QHeaderView *header = d->header;
1696 const QModelIndex current = currentIndex();
1697 const QModelIndex hover = d->hover;
1698 const bool reverse = isRightToLeft();
1699 const QStyle::State state = opt.state;
1700 const bool spanning = d->spanning;
1701 const int left = (spanning ? header->visualIndex(0) : d->leftAndRight.first);
1702 const int right = (spanning ? header->visualIndex(0) : d->leftAndRight.second);
1703 const bool alternate = d->alternatingColors;
1704 const bool enabled = (state & QStyle::State_Enabled) != 0;
1705 const bool allColumnsShowFocus = d->allColumnsShowFocus;
1710 bool indexWidgetHasFocus =
false;
1711 if ((current.row() == index.row()) && !d->editorIndexHash.isEmpty()) {
1712 const int r = index.row();
1713 QWidget *fw = QApplication::focusWidget();
1714 for (
int c = 0; c < header->count(); ++c) {
1715 QModelIndex idx = d->model->index(r, c, parent);
1716 if (QWidget *editor = indexWidget(idx)) {
1717 if (ancestorOf(editor, fw)) {
1718 indexWidgetHasFocus =
true;
1725 const bool widgetHasFocus = hasFocus();
1726 bool currentRowHasFocus =
false;
1727 if (allColumnsShowFocus && widgetHasFocus && current.isValid()) {
1729 const int r = index.row();
1730 for (
int c = 0; c < left && !currentRowHasFocus; ++c) {
1731 QModelIndex idx = d->model->index(r, c, parent);
1732 currentRowHasFocus = (idx == current);
1734 QModelIndex parent = d->model->parent(index);
1735 for (
int c = right; c < header->count() && !currentRowHasFocus; ++c) {
1736 currentRowHasFocus = (d->model->index(r, c, parent) == current);
1745 opt.showDecorationSelected = (d->selectionBehavior & SelectRows)
1746 || option.showDecorationSelected;
1748 int width, height = option.rect.height();
1750 QModelIndex modelIndex;
1751 const bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows
1752 && index.parent() == hover.parent()
1753 && index.row() == hover.row();
1755 QList<
int> logicalIndices;
1756 QList<QStyleOptionViewItem::ViewItemPosition>
1758 d->calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right);
1760 for (
int currentLogicalSection = 0; currentLogicalSection < logicalIndices.size(); ++currentLogicalSection) {
1761 int headerSection = logicalIndices.at(currentLogicalSection);
1762 position = columnViewportPosition(headerSection) + offset.x();
1763 width = header->sectionSize(headerSection);
1766 int lastSection = header->logicalIndex(header->count() - 1);
1768 width = columnViewportPosition(lastSection) + header->sectionSize(lastSection) - position;
1770 width += position - columnViewportPosition(lastSection);
1771 position = columnViewportPosition(lastSection);
1775 modelIndex = d->model->index(index.row(), headerSection, parent);
1776 if (!modelIndex.isValid())
1780 opt.viewItemPosition = viewItemPosList.at(currentLogicalSection);
1783 if (indexWidgetHasFocus)
1784 opt.state |= QStyle::State_Active;
1786 if (d->selectionModel->isSelected(modelIndex))
1787 opt.state |= QStyle::State_Selected;
1788 if (widgetHasFocus && (current == modelIndex)) {
1789 if (allColumnsShowFocus)
1790 currentRowHasFocus =
true;
1792 opt.state |= QStyle::State_HasFocus;
1794 opt.state.setFlag(QStyle::State_MouseOver,
1795 (hoverRow || modelIndex == hover)
1796 && (option.showDecorationSelected || d->hoverBranch == -1));
1799 QPalette::ColorGroup cg;
1800 if ((d->model->flags(modelIndex) & Qt::ItemIsEnabled) == 0) {
1801 opt.state &= ~QStyle::State_Enabled;
1802 cg = QPalette::Disabled;
1803 }
else if (opt.state & QStyle::State_Active) {
1804 cg = QPalette::Active;
1806 cg = QPalette::Inactive;
1808 opt.palette.setCurrentColorGroup(cg);
1812 opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
1814 opt.features &= ~QStyleOptionViewItem::IsDecoratedRootColumn;
1817
1818
1819
1820 if (d->isTreePosition(headerSection)) {
1821 const int i = d->indentationForItem(d->current);
1822 QRect branches(reverse ? position + width - i : position, y, i, height);
1823 const bool setClipRect = branches.width() > width;
1826 painter->setClipRect(QRect(position, y, width, height));
1835 const bool oldShowDecorationSelected = opt.showDecorationSelected;
1836 opt.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected,
1838 opt.rect = branches;
1839 if (opt.rect.width() > 0) {
1841 opt.features |= QStyleOptionViewItem::IsDecoratedRootColumn;
1843 opt.features |= QStyleOptionViewItem::IsDecorationForRootColumn;
1844 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1845 opt.features &= ~QStyleOptionViewItem::IsDecorationForRootColumn;
1850 QStyle::State oldState = opt.state;
1851 opt.state &= ~QStyle::State_Selected;
1852 opt.rect.setRect(reverse ? position : i + position, y, width - i, height);
1853 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1854 opt.state = oldState;
1855 opt.showDecorationSelected = oldShowDecorationSelected;
1858 drawBranches(painter, branches, index);
1862 QStyle::State oldState = opt.state;
1863 opt.state &= ~QStyle::State_Selected;
1864 opt.rect.setRect(position, y, width, height);
1865 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1866 opt.state = oldState;
1869 itemDelegateForIndex(modelIndex)->paint(painter, opt, modelIndex);
1872 if (currentRowHasFocus) {
1873 QStyleOptionFocusRect o;
1874 o.QStyleOption::operator=(option);
1875 o.state |= QStyle::State_KeyboardFocusChange;
1876 QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled)
1877 ? QPalette::Normal : QPalette::Disabled;
1878 o.backgroundColor = option.palette.color(cg, d->selectionModel->isSelected(index)
1879 ? QPalette::Highlight : QPalette::Window);
1881 if (!option.showDecorationSelected)
1882 x = header->sectionPosition(0) + d->indentationForItem(d->current);
1883 QRect focusRect(x - header->offset(), y, header->length() - x, height);
1884 o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), focusRect);
1885 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter);
1888 if (allColumnsShowFocus && !option.showDecorationSelected
1889 && header->sectionsMoved() && (header->visualIndex(0) != 0)) {
1890 QRect sectionRect(0, y, header->sectionPosition(0), height);
1891 o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), sectionRect);
1892 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter);
1902void QTreeView::drawBranches(QPainter *painter,
const QRect &rect,
1903 const QModelIndex &index)
const
1905 Q_D(
const QTreeView);
1906 const bool reverse = isRightToLeft();
1907 const int indent = d->indent;
1908 const int outer = d->rootDecoration ? 0 : 1;
1909 const int item = d->current;
1910 const QTreeViewItem &viewItem = d->viewItems.at(item);
1911 int level = viewItem.level;
1912 QRect primitive(reverse ? rect.left() : rect.right() + 1, rect.top(), indent, rect.height());
1914 QModelIndex parent = index.parent();
1915 QModelIndex current = parent;
1916 QModelIndex ancestor = current.parent();
1918 QStyleOptionViewItem opt;
1919 initViewItemOption(&opt);
1920 QStyle::State extraFlags = QStyle::State_None;
1922 extraFlags |= QStyle::State_Enabled;
1924 extraFlags |= QStyle::State_Active;
1925 QPainterStateGuard psg(painter, QPainterStateGuard::InitialState::NoSave);
1926 if (verticalScrollMode() == QAbstractItemView::ScrollPerPixel) {
1928 painter->setBrushOrigin(QPoint(0, verticalOffset()));
1931 if (d->alternatingColors) {
1932 opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
1937 bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows
1938 && opt.showDecorationSelected
1939 && index.parent() == d->hover.parent()
1940 && index.row() == d->hover.row();
1942 if (d->selectionModel->isSelected(index))
1943 extraFlags |= QStyle::State_Selected;
1945 if (level >= outer) {
1947 primitive.moveLeft(reverse ? primitive.left() : primitive.left() - indent);
1948 opt.rect = primitive;
1950 const bool expanded = viewItem.expanded;
1951 const bool children = viewItem.hasChildren;
1952 bool moreSiblings = viewItem.hasMoreSiblings;
1954 opt.state = QStyle::State_Item | extraFlags
1955 | (moreSiblings ? QStyle::State_Sibling : QStyle::State_None)
1956 | (children ? QStyle::State_Children : QStyle::State_None)
1957 | (expanded ? QStyle::State_Open : QStyle::State_None);
1958 opt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch);
1960 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter,
this);
1963 for (--level; level >= outer; --level) {
1964 primitive.moveLeft(reverse ? primitive.left() + indent : primitive.left() - indent);
1965 opt.rect = primitive;
1966 opt.state = extraFlags;
1967 bool moreSiblings =
false;
1968 if (d->hiddenIndexes.isEmpty()) {
1969 moreSiblings = (d->model->rowCount(ancestor) - 1 > current.row());
1971 int successor = item + viewItem.total + 1;
1972 while (successor < d->viewItems.size()
1973 && d->viewItems.at(successor).level >= uint(level)) {
1974 const QTreeViewItem &successorItem = d->viewItems.at(successor);
1975 if (successorItem.level == uint(level)) {
1976 moreSiblings =
true;
1979 successor += successorItem.total + 1;
1983 opt.state |= QStyle::State_Sibling;
1984 opt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch);
1986 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter,
this);
1988 ancestor = current.parent();
2270QModelIndex QTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
2273 Q_UNUSED(modifiers);
2275 d->executePostedLayout();
2277 QModelIndex current = currentIndex();
2278 if (!current.isValid()) {
2279 int i = d->below(-1);
2281 while (c < d->header->count() && d->header->isSectionHidden(d->header->logicalIndex(c)))
2283 if (i < d->viewItems.size() && c < d->header->count()) {
2284 return d->modelIndex(i, d->header->logicalIndex(c));
2286 return QModelIndex();
2289 const int vi = qMax(0, d->viewIndex(current));
2291 if (isRightToLeft()) {
2292 if (cursorAction == MoveRight)
2293 cursorAction = MoveLeft;
2294 else if (cursorAction == MoveLeft)
2295 cursorAction = MoveRight;
2297 switch (cursorAction) {
2300#ifdef QT_KEYPAD_NAVIGATION
2301 if (vi == d->viewItems.count()-1 && QApplicationPrivate::keypadNavigationEnabled())
2302 return d->model->index(0, current.column(), d->root);
2304 return d->modelIndex(d->below(vi), current.column());
2307#ifdef QT_KEYPAD_NAVIGATION
2308 if (vi == 0 && QApplicationPrivate::keypadNavigationEnabled())
2309 return d->modelIndex(d->viewItems.count() - 1, current.column());
2311 return d->modelIndex(d->above(vi), current.column());
2313 QScrollBar *sb = horizontalScrollBar();
2314 if (vi < d->viewItems.size() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) {
2315 d->collapse(vi,
true);
2316 d->moveCursorUpdatedView =
true;
2318 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren,
nullptr,
this);
2320 QModelIndex par = current.parent();
2321 if (par.isValid() && par != rootIndex())
2327 if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2328 int visualColumn = d->header->visualIndex(current.column()) - 1;
2329 while (visualColumn >= 0 && isColumnHidden(d->header->logicalIndex(visualColumn)))
2331 int newColumn = d->header->logicalIndex(visualColumn);
2332 QModelIndex next = current.sibling(current.row(), newColumn);
2337 int oldValue = sb->value();
2338 sb->setValue(sb->value() - sb->singleStep());
2339 if (oldValue != sb->value())
2340 d->moveCursorUpdatedView =
true;
2345 viewport()->update();
2349 if (vi < d->viewItems.size() && !d->viewItems.at(vi).expanded && d->itemsExpandable
2350 && d->hasVisibleChildren(d->viewItems.at(vi).index)) {
2351 d->expand(vi,
true);
2352 d->moveCursorUpdatedView =
true;
2354 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren,
nullptr,
this);
2356 QModelIndex idx = d->modelIndex(d->below(vi));
2357 if (idx.parent() == current)
2363 if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2364 int visualColumn = d->header->visualIndex(current.column()) + 1;
2365 while (visualColumn < d->model->columnCount(current.parent()) && isColumnHidden(d->header->logicalIndex(visualColumn)))
2367 const int newColumn = d->header->logicalIndex(visualColumn);
2368 const QModelIndex next = current.sibling(current.row(), newColumn);
2374 QScrollBar *sb = horizontalScrollBar();
2375 int oldValue = sb->value();
2376 sb->setValue(sb->value() + sb->singleStep());
2377 if (oldValue != sb->value())
2378 d->moveCursorUpdatedView =
true;
2382 viewport()->update();
2385 return d->modelIndex(d->pageUp(vi), current.column());
2387 return d->modelIndex(d->pageDown(vi), current.column());
2389 return d->modelIndex(d->itemForKeyHome(), current.column());
2391 return d->modelIndex(d->itemForKeyEnd(), current.column());
2402void QTreeView::setSelection(
const QRect &rect, QItemSelectionModel::SelectionFlags command)
2405 if (!selectionModel() || rect.isNull())
2408 d->executePostedLayout();
2409 QPoint tl(isRightToLeft() ? qMax(rect.left(), rect.right())
2410 : qMin(rect.left(), rect.right()), qMin(rect.top(), rect.bottom()));
2411 QPoint br(isRightToLeft() ? qMin(rect.left(), rect.right()) :
2412 qMax(rect.left(), rect.right()), qMax(rect.top(), rect.bottom()));
2413 QModelIndex topLeft = indexAt(tl);
2414 QModelIndex bottomRight = indexAt(br);
2415 if (!topLeft.isValid() && !bottomRight.isValid()) {
2416 if (command & QItemSelectionModel::Clear)
2417 selectionModel()->clear();
2420 if (!topLeft.isValid() && !d->viewItems.isEmpty())
2421 topLeft = d->viewItems.constFirst().index;
2422 if (!bottomRight.isValid() && !d->viewItems.isEmpty()) {
2423 const int column = d->header->logicalIndex(d->header->count() - 1);
2424 const QModelIndex index = d->viewItems.constLast().index;
2425 bottomRight = index.sibling(index.row(), column);
2428 if (!d->isIndexEnabled(topLeft) || !d->isIndexEnabled(bottomRight))
2431 d->select(topLeft, bottomRight, command);
2441QRegion QTreeView::visualRegionForSelection(
const QItemSelection &selection)
const
2443 Q_D(
const QTreeView);
2444 if (selection.isEmpty())
2447 QRegion selectionRegion;
2448 const QRect &viewportRect = d->viewport->rect();
2449 for (
const auto &range : selection) {
2450 if (!range.isValid())
2452 QModelIndex parent = range.parent();
2453 QModelIndex leftIndex = range.topLeft();
2454 int columnCount = d->model->columnCount(parent);
2455 while (leftIndex.isValid() && isIndexHidden(leftIndex)) {
2456 if (leftIndex.column() + 1 < columnCount)
2457 leftIndex = d->model->index(leftIndex.row(), leftIndex.column() + 1, parent);
2459 leftIndex = QModelIndex();
2461 if (!leftIndex.isValid())
2463 const QRect leftRect = d->visualRect(leftIndex, QTreeViewPrivate::SingleSection);
2464 int top = leftRect.top();
2465 QModelIndex rightIndex = range.bottomRight();
2466 while (rightIndex.isValid() && isIndexHidden(rightIndex)) {
2467 if (rightIndex.column() - 1 >= 0)
2468 rightIndex = d->model->index(rightIndex.row(), rightIndex.column() - 1, parent);
2470 rightIndex = QModelIndex();
2472 if (!rightIndex.isValid())
2474 const QRect rightRect = d->visualRect(rightIndex, QTreeViewPrivate::SingleSection);
2475 int bottom = rightRect.bottom();
2477 qSwap<
int>(top, bottom);
2478 int height = bottom - top + 1;
2479 if (d->header->sectionsMoved()) {
2480 for (
int c = range.left(); c <= range.right(); ++c) {
2481 const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height);
2482 if (viewportRect.intersects(rangeRect))
2483 selectionRegion += rangeRect;
2486 QRect combined = leftRect|rightRect;
2487 combined.setX(columnViewportPosition(isRightToLeft() ? range.right() : range.left()));
2488 if (viewportRect.intersects(combined))
2489 selectionRegion += combined;
2492 return selectionRegion;
2519void QTreeView::scrollContentsBy(
int dx,
int dy)
2523 d->delayedAutoScroll.stop();
2525 dx = isRightToLeft() ? -dx : dx;
2527 int oldOffset = d->header->offset();
2528 d->header->d_func()->setScrollOffset(horizontalScrollBar(), horizontalScrollMode());
2529 if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) {
2530 int newOffset = d->header->offset();
2531 dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset;
2535 const int itemHeight = d->defaultItemHeight <= 0 ? sizeHintForRow(0) : d->defaultItemHeight;
2536 if (d->viewItems.isEmpty() || itemHeight == 0)
2540 int viewCount = d->viewport->height() / itemHeight;
2541 int maxDeltaY = qMin(d->viewItems.size(), viewCount);
2543 if (qAbs(dy) > qAbs(maxDeltaY) && d->editorIndexHash.isEmpty()) {
2544 verticalScrollBar()->update();
2545 d->viewport->update();
2549 if (dy && verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
2550 int currentScrollbarValue = verticalScrollBar()->value();
2551 int previousScrollbarValue = currentScrollbarValue + dy;
2552 int currentViewIndex = currentScrollbarValue;
2553 int previousViewIndex = previousScrollbarValue;
2555 if (previousViewIndex < currentViewIndex) {
2556 for (
int i = previousViewIndex; i < currentViewIndex; ++i) {
2557 if (i < d->viewItems.size())
2558 dy -= d->itemHeight(i);
2560 }
else if (previousViewIndex > currentViewIndex) {
2561 for (
int i = previousViewIndex - 1; i >= currentViewIndex; --i) {
2562 if (i < d->viewItems.size())
2563 dy += d->itemHeight(i);
2568 d->scrollContentsBy(dx, dy);
2850void QTreeView::expandToDepth(
int depth)
2853 d->viewItems.clear();
2854 QSet<QPersistentModelIndex> old_expandedIndexes;
2855 old_expandedIndexes = d->expandedIndexes;
2856 d->expandedIndexes.clear();
2857 d->interruptDelayedItemsLayout();
2859 for (
int i = 0; i < d->viewItems.size(); ++i) {
2860 if (q20::cmp_less_equal(d->viewItems.at(i).level, depth)) {
2861 d->viewItems[i].expanded =
true;
2863 d->storeExpanded(d->viewItems.at(i).index);
2867 bool someSignalEnabled = isSignalConnected(QMetaMethod::fromSignal(&QTreeView::collapsed));
2868 someSignalEnabled |= isSignalConnected(QMetaMethod::fromSignal(&QTreeView::expanded));
2870 if (!signalsBlocked() && someSignalEnabled) {
2872 QSet<QPersistentModelIndex> collapsedIndexes = old_expandedIndexes - d->expandedIndexes;
2873 QSet<QPersistentModelIndex>::const_iterator i = collapsedIndexes.constBegin();
2874 for (; i != collapsedIndexes.constEnd(); ++i) {
2875 const QPersistentModelIndex &mi = (*i);
2876 if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
2880 QSet<QPersistentModelIndex> expandedIndexs = d->expandedIndexes - old_expandedIndexes;
2881 i = expandedIndexs.constBegin();
2882 for (; i != expandedIndexs.constEnd(); ++i) {
2883 const QPersistentModelIndex &mi = (*i);
2884 if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
2890 d->viewport->update();
2891 d->updateAccessibility();
2949int QTreeView::sizeHintForColumn(
int column)
const
2951 Q_D(
const QTreeView);
2952 d->executePostedLayout();
2953 if (d->viewItems.isEmpty())
2957 QStyleOptionViewItem option;
2958 initViewItemOption(&option);
2959 const QList<QTreeViewItem> viewItems = d->viewItems;
2961 const int maximumProcessRows = d->header->resizeContentsPrecision();
2964 int start = d->firstVisibleItem(&offset);
2965 int end = d->lastVisibleItem(start, offset);
2966 if (start < 0 || end < 0 || end == viewItems.size() - 1) {
2967 end = viewItems.size() - 1;
2968 if (maximumProcessRows < 0) {
2970 }
else if (maximumProcessRows == 0) {
2971 start = qMax(0, end - 1);
2972 int remainingHeight = viewport()->height();
2973 while (start > 0 && remainingHeight > 0) {
2974 remainingHeight -= d->itemHeight(start);
2978 start = qMax(0, end - maximumProcessRows);
2982 int rowsProcessed = 0;
2984 for (
int i = start; i <= end; ++i) {
2985 if (viewItems.at(i).spanning)
2987 QModelIndex index = viewItems.at(i).index;
2988 index = index.sibling(index.row(), column);
2989 w = d->widthHintForIndex(index, w, option, i);
2991 if (rowsProcessed == maximumProcessRows)
2996 int actualBottom = viewItems.size() - 1;
2998 if (maximumProcessRows == 0)
3001 while (rowsProcessed != maximumProcessRows && (start > 0 || end < actualBottom)) {
3004 if ((rowsProcessed % 2 && start > 0) || end == actualBottom) {
3007 if (viewItems.at(start).spanning)
3013 while (end < actualBottom) {
3015 if (viewItems.at(end).spanning)
3024 QModelIndex index = viewItems.at(idx).index;
3025 index = index.sibling(index.row(), column);
3026 w = d->widthHintForIndex(index, w, option, idx);
3037int QTreeView::indexRowSizeHint(
const QModelIndex &index)
const
3039 Q_D(
const QTreeView);
3040 if (!d->isIndexValid(index) || !d->itemDelegate)
3045 int indexRow = index.row();
3046 int count = d->header->count();
3047 bool emptyHeader = (count == 0);
3048 QModelIndex parent = index.parent();
3050 if (count && isVisible()) {
3052 start = d->header->visualIndexAt(0);
3055 count = d->model->columnCount(parent);
3058 if (isRightToLeft()) {
3059 start = (start == -1 ? count - 1 : start);
3062 start = (start == -1 ? 0 : start);
3070 QStyleOptionViewItem option;
3071 initViewItemOption(&option);
3077 option.rect.setWidth(-1);
3079 for (
int column = start; column <= end; ++column) {
3080 int logicalColumn = emptyHeader ? column : d->header->logicalIndex(column);
3081 if (d->header->isSectionHidden(logicalColumn))
3083 QModelIndex idx = d->model->index(indexRow, logicalColumn, parent);
3084 if (idx.isValid()) {
3085 QWidget *editor = d->editorForIndex(idx).widget.data();
3086 if (editor && d->persistent.contains(editor)) {
3087 height = qMax(height, editor->sizeHint().height());
3088 int min = editor->minimumSize().height();
3089 int max = editor->maximumSize().height();
3090 height = qBound(min, height, max);
3092 int hint = itemDelegateForIndex(idx)->sizeHint(option, idx).height();
3093 height = qMax(height, hint);
3419void QTreeViewPrivate::layout(
int i,
bool recursiveExpanding,
bool afterIsUninitialized)
3422 QModelIndex current;
3423 QModelIndex parent = (i < 0) ? (QModelIndex)root : modelIndex(i);
3425 if (i>=0 && !parent.isValid()) {
3432#if QT_CONFIG(accessibility)
3436 const auto resetModelIfNeeded = qScopeGuard([oldViewItemsSize = viewItems.size(),
this]{
3437 pendingAccessibilityUpdate |= oldViewItemsSize != viewItems.size();
3442 if (model->hasChildren(parent)) {
3443 if (model->canFetchMore(parent)) {
3445 model->fetchMore(parent);
3447 const int itemHeight = defaultItemHeight <= 0 ? q->sizeHintForRow(0) : defaultItemHeight;
3448 const int viewCount = itemHeight ? viewport->height() / itemHeight : 0;
3450 while ((count = model->rowCount(parent)) < viewCount &&
3451 count != lastCount && model->canFetchMore(parent)) {
3452 model->fetchMore(parent);
3456 count = model->rowCount(parent);
3460 bool expanding =
true;
3462 if (uniformRowHeights) {
3463 QModelIndex index = model->index(0, 0, parent);
3464 defaultItemHeight = q->indexRowSizeHint(index);
3466 viewItems.resize(count);
3467 afterIsUninitialized =
true;
3468 }
else if (q20::cmp_not_equal(viewItems[i].total, count)) {
3469 if (!afterIsUninitialized)
3470 insertViewItems(i + 1, count, QTreeViewItem());
3472 viewItems.resize(viewItems.size() + count);
3478 int level = (i >= 0 ? viewItems.at(i).level + 1 : 0);
3482 QTreeViewItem *item =
nullptr;
3483 for (
int j = first; j < first + count; ++j) {
3484 current = model->index(j - first, 0, parent);
3485 if (isRowHidden(current)) {
3487 last = j - hidden + children;
3489 last = j - hidden + children;
3491 item->hasMoreSiblings =
true;
3492 item = &viewItems[last];
3493 item->index = current;
3494 item->parentItem = i;
3495 item->level = level;
3497 item->spanning = q->isFirstColumnSpanned(current.row(), parent);
3498 item->expanded =
false;
3500 item->hasMoreSiblings =
false;
3501 if ((recursiveExpanding && !(current.flags() & Qt::ItemNeverHasChildren)) || isIndexExpanded(current)) {
3502 if (recursiveExpanding && storeExpanded(current) && !q->signalsBlocked())
3503 emit q->expanded(current);
3504 item->expanded =
true;
3505 layout(last, recursiveExpanding, afterIsUninitialized);
3506 item = &viewItems[last];
3507 children += item->total;
3508 item->hasChildren = item->total > 0;
3509 last = j - hidden + children;
3511 item->hasChildren = hasVisibleChildren(current);
3518 if (!afterIsUninitialized)
3519 removeViewItems(last + 1, hidden);
3521 viewItems.resize(viewItems.size() - hidden);
3528 viewItems[i].total += count - hidden;
3529 i = viewItems[i].parentItem;
3657int QTreeViewPrivate::itemAtCoordinate(
int coordinate)
const
3659 const int itemCount = viewItems.size();
3662 if (uniformRowHeights && defaultItemHeight <= 0)
3664 if (verticalScrollMode == QAbstractItemView::ScrollPerPixel) {
3665 if (uniformRowHeights) {
3666 const int viewItemIndex = (coordinate + vbar->value()) / defaultItemHeight;
3667 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3670 int viewItemCoordinate = 0;
3671 const int contentsCoordinate = coordinate + vbar->value();
3672 for (
int viewItemIndex = 0; viewItemIndex < viewItems.size(); ++viewItemIndex) {
3673 viewItemCoordinate += itemHeight(viewItemIndex);
3674 if (viewItemCoordinate > contentsCoordinate)
3675 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3678 int topViewItemIndex = vbar->value();
3679 if (uniformRowHeights) {
3681 coordinate -= defaultItemHeight - 1;
3682 const int viewItemIndex = topViewItemIndex + (coordinate / defaultItemHeight);
3683 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3685 if (coordinate >= 0) {
3687 int viewItemCoordinate = 0;
3688 for (
int viewItemIndex = topViewItemIndex; viewItemIndex < viewItems.size(); ++viewItemIndex) {
3689 viewItemCoordinate += itemHeight(viewItemIndex);
3690 if (viewItemCoordinate > coordinate)
3691 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3695 int viewItemCoordinate = 0;
3696 for (
int viewItemIndex = topViewItemIndex; viewItemIndex >= 0; --viewItemIndex) {
3697 if (viewItemCoordinate <= coordinate)
3698 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3699 viewItemCoordinate -= itemHeight(viewItemIndex);
3813void QTreeViewPrivate::updateScrollBars()
3816 QSize viewportSize = viewport->size();
3817 if (!viewportSize.isValid())
3818 viewportSize = QSize(0, 0);
3820 executePostedLayout();
3821 if (viewItems.isEmpty()) {
3825 int itemsInViewport = 0;
3826 if (uniformRowHeights) {
3827 if (defaultItemHeight <= 0)
3828 itemsInViewport = viewItems.size();
3830 itemsInViewport = viewportSize.height() / defaultItemHeight;
3832 const int itemsCount = viewItems.size();
3833 const int viewportHeight = viewportSize.height();
3834 for (
int height = 0, item = itemsCount - 1; item >= 0; --item) {
3835 height += itemHeight(item);
3836 if (height > viewportHeight)
3841 if (verticalScrollMode == QAbstractItemView::ScrollPerItem) {
3842 if (!viewItems.isEmpty())
3843 itemsInViewport = qMax(1, itemsInViewport);
3844 vbar->setRange(0, viewItems.size() - itemsInViewport);
3845 vbar->setPageStep(itemsInViewport);
3846 vbar->setSingleStep(1);
3848 int contentsHeight = 0;
3849 if (uniformRowHeights) {
3850 contentsHeight = defaultItemHeight * viewItems.size();
3852 for (
int i = 0; i < viewItems.size(); ++i)
3853 contentsHeight += itemHeight(i);
3855 vbar->setRange(0, contentsHeight - viewportSize.height());
3856 vbar->setPageStep(viewportSize.height());
3857 vbar->d_func()->itemviewChangeSingleStep(qMax(viewportSize.height() / (itemsInViewport + 1), 2));
3860 const int columnCount = header->count();
3861 const int viewportWidth = viewportSize.width();
3862 int columnsInViewport = 0;
3863 for (
int width = 0, column = columnCount - 1; column >= 0; --column) {
3864 int logical = header->logicalIndex(column);
3865 width += header->sectionSize(logical);
3866 if (width > viewportWidth)
3868 ++columnsInViewport;
3870 if (columnCount > 0)
3871 columnsInViewport = qMax(1, columnsInViewport);
3872 if (horizontalScrollMode == QAbstractItemView::ScrollPerItem) {
3873 hbar->setRange(0, columnCount - columnsInViewport);
3874 hbar->setPageStep(columnsInViewport);
3875 hbar->setSingleStep(1);
3877 const int horizontalLength = header->length();
3878 const QSize maxSize = q->maximumViewportSize();
3879 if (maxSize.width() >= horizontalLength && vbar->maximum() <= 0)
3880 viewportSize = maxSize;
3881 hbar->setPageStep(viewportSize.width());
3882 hbar->setRange(0, qMax(horizontalLength - viewportSize.width(), 0));
3883 hbar->d_func()->itemviewChangeSingleStep(qMax(viewportSize.width() / (columnsInViewport + 1), 2));
3983void QTreeViewPrivate::select(
const QModelIndex &topIndex,
const QModelIndex &bottomIndex,
3984 QItemSelectionModel::SelectionFlags command)
3987 QItemSelection selection;
3988 const int top = viewIndex(topIndex),
3989 bottom = viewIndex(bottomIndex);
3991 const QList<std::pair<
int,
int>> colRanges = columnRanges(topIndex, bottomIndex);
3992 QList<std::pair<
int,
int>>::const_iterator it;
3993 for (it = colRanges.begin(); it != colRanges.end(); ++it) {
3994 const int left = (*it).first,
3995 right = (*it).second;
3997 QModelIndex previous;
3998 QItemSelectionRange currentRange;
3999 QStack<QItemSelectionRange> rangeStack;
4000 for (
int i = top; i <= bottom; ++i) {
4001 QModelIndex index = modelIndex(i);
4002 QModelIndex parent = index.parent();
4003 QModelIndex previousParent = previous.parent();
4004 if (previous.isValid() && parent == previousParent) {
4006 if (qAbs(previous.row() - index.row()) > 1) {
4008 if (currentRange.isValid()) {
4009 selection.append(currentRange);
4012 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4014 QModelIndex tl = model->index(currentRange.top(), currentRange.left(),
4015 currentRange.parent());
4016 currentRange = QItemSelectionRange(tl, index.sibling(index.row(), right));
4018 }
else if (previous.isValid() && parent == model->index(previous.row(), 0, previousParent)) {
4020 rangeStack.push(currentRange);
4021 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4023 if (currentRange.isValid())
4024 selection.append(currentRange);
4025 if (rangeStack.isEmpty()) {
4026 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4028 currentRange = rangeStack.pop();
4029 index = currentRange.bottomRight();
4035 if (currentRange.isValid())
4036 selection.append(currentRange);
4037 for (
int i = 0; i < rangeStack.size(); ++i)
4038 selection.append(rangeStack.at(i));
4040 q->selectionModel()->select(selection, command);