184void QTreeView::setModel(QAbstractItemModel *model)
187 if (model == d->model)
189 if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
190 for (
const 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);
1035 int hitIndex = d->viewIndex(match.at(0));
1036 if (hitIndex >= 0 && hitIndex < startIndex)
1037 bestAbove = bestAbove == -1 ? hitIndex : qMin(hitIndex, bestAbove);
1038 else if (hitIndex >= startIndex)
1039 bestBelow = bestBelow == -1 ? hitIndex : qMin(hitIndex, bestBelow);
1042 previousLevel = d->viewItems.at(i).level;
1047 index = d->viewItems.at(bestBelow).index;
1048 else if (bestAbove > -1)
1049 index = d->viewItems.at(bestAbove).index;
1051 if (start.column() > 0)
1052 index = index.sibling(index.row(), start.column());
1054 if (index.isValid())
1055 setCurrentIndex(index);
1133void QTreeView::scrollTo(
const QModelIndex &index, ScrollHint hint)
1137 if (!d->isIndexValid(index))
1140 d->executePostedLayout();
1141 d->updateScrollBars();
1144 QModelIndex parent = index.parent();
1145 while (parent != d->root && parent.isValid() && state() == NoState && d->itemsExpandable) {
1146 if (!isExpanded(parent))
1148 parent = d->model->parent(parent);
1151 int item = d->viewIndex(index);
1155 QRect area = d->viewport->rect();
1158 if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
1159 int top = verticalScrollBar()->value();
1160 int bottom = top + verticalScrollBar()->pageStep();
1161 if (hint == EnsureVisible && item >= top && item < bottom) {
1163 }
else if (hint == PositionAtTop || (hint == EnsureVisible && item < top)) {
1164 verticalScrollBar()->setValue(item);
1166 const int currentItemHeight = d->itemHeight(item);
1167 int y = (hint == PositionAtCenter
1169 ? area.height() / 2 + currentItemHeight - 1
1172 if (y > currentItemHeight) {
1174 y -= d->itemHeight(item);
1182 verticalScrollBar()->setValue(item);
1185 QRect rect(columnViewportPosition(index.column()),
1186 d->coordinateForItem(item),
1187 columnWidth(index.column()),
1188 d->itemHeight(item));
1190 if (rect.isEmpty()) {
1192 }
else if (hint == EnsureVisible && area.contains(rect)) {
1193 d->viewport->update(rect);
1196 bool above = (hint == EnsureVisible
1197 && (rect.top() < area.top()
1198 || area.height() < rect.height()));
1199 bool below = (hint == EnsureVisible
1200 && rect.bottom() > area.bottom()
1201 && rect.height() < area.height());
1203 int verticalValue = verticalScrollBar()->value();
1204 if (hint == PositionAtTop || above)
1205 verticalValue += rect.top();
1206 else if (hint == PositionAtBottom || below)
1207 verticalValue += rect.bottom() - area.height();
1208 else if (hint == PositionAtCenter)
1209 verticalValue += rect.top() - ((area.height() - rect.height()) / 2);
1210 verticalScrollBar()->setValue(verticalValue);
1214 int viewportWidth = d->viewport->width();
1215 int horizontalOffset = d->header->offset();
1216 int horizontalPosition = d->header->sectionPosition(index.column());
1217 int cellWidth = d->header->sectionSize(index.column());
1219 if (hint == PositionAtCenter) {
1220 horizontalScrollBar()->setValue(horizontalPosition - ((viewportWidth - cellWidth) / 2));
1222 if (horizontalPosition - horizontalOffset < 0 || cellWidth > viewportWidth)
1223 horizontalScrollBar()->setValue(horizontalPosition);
1224 else if (horizontalPosition - horizontalOffset + cellWidth > viewportWidth)
1225 horizontalScrollBar()->setValue(horizontalPosition - viewportWidth + cellWidth);
1401QRect QTreeViewPrivate::intersectedRect(
const QRect rect,
const QModelIndex &topLeft,
const QModelIndex &bottomRight)
const
1403 const auto parentIdx = topLeft.parent();
1404 executePostedLayout();
1406 int left = std::numeric_limits<
int>::max();
1407 int right = std::numeric_limits<
int>::min();
1408 for (
int row = topLeft.row(); row <= bottomRight.row(); ++row) {
1409 const auto idxCol0 = model->index(row, 0, parentIdx);
1410 if (isRowHidden(idxCol0))
1413 if (left != std::numeric_limits<
int>::max()) {
1415 rowRect = visualRect(idxCol0, FullRow);
1416 if (!rowRect.intersects(rect))
1418 rowRect = QRect(left, rowRect.top(), right, rowRect.bottom());
1419 }
else if (!spanningIndexes.isEmpty() && spanningIndexes.contains(idxCol0)) {
1422 rowRect = visualRect(idxCol0, FullRow);
1423 if (!rowRect.intersects(rect))
1426 for (
int col = topLeft.column(); col <= bottomRight.column(); ++col) {
1427 if (header->isSectionHidden(col))
1429 const QModelIndex idx(model->index(row, col, parentIdx));
1430 const QRect idxRect = visualRect(idx, SingleSection);
1431 if (idxRect.isNull())
1434 if (idxRect.top() > rect.bottom() || idxRect.bottom() < rect.top())
1436 if (!idxRect.intersects(rect))
1438 rowRect = rowRect.united(idxRect);
1439 if (rowRect.left() < rect.left() && rowRect.right() > rect.right())
1442 if (rowRect.isValid()) {
1443 left = std::min(left, rowRect.left());
1444 right = std::max(right, rowRect.right());
1447 updateRect = updateRect.united(rowRect);
1448 if (updateRect.contains(rect))
1451 return rect.intersected(updateRect);
1505void QTreeView::drawTree(QPainter *painter,
const QRegion ®ion)
const
1507 Q_D(
const QTreeView);
1509 const QList<QTreeViewItem> &viewItems = d->viewItems;
1511 QStyleOptionViewItem option;
1512 initViewItemOption(&option);
1513 const QStyle::State state = option.state;
1516 if (viewItems.size() == 0 || d->header->count() == 0 || !d->itemDelegate) {
1517 d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1);
1521 int firstVisibleItemOffset = 0;
1522 const int firstVisibleItem = d->firstVisibleItem(&firstVisibleItemOffset);
1523 if (firstVisibleItem < 0) {
1524 d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1);
1528 const int viewportWidth = d->viewport->width();
1530 QPoint hoverPos = d->viewport->mapFromGlobal(QCursor::pos());
1531 d->hoverBranch = d->itemDecorationAt(hoverPos);
1534 bool multipleRects = (region.rectCount() > 1);
1535 for (
const QRect &a : region) {
1536 const QRect area = (multipleRects
1537 ? QRect(0, a.y(), viewportWidth, a.height())
1539 d->leftAndRight = d->startAndEndColumns(area);
1541 int i = firstVisibleItem;
1542 int y = firstVisibleItemOffset;
1545 for (; i < viewItems.size(); ++i) {
1546 const int itemHeight = d->itemHeight(i);
1547 if (y + itemHeight > area.top())
1553 for (; i < viewItems.size() && y <= area.bottom(); ++i) {
1554 const QModelIndex &index = viewItems.at(i).index;
1555 const int itemHeight = d->itemHeight(i);
1556 option.rect = d->visualRect(index, QTreeViewPrivate::FullRow);
1557 option.state = state | (viewItems.at(i).expanded ? QStyle::State_Open : QStyle::State_None)
1558 | (viewItems.at(i).hasChildren ? QStyle::State_Children : QStyle::State_None)
1559 | (viewItems.at(i).hasMoreSiblings ? QStyle::State_Sibling : QStyle::State_None);
1561 d->spanning = viewItems.at(i).spanning;
1562 if (!multipleRects || !drawn.contains(i)) {
1563 drawRow(painter, option, viewItems.at(i).index);
1570 if (y <= area.bottom()) {
1572 d->paintAlternatingRowColors(painter, &option, y, area.bottom());
1587void QTreeViewPrivate::calcLogicalIndices(
1588 QList<
int> *logicalIndices, QList<QStyleOptionViewItem::ViewItemPosition> *itemPositions,
1589 int left,
int right)
const
1591 const int columnCount = header->count();
1593
1594
1595 int logicalIndexBeforeLeft = -1, logicalIndexAfterRight = -1;
1596 for (
int visualIndex = left - 1; visualIndex >= 0; --visualIndex) {
1597 int logicalIndex = header->logicalIndex(visualIndex);
1598 if (!header->isSectionHidden(logicalIndex)) {
1599 logicalIndexBeforeLeft = logicalIndex;
1604 for (
int visualIndex = left; visualIndex < columnCount; ++visualIndex) {
1605 int logicalIndex = header->logicalIndex(visualIndex);
1606 if (!header->isSectionHidden(logicalIndex)) {
1607 if (visualIndex > right) {
1608 logicalIndexAfterRight = logicalIndex;
1611 logicalIndices->append(logicalIndex);
1615 const auto indicesCount = logicalIndices->size();
1616 itemPositions->resize(indicesCount);
1617 for (qsizetype currentLogicalSection = 0; currentLogicalSection < indicesCount; ++currentLogicalSection) {
1619 if (indicesCount == 1 || spanning) {
1620 (*itemPositions)[currentLogicalSection] = QStyleOptionViewItem::OnlyOne;
1623 const int headerSection = logicalIndices->at(currentLogicalSection);
1625 int nextLogicalSection = currentLogicalSection + 1 >= indicesCount
1626 ? logicalIndexAfterRight
1627 : logicalIndices->at(currentLogicalSection + 1);
1628 int prevLogicalSection = currentLogicalSection - 1 < 0
1629 ? logicalIndexBeforeLeft
1630 : logicalIndices->at(currentLogicalSection - 1);
1631 QStyleOptionViewItem::ViewItemPosition pos;
1632 if ((nextLogicalSection != 0 && prevLogicalSection == -1) || isTreePosition(headerSection))
1633 pos = QStyleOptionViewItem::Beginning;
1634 else if (nextLogicalSection == 0 || nextLogicalSection == -1)
1635 pos = QStyleOptionViewItem::End;
1637 pos = QStyleOptionViewItem::Middle;
1638 (*itemPositions)[currentLogicalSection] = pos;
1668void QTreeView::drawRow(QPainter *painter,
const QStyleOptionViewItem &option,
1669 const QModelIndex &index)
const
1671 Q_D(
const QTreeView);
1672 QStyleOptionViewItem opt = option;
1673 const QPoint offset = d->scrollDelayOffset;
1674 const int y = option.rect.y() + offset.y();
1675 const QModelIndex parent = index.parent();
1676 const QHeaderView *header = d->header;
1677 const QModelIndex current = currentIndex();
1678 const QModelIndex hover = d->hover;
1679 const bool reverse = isRightToLeft();
1680 const QStyle::State state = opt.state;
1681 const bool spanning = d->spanning;
1682 const int left = (spanning ? header->visualIndex(0) : d->leftAndRight.first);
1683 const int right = (spanning ? header->visualIndex(0) : d->leftAndRight.second);
1684 const bool alternate = d->alternatingColors;
1685 const bool enabled = (state & QStyle::State_Enabled) != 0;
1686 const bool allColumnsShowFocus = d->allColumnsShowFocus;
1691 bool indexWidgetHasFocus =
false;
1692 if ((current.row() == index.row()) && !d->editorIndexHash.isEmpty()) {
1693 const int r = index.row();
1694 QWidget *fw = QApplication::focusWidget();
1695 for (
int c = 0; c < header->count(); ++c) {
1696 QModelIndex idx = d->model->index(r, c, parent);
1697 if (QWidget *editor = indexWidget(idx)) {
1698 if (ancestorOf(editor, fw)) {
1699 indexWidgetHasFocus =
true;
1706 const bool widgetHasFocus = hasFocus();
1707 bool currentRowHasFocus =
false;
1708 if (allColumnsShowFocus && widgetHasFocus && current.isValid()) {
1710 const int r = index.row();
1711 for (
int c = 0; c < left && !currentRowHasFocus; ++c) {
1712 QModelIndex idx = d->model->index(r, c, parent);
1713 currentRowHasFocus = (idx == current);
1715 QModelIndex parent = d->model->parent(index);
1716 for (
int c = right; c < header->count() && !currentRowHasFocus; ++c) {
1717 currentRowHasFocus = (d->model->index(r, c, parent) == current);
1726 opt.showDecorationSelected = (d->selectionBehavior & SelectRows)
1727 || option.showDecorationSelected;
1729 int width, height = option.rect.height();
1731 QModelIndex modelIndex;
1732 const bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows
1733 && index.parent() == hover.parent()
1734 && index.row() == hover.row();
1736 QList<
int> logicalIndices;
1737 QList<QStyleOptionViewItem::ViewItemPosition>
1739 d->calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right);
1741 for (
int currentLogicalSection = 0; currentLogicalSection < logicalIndices.size(); ++currentLogicalSection) {
1742 int headerSection = logicalIndices.at(currentLogicalSection);
1743 position = columnViewportPosition(headerSection) + offset.x();
1744 width = header->sectionSize(headerSection);
1747 int lastSection = header->logicalIndex(header->count() - 1);
1749 width = columnViewportPosition(lastSection) + header->sectionSize(lastSection) - position;
1751 width += position - columnViewportPosition(lastSection);
1752 position = columnViewportPosition(lastSection);
1756 modelIndex = d->model->index(index.row(), headerSection, parent);
1757 if (!modelIndex.isValid())
1761 opt.viewItemPosition = viewItemPosList.at(currentLogicalSection);
1764 if (indexWidgetHasFocus)
1765 opt.state |= QStyle::State_Active;
1767 if (d->selectionModel->isSelected(modelIndex))
1768 opt.state |= QStyle::State_Selected;
1769 if (widgetHasFocus && (current == modelIndex)) {
1770 if (allColumnsShowFocus)
1771 currentRowHasFocus =
true;
1773 opt.state |= QStyle::State_HasFocus;
1775 opt.state.setFlag(QStyle::State_MouseOver,
1776 (hoverRow || modelIndex == hover)
1777 && (option.showDecorationSelected || d->hoverBranch == -1));
1780 QPalette::ColorGroup cg;
1781 if ((d->model->flags(modelIndex) & Qt::ItemIsEnabled) == 0) {
1782 opt.state &= ~QStyle::State_Enabled;
1783 cg = QPalette::Disabled;
1784 }
else if (opt.state & QStyle::State_Active) {
1785 cg = QPalette::Active;
1787 cg = QPalette::Inactive;
1789 opt.palette.setCurrentColorGroup(cg);
1793 opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
1795 opt.features &= ~QStyleOptionViewItem::IsDecoratedRootColumn;
1798
1799
1800
1801 if (d->isTreePosition(headerSection)) {
1802 const int i = d->indentationForItem(d->current);
1803 QRect branches(reverse ? position + width - i : position, y, i, height);
1804 const bool setClipRect = branches.width() > width;
1807 painter->setClipRect(QRect(position, y, width, height));
1816 const bool oldShowDecorationSelected = opt.showDecorationSelected;
1817 opt.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected,
1819 opt.rect = branches;
1820 if (opt.rect.width() > 0) {
1822 opt.features |= QStyleOptionViewItem::IsDecoratedRootColumn;
1824 opt.features |= QStyleOptionViewItem::IsDecorationForRootColumn;
1825 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1826 opt.features &= ~QStyleOptionViewItem::IsDecorationForRootColumn;
1831 QStyle::State oldState = opt.state;
1832 opt.state &= ~QStyle::State_Selected;
1833 opt.rect.setRect(reverse ? position : i + position, y, width - i, height);
1834 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1835 opt.state = oldState;
1836 opt.showDecorationSelected = oldShowDecorationSelected;
1839 drawBranches(painter, branches, index);
1843 QStyle::State oldState = opt.state;
1844 opt.state &= ~QStyle::State_Selected;
1845 opt.rect.setRect(position, y, width, height);
1846 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1847 opt.state = oldState;
1850 itemDelegateForIndex(modelIndex)->paint(painter, opt, modelIndex);
1853 if (currentRowHasFocus) {
1854 QStyleOptionFocusRect o;
1855 o.QStyleOption::operator=(option);
1856 o.state |= QStyle::State_KeyboardFocusChange;
1857 QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled)
1858 ? QPalette::Normal : QPalette::Disabled;
1859 o.backgroundColor = option.palette.color(cg, d->selectionModel->isSelected(index)
1860 ? QPalette::Highlight : QPalette::Window);
1862 if (!option.showDecorationSelected)
1863 x = header->sectionPosition(0) + d->indentationForItem(d->current);
1864 QRect focusRect(x - header->offset(), y, header->length() - x, height);
1865 o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), focusRect);
1866 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter);
1869 if (allColumnsShowFocus && !option.showDecorationSelected
1870 && header->sectionsMoved() && (header->visualIndex(0) != 0)) {
1871 QRect sectionRect(0, y, header->sectionPosition(0), height);
1872 o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), sectionRect);
1873 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter);
1883void QTreeView::drawBranches(QPainter *painter,
const QRect &rect,
1884 const QModelIndex &index)
const
1886 Q_D(
const QTreeView);
1887 const bool reverse = isRightToLeft();
1888 const int indent = d->indent;
1889 const int outer = d->rootDecoration ? 0 : 1;
1890 const int item = d->current;
1891 const QTreeViewItem &viewItem = d->viewItems.at(item);
1892 int level = viewItem.level;
1893 QRect primitive(reverse ? rect.left() : rect.right() + 1, rect.top(), indent, rect.height());
1895 QModelIndex parent = index.parent();
1896 QModelIndex current = parent;
1897 QModelIndex ancestor = current.parent();
1899 QStyleOptionViewItem opt;
1900 initViewItemOption(&opt);
1901 QStyle::State extraFlags = QStyle::State_None;
1903 extraFlags |= QStyle::State_Enabled;
1905 extraFlags |= QStyle::State_Active;
1906 QPainterStateGuard psg(painter, QPainterStateGuard::InitialState::NoSave);
1907 if (verticalScrollMode() == QAbstractItemView::ScrollPerPixel) {
1909 painter->setBrushOrigin(QPoint(0, verticalOffset()));
1912 if (d->alternatingColors) {
1913 opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
1918 bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows
1919 && opt.showDecorationSelected
1920 && index.parent() == d->hover.parent()
1921 && index.row() == d->hover.row();
1923 if (d->selectionModel->isSelected(index))
1924 extraFlags |= QStyle::State_Selected;
1926 if (level >= outer) {
1928 primitive.moveLeft(reverse ? primitive.left() : primitive.left() - indent);
1929 opt.rect = primitive;
1931 const bool expanded = viewItem.expanded;
1932 const bool children = viewItem.hasChildren;
1933 bool moreSiblings = viewItem.hasMoreSiblings;
1935 opt.state = QStyle::State_Item | extraFlags
1936 | (moreSiblings ? QStyle::State_Sibling : QStyle::State_None)
1937 | (children ? QStyle::State_Children : QStyle::State_None)
1938 | (expanded ? QStyle::State_Open : QStyle::State_None);
1939 opt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch);
1941 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter,
this);
1944 for (--level; level >= outer; --level) {
1945 primitive.moveLeft(reverse ? primitive.left() + indent : primitive.left() - indent);
1946 opt.rect = primitive;
1947 opt.state = extraFlags;
1948 bool moreSiblings =
false;
1949 if (d->hiddenIndexes.isEmpty()) {
1950 moreSiblings = (d->model->rowCount(ancestor) - 1 > current.row());
1952 int successor = item + viewItem.total + 1;
1953 while (successor < d->viewItems.size()
1954 && d->viewItems.at(successor).level >= uint(level)) {
1955 const QTreeViewItem &successorItem = d->viewItems.at(successor);
1956 if (successorItem.level == uint(level)) {
1957 moreSiblings =
true;
1960 successor += successorItem.total + 1;
1964 opt.state |= QStyle::State_Sibling;
1965 opt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch);
1967 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter,
this);
1969 ancestor = current.parent();
2251QModelIndex QTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
2254 Q_UNUSED(modifiers);
2256 d->executePostedLayout();
2258 QModelIndex current = currentIndex();
2259 if (!current.isValid()) {
2260 int i = d->below(-1);
2262 while (c < d->header->count() && d->header->isSectionHidden(d->header->logicalIndex(c)))
2264 if (i < d->viewItems.size() && c < d->header->count()) {
2265 return d->modelIndex(i, d->header->logicalIndex(c));
2267 return QModelIndex();
2270 const int vi = qMax(0, d->viewIndex(current));
2272 if (isRightToLeft()) {
2273 if (cursorAction == MoveRight)
2274 cursorAction = MoveLeft;
2275 else if (cursorAction == MoveLeft)
2276 cursorAction = MoveRight;
2278 switch (cursorAction) {
2281#ifdef QT_KEYPAD_NAVIGATION
2282 if (vi == d->viewItems.count()-1 && QApplicationPrivate::keypadNavigationEnabled())
2283 return d->model->index(0, current.column(), d->root);
2285 return d->modelIndex(d->below(vi), current.column());
2288#ifdef QT_KEYPAD_NAVIGATION
2289 if (vi == 0 && QApplicationPrivate::keypadNavigationEnabled())
2290 return d->modelIndex(d->viewItems.count() - 1, current.column());
2292 return d->modelIndex(d->above(vi), current.column());
2294 QScrollBar *sb = horizontalScrollBar();
2295 if (vi < d->viewItems.size() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) {
2296 d->collapse(vi,
true);
2297 d->moveCursorUpdatedView =
true;
2299 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren,
nullptr,
this);
2301 QModelIndex par = current.parent();
2302 if (par.isValid() && par != rootIndex())
2308 if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2309 int visualColumn = d->header->visualIndex(current.column()) - 1;
2310 while (visualColumn >= 0 && isColumnHidden(d->header->logicalIndex(visualColumn)))
2312 int newColumn = d->header->logicalIndex(visualColumn);
2313 QModelIndex next = current.sibling(current.row(), newColumn);
2318 int oldValue = sb->value();
2319 sb->setValue(sb->value() - sb->singleStep());
2320 if (oldValue != sb->value())
2321 d->moveCursorUpdatedView =
true;
2326 viewport()->update();
2330 if (vi < d->viewItems.size() && !d->viewItems.at(vi).expanded && d->itemsExpandable
2331 && d->hasVisibleChildren(d->viewItems.at(vi).index)) {
2332 d->expand(vi,
true);
2333 d->moveCursorUpdatedView =
true;
2335 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren,
nullptr,
this);
2337 QModelIndex idx = d->modelIndex(d->below(vi));
2338 if (idx.parent() == current)
2344 if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2345 int visualColumn = d->header->visualIndex(current.column()) + 1;
2346 while (visualColumn < d->model->columnCount(current.parent()) && isColumnHidden(d->header->logicalIndex(visualColumn)))
2348 const int newColumn = d->header->logicalIndex(visualColumn);
2349 const QModelIndex next = current.sibling(current.row(), newColumn);
2355 QScrollBar *sb = horizontalScrollBar();
2356 int oldValue = sb->value();
2357 sb->setValue(sb->value() + sb->singleStep());
2358 if (oldValue != sb->value())
2359 d->moveCursorUpdatedView =
true;
2363 viewport()->update();
2366 return d->modelIndex(d->pageUp(vi), current.column());
2368 return d->modelIndex(d->pageDown(vi), current.column());
2370 return d->modelIndex(d->itemForKeyHome(), current.column());
2372 return d->modelIndex(d->itemForKeyEnd(), current.column());
2383void QTreeView::setSelection(
const QRect &rect, QItemSelectionModel::SelectionFlags command)
2386 if (!selectionModel() || rect.isNull())
2389 d->executePostedLayout();
2390 QPoint tl(isRightToLeft() ? qMax(rect.left(), rect.right())
2391 : qMin(rect.left(), rect.right()), qMin(rect.top(), rect.bottom()));
2392 QPoint br(isRightToLeft() ? qMin(rect.left(), rect.right()) :
2393 qMax(rect.left(), rect.right()), qMax(rect.top(), rect.bottom()));
2394 QModelIndex topLeft = indexAt(tl);
2395 QModelIndex bottomRight = indexAt(br);
2396 if (!topLeft.isValid() && !bottomRight.isValid()) {
2397 if (command & QItemSelectionModel::Clear)
2398 selectionModel()->clear();
2401 if (!topLeft.isValid() && !d->viewItems.isEmpty())
2402 topLeft = d->viewItems.constFirst().index;
2403 if (!bottomRight.isValid() && !d->viewItems.isEmpty()) {
2404 const int column = d->header->logicalIndex(d->header->count() - 1);
2405 const QModelIndex index = d->viewItems.constLast().index;
2406 bottomRight = index.sibling(index.row(), column);
2409 if (!d->isIndexEnabled(topLeft) || !d->isIndexEnabled(bottomRight))
2412 d->select(topLeft, bottomRight, command);
2422QRegion QTreeView::visualRegionForSelection(
const QItemSelection &selection)
const
2424 Q_D(
const QTreeView);
2425 if (selection.isEmpty())
2428 QRegion selectionRegion;
2429 const QRect &viewportRect = d->viewport->rect();
2430 for (
const auto &range : selection) {
2431 if (!range.isValid())
2433 QModelIndex parent = range.parent();
2434 QModelIndex leftIndex = range.topLeft();
2435 int columnCount = d->model->columnCount(parent);
2436 while (leftIndex.isValid() && isIndexHidden(leftIndex)) {
2437 if (leftIndex.column() + 1 < columnCount)
2438 leftIndex = d->model->index(leftIndex.row(), leftIndex.column() + 1, parent);
2440 leftIndex = QModelIndex();
2442 if (!leftIndex.isValid())
2444 const QRect leftRect = d->visualRect(leftIndex, QTreeViewPrivate::SingleSection);
2445 int top = leftRect.top();
2446 QModelIndex rightIndex = range.bottomRight();
2447 while (rightIndex.isValid() && isIndexHidden(rightIndex)) {
2448 if (rightIndex.column() - 1 >= 0)
2449 rightIndex = d->model->index(rightIndex.row(), rightIndex.column() - 1, parent);
2451 rightIndex = QModelIndex();
2453 if (!rightIndex.isValid())
2455 const QRect rightRect = d->visualRect(rightIndex, QTreeViewPrivate::SingleSection);
2456 int bottom = rightRect.bottom();
2458 qSwap<
int>(top, bottom);
2459 int height = bottom - top + 1;
2460 if (d->header->sectionsMoved()) {
2461 for (
int c = range.left(); c <= range.right(); ++c) {
2462 const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height);
2463 if (viewportRect.intersects(rangeRect))
2464 selectionRegion += rangeRect;
2467 QRect combined = leftRect|rightRect;
2468 combined.setX(columnViewportPosition(isRightToLeft() ? range.right() : range.left()));
2469 if (viewportRect.intersects(combined))
2470 selectionRegion += combined;
2473 return selectionRegion;
2500void QTreeView::scrollContentsBy(
int dx,
int dy)
2504 d->delayedAutoScroll.stop();
2506 dx = isRightToLeft() ? -dx : dx;
2508 int oldOffset = d->header->offset();
2509 d->header->d_func()->setScrollOffset(horizontalScrollBar(), horizontalScrollMode());
2510 if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) {
2511 int newOffset = d->header->offset();
2512 dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset;
2516 const int itemHeight = d->defaultItemHeight <= 0 ? sizeHintForRow(0) : d->defaultItemHeight;
2517 if (d->viewItems.isEmpty() || itemHeight == 0)
2521 int viewCount = d->viewport->height() / itemHeight;
2522 int maxDeltaY = qMin(d->viewItems.size(), viewCount);
2524 if (qAbs(dy) > qAbs(maxDeltaY) && d->editorIndexHash.isEmpty()) {
2525 verticalScrollBar()->update();
2526 d->viewport->update();
2530 if (dy && verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
2531 int currentScrollbarValue = verticalScrollBar()->value();
2532 int previousScrollbarValue = currentScrollbarValue + dy;
2533 int currentViewIndex = currentScrollbarValue;
2534 int previousViewIndex = previousScrollbarValue;
2536 if (previousViewIndex < currentViewIndex) {
2537 for (
int i = previousViewIndex; i < currentViewIndex; ++i) {
2538 if (i < d->viewItems.size())
2539 dy -= d->itemHeight(i);
2541 }
else if (previousViewIndex > currentViewIndex) {
2542 for (
int i = previousViewIndex - 1; i >= currentViewIndex; --i) {
2543 if (i < d->viewItems.size())
2544 dy += d->itemHeight(i);
2549 d->scrollContentsBy(dx, dy);
2831void QTreeView::expandToDepth(
int depth)
2834 d->viewItems.clear();
2835 QSet<QPersistentModelIndex> old_expandedIndexes;
2836 old_expandedIndexes = d->expandedIndexes;
2837 d->expandedIndexes.clear();
2838 d->interruptDelayedItemsLayout();
2840 for (
int i = 0; i < d->viewItems.size(); ++i) {
2841 if (q20::cmp_less_equal(d->viewItems.at(i).level, depth)) {
2842 d->viewItems[i].expanded =
true;
2844 d->storeExpanded(d->viewItems.at(i).index);
2848 bool someSignalEnabled = isSignalConnected(QMetaMethod::fromSignal(&QTreeView::collapsed));
2849 someSignalEnabled |= isSignalConnected(QMetaMethod::fromSignal(&QTreeView::expanded));
2851 if (!signalsBlocked() && someSignalEnabled) {
2853 QSet<QPersistentModelIndex> collapsedIndexes = old_expandedIndexes - d->expandedIndexes;
2854 QSet<QPersistentModelIndex>::const_iterator i = collapsedIndexes.constBegin();
2855 for (; i != collapsedIndexes.constEnd(); ++i) {
2856 const QPersistentModelIndex &mi = (*i);
2857 if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
2861 QSet<QPersistentModelIndex> expandedIndexs = d->expandedIndexes - old_expandedIndexes;
2862 i = expandedIndexs.constBegin();
2863 for (; i != expandedIndexs.constEnd(); ++i) {
2864 const QPersistentModelIndex &mi = (*i);
2865 if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
2871 d->viewport->update();
2872 d->updateAccessibility();
2930int QTreeView::sizeHintForColumn(
int column)
const
2932 Q_D(
const QTreeView);
2933 d->executePostedLayout();
2934 if (d->viewItems.isEmpty())
2938 QStyleOptionViewItem option;
2939 initViewItemOption(&option);
2940 const QList<QTreeViewItem> viewItems = d->viewItems;
2942 const int maximumProcessRows = d->header->resizeContentsPrecision();
2945 int start = d->firstVisibleItem(&offset);
2946 int end = d->lastVisibleItem(start, offset);
2947 if (start < 0 || end < 0 || end == viewItems.size() - 1) {
2948 end = viewItems.size() - 1;
2949 if (maximumProcessRows < 0) {
2951 }
else if (maximumProcessRows == 0) {
2952 start = qMax(0, end - 1);
2953 int remainingHeight = viewport()->height();
2954 while (start > 0 && remainingHeight > 0) {
2955 remainingHeight -= d->itemHeight(start);
2959 start = qMax(0, end - maximumProcessRows);
2963 int rowsProcessed = 0;
2965 for (
int i = start; i <= end; ++i) {
2966 if (viewItems.at(i).spanning)
2968 QModelIndex index = viewItems.at(i).index;
2969 index = index.sibling(index.row(), column);
2970 w = d->widthHintForIndex(index, w, option, i);
2972 if (rowsProcessed == maximumProcessRows)
2977 int actualBottom = viewItems.size() - 1;
2979 if (maximumProcessRows == 0)
2982 while (rowsProcessed != maximumProcessRows && (start > 0 || end < actualBottom)) {
2985 if ((rowsProcessed % 2 && start > 0) || end == actualBottom) {
2988 if (viewItems.at(start).spanning)
2994 while (end < actualBottom) {
2996 if (viewItems.at(end).spanning)
3005 QModelIndex index = viewItems.at(idx).index;
3006 index = index.sibling(index.row(), column);
3007 w = d->widthHintForIndex(index, w, option, idx);
3018int QTreeView::indexRowSizeHint(
const QModelIndex &index)
const
3020 Q_D(
const QTreeView);
3021 if (!d->isIndexValid(index) || !d->itemDelegate)
3026 int indexRow = index.row();
3027 int count = d->header->count();
3028 bool emptyHeader = (count == 0);
3029 QModelIndex parent = index.parent();
3031 if (count && isVisible()) {
3033 start = d->header->visualIndexAt(0);
3036 count = d->model->columnCount(parent);
3039 if (isRightToLeft()) {
3040 start = (start == -1 ? count - 1 : start);
3043 start = (start == -1 ? 0 : start);
3051 QStyleOptionViewItem option;
3052 initViewItemOption(&option);
3058 option.rect.setWidth(-1);
3060 for (
int column = start; column <= end; ++column) {
3061 int logicalColumn = emptyHeader ? column : d->header->logicalIndex(column);
3062 if (d->header->isSectionHidden(logicalColumn))
3064 QModelIndex idx = d->model->index(indexRow, logicalColumn, parent);
3065 if (idx.isValid()) {
3066 QWidget *editor = d->editorForIndex(idx).widget.data();
3067 if (editor && d->persistent.contains(editor)) {
3068 height = qMax(height, editor->sizeHint().height());
3069 int min = editor->minimumSize().height();
3070 int max = editor->maximumSize().height();
3071 height = qBound(min, height, max);
3073 int hint = itemDelegateForIndex(idx)->sizeHint(option, idx).height();
3074 height = qMax(height, hint);
3414void QTreeViewPrivate::layout(
int i,
bool recursiveExpanding,
bool afterIsUninitialized)
3417 QModelIndex current;
3418 QModelIndex parent = (i < 0) ? (QModelIndex)root : modelIndex(i);
3420 if (i>=0 && !parent.isValid()) {
3427#if QT_CONFIG(accessibility)
3431 const auto resetModelIfNeeded = qScopeGuard([oldViewItemsSize = viewItems.size(),
this]{
3432 pendingAccessibilityUpdate |= oldViewItemsSize != viewItems.size();
3437 if (model->hasChildren(parent)) {
3438 if (model->canFetchMore(parent)) {
3440 model->fetchMore(parent);
3442 const int itemHeight = defaultItemHeight <= 0 ? q->sizeHintForRow(0) : defaultItemHeight;
3443 const int viewCount = itemHeight ? viewport->height() / itemHeight : 0;
3445 while ((count = model->rowCount(parent)) < viewCount &&
3446 count != lastCount && model->canFetchMore(parent)) {
3447 model->fetchMore(parent);
3451 count = model->rowCount(parent);
3455 bool expanding =
true;
3457 if (uniformRowHeights) {
3458 QModelIndex index = model->index(0, 0, parent);
3459 defaultItemHeight = q->indexRowSizeHint(index);
3461 viewItems.resize(count);
3462 afterIsUninitialized =
true;
3463 }
else if (q20::cmp_not_equal(viewItems[i].total, count)) {
3464 if (!afterIsUninitialized)
3465 insertViewItems(i + 1, count, QTreeViewItem());
3467 viewItems.resize(viewItems.size() + count);
3473 int level = (i >= 0 ? viewItems.at(i).level + 1 : 0);
3477 QTreeViewItem *item =
nullptr;
3478 for (
int j = first; j < first + count; ++j) {
3479 current = model->index(j - first, 0, parent);
3480 if (isRowHidden(current)) {
3482 last = j - hidden + children;
3484 last = j - hidden + children;
3486 item->hasMoreSiblings =
true;
3487 item = &viewItems[last];
3488 item->index = current;
3489 item->parentItem = i;
3490 item->level = level;
3492 item->spanning = q->isFirstColumnSpanned(current.row(), parent);
3493 item->expanded =
false;
3495 item->hasMoreSiblings =
false;
3496 if ((recursiveExpanding && !(current.flags() & Qt::ItemNeverHasChildren)) || isIndexExpanded(current)) {
3497 if (recursiveExpanding && storeExpanded(current) && !q->signalsBlocked())
3498 emit q->expanded(current);
3499 item->expanded =
true;
3500 layout(last, recursiveExpanding, afterIsUninitialized);
3501 item = &viewItems[last];
3502 children += item->total;
3503 item->hasChildren = item->total > 0;
3504 last = j - hidden + children;
3506 item->hasChildren = hasVisibleChildren(current);
3513 if (!afterIsUninitialized)
3514 removeViewItems(last + 1, hidden);
3516 viewItems.resize(viewItems.size() - hidden);
3523 viewItems[i].total += count - hidden;
3524 i = viewItems[i].parentItem;
3652int QTreeViewPrivate::itemAtCoordinate(
int coordinate)
const
3654 const int itemCount = viewItems.size();
3657 if (uniformRowHeights && defaultItemHeight <= 0)
3659 if (verticalScrollMode == QAbstractItemView::ScrollPerPixel) {
3660 if (uniformRowHeights) {
3661 const int viewItemIndex = (coordinate + vbar->value()) / defaultItemHeight;
3662 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3665 int viewItemCoordinate = 0;
3666 const int contentsCoordinate = coordinate + vbar->value();
3667 for (
int viewItemIndex = 0; viewItemIndex < viewItems.size(); ++viewItemIndex) {
3668 viewItemCoordinate += itemHeight(viewItemIndex);
3669 if (viewItemCoordinate > contentsCoordinate)
3670 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3673 int topViewItemIndex = vbar->value();
3674 if (uniformRowHeights) {
3676 coordinate -= defaultItemHeight - 1;
3677 const int viewItemIndex = topViewItemIndex + (coordinate / defaultItemHeight);
3678 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3680 if (coordinate >= 0) {
3682 int viewItemCoordinate = 0;
3683 for (
int viewItemIndex = topViewItemIndex; viewItemIndex < viewItems.size(); ++viewItemIndex) {
3684 viewItemCoordinate += itemHeight(viewItemIndex);
3685 if (viewItemCoordinate > coordinate)
3686 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3690 int viewItemCoordinate = 0;
3691 for (
int viewItemIndex = topViewItemIndex; viewItemIndex >= 0; --viewItemIndex) {
3692 if (viewItemCoordinate <= coordinate)
3693 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3694 viewItemCoordinate -= itemHeight(viewItemIndex);
3808void QTreeViewPrivate::updateScrollBars()
3811 QSize viewportSize = viewport->size();
3812 if (!viewportSize.isValid())
3813 viewportSize = QSize(0, 0);
3815 executePostedLayout();
3816 if (viewItems.isEmpty()) {
3820 int itemsInViewport = 0;
3821 if (uniformRowHeights) {
3822 if (defaultItemHeight <= 0)
3823 itemsInViewport = viewItems.size();
3825 itemsInViewport = viewportSize.height() / defaultItemHeight;
3827 const int itemsCount = viewItems.size();
3828 const int viewportHeight = viewportSize.height();
3829 for (
int height = 0, item = itemsCount - 1; item >= 0; --item) {
3830 height += itemHeight(item);
3831 if (height > viewportHeight)
3836 if (verticalScrollMode == QAbstractItemView::ScrollPerItem) {
3837 if (!viewItems.isEmpty())
3838 itemsInViewport = qMax(1, itemsInViewport);
3839 vbar->setRange(0, viewItems.size() - itemsInViewport);
3840 vbar->setPageStep(itemsInViewport);
3841 vbar->setSingleStep(1);
3843 int contentsHeight = 0;
3844 if (uniformRowHeights) {
3845 contentsHeight = defaultItemHeight * viewItems.size();
3847 for (
int i = 0; i < viewItems.size(); ++i)
3848 contentsHeight += itemHeight(i);
3850 vbar->setRange(0, contentsHeight - viewportSize.height());
3851 vbar->setPageStep(viewportSize.height());
3852 vbar->d_func()->itemviewChangeSingleStep(qMax(viewportSize.height() / (itemsInViewport + 1), 2));
3855 const int columnCount = header->count();
3856 const int viewportWidth = viewportSize.width();
3857 int columnsInViewport = 0;
3858 for (
int width = 0, column = columnCount - 1; column >= 0; --column) {
3859 int logical = header->logicalIndex(column);
3860 width += header->sectionSize(logical);
3861 if (width > viewportWidth)
3863 ++columnsInViewport;
3865 if (columnCount > 0)
3866 columnsInViewport = qMax(1, columnsInViewport);
3867 if (horizontalScrollMode == QAbstractItemView::ScrollPerItem) {
3868 hbar->setRange(0, columnCount - columnsInViewport);
3869 hbar->setPageStep(columnsInViewport);
3870 hbar->setSingleStep(1);
3872 const int horizontalLength = header->length();
3873 const QSize maxSize = q->maximumViewportSize();
3874 if (maxSize.width() >= horizontalLength && vbar->maximum() <= 0)
3875 viewportSize = maxSize;
3876 hbar->setPageStep(viewportSize.width());
3877 hbar->setRange(0, qMax(horizontalLength - viewportSize.width(), 0));
3878 hbar->d_func()->itemviewChangeSingleStep(qMax(viewportSize.width() / (columnsInViewport + 1), 2));
3978void QTreeViewPrivate::select(
const QModelIndex &topIndex,
const QModelIndex &bottomIndex,
3979 QItemSelectionModel::SelectionFlags command)
3982 QItemSelection selection;
3983 const int top = viewIndex(topIndex),
3984 bottom = viewIndex(bottomIndex);
3986 const QList<std::pair<
int,
int>> colRanges = columnRanges(topIndex, bottomIndex);
3987 QList<std::pair<
int,
int>>::const_iterator it;
3988 for (it = colRanges.begin(); it != colRanges.end(); ++it) {
3989 const int left = (*it).first,
3990 right = (*it).second;
3992 QModelIndex previous;
3993 QItemSelectionRange currentRange;
3994 QStack<QItemSelectionRange> rangeStack;
3995 for (
int i = top; i <= bottom; ++i) {
3996 QModelIndex index = modelIndex(i);
3997 QModelIndex parent = index.parent();
3998 QModelIndex previousParent = previous.parent();
3999 if (previous.isValid() && parent == previousParent) {
4001 if (qAbs(previous.row() - index.row()) > 1) {
4003 if (currentRange.isValid()) {
4004 selection.append(currentRange);
4007 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4009 QModelIndex tl = model->index(currentRange.top(), currentRange.left(),
4010 currentRange.parent());
4011 currentRange = QItemSelectionRange(tl, index.sibling(index.row(), right));
4013 }
else if (previous.isValid() && parent == model->index(previous.row(), 0, previousParent)) {
4015 rangeStack.push(currentRange);
4016 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4018 if (currentRange.isValid())
4019 selection.append(currentRange);
4020 if (rangeStack.isEmpty()) {
4021 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4023 currentRange = rangeStack.pop();
4024 index = currentRange.bottomRight();
4030 if (currentRange.isValid())
4031 selection.append(currentRange);
4032 for (
int i = 0; i < rangeStack.size(); ++i)
4033 selection.append(rangeStack.at(i));
4035 q->selectionModel()->select(selection, command);