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, 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);
1134void QTreeView::scrollTo(
const QModelIndex &index, ScrollHint hint)
1138 if (!d->isIndexValid(index))
1141 d->executePostedLayout();
1142 d->updateScrollBars();
1145 QModelIndex parent = index.parent();
1146 while (parent != d->root && parent.isValid() && state() == NoState && d->itemsExpandable) {
1147 if (!isExpanded(parent))
1149 parent = d->model->parent(parent);
1152 int item = d->viewIndex(index);
1156 QRect area = d->viewport->rect();
1159 if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
1160 int top = verticalScrollBar()->value();
1161 int bottom = top + verticalScrollBar()->pageStep();
1162 if (hint == EnsureVisible && item >= top && item < bottom) {
1164 }
else if (hint == PositionAtTop || (hint == EnsureVisible && item < top)) {
1165 verticalScrollBar()->setValue(item);
1167 const int currentItemHeight = d->itemHeight(item);
1168 int y = (hint == PositionAtCenter
1170 ? area.height() / 2 + currentItemHeight - 1
1173 if (y > currentItemHeight) {
1175 y -= d->itemHeight(item);
1183 verticalScrollBar()->setValue(item);
1186 QRect rect(columnViewportPosition(index.column()),
1187 d->coordinateForItem(item),
1188 columnWidth(index.column()),
1189 d->itemHeight(item));
1191 if (rect.isEmpty()) {
1193 }
else if (hint == EnsureVisible && area.contains(rect)) {
1194 d->viewport->update(rect);
1197 bool above = (hint == EnsureVisible
1198 && (rect.top() < area.top()
1199 || area.height() < rect.height()));
1200 bool below = (hint == EnsureVisible
1201 && rect.bottom() > area.bottom()
1202 && rect.height() < area.height());
1204 int verticalValue = verticalScrollBar()->value();
1205 if (hint == PositionAtTop || above)
1206 verticalValue += rect.top();
1207 else if (hint == PositionAtBottom || below)
1208 verticalValue += rect.bottom() - area.height();
1209 else if (hint == PositionAtCenter)
1210 verticalValue += rect.top() - ((area.height() - rect.height()) / 2);
1211 verticalScrollBar()->setValue(verticalValue);
1215 int viewportWidth = d->viewport->width();
1216 int horizontalOffset = d->header->offset();
1217 int horizontalPosition = d->header->sectionPosition(index.column());
1218 int cellWidth = d->header->sectionSize(index.column());
1220 if (hint == PositionAtCenter) {
1221 horizontalScrollBar()->setValue(horizontalPosition - ((viewportWidth - cellWidth) / 2));
1223 if (horizontalPosition - horizontalOffset < 0 || cellWidth > viewportWidth)
1224 horizontalScrollBar()->setValue(horizontalPosition);
1225 else if (horizontalPosition - horizontalOffset + cellWidth > viewportWidth)
1226 horizontalScrollBar()->setValue(horizontalPosition - viewportWidth + cellWidth);
1402QRect QTreeViewPrivate::intersectedRect(
const QRect rect,
const QModelIndex &topLeft,
const QModelIndex &bottomRight)
const
1404 const auto parentIdx = topLeft.parent();
1405 executePostedLayout();
1407 int left = std::numeric_limits<
int>::max();
1408 int right = std::numeric_limits<
int>::min();
1409 for (
int row = topLeft.row(); row <= bottomRight.row(); ++row) {
1410 const auto idxCol0 = model->index(row, 0, parentIdx);
1411 if (isRowHidden(idxCol0))
1414 if (left != std::numeric_limits<
int>::max()) {
1416 rowRect = visualRect(idxCol0, FullRow);
1417 if (!rowRect.intersects(rect))
1419 rowRect = QRect(left, rowRect.top(), right, rowRect.bottom());
1420 }
else if (!spanningIndexes.isEmpty() && spanningIndexes.contains(idxCol0)) {
1423 rowRect = visualRect(idxCol0, FullRow);
1424 if (!rowRect.intersects(rect))
1427 for (
int col = topLeft.column(); col <= bottomRight.column(); ++col) {
1428 if (header->isSectionHidden(col))
1430 const QModelIndex idx(model->index(row, col, parentIdx));
1431 const QRect idxRect = visualRect(idx, SingleSection);
1432 if (idxRect.isNull())
1435 if (idxRect.top() > rect.bottom() || idxRect.bottom() < rect.top())
1437 if (!idxRect.intersects(rect))
1439 rowRect = rowRect.united(idxRect);
1440 if (rowRect.left() < rect.left() && rowRect.right() > rect.right())
1443 if (rowRect.isValid()) {
1444 left = std::min(left, rowRect.left());
1445 right = std::max(right, rowRect.right());
1448 updateRect = updateRect.united(rowRect);
1449 if (updateRect.contains(rect))
1452 return rect.intersected(updateRect);
1506void QTreeView::drawTree(QPainter *painter,
const QRegion ®ion)
const
1508 Q_D(
const QTreeView);
1510 const QList<QTreeViewItem> &viewItems = d->viewItems;
1512 QStyleOptionViewItem option;
1513 initViewItemOption(&option);
1514 const QStyle::State state = option.state;
1517 if (viewItems.size() == 0 || d->header->count() == 0 || !d->itemDelegate) {
1518 d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1);
1522 int firstVisibleItemOffset = 0;
1523 const int firstVisibleItem = d->firstVisibleItem(&firstVisibleItemOffset);
1524 if (firstVisibleItem < 0) {
1525 d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1);
1529 const int viewportWidth = d->viewport->width();
1531 QPoint hoverPos = d->viewport->mapFromGlobal(QCursor::pos());
1532 d->hoverBranch = d->itemDecorationAt(hoverPos);
1535 bool multipleRects = (region.rectCount() > 1);
1536 for (
const QRect &a : region) {
1537 const QRect area = (multipleRects
1538 ? QRect(0, a.y(), viewportWidth, a.height())
1540 d->leftAndRight = d->startAndEndColumns(area);
1542 int i = firstVisibleItem;
1543 int y = firstVisibleItemOffset;
1546 for (; i < viewItems.size(); ++i) {
1547 const int itemHeight = d->itemHeight(i);
1548 if (y + itemHeight > area.top())
1554 for (; i < viewItems.size() && y <= area.bottom(); ++i) {
1555 const QModelIndex &index = viewItems.at(i).index;
1556 const int itemHeight = d->itemHeight(i);
1557 option.rect = d->visualRect(index, QTreeViewPrivate::FullRow);
1558 option.state = state | (viewItems.at(i).expanded ? QStyle::State_Open : QStyle::State_None)
1559 | (viewItems.at(i).hasChildren ? QStyle::State_Children : QStyle::State_None)
1560 | (viewItems.at(i).hasMoreSiblings ? QStyle::State_Sibling : QStyle::State_None);
1562 d->spanning = viewItems.at(i).spanning;
1563 if (!multipleRects || !drawn.contains(i)) {
1564 drawRow(painter, option, viewItems.at(i).index);
1571 if (y <= area.bottom()) {
1573 d->paintAlternatingRowColors(painter, &option, y, area.bottom());
1588void QTreeViewPrivate::calcLogicalIndices(
1589 QList<
int> *logicalIndices, QList<QStyleOptionViewItem::ViewItemPosition> *itemPositions,
1590 int left,
int right)
const
1592 const int columnCount = header->count();
1594
1595
1596 int logicalIndexBeforeLeft = -1, logicalIndexAfterRight = -1;
1597 for (
int visualIndex = left - 1; visualIndex >= 0; --visualIndex) {
1598 int logicalIndex = header->logicalIndex(visualIndex);
1599 if (!header->isSectionHidden(logicalIndex)) {
1600 logicalIndexBeforeLeft = logicalIndex;
1605 for (
int visualIndex = left; visualIndex < columnCount; ++visualIndex) {
1606 int logicalIndex = header->logicalIndex(visualIndex);
1607 if (!header->isSectionHidden(logicalIndex)) {
1608 if (visualIndex > right) {
1609 logicalIndexAfterRight = logicalIndex;
1612 logicalIndices->append(logicalIndex);
1616 const auto indicesCount = logicalIndices->size();
1617 itemPositions->resize(indicesCount);
1618 for (qsizetype currentLogicalSection = 0; currentLogicalSection < indicesCount; ++currentLogicalSection) {
1620 if (indicesCount == 1 || spanning) {
1621 (*itemPositions)[currentLogicalSection] = QStyleOptionViewItem::OnlyOne;
1624 const int headerSection = logicalIndices->at(currentLogicalSection);
1626 int nextLogicalSection = currentLogicalSection + 1 >= indicesCount
1627 ? logicalIndexAfterRight
1628 : logicalIndices->at(currentLogicalSection + 1);
1629 int prevLogicalSection = currentLogicalSection - 1 < 0
1630 ? logicalIndexBeforeLeft
1631 : logicalIndices->at(currentLogicalSection - 1);
1632 QStyleOptionViewItem::ViewItemPosition pos;
1633 if ((nextLogicalSection != 0 && prevLogicalSection == -1) || isTreePosition(headerSection))
1634 pos = QStyleOptionViewItem::Beginning;
1635 else if (nextLogicalSection == 0 || nextLogicalSection == -1)
1636 pos = QStyleOptionViewItem::End;
1638 pos = QStyleOptionViewItem::Middle;
1639 (*itemPositions)[currentLogicalSection] = pos;
1669void QTreeView::drawRow(QPainter *painter,
const QStyleOptionViewItem &option,
1670 const QModelIndex &index)
const
1672 Q_D(
const QTreeView);
1673 QStyleOptionViewItem opt = option;
1674 const QPoint offset = d->scrollDelayOffset;
1675 const int y = option.rect.y() + offset.y();
1676 const QModelIndex parent = index.parent();
1677 const QHeaderView *header = d->header;
1678 const QModelIndex current = currentIndex();
1679 const QModelIndex hover = d->hover;
1680 const bool reverse = isRightToLeft();
1681 const QStyle::State state = opt.state;
1682 const bool spanning = d->spanning;
1683 const int left = (spanning ? header->visualIndex(0) : d->leftAndRight.first);
1684 const int right = (spanning ? header->visualIndex(0) : d->leftAndRight.second);
1685 const bool alternate = d->alternatingColors;
1686 const bool enabled = (state & QStyle::State_Enabled) != 0;
1687 const bool allColumnsShowFocus = d->allColumnsShowFocus;
1692 bool indexWidgetHasFocus =
false;
1693 if ((current.row() == index.row()) && !d->editorIndexHash.isEmpty()) {
1694 const int r = index.row();
1695 QWidget *fw = QApplication::focusWidget();
1696 for (
int c = 0; c < header->count(); ++c) {
1697 QModelIndex idx = d->model->index(r, c, parent);
1698 if (QWidget *editor = indexWidget(idx)) {
1699 if (ancestorOf(editor, fw)) {
1700 indexWidgetHasFocus =
true;
1707 const bool widgetHasFocus = hasFocus();
1708 bool currentRowHasFocus =
false;
1709 if (allColumnsShowFocus && widgetHasFocus && current.isValid()) {
1711 const int r = index.row();
1712 for (
int c = 0; c < left && !currentRowHasFocus; ++c) {
1713 QModelIndex idx = d->model->index(r, c, parent);
1714 currentRowHasFocus = (idx == current);
1716 QModelIndex parent = d->model->parent(index);
1717 for (
int c = right; c < header->count() && !currentRowHasFocus; ++c) {
1718 currentRowHasFocus = (d->model->index(r, c, parent) == current);
1727 opt.showDecorationSelected = (d->selectionBehavior & SelectRows)
1728 || option.showDecorationSelected;
1730 int width, height = option.rect.height();
1732 QModelIndex modelIndex;
1733 const bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows
1734 && index.parent() == hover.parent()
1735 && index.row() == hover.row();
1737 QList<
int> logicalIndices;
1738 QList<QStyleOptionViewItem::ViewItemPosition>
1740 d->calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right);
1742 for (
int currentLogicalSection = 0; currentLogicalSection < logicalIndices.size(); ++currentLogicalSection) {
1743 int headerSection = logicalIndices.at(currentLogicalSection);
1744 position = columnViewportPosition(headerSection) + offset.x();
1745 width = header->sectionSize(headerSection);
1748 int lastSection = header->logicalIndex(header->count() - 1);
1750 width = columnViewportPosition(lastSection) + header->sectionSize(lastSection) - position;
1752 width += position - columnViewportPosition(lastSection);
1753 position = columnViewportPosition(lastSection);
1757 modelIndex = d->model->index(index.row(), headerSection, parent);
1758 if (!modelIndex.isValid())
1762 opt.viewItemPosition = viewItemPosList.at(currentLogicalSection);
1765 if (indexWidgetHasFocus)
1766 opt.state |= QStyle::State_Active;
1768 if (d->selectionModel->isSelected(modelIndex))
1769 opt.state |= QStyle::State_Selected;
1770 if (widgetHasFocus && (current == modelIndex)) {
1771 if (allColumnsShowFocus)
1772 currentRowHasFocus =
true;
1774 opt.state |= QStyle::State_HasFocus;
1776 opt.state.setFlag(QStyle::State_MouseOver,
1777 (hoverRow || modelIndex == hover)
1778 && (option.showDecorationSelected || d->hoverBranch == -1));
1781 QPalette::ColorGroup cg;
1782 if ((d->model->flags(modelIndex) & Qt::ItemIsEnabled) == 0) {
1783 opt.state &= ~QStyle::State_Enabled;
1784 cg = QPalette::Disabled;
1785 }
else if (opt.state & QStyle::State_Active) {
1786 cg = QPalette::Active;
1788 cg = QPalette::Inactive;
1790 opt.palette.setCurrentColorGroup(cg);
1794 opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
1796 opt.features &= ~QStyleOptionViewItem::IsDecoratedRootColumn;
1799
1800
1801
1802 if (d->isTreePosition(headerSection)) {
1803 const int i = d->indentationForItem(d->current);
1804 QRect branches(reverse ? position + width - i : position, y, i, height);
1805 const bool setClipRect = branches.width() > width;
1808 painter->setClipRect(QRect(position, y, width, height));
1817 const bool oldShowDecorationSelected = opt.showDecorationSelected;
1818 opt.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected,
1820 opt.rect = branches;
1821 if (opt.rect.width() > 0) {
1823 opt.features |= QStyleOptionViewItem::IsDecoratedRootColumn;
1825 opt.features |= QStyleOptionViewItem::IsDecorationForRootColumn;
1826 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1827 opt.features &= ~QStyleOptionViewItem::IsDecorationForRootColumn;
1832 QStyle::State oldState = opt.state;
1833 opt.state &= ~QStyle::State_Selected;
1834 opt.rect.setRect(reverse ? position : i + position, y, width - i, height);
1835 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1836 opt.state = oldState;
1837 opt.showDecorationSelected = oldShowDecorationSelected;
1840 drawBranches(painter, branches, index);
1844 QStyle::State oldState = opt.state;
1845 opt.state &= ~QStyle::State_Selected;
1846 opt.rect.setRect(position, y, width, height);
1847 style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter,
this);
1848 opt.state = oldState;
1851 itemDelegateForIndex(modelIndex)->paint(painter, opt, modelIndex);
1854 if (currentRowHasFocus) {
1855 QStyleOptionFocusRect o;
1856 o.QStyleOption::operator=(option);
1857 o.state |= QStyle::State_KeyboardFocusChange;
1858 QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled)
1859 ? QPalette::Normal : QPalette::Disabled;
1860 o.backgroundColor = option.palette.color(cg, d->selectionModel->isSelected(index)
1861 ? QPalette::Highlight : QPalette::Window);
1863 if (!option.showDecorationSelected)
1864 x = header->sectionPosition(0) + d->indentationForItem(d->current);
1865 QRect focusRect(x - header->offset(), y, header->length() - x, height);
1866 o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), focusRect);
1867 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter);
1870 if (allColumnsShowFocus && !option.showDecorationSelected
1871 && header->sectionsMoved() && (header->visualIndex(0) != 0)) {
1872 QRect sectionRect(0, y, header->sectionPosition(0), height);
1873 o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), sectionRect);
1874 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter);
1884void QTreeView::drawBranches(QPainter *painter,
const QRect &rect,
1885 const QModelIndex &index)
const
1887 Q_D(
const QTreeView);
1888 const bool reverse = isRightToLeft();
1889 const int indent = d->indent;
1890 const int outer = d->rootDecoration ? 0 : 1;
1891 const int item = d->current;
1892 const QTreeViewItem &viewItem = d->viewItems.at(item);
1893 int level = viewItem.level;
1894 QRect primitive(reverse ? rect.left() : rect.right() + 1, rect.top(), indent, rect.height());
1896 QModelIndex parent = index.parent();
1897 QModelIndex current = parent;
1898 QModelIndex ancestor = current.parent();
1900 QStyleOptionViewItem opt;
1901 initViewItemOption(&opt);
1902 QStyle::State extraFlags = QStyle::State_None;
1904 extraFlags |= QStyle::State_Enabled;
1906 extraFlags |= QStyle::State_Active;
1907 QPainterStateGuard psg(painter, QPainterStateGuard::InitialState::NoSave);
1908 if (verticalScrollMode() == QAbstractItemView::ScrollPerPixel) {
1910 painter->setBrushOrigin(QPoint(0, verticalOffset()));
1913 if (d->alternatingColors) {
1914 opt.features.setFlag(QStyleOptionViewItem::Alternate, d->current & 1);
1919 bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows
1920 && opt.showDecorationSelected
1921 && index.parent() == d->hover.parent()
1922 && index.row() == d->hover.row();
1924 if (d->selectionModel->isSelected(index))
1925 extraFlags |= QStyle::State_Selected;
1927 if (level >= outer) {
1929 primitive.moveLeft(reverse ? primitive.left() : primitive.left() - indent);
1930 opt.rect = primitive;
1932 const bool expanded = viewItem.expanded;
1933 const bool children = viewItem.hasChildren;
1934 bool moreSiblings = viewItem.hasMoreSiblings;
1936 opt.state = QStyle::State_Item | extraFlags
1937 | (moreSiblings ? QStyle::State_Sibling : QStyle::State_None)
1938 | (children ? QStyle::State_Children : QStyle::State_None)
1939 | (expanded ? QStyle::State_Open : QStyle::State_None);
1940 opt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch);
1942 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter,
this);
1945 for (--level; level >= outer; --level) {
1946 primitive.moveLeft(reverse ? primitive.left() + indent : primitive.left() - indent);
1947 opt.rect = primitive;
1948 opt.state = extraFlags;
1949 bool moreSiblings =
false;
1950 if (d->hiddenIndexes.isEmpty()) {
1951 moreSiblings = (d->model->rowCount(ancestor) - 1 > current.row());
1953 int successor = item + viewItem.total + 1;
1954 while (successor < d->viewItems.size()
1955 && d->viewItems.at(successor).level >= uint(level)) {
1956 const QTreeViewItem &successorItem = d->viewItems.at(successor);
1957 if (successorItem.level == uint(level)) {
1958 moreSiblings =
true;
1961 successor += successorItem.total + 1;
1965 opt.state |= QStyle::State_Sibling;
1966 opt.state.setFlag(QStyle::State_MouseOver, hoverRow || item == d->hoverBranch);
1968 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter,
this);
1970 ancestor = current.parent();
2252QModelIndex QTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
2255 Q_UNUSED(modifiers);
2257 d->executePostedLayout();
2259 QModelIndex current = currentIndex();
2260 if (!current.isValid()) {
2261 int i = d->below(-1);
2263 while (c < d->header->count() && d->header->isSectionHidden(d->header->logicalIndex(c)))
2265 if (i < d->viewItems.size() && c < d->header->count()) {
2266 return d->modelIndex(i, d->header->logicalIndex(c));
2268 return QModelIndex();
2271 const int vi = qMax(0, d->viewIndex(current));
2273 if (isRightToLeft()) {
2274 if (cursorAction == MoveRight)
2275 cursorAction = MoveLeft;
2276 else if (cursorAction == MoveLeft)
2277 cursorAction = MoveRight;
2279 switch (cursorAction) {
2282#ifdef QT_KEYPAD_NAVIGATION
2283 if (vi == d->viewItems.count()-1 && QApplicationPrivate::keypadNavigationEnabled())
2284 return d->model->index(0, current.column(), d->root);
2286 return d->modelIndex(d->below(vi), current.column());
2289#ifdef QT_KEYPAD_NAVIGATION
2290 if (vi == 0 && QApplicationPrivate::keypadNavigationEnabled())
2291 return d->modelIndex(d->viewItems.count() - 1, current.column());
2293 return d->modelIndex(d->above(vi), current.column());
2295 QScrollBar *sb = horizontalScrollBar();
2296 if (vi < d->viewItems.size() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) {
2297 d->collapse(vi,
true);
2298 d->moveCursorUpdatedView =
true;
2300 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren,
nullptr,
this);
2302 QModelIndex par = current.parent();
2303 if (par.isValid() && par != rootIndex())
2309 if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2310 int visualColumn = d->header->visualIndex(current.column()) - 1;
2311 while (visualColumn >= 0 && isColumnHidden(d->header->logicalIndex(visualColumn)))
2313 int newColumn = d->header->logicalIndex(visualColumn);
2314 QModelIndex next = current.sibling(current.row(), newColumn);
2319 int oldValue = sb->value();
2320 sb->setValue(sb->value() - sb->singleStep());
2321 if (oldValue != sb->value())
2322 d->moveCursorUpdatedView =
true;
2327 viewport()->update();
2331 if (vi < d->viewItems.size() && !d->viewItems.at(vi).expanded && d->itemsExpandable
2332 && d->hasVisibleChildren(d->viewItems.at(vi).index)) {
2333 d->expand(vi,
true);
2334 d->moveCursorUpdatedView =
true;
2336 bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren,
nullptr,
this);
2338 QModelIndex idx = d->modelIndex(d->below(vi));
2339 if (idx.parent() == current)
2345 if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) {
2346 int visualColumn = d->header->visualIndex(current.column()) + 1;
2347 while (visualColumn < d->model->columnCount(current.parent()) && isColumnHidden(d->header->logicalIndex(visualColumn)))
2349 const int newColumn = d->header->logicalIndex(visualColumn);
2350 const QModelIndex next = current.sibling(current.row(), newColumn);
2356 QScrollBar *sb = horizontalScrollBar();
2357 int oldValue = sb->value();
2358 sb->setValue(sb->value() + sb->singleStep());
2359 if (oldValue != sb->value())
2360 d->moveCursorUpdatedView =
true;
2364 viewport()->update();
2367 return d->modelIndex(d->pageUp(vi), current.column());
2369 return d->modelIndex(d->pageDown(vi), current.column());
2371 return d->modelIndex(d->itemForKeyHome(), current.column());
2373 return d->modelIndex(d->itemForKeyEnd(), current.column());
2384void QTreeView::setSelection(
const QRect &rect, QItemSelectionModel::SelectionFlags command)
2387 if (!selectionModel() || rect.isNull())
2390 d->executePostedLayout();
2391 QPoint tl(isRightToLeft() ? qMax(rect.left(), rect.right())
2392 : qMin(rect.left(), rect.right()), qMin(rect.top(), rect.bottom()));
2393 QPoint br(isRightToLeft() ? qMin(rect.left(), rect.right()) :
2394 qMax(rect.left(), rect.right()), qMax(rect.top(), rect.bottom()));
2395 QModelIndex topLeft = indexAt(tl);
2396 QModelIndex bottomRight = indexAt(br);
2397 if (!topLeft.isValid() && !bottomRight.isValid()) {
2398 if (command & QItemSelectionModel::Clear)
2399 selectionModel()->clear();
2402 if (!topLeft.isValid() && !d->viewItems.isEmpty())
2403 topLeft = d->viewItems.constFirst().index;
2404 if (!bottomRight.isValid() && !d->viewItems.isEmpty()) {
2405 const int column = d->header->logicalIndex(d->header->count() - 1);
2406 const QModelIndex index = d->viewItems.constLast().index;
2407 bottomRight = index.sibling(index.row(), column);
2410 if (!d->isIndexEnabled(topLeft) || !d->isIndexEnabled(bottomRight))
2413 d->select(topLeft, bottomRight, command);
2423QRegion QTreeView::visualRegionForSelection(
const QItemSelection &selection)
const
2425 Q_D(
const QTreeView);
2426 if (selection.isEmpty())
2429 QRegion selectionRegion;
2430 const QRect &viewportRect = d->viewport->rect();
2431 for (
const auto &range : selection) {
2432 if (!range.isValid())
2434 QModelIndex parent = range.parent();
2435 QModelIndex leftIndex = range.topLeft();
2436 int columnCount = d->model->columnCount(parent);
2437 while (leftIndex.isValid() && isIndexHidden(leftIndex)) {
2438 if (leftIndex.column() + 1 < columnCount)
2439 leftIndex = d->model->index(leftIndex.row(), leftIndex.column() + 1, parent);
2441 leftIndex = QModelIndex();
2443 if (!leftIndex.isValid())
2445 const QRect leftRect = d->visualRect(leftIndex, QTreeViewPrivate::SingleSection);
2446 int top = leftRect.top();
2447 QModelIndex rightIndex = range.bottomRight();
2448 while (rightIndex.isValid() && isIndexHidden(rightIndex)) {
2449 if (rightIndex.column() - 1 >= 0)
2450 rightIndex = d->model->index(rightIndex.row(), rightIndex.column() - 1, parent);
2452 rightIndex = QModelIndex();
2454 if (!rightIndex.isValid())
2456 const QRect rightRect = d->visualRect(rightIndex, QTreeViewPrivate::SingleSection);
2457 int bottom = rightRect.bottom();
2459 qSwap<
int>(top, bottom);
2460 int height = bottom - top + 1;
2461 if (d->header->sectionsMoved()) {
2462 for (
int c = range.left(); c <= range.right(); ++c) {
2463 const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height);
2464 if (viewportRect.intersects(rangeRect))
2465 selectionRegion += rangeRect;
2468 QRect combined = leftRect|rightRect;
2469 combined.setX(columnViewportPosition(isRightToLeft() ? range.right() : range.left()));
2470 if (viewportRect.intersects(combined))
2471 selectionRegion += combined;
2474 return selectionRegion;
2501void QTreeView::scrollContentsBy(
int dx,
int dy)
2505 d->delayedAutoScroll.stop();
2507 dx = isRightToLeft() ? -dx : dx;
2509 int oldOffset = d->header->offset();
2510 d->header->d_func()->setScrollOffset(horizontalScrollBar(), horizontalScrollMode());
2511 if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) {
2512 int newOffset = d->header->offset();
2513 dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset;
2517 const int itemHeight = d->defaultItemHeight <= 0 ? sizeHintForRow(0) : d->defaultItemHeight;
2518 if (d->viewItems.isEmpty() || itemHeight == 0)
2522 int viewCount = d->viewport->height() / itemHeight;
2523 int maxDeltaY = qMin(d->viewItems.size(), viewCount);
2525 if (qAbs(dy) > qAbs(maxDeltaY) && d->editorIndexHash.isEmpty()) {
2526 verticalScrollBar()->update();
2527 d->viewport->update();
2531 if (dy && verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
2532 int currentScrollbarValue = verticalScrollBar()->value();
2533 int previousScrollbarValue = currentScrollbarValue + dy;
2534 int currentViewIndex = currentScrollbarValue;
2535 int previousViewIndex = previousScrollbarValue;
2537 if (previousViewIndex < currentViewIndex) {
2538 for (
int i = previousViewIndex; i < currentViewIndex; ++i) {
2539 if (i < d->viewItems.size())
2540 dy -= d->itemHeight(i);
2542 }
else if (previousViewIndex > currentViewIndex) {
2543 for (
int i = previousViewIndex - 1; i >= currentViewIndex; --i) {
2544 if (i < d->viewItems.size())
2545 dy += d->itemHeight(i);
2550 d->scrollContentsBy(dx, dy);
2832void QTreeView::expandToDepth(
int depth)
2835 d->viewItems.clear();
2836 QSet<QPersistentModelIndex> old_expandedIndexes;
2837 old_expandedIndexes = d->expandedIndexes;
2838 d->expandedIndexes.clear();
2839 d->interruptDelayedItemsLayout();
2841 for (
int i = 0; i < d->viewItems.size(); ++i) {
2842 if (q20::cmp_less_equal(d->viewItems.at(i).level, depth)) {
2843 d->viewItems[i].expanded =
true;
2845 d->storeExpanded(d->viewItems.at(i).index);
2849 bool someSignalEnabled = isSignalConnected(QMetaMethod::fromSignal(&QTreeView::collapsed));
2850 someSignalEnabled |= isSignalConnected(QMetaMethod::fromSignal(&QTreeView::expanded));
2852 if (!signalsBlocked() && someSignalEnabled) {
2854 QSet<QPersistentModelIndex> collapsedIndexes = old_expandedIndexes - d->expandedIndexes;
2855 QSet<QPersistentModelIndex>::const_iterator i = collapsedIndexes.constBegin();
2856 for (; i != collapsedIndexes.constEnd(); ++i) {
2857 const QPersistentModelIndex &mi = (*i);
2858 if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
2862 QSet<QPersistentModelIndex> expandedIndexs = d->expandedIndexes - old_expandedIndexes;
2863 i = expandedIndexs.constBegin();
2864 for (; i != expandedIndexs.constEnd(); ++i) {
2865 const QPersistentModelIndex &mi = (*i);
2866 if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren))
2872 d->viewport->update();
2873 d->updateAccessibility();
2931int QTreeView::sizeHintForColumn(
int column)
const
2933 Q_D(
const QTreeView);
2934 d->executePostedLayout();
2935 if (d->viewItems.isEmpty())
2939 QStyleOptionViewItem option;
2940 initViewItemOption(&option);
2941 const QList<QTreeViewItem> viewItems = d->viewItems;
2943 const int maximumProcessRows = d->header->resizeContentsPrecision();
2946 int start = d->firstVisibleItem(&offset);
2947 int end = d->lastVisibleItem(start, offset);
2948 if (start < 0 || end < 0 || end == viewItems.size() - 1) {
2949 end = viewItems.size() - 1;
2950 if (maximumProcessRows < 0) {
2952 }
else if (maximumProcessRows == 0) {
2953 start = qMax(0, end - 1);
2954 int remainingHeight = viewport()->height();
2955 while (start > 0 && remainingHeight > 0) {
2956 remainingHeight -= d->itemHeight(start);
2960 start = qMax(0, end - maximumProcessRows);
2964 int rowsProcessed = 0;
2966 for (
int i = start; i <= end; ++i) {
2967 if (viewItems.at(i).spanning)
2969 QModelIndex index = viewItems.at(i).index;
2970 index = index.sibling(index.row(), column);
2971 w = d->widthHintForIndex(index, w, option, i);
2973 if (rowsProcessed == maximumProcessRows)
2978 int actualBottom = viewItems.size() - 1;
2980 if (maximumProcessRows == 0)
2983 while (rowsProcessed != maximumProcessRows && (start > 0 || end < actualBottom)) {
2986 if ((rowsProcessed % 2 && start > 0) || end == actualBottom) {
2989 if (viewItems.at(start).spanning)
2995 while (end < actualBottom) {
2997 if (viewItems.at(end).spanning)
3006 QModelIndex index = viewItems.at(idx).index;
3007 index = index.sibling(index.row(), column);
3008 w = d->widthHintForIndex(index, w, option, idx);
3019int QTreeView::indexRowSizeHint(
const QModelIndex &index)
const
3021 Q_D(
const QTreeView);
3022 if (!d->isIndexValid(index) || !d->itemDelegate)
3027 int indexRow = index.row();
3028 int count = d->header->count();
3029 bool emptyHeader = (count == 0);
3030 QModelIndex parent = index.parent();
3032 if (count && isVisible()) {
3034 start = d->header->visualIndexAt(0);
3037 count = d->model->columnCount(parent);
3040 if (isRightToLeft()) {
3041 start = (start == -1 ? count - 1 : start);
3044 start = (start == -1 ? 0 : start);
3052 QStyleOptionViewItem option;
3053 initViewItemOption(&option);
3059 option.rect.setWidth(-1);
3061 for (
int column = start; column <= end; ++column) {
3062 int logicalColumn = emptyHeader ? column : d->header->logicalIndex(column);
3063 if (d->header->isSectionHidden(logicalColumn))
3065 QModelIndex idx = d->model->index(indexRow, logicalColumn, parent);
3066 if (idx.isValid()) {
3067 QWidget *editor = d->editorForIndex(idx).widget.data();
3068 if (editor && d->persistent.contains(editor)) {
3069 height = qMax(height, editor->sizeHint().height());
3070 int min = editor->minimumSize().height();
3071 int max = editor->maximumSize().height();
3072 height = qBound(min, height, max);
3074 int hint = itemDelegateForIndex(idx)->sizeHint(option, idx).height();
3075 height = qMax(height, hint);
3415void QTreeViewPrivate::layout(
int i,
bool recursiveExpanding,
bool afterIsUninitialized)
3418 QModelIndex current;
3419 QModelIndex parent = (i < 0) ? (QModelIndex)root : modelIndex(i);
3421 if (i>=0 && !parent.isValid()) {
3428#if QT_CONFIG(accessibility)
3432 const auto resetModelIfNeeded = qScopeGuard([oldViewItemsSize = viewItems.size(),
this]{
3433 pendingAccessibilityUpdate |= oldViewItemsSize != viewItems.size();
3438 if (model->hasChildren(parent)) {
3439 if (model->canFetchMore(parent)) {
3441 model->fetchMore(parent);
3443 const int itemHeight = defaultItemHeight <= 0 ? q->sizeHintForRow(0) : defaultItemHeight;
3444 const int viewCount = itemHeight ? viewport->height() / itemHeight : 0;
3446 while ((count = model->rowCount(parent)) < viewCount &&
3447 count != lastCount && model->canFetchMore(parent)) {
3448 model->fetchMore(parent);
3452 count = model->rowCount(parent);
3456 bool expanding =
true;
3458 if (uniformRowHeights) {
3459 QModelIndex index = model->index(0, 0, parent);
3460 defaultItemHeight = q->indexRowSizeHint(index);
3462 viewItems.resize(count);
3463 afterIsUninitialized =
true;
3464 }
else if (q20::cmp_not_equal(viewItems[i].total, count)) {
3465 if (!afterIsUninitialized)
3466 insertViewItems(i + 1, count, QTreeViewItem());
3468 viewItems.resize(viewItems.size() + count);
3474 int level = (i >= 0 ? viewItems.at(i).level + 1 : 0);
3478 QTreeViewItem *item =
nullptr;
3479 for (
int j = first; j < first + count; ++j) {
3480 current = model->index(j - first, 0, parent);
3481 if (isRowHidden(current)) {
3483 last = j - hidden + children;
3485 last = j - hidden + children;
3487 item->hasMoreSiblings =
true;
3488 item = &viewItems[last];
3489 item->index = current;
3490 item->parentItem = i;
3491 item->level = level;
3493 item->spanning = q->isFirstColumnSpanned(current.row(), parent);
3494 item->expanded =
false;
3496 item->hasMoreSiblings =
false;
3497 if ((recursiveExpanding && !(current.flags() & Qt::ItemNeverHasChildren)) || isIndexExpanded(current)) {
3498 if (recursiveExpanding && storeExpanded(current) && !q->signalsBlocked())
3499 emit q->expanded(current);
3500 item->expanded =
true;
3501 layout(last, recursiveExpanding, afterIsUninitialized);
3502 item = &viewItems[last];
3503 children += item->total;
3504 item->hasChildren = item->total > 0;
3505 last = j - hidden + children;
3507 item->hasChildren = hasVisibleChildren(current);
3514 if (!afterIsUninitialized)
3515 removeViewItems(last + 1, hidden);
3517 viewItems.resize(viewItems.size() - hidden);
3524 viewItems[i].total += count - hidden;
3525 i = viewItems[i].parentItem;
3653int QTreeViewPrivate::itemAtCoordinate(
int coordinate)
const
3655 const int itemCount = viewItems.size();
3658 if (uniformRowHeights && defaultItemHeight <= 0)
3660 if (verticalScrollMode == QAbstractItemView::ScrollPerPixel) {
3661 if (uniformRowHeights) {
3662 const int viewItemIndex = (coordinate + vbar->value()) / defaultItemHeight;
3663 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3666 int viewItemCoordinate = 0;
3667 const int contentsCoordinate = coordinate + vbar->value();
3668 for (
int viewItemIndex = 0; viewItemIndex < viewItems.size(); ++viewItemIndex) {
3669 viewItemCoordinate += itemHeight(viewItemIndex);
3670 if (viewItemCoordinate > contentsCoordinate)
3671 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3674 int topViewItemIndex = vbar->value();
3675 if (uniformRowHeights) {
3677 coordinate -= defaultItemHeight - 1;
3678 const int viewItemIndex = topViewItemIndex + (coordinate / defaultItemHeight);
3679 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3681 if (coordinate >= 0) {
3683 int viewItemCoordinate = 0;
3684 for (
int viewItemIndex = topViewItemIndex; viewItemIndex < viewItems.size(); ++viewItemIndex) {
3685 viewItemCoordinate += itemHeight(viewItemIndex);
3686 if (viewItemCoordinate > coordinate)
3687 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3691 int viewItemCoordinate = 0;
3692 for (
int viewItemIndex = topViewItemIndex; viewItemIndex >= 0; --viewItemIndex) {
3693 if (viewItemCoordinate <= coordinate)
3694 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3695 viewItemCoordinate -= itemHeight(viewItemIndex);
3809void QTreeViewPrivate::updateScrollBars()
3812 QSize viewportSize = viewport->size();
3813 if (!viewportSize.isValid())
3814 viewportSize = QSize(0, 0);
3816 executePostedLayout();
3817 if (viewItems.isEmpty()) {
3821 int itemsInViewport = 0;
3822 if (uniformRowHeights) {
3823 if (defaultItemHeight <= 0)
3824 itemsInViewport = viewItems.size();
3826 itemsInViewport = viewportSize.height() / defaultItemHeight;
3828 const int itemsCount = viewItems.size();
3829 const int viewportHeight = viewportSize.height();
3830 for (
int height = 0, item = itemsCount - 1; item >= 0; --item) {
3831 height += itemHeight(item);
3832 if (height > viewportHeight)
3837 if (verticalScrollMode == QAbstractItemView::ScrollPerItem) {
3838 if (!viewItems.isEmpty())
3839 itemsInViewport = qMax(1, itemsInViewport);
3840 vbar->setRange(0, viewItems.size() - itemsInViewport);
3841 vbar->setPageStep(itemsInViewport);
3842 vbar->setSingleStep(1);
3844 int contentsHeight = 0;
3845 if (uniformRowHeights) {
3846 contentsHeight = defaultItemHeight * viewItems.size();
3848 for (
int i = 0; i < viewItems.size(); ++i)
3849 contentsHeight += itemHeight(i);
3851 vbar->setRange(0, contentsHeight - viewportSize.height());
3852 vbar->setPageStep(viewportSize.height());
3853 vbar->d_func()->itemviewChangeSingleStep(qMax(viewportSize.height() / (itemsInViewport + 1), 2));
3856 const int columnCount = header->count();
3857 const int viewportWidth = viewportSize.width();
3858 int columnsInViewport = 0;
3859 for (
int width = 0, column = columnCount - 1; column >= 0; --column) {
3860 int logical = header->logicalIndex(column);
3861 width += header->sectionSize(logical);
3862 if (width > viewportWidth)
3864 ++columnsInViewport;
3866 if (columnCount > 0)
3867 columnsInViewport = qMax(1, columnsInViewport);
3868 if (horizontalScrollMode == QAbstractItemView::ScrollPerItem) {
3869 hbar->setRange(0, columnCount - columnsInViewport);
3870 hbar->setPageStep(columnsInViewport);
3871 hbar->setSingleStep(1);
3873 const int horizontalLength = header->length();
3874 const QSize maxSize = q->maximumViewportSize();
3875 if (maxSize.width() >= horizontalLength && vbar->maximum() <= 0)
3876 viewportSize = maxSize;
3877 hbar->setPageStep(viewportSize.width());
3878 hbar->setRange(0, qMax(horizontalLength - viewportSize.width(), 0));
3879 hbar->d_func()->itemviewChangeSingleStep(qMax(viewportSize.width() / (columnsInViewport + 1), 2));
3979void QTreeViewPrivate::select(
const QModelIndex &topIndex,
const QModelIndex &bottomIndex,
3980 QItemSelectionModel::SelectionFlags command)
3983 QItemSelection selection;
3984 const int top = viewIndex(topIndex),
3985 bottom = viewIndex(bottomIndex);
3987 const QList<std::pair<
int,
int>> colRanges = columnRanges(topIndex, bottomIndex);
3988 QList<std::pair<
int,
int>>::const_iterator it;
3989 for (it = colRanges.begin(); it != colRanges.end(); ++it) {
3990 const int left = (*it).first,
3991 right = (*it).second;
3993 QModelIndex previous;
3994 QItemSelectionRange currentRange;
3995 QStack<QItemSelectionRange> rangeStack;
3996 for (
int i = top; i <= bottom; ++i) {
3997 QModelIndex index = modelIndex(i);
3998 QModelIndex parent = index.parent();
3999 QModelIndex previousParent = previous.parent();
4000 if (previous.isValid() && parent == previousParent) {
4002 if (qAbs(previous.row() - index.row()) > 1) {
4004 if (currentRange.isValid()) {
4005 selection.append(currentRange);
4008 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4010 QModelIndex tl = model->index(currentRange.top(), currentRange.left(),
4011 currentRange.parent());
4012 currentRange = QItemSelectionRange(tl, index.sibling(index.row(), right));
4014 }
else if (previous.isValid() && parent == model->index(previous.row(), 0, previousParent)) {
4016 rangeStack.push(currentRange);
4017 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4019 if (currentRange.isValid())
4020 selection.append(currentRange);
4021 if (rangeStack.isEmpty()) {
4022 currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right));
4024 currentRange = rangeStack.pop();
4025 index = currentRange.bottomRight();
4031 if (currentRange.isValid())
4032 selection.append(currentRange);
4033 for (
int i = 0; i < rangeStack.size(); ++i)
4034 selection.append(rangeStack.at(i));
4036 q->selectionModel()->select(selection, command);