43 #ifndef QT_NO_TREEVIEW 55 #ifndef QT_NO_ACCESSIBILITY 60 #include <private/qtreeview_p.h> 226 if (model ==
d->model)
235 if (
d->selectionModel) {
237 d->model,
SLOT(submit()));
242 d->viewItems.clear();
243 d->expandedIndexes.clear();
244 d->hiddenIndexes.clear();
245 d->header->setModel(model);
253 d->header,
SLOT(_q_layoutChanged()));
260 if (
d->sortingEnabled)
261 d->_q_sortIndicatorChanged(
header()->sortIndicatorSection(),
header()->sortIndicatorOrder());
270 d->header->setRootIndex(index);
281 if (
d->selectionModel) {
284 d->model,
SLOT(submit()));
287 d->header->setSelectionModel(selectionModel);
290 if (
d->selectionModel) {
293 d->model,
SLOT(submit()));
319 if (header ==
d->header || !header)
321 if (
d->header &&
d->header->parent() ==
this)
324 d->header->setParent(
this);
326 if (!
d->header->model()) {
327 d->header->setModel(
d->model);
328 if (
d->selectionModel)
329 d->header->setSelectionModel(
d->selectionModel);
363 return d->autoExpandDelay;
369 d->autoExpandDelay = delay;
395 if (i !=
d->indent) {
397 d->viewport->update();
418 return d->rootDecoration;
424 if (show !=
d->rootDecoration) {
425 d->rootDecoration =
show;
426 d->viewport->update();
449 return d->uniformRowHeights;
455 d->uniformRowHeights = uniform;
474 return d->itemsExpandable;
480 d->itemsExpandable = enable;
499 return d->expandsOnDoubleClick;
505 d->expandsOnDoubleClick = enable;
514 return d->header->sectionViewportPosition(column);
525 return d->header->sectionSize(column);
541 d->header->resizeSection(column, width);
551 return d->header->logicalIndexAt(x);
562 return d->header->isSectionHidden(column);
573 if (column < 0 || column >=
d->header->count())
575 d->header->setSectionHidden(column, hide);
594 return d->header->isHidden();
600 d->header->setHidden(hide);
614 return d->isRowHidden(
d->model->index(row, 0, parent));
632 d->hiddenIndexes.insert(index);
633 }
else if(
d->isPersistent(index)) {
634 d->hiddenIndexes.remove(index);
637 d->doDelayedItemsLayout();
654 if (
d->spanningIndexes.isEmpty() || !
d->model)
657 for (
int i = 0; i <
d->spanningIndexes.count(); ++i)
658 if (
d->spanningIndexes.at(i) ==
index)
686 if (!
d->spanningIndexes.contains(persistent))
687 d->spanningIndexes.append(persistent);
690 int i =
d->spanningIndexes.indexOf(persistent);
692 d->spanningIndexes.remove(i);
695 d->executePostedLayout();
696 int i =
d->viewIndex(index);
698 d->viewItems[i].spanning = span;
700 d->viewport->update();
711 if (
d->delayedPendingLayout)
717 bool sizeChanged =
false;
718 int topViewIndex =
d->viewIndex(topLeft);
719 if (topViewIndex == 0) {
721 sizeChanged =
d->defaultItemHeight != newDefaultItemHeight;
722 d->defaultItemHeight = newDefaultItemHeight;
725 if (topViewIndex != -1) {
726 if (topLeft.
row() == bottomRight.
row()) {
727 int oldHeight =
d->itemHeight(topViewIndex);
728 d->invalidateHeightCache(topViewIndex);
729 sizeChanged |= (oldHeight !=
d->itemHeight(topViewIndex));
730 if (topLeft.
column() == 0)
731 d->viewItems[topViewIndex].hasChildren =
d->hasVisibleChildren(topLeft);
733 int bottomViewIndex =
d->viewIndex(bottomRight);
734 for (
int i = topViewIndex; i <= bottomViewIndex; ++i) {
735 int oldHeight =
d->itemHeight(i);
736 d->invalidateHeightCache(i);
737 sizeChanged |= (oldHeight !=
d->itemHeight(i));
738 if (topLeft.
column() == 0)
739 d->viewItems[i].hasChildren =
d->hasVisibleChildren(
d->viewItems.at(i).index);
745 d->updateScrollBars();
746 d->viewport->update();
763 d->header->hideSection(column);
774 d->header->showSection(column);
790 if (!
d->isIndexValid(index))
792 if (
d->delayedPendingLayout) {
794 if (
d->storeExpanded(index))
799 int i =
d->viewIndex(index);
802 if (!
d->isAnimating()) {
804 d->viewport->update();
806 }
else if (
d->storeExpanded(index)) {
824 if (!
d->isIndexValid(index))
827 d->delayedAutoScroll.stop();
829 if (
d->delayedPendingLayout) {
831 if (
d->isPersistent(index) &&
d->expandedIndexes.remove(index))
835 int i =
d->viewIndex(index);
837 d->collapse(i,
true);
838 if (!
d->isAnimating()) {
843 if (
d->isPersistent(index) &&
d->expandedIndexes.remove(index))
862 return d->isIndexExpanded(index);
913 d->sortingEnabled = enable;
919 return d->sortingEnabled;
941 d->animationsEnabled = animate;
947 return d->animationsEnabled;
967 if (
d->allColumnsShowFocus == enable)
969 d->allColumnsShowFocus = enable;
970 d->viewport->update();
976 return d->allColumnsShowFocus;
998 if (
d->wrapItemText == on)
1000 d->wrapItemText = on;
1001 d->doDelayedItemsLayout();
1007 return d->wrapItemText;
1017 if (!
d->model->rowCount(
d->root) || !
d->model->columnCount(
d->root))
1024 start =
d->model->index(0, 0,
d->root);
1026 bool skipRow =
false;
1027 bool keyboardTimeWasValid =
d->keyboardInputTime.isValid();
1028 qint64 keyboardInputTimeElapsed =
d->keyboardInputTime.restart();
1029 if (search.
isEmpty() || !keyboardTimeWasValid
1031 d->keyboardInput = search;
1034 d->keyboardInput += search;
1038 bool sameKey =
false;
1039 if (
d->keyboardInput.length() > 1) {
1040 int c =
d->keyboardInput.count(
d->keyboardInput.at(
d->keyboardInput.length() - 1));
1041 sameKey = (c ==
d->keyboardInput.length());
1051 start =
d->model->index(0, start.
column(),
d->root);
1054 d->executePostedLayout();
1055 int startIndex =
d->viewIndex(start);
1056 if (startIndex <= -1)
1059 int previousLevel = -1;
1062 QString searchString = sameKey ?
QString(
d->keyboardInput.at(0)) :
d->keyboardInput;
1063 for (
int i = 0; i <
d->viewItems.count(); ++i) {
1064 if ((
int)
d->viewItems.at(i).level > previousLevel) {
1069 if (match.
count()) {
1070 int hitIndex =
d->viewIndex(match.
at(0));
1071 if (hitIndex >= 0 && hitIndex < startIndex)
1072 bestAbove = bestAbove == -1 ? hitIndex :
qMin(hitIndex, bestAbove);
1073 else if (hitIndex >= startIndex)
1074 bestBelow = bestBelow == -1 ? hitIndex :
qMin(hitIndex, bestBelow);
1077 previousLevel =
d->viewItems.at(i).level;
1082 index =
d->viewItems.at(bestBelow).index;
1083 else if (bestAbove > -1)
1084 index =
d->viewItems.at(bestAbove).index;
1087 QItemSelectionModel::SelectionFlags flags = (
d->selectionMode ==
SingleSelection 1088 ? QItemSelectionModel::SelectionFlags(
1090 |
d->selectionBehaviorFlags())
1091 : QItemSelectionModel::SelectionFlags(
1108 d->executePostedLayout();
1110 int vi =
d->viewIndex(index);
1114 bool spanning =
d->viewItems.at(vi).spanning;
1120 if (index.
column() == 0) {
1121 int i =
d->indentationForItem(vi);
1127 int y =
d->coordinateForItem(vi);
1128 int h =
d->itemHeight(vi);
1130 return QRect(x, y, w, h);
1145 if (!
d->isIndexValid(index))
1148 d->executePostedLayout();
1149 d->updateScrollBars();
1156 parent =
d->model->parent(parent);
1159 int item =
d->viewIndex(index);
1169 if (hint ==
EnsureVisible && item >= top && item < bottom) {
1174 const int currentItemHeight =
d->itemHeight(item);
1177 ? area.
height() / 2 + currentItemHeight - 1
1180 if (y > currentItemHeight) {
1182 y -=
d->itemHeight(item);
1194 d->coordinateForItem(item),
1196 d->itemHeight(item));
1201 d->viewport->update(
rect);
1222 int viewportWidth =
d->viewport->width();
1224 int horizontalPosition =
d->header->sectionPosition(index.
column());
1225 int cellWidth =
d->header->sectionSize(index.
column());
1230 if (horizontalPosition - horizontalOffset < 0 || cellWidth > viewportWidth)
1232 else if (horizontalPosition - horizontalOffset + cellWidth > viewportWidth)
1243 if (event->
timerId() ==
d->columnResizeTimerID) {
1246 d->columnResizeTimerID = 0;
1248 int viewportHeight =
d->viewport->height();
1249 int viewportWidth =
d->viewport->width();
1250 for (
int i =
d->columnsToUpdate.size() - 1; i >= 0; --i) {
1251 int column =
d->columnsToUpdate.at(i);
1256 rect |=
QRect(x, 0, viewportWidth - x, viewportHeight);
1259 d->columnsToUpdate.clear();
1260 }
else if (event->
timerId() ==
d->openTimer.timerId()) {
1263 &&
d->viewport->rect().contains(pos)) {
1267 d->openTimer.stop();
1276 #ifndef QT_NO_DRAGANDDROP 1280 if (
d->autoExpandDelay >= 0)
1281 d->openTimer.start(
d->autoExpandDelay,
this);
1292 switch (event->
type()) {
1297 int oldBranch =
d->hoverBranch;
1298 d->hoverBranch =
d->itemDecorationAt(he->
pos());
1300 if (
d->hover != newIndex ||
d->hoverBranch != oldBranch) {
1321 d->executePostedLayout();
1323 #ifndef QT_NO_ANIMATION 1324 if (
d->isAnimating()) {
1326 d->drawAnimatedOperation(&painter);
1328 #endif //QT_NO_ANIMATION 1331 #ifndef QT_NO_DRAGANDDROP 1332 d->paintDropIndicator(&painter);
1343 if (rowHeight <= 0) {
1348 while (y <= bottom) {
1370 int i = itemDecorationAt(pos);
1371 if ((i != -1) &&
itemsExpandable && hasVisibleChildren(viewItems.at(i).index)) {
1372 if (viewItems.at(i).expanded)
1376 if (!isAnimating()) {
1377 q->updateGeometries();
1402 if (spanningIndexes.isEmpty())
1406 if (idx.
column() > 0 && q->isFirstColumnSpanned(idx.
row(), idx.
parent()))
1415 const int row = viewIndex(current);
1425 const bool spanning = viewItems.
at(row).spanning;
1428 calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right);
1430 int columnIndex = 0;
1461 if (viewItems.
count() == 0 ||
d->header->count() == 0 || !
d->itemDelegate) {
1466 int firstVisibleItemOffset = 0;
1467 const int firstVisibleItem =
d->firstVisibleItem(&firstVisibleItemOffset);
1468 if (firstVisibleItem < 0) {
1473 const int viewportWidth =
d->viewport->width();
1476 d->hoverBranch =
d->itemDecorationAt(hoverPos);
1480 bool multipleRects = (rects.
size() > 1);
1481 for (
int a = 0;
a < rects.
size(); ++
a) {
1485 d->leftAndRight =
d->startAndEndColumns(area);
1487 int i = firstVisibleItem;
1488 int y = firstVisibleItemOffset;
1491 for (; i < viewItems.
count(); ++i) {
1492 const int itemHeight =
d->itemHeight(i);
1493 if (y + itemHeight > area.
top())
1499 for (; i < viewItems.
count() && y <= area.
bottom(); ++i) {
1500 const int itemHeight =
d->itemHeight(i);
1501 option.
rect.
setRect(0, y, viewportWidth, itemHeight);
1507 if (!multipleRects || !drawn.
contains(i)) {
1515 if (y <= area.
bottom()) {
1517 d->paintAlternatingRowColors(painter, &option, y, area.
bottom());
1538 int logicalIndexBeforeLeft = -1, logicalIndexAfterRight = -1;
1542 logicalIndexBeforeLeft = logicalIndex;
1551 logicalIndexAfterRight = logicalIndex;
1554 logicalIndices->
append(logicalIndex);
1559 for (
int currentLogicalSection = 0; currentLogicalSection < logicalIndices->
count(); ++currentLogicalSection) {
1560 const int headerSection = logicalIndices->
at(currentLogicalSection);
1562 int nextLogicalSection = currentLogicalSection + 1 >= logicalIndices->
count()
1563 ? logicalIndexAfterRight
1564 : logicalIndices->
at(currentLogicalSection + 1);
1565 int prevLogicalSection = currentLogicalSection - 1 < 0
1566 ? logicalIndexBeforeLeft
1567 : logicalIndices->
at(currentLogicalSection - 1);
1569 if (columnCount == 1 || (nextLogicalSection == 0 && prevLogicalSection == -1)
1570 || (headerSection == 0 && nextLogicalSection == -1) || spanning)
1572 else if (headerSection == 0 || (nextLogicalSection != 0 && prevLogicalSection == -1))
1574 else if (nextLogicalSection == 0 || nextLogicalSection == -1)
1578 (*itemPositions)[currentLogicalSection] =
pos;
1595 const QPoint offset =
d->scrollDelayOffset;
1596 const int y = option.
rect.
y() + offset.
y();
1603 const bool spanning =
d->spanning;
1604 const int left = (spanning ? header->
visualIndex(0) :
d->leftAndRight.first);
1606 const bool alternate =
d->alternatingColors;
1613 bool indexWidgetHasFocus =
false;
1614 if ((current.
row() == index.
row()) && !
d->editorIndexHash.isEmpty()) {
1615 const int r = index.
row();
1617 for (
int c = 0;
c < header->
count(); ++
c) {
1621 indexWidgetHasFocus =
true;
1628 const bool widgetHasFocus =
hasFocus();
1629 bool currentRowHasFocus =
false;
1630 if (allColumnsShowFocus && widgetHasFocus && current.
isValid()) {
1632 const int r = index.
row();
1633 for (
int c = 0;
c < left && !currentRowHasFocus; ++
c) {
1635 currentRowHasFocus = (idx == current);
1638 for (
int c = right;
c < header->
count() && !currentRowHasFocus; ++
c) {
1639 currentRowHasFocus = (
d->model->index(r,
c, parent) == current);
1653 && index.
row() == hover.
row();
1657 d->calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right);
1659 for (
int currentLogicalSection = 0; currentLogicalSection < logicalIndices.
count(); ++currentLogicalSection) {
1660 int headerSection = logicalIndices.
at(currentLogicalSection);
1674 modelIndex =
d->model->index(index.
row(), headerSection,
parent);
1682 if (indexWidgetHasFocus)
1685 if (
d->selectionModel->isSelected(modelIndex))
1687 if (widgetHasFocus && (current == modelIndex)) {
1688 if (allColumnsShowFocus)
1689 currentRowHasFocus =
true;
1693 if ((hoverRow || modelIndex == hover)
1713 if (
d->current & 1) {
1724 if (headerSection == 0) {
1725 const int i =
d->indentationForItem(
d->current);
1726 QRect branches(reverse ? position + width - i : position, y, i,
height);
1727 const bool setClipRect = branches.
width() >
width;
1733 opt.
rect = branches;
1742 opt.
state = oldState;
1752 opt.
state = oldState;
1755 d->delegateForIndex(modelIndex)->paint(painter, opt, modelIndex);
1758 if (currentRowHasFocus) {
1760 o.QStyleOption::operator=(option);
1793 const int indent =
d->indent;
1794 const int outer =
d->rootDecoration ? 0 : 1;
1795 const int item =
d->current;
1797 int level = viewItem.
level;
1814 if (
d->alternatingColors) {
1815 if (
d->current & 1) {
1826 && index.
parent() ==
d->hover.parent()
1827 && index.
row() ==
d->hover.row();
1829 if (
d->selectionModel->isSelected(index))
1832 if (level >= outer) {
1834 primitive.moveLeft(reverse ? primitive.left() : primitive.left() - indent);
1835 opt.
rect = primitive;
1845 if (hoverRow || item ==
d->hoverBranch)
1852 for (--level; level >= outer; --level) {
1853 primitive.moveLeft(reverse ? primitive.left() + indent : primitive.left() - indent);
1854 opt.
rect = primitive;
1855 opt.
state = extraFlags;
1856 bool moreSiblings =
false;
1857 if (
d->hiddenIndexes.isEmpty()) {
1858 moreSiblings = (
d->model->rowCount(ancestor) - 1 > current.
row());
1860 int successor = item + viewItem.
total + 1;
1861 while (successor < d->viewItems.size()
1862 &&
d->viewItems.at(successor).level >=
uint(level)) {
1864 if (successorItem.
level ==
uint(level)) {
1865 moreSiblings =
true;
1868 successor += successorItem.
total + 1;
1873 if (hoverRow || item ==
d->hoverBranch)
1879 ancestor = current.
parent();
1890 bool handled =
false;
1892 handled =
d->expandOrCollapseItemAtPos(event->
pos());
1893 if (!handled &&
d->itemDecorationAt(event->
pos()) == -1)
1903 if (
d->itemDecorationAt(event->
pos()) == -1) {
1909 d->expandOrCollapseItemAtPos(event->
pos());
1922 int i =
d->itemDecorationAt(event->
pos());
1924 i =
d->itemAtCoordinate(event->
y());
1931 if (
d->pressedIndex != persistent) {
1948 d->executePostedLayout();
1949 if (
d->itemsExpandable
1950 &&
d->expandsOnDoubleClick
1951 &&
d->hasVisibleChildren(persistent)) {
1952 if (!((i < d->viewItems.count()) && (
d->viewItems.at(i).index == firstColumnIndex))) {
1954 for (i = 0; i <
d->viewItems.count(); ++i) {
1955 if (
d->viewItems.at(i).index == firstColumnIndex)
1958 if (i ==
d->viewItems.count())
1961 if (
d->viewItems.at(i).expanded)
1962 d->collapse(i,
true);
1977 if (
d->itemDecorationAt(event->
pos()) == -1)
1989 if (
d->isIndexValid(current) &&
d->model &&
d->itemsExpandable) {
1990 switch (event->
key()) {
1993 parents.
push(current);
1996 for (
int row = 0; row <
d->model->rowCount(parent); ++row) {
1998 if (!
d->isIndexValid(child))
2000 parents.
push(child);
2024 d->executePostedLayout();
2031 if (
d->viewItems.at(visualIndex).spanning)
2034 int column =
d->columnAt(point.
x());
2035 if (column == idx.
column())
2048 if (!
d->isIndexValid(index))
2050 d->executePostedLayout();
2051 int i =
d->viewIndex(index);
2054 return d->viewItems.at(i).index;
2063 if (!
d->isIndexValid(index))
2065 d->executePostedLayout();
2066 int i =
d->viewIndex(index);
2067 if (++i >=
d->viewItems.count())
2069 return d->viewItems.at(i).index;
2083 if (
d->hasRemovedItems) {
2085 d->hasRemovedItems =
false;
2087 while (it !=
d->expandedIndexes.constEnd()) {
2089 it =
d->expandedIndexes.erase(it);
2093 it =
d->hiddenIndexes.begin();
2094 while (it !=
d->hiddenIndexes.constEnd()) {
2096 it =
d->hiddenIndexes.erase(it);
2101 d->viewItems.clear();
2103 if (
d->model->hasChildren(parent)) {
2107 d->header->doItemsLayout();
2116 d->expandedIndexes.clear();
2117 d->hiddenIndexes.clear();
2118 d->spanningIndexes.clear();
2119 d->viewItems.clear();
2134 return d->header->offset();
2146 if (
d->uniformRowHeights)
2151 d->executePostedLayout();
2153 for (
int i = 0; i <
d->viewItems.count(); ++i) {
2156 offset +=
d->itemHeight(i);
2173 d->executePostedLayout();
2177 int i =
d->below(-1);
2179 while (c < d->
header->
count() &&
d->header->isSectionHidden(c))
2181 if (i < d->viewItems.count() && c <
d->header->count()) {
2182 return d->modelIndex(i, c);
2187 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) 2190 &&
d->selectionModel
2191 &&
d->selectionModel->hasSelection()) {
2193 const bool moveUpDown = (cursorAction ==
MoveUp || cursorAction ==
MoveDown);
2198 if (!contiguousSelection && (moveUpDown || moveNextPrev)) {
2204 for (
int i = 0; i < selection.
count(); ++i) {
2208 index = useTopIndex ?
qMin(index, candidate) :
qMax(index, candidate);
2211 if (index >= 0 && index <
INT_MAX)
2217 vi =
qMax(0,
d->viewIndex(current));
2225 switch (cursorAction) {
2228 #ifdef QT_KEYPAD_NAVIGATION 2229 if (vi ==
d->viewItems.count()-1 && QApplication::keypadNavigationEnabled())
2230 return d->model->index(0, current.
column(),
d->root);
2232 return d->modelIndex(
d->below(vi), current.
column());
2235 #ifdef QT_KEYPAD_NAVIGATION 2236 if (vi == 0 && QApplication::keypadNavigationEnabled())
2237 return d->modelIndex(
d->viewItems.count() - 1, current.
column());
2239 return d->modelIndex(
d->above(vi), current.
column());
2242 if (vi < d->viewItems.count() &&
d->viewItems.at(vi).expanded &&
d->itemsExpandable && sb->
value() == sb->
minimum()) {
2243 d->collapse(vi,
true);
2244 d->moveCursorUpdatedView =
true;
2256 int visualColumn =
d->header->visualIndex(current.
column()) - 1;
2257 while (visualColumn >= 0 &&
isColumnHidden(
d->header->logicalIndex(visualColumn)))
2259 int newColumn =
d->header->logicalIndex(visualColumn);
2265 int oldValue = sb->
value();
2267 if (oldValue != sb->
value())
2268 d->moveCursorUpdatedView =
true;
2277 if (vi < d->viewItems.count() && !
d->viewItems.at(vi).expanded &&
d->itemsExpandable
2278 &&
d->hasVisibleChildren(
d->viewItems.at(vi).index)) {
2279 d->expand(vi,
true);
2280 d->moveCursorUpdatedView =
true;
2285 if (idx.
parent() == current)
2292 int visualColumn =
d->header->visualIndex(current.
column()) + 1;
2303 int oldValue = sb->
value();
2305 if (oldValue != sb->
value())
2306 d->moveCursorUpdatedView =
true;
2313 return d->modelIndex(
d->pageUp(vi), current.
column());
2315 return d->modelIndex(
d->pageDown(vi), current.
column());
2317 return d->model->index(0, current.
column(),
d->root);
2319 return d->modelIndex(
d->viewItems.count() - 1, current.
column());
2336 d->executePostedLayout();
2348 if (!topLeft.
isValid() && !
d->viewItems.isEmpty())
2349 topLeft =
d->viewItems.first().index;
2350 if (!bottomRight.
isValid() && !
d->viewItems.isEmpty()) {
2351 const int column =
d->header->logicalIndex(
d->header->count() - 1);
2353 bottomRight = index.
sibling(index.
row(), column);
2356 if (!
d->isIndexEnabled(topLeft) || !
d->isIndexEnabled(bottomRight))
2359 d->select(topLeft, bottomRight, command);
2376 const QRect &viewportRect =
d->viewport->rect();
2377 for (
int i = 0; i < selection.
count(); ++i) {
2383 int columnCount =
d->model->columnCount(parent);
2385 if (leftIndex.
column() + 1 < columnCount)
2386 leftIndex =
d->model->index(leftIndex.
row(), leftIndex.
column() + 1,
parent);
2393 int top = leftRect.
top();
2396 if (rightIndex.
column() - 1 >= 0)
2397 rightIndex =
d->model->index(rightIndex.
row(), rightIndex.
column() - 1,
parent);
2404 int bottom = rightRect.
bottom();
2406 qSwap<int>(top, bottom);
2407 int height = bottom - top + 1;
2408 if (
d->header->sectionsMoved()) {
2412 selectionRegion += rangeRect;
2415 QRect combined = leftRect|rightRect;
2418 selectionRegion += combined;
2421 return selectionRegion;
2433 for (
int i = 0; i < modelSelected.
count(); ++i) {
2440 viewSelected.
append(modelSelected.
at(i));
2442 return viewSelected;
2452 d->delayedAutoScroll.stop();
2457 int oldOffset =
d->header->offset();
2459 d->header->setOffsetToLastSection();
2462 int newOffset =
d->header->offset();
2463 dx =
isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset;
2469 const int itemHeight =
d->defaultItemHeight <= 0 ?
sizeHintForRow(0) :
d->defaultItemHeight;
2470 if (
d->viewItems.isEmpty() || itemHeight == 0)
2474 int viewCount =
d->viewport->height() / itemHeight;
2475 int maxDeltaY =
qMin(
d->viewItems.count(), viewCount);
2477 if (
qAbs(dy) >
qAbs(maxDeltaY) &&
d->editorIndexHash.isEmpty()) {
2479 d->viewport->update();
2485 int previousScrollbarValue = currentScrollbarValue + dy;
2486 int currentViewIndex = currentScrollbarValue;
2487 int previousViewIndex = previousScrollbarValue;
2490 if (previousViewIndex < currentViewIndex) {
2491 for (
int i = previousViewIndex; i < currentViewIndex; ++i) {
2492 if (i < d->viewItems.
count())
2493 dy -=
d->itemHeight(i);
2495 }
else if (previousViewIndex > currentViewIndex) {
2496 for (
int i = previousViewIndex - 1; i >= currentViewIndex; --i) {
2497 if (i < d->viewItems.
count())
2498 dy +=
d->itemHeight(i);
2503 d->scrollContentsBy(dx, dy);
2513 d->viewport->update();
2532 if (
d->delayedPendingLayout) {
2543 const int parentRowCount =
d->model->rowCount(parent);
2544 const int delta = end - start + 1;
2545 if (parent !=
d->root && !
d->isIndexExpanded(parent) && parentRowCount > delta) {
2550 const int parentItem =
d->viewIndex(parent);
2551 if (((parentItem != -1) &&
d->viewItems.at(parentItem).expanded)
2552 || (parent ==
d->root)) {
2553 d->doDelayedItemsLayout();
2554 }
else if (parentItem != -1 && (
d->model->rowCount(parent) == end - start + 1)) {
2556 d->viewItems[parentItem].hasChildren =
true;
2570 d->viewItems.clear();
2585 d->viewItems.clear();
2586 d->doDelayedItemsLayout();
2587 d->hasRemovedItems =
true;
2588 d->_q_rowsRemoved(parent, start, end);
2598 if (oldCount == 0 && newCount > 0) {
2600 d->doDelayedItemsLayout();
2616 d->executePostedLayout();
2617 if (column < 0 || column >=
d->header->count())
2620 int header =
d->header->isHidden() ? 0 :
d->header->sectionSizeHint(column);
2621 d->header->resizeSection(column,
qMax(contents, header));
2658 d->header->setSortIndicator(column, order);
2660 if (!
d->sortingEnabled)
2661 d->model->sort(column, order);
2673 d->executePostedLayout();
2677 d->select(
d->viewItems.first().index, lastItemIndex,
2698 d->viewItems.clear();
2699 d->interruptDelayedItemsLayout();
2700 d->layout(-1,
true);
2702 d->viewport->update();
2718 d->expandedIndexes.clear();
2734 d->viewItems.clear();
2735 d->expandedIndexes.clear();
2736 d->interruptDelayedItemsLayout();
2738 for (
int i = 0; i <
d->viewItems.count(); ++i) {
2739 if (
d->viewItems.at(i).level <= (
uint)depth) {
2740 d->viewItems[i].expanded =
true;
2742 d->storeExpanded(
d->viewItems.at(i).index);
2746 d->viewport->update();
2759 d->columnsToUpdate.append(column);
2760 if (
d->columnResizeTimerID == 0)
2771 if (
d->geometryRecursionBlock)
2773 d->geometryRecursionBlock =
true;
2774 QSize hint =
d->header->isHidden() ?
QSize(0, 0) :
d->header->sizeHint();
2776 QRect vg =
d->viewport->geometry();
2777 QRect geometryRect(vg.left(), vg.top() - hint.
height(), vg.width(), hint.
height());
2778 d->header->setGeometry(geometryRect);
2781 d->updateScrollBars();
2782 d->geometryRecursionBlock =
false;
2804 d->executePostedLayout();
2805 if (
d->viewItems.isEmpty())
2816 start =
qMax(0,
d->firstVisibleItem() - 100);
2817 end =
qMin(end, start + 900);
2820 for (
int i = start; i <
end; ++i) {
2825 QWidget *editor =
d->editorForIndex(index).widget.data();
2826 if (editor &&
d->persistent.contains(editor)) {
2832 int hint =
d->delegateForIndex(index)->sizeHint(option, index).width();
2833 w =
qMax(w, hint + (column == 0 ?
d->indentationForItem(i) : 0));
2846 if (!
d->isIndexValid(index) || !
d->itemDelegate)
2851 int indexRow = index.
row();
2852 int count =
d->header->count();
2853 bool emptyHeader = (count == 0);
2858 start =
d->header->visualIndexAt(0);
2861 count =
d->model->columnCount(parent);
2865 start = (start == -1 ? count - 1 : start);
2868 start = (start == -1 ? 0 : start);
2884 for (
int column = start; column <=
end; ++column) {
2885 int logicalColumn = emptyHeader ? column :
d->header->logicalIndex(column);
2886 if (
d->header->isSectionHidden(logicalColumn))
2888 QModelIndex idx =
d->model->index(indexRow, logicalColumn, parent);
2890 QWidget *editor =
d->editorForIndex(idx).widget.data();
2891 if (editor &&
d->persistent.contains(editor)) {
2895 height =
qBound(min, height, max);
2897 int hint =
d->delegateForIndex(idx)->sizeHint(option, idx).height();
2898 height =
qMax(height, hint);
2916 d->executePostedLayout();
2917 int i =
d->viewIndex(index);
2920 return d->itemHeight(i);
2945 updateStyledFrameWidths();
2955 q->setHeader(header);
2956 #ifndef QT_NO_ANIMATION 2958 #endif //QT_NO_ANIMATION 2965 if (item == -1 || viewItems.at(item).expanded)
2968 #ifndef QT_NO_ANIMATION 2969 if (emitSignal && animationsEnabled)
2971 #endif //QT_NO_ANIMATION 2974 stateBeforeAnimation =
state;
2977 storeExpanded(index);
2978 viewItems[item].expanded =
true;
2980 q->setState(stateBeforeAnimation);
2985 emit q->expanded(index);
2986 #ifndef QT_NO_ANIMATION 2987 if (animationsEnabled)
2988 beginAnimatedOperation();
2989 #endif //QT_NO_ANIMATION 2995 viewItems.insert(pos, count, viewItem);
2997 for (
int i = pos + count; i < viewItems.count(); i++)
2998 if (items[i].parentItem >= pos)
3000 #ifndef QT_NO_ACCESSIBILITY 3012 viewItems.remove(pos, count);
3014 for (
int i = pos; i < viewItems.count(); i++)
3015 if (items[i].parentItem >= pos)
3017 #ifndef QT_NO_ACCESSIBILITY 3028 bool QTreeViewPrivate::checkViewItems()
const 3030 for (
int i = 0; i < viewItems.count(); ++i) {
3046 if (item == -1 || expandedIndexes.isEmpty())
3050 delayedAutoScroll.stop();
3052 int total = viewItems.at(item).total;
3053 const QModelIndex &modelIndex = viewItems.at(item).index;
3054 if (!isPersistent(modelIndex))
3057 if (it == expandedIndexes.
end() || viewItems.at(item).expanded ==
false)
3060 #ifndef QT_NO_ANIMATION 3061 if (emitSignal && animationsEnabled)
3063 #endif //QT_NO_ANIMATION 3067 stateBeforeAnimation =
state;
3069 expandedIndexes.erase(it);
3070 viewItems[item].expanded =
false;
3072 while (index > -1) {
3073 viewItems[
index].total -= total;
3074 index = viewItems[
index].parentItem;
3076 removeViewItems(item + 1, total);
3077 q->setState(stateBeforeAnimation);
3080 emit q->collapsed(modelIndex);
3081 #ifndef QT_NO_ANIMATION 3082 if (animationsEnabled)
3083 beginAnimatedOperation();
3084 #endif //QT_NO_ANIMATION 3088 #ifndef QT_NO_ANIMATION 3091 animatedOperation.item = item;
3092 animatedOperation.viewport =
viewport;
3093 animatedOperation.setDirection(direction);
3095 int top = coordinateForItem(item) + itemHeight(item);
3099 const int limit = rect.
height() * 2;
3101 int c = item + viewItems.at(item).total + 1;
3102 for (
int i = item + 1; i < c && h < limit; ++i)
3105 animatedOperation.setEndValue(top + h);
3107 animatedOperation.setStartValue(top);
3108 animatedOperation.before = renderTreeToPixmapForAnimation(rect);
3116 rect.
setTop(animatedOperation.top());
3118 const int limit = rect.
height() * 2;
3120 int c = animatedOperation.item + viewItems.at(animatedOperation.item).total + 1;
3121 for (
int i = animatedOperation.item + 1; i < c && h < limit; ++i)
3124 animatedOperation.setEndValue(animatedOperation.top() + h);
3128 animatedOperation.after = renderTreeToPixmapForAnimation(rect);
3131 animatedOperation.start();
3137 const int start = animatedOperation.startValue().toInt(),
3138 end = animatedOperation.endValue().toInt(),
3139 current = animatedOperation.currentValue().toInt();
3141 const QPixmap top = collapsing ? animatedOperation.before : animatedOperation.after;
3143 const QPixmap bottom = collapsing ? animatedOperation.after : animatedOperation.before;
3157 q->drawTree(&painter,
QRegion(rect));
3165 option.
rect = q->visualRect(index);
3169 delegate->updateEditorGeometry(editor, option, index);
3188 q->setState(stateBeforeAnimation);
3189 q->updateGeometries();
3192 #endif //QT_NO_ANIMATION 3201 if (start <= 0 && 0 <= end)
3208 if (start <= 0 && 0 <= end)
3209 doDelayedItemsLayout();
3226 if (i>=0 && !parent.
isValid()) {
3240 bool expanding =
true;
3244 defaultItemHeight = q->indexRowSizeHint(index);
3246 viewItems.resize(count);
3247 afterIsUninitialized =
true;
3248 }
else if (viewItems[i].total != (
uint)count) {
3249 if (!afterIsUninitialized)
3252 viewItems.resize(viewItems.count() + count);
3258 int level = (i >= 0 ? viewItems.at(i).level + 1 : 0);
3263 for (
int j = first; j < first + count; ++j) {
3264 current =
model->
index(j - first, 0, parent);
3272 item = &viewItems[last];
3273 item->
index = current;
3275 item->
level = level;
3281 if (recursiveExpanding || isIndexExpanded(current)) {
3282 if (recursiveExpanding)
3283 expandedIndexes.insert(current);
3285 layout(last, recursiveExpanding, afterIsUninitialized);
3286 item = &viewItems[last];
3287 children += item->
total;
3298 if (!afterIsUninitialized)
3299 removeViewItems(last + 1, hidden);
3301 viewItems.resize(viewItems.size() - hidden);
3308 viewItems[i].total += count - hidden;
3309 i = viewItems[i].parentItem;
3316 while (isItemHiddenOrDisabled(index))
3318 return index == -1 ? 0 :
index;
3324 while (isItemHiddenOrDisabled(index))
3326 return index == -1 ? viewItems.count() - 1 :
index;
3331 if (item < 0 || item >= viewItems.count())
3333 int level = viewItems.at(item).level;
3336 return level * indent;
3342 return defaultItemHeight;
3343 if (viewItems.isEmpty())
3348 int height = viewItems.at(item).height;
3350 height = q_func()->indexRowSizeHint(index);
3351 viewItems[item].height =
height;
3353 return qMax(height, 0);
3368 return (item * defaultItemHeight) - vbar->value();
3371 for (
int i = 0; i < viewItems.count(); ++i) {
3373 return y - vbar->value();
3377 int topViewItemIndex = vbar->value();
3379 return defaultItemHeight * (item - topViewItemIndex);
3380 if (item >= topViewItemIndex) {
3383 int viewItemCoordinate = 0;
3384 int viewItemIndex = topViewItemIndex;
3385 while (viewItemIndex < viewItems.count()) {
3386 if (viewItemIndex == item)
3387 return viewItemCoordinate;
3388 viewItemCoordinate += itemHeight(viewItemIndex);
3393 return viewItemCoordinate;
3396 int viewItemCoordinate = 0;
3397 for (
int viewItemIndex = topViewItemIndex; viewItemIndex > 0; --viewItemIndex) {
3398 if (viewItemIndex == item)
3399 return viewItemCoordinate;
3400 viewItemCoordinate -= itemHeight(viewItemIndex - 1);
3402 return viewItemCoordinate;
3420 const int itemCount = viewItems.count();
3427 const int viewItemIndex = (coordinate + vbar->value()) / defaultItemHeight;
3428 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3431 int viewItemCoordinate = 0;
3432 const int contentsCoordinate = coordinate + vbar->value();
3433 for (
int viewItemIndex = 0; viewItemIndex < viewItems.count(); ++viewItemIndex) {
3434 viewItemCoordinate += itemHeight(viewItemIndex);
3435 if (viewItemCoordinate >= contentsCoordinate)
3436 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3439 int topViewItemIndex = vbar->value();
3442 coordinate -= defaultItemHeight - 1;
3443 const int viewItemIndex = topViewItemIndex + (coordinate / defaultItemHeight);
3444 return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex);
3446 if (coordinate >= 0) {
3448 int viewItemCoordinate = 0;
3449 for (
int viewItemIndex = topViewItemIndex; viewItemIndex < viewItems.count(); ++viewItemIndex) {
3450 viewItemCoordinate += itemHeight(viewItemIndex);
3451 if (viewItemCoordinate > coordinate)
3452 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3456 int viewItemCoordinate = 0;
3457 for (
int viewItemIndex = topViewItemIndex; viewItemIndex >= 0; --viewItemIndex) {
3458 if (viewItemCoordinate <= coordinate)
3459 return (viewItemIndex >= itemCount ? -1 : viewItemIndex);
3460 viewItemCoordinate -= itemHeight(viewItemIndex);
3469 if (!_index.
isValid() || viewItems.isEmpty())
3472 const int totalCount = viewItems.count();
3474 const int row = index.
row();
3478 int localCount =
qMin(lastViewedItem - 1, totalCount - lastViewedItem);
3479 for (
int i = 0; i < localCount; ++i) {
3480 const QModelIndex &idx1 = viewItems.at(lastViewedItem + i).index;
3482 lastViewedItem = lastViewedItem + i;
3483 return lastViewedItem;
3485 const QModelIndex &idx2 = viewItems.at(lastViewedItem - i - 1).index;
3487 lastViewedItem = lastViewedItem - i - 1;
3488 return lastViewedItem;
3492 for (
int j =
qMax(0, lastViewedItem + localCount); j < totalCount; ++j) {
3499 for (
int j =
qMin(totalCount, lastViewedItem - localCount) - 1; j >= 0; --j) {
3513 if (i < 0 || i >= viewItems.count())
3524 const int value = vbar->value();
3528 return (value < 0 || value >= viewItems.count()) ? -1 : value;
3532 if (!defaultItemHeight)
3536 *offset = -(value % defaultItemHeight);
3537 return value / defaultItemHeight;
3540 for (
int i = 0; i < viewItems.count(); ++i) {
3544 *offset = y - value - itemHeight(i);
3561 viewportSize =
QSize(0, 0);
3563 if (viewItems.isEmpty()) {
3567 int itemsInViewport = 0;
3569 if (defaultItemHeight <= 0)
3570 itemsInViewport = viewItems.count();
3572 itemsInViewport = viewportSize.
height() / defaultItemHeight;
3574 const int itemsCount = viewItems.count();
3575 const int viewportHeight = viewportSize.
height();
3576 for (
int height = 0, item = itemsCount - 1; item >= 0; --item) {
3577 height += itemHeight(item);
3578 if (
height > viewportHeight)
3584 if (!viewItems.isEmpty())
3585 itemsInViewport =
qMax(1, itemsInViewport);
3586 vbar->setRange(0, viewItems.count() - itemsInViewport);
3587 vbar->setPageStep(itemsInViewport);
3588 vbar->setSingleStep(1);
3590 int contentsHeight = 0;
3592 contentsHeight = defaultItemHeight * viewItems.count();
3594 for (
int i = 0; i < viewItems.count(); ++i)
3595 contentsHeight += itemHeight(i);
3597 vbar->setRange(0, contentsHeight - viewportSize.
height());
3598 vbar->setPageStep(viewportSize.
height());
3599 vbar->setSingleStep(
qMax(viewportSize.
height() / (itemsInViewport + 1), 2));
3603 const int viewportWidth = viewportSize.
width();
3604 int columnsInViewport = 0;
3605 for (
int width = 0, column = columnCount - 1; column >= 0; --column) {
3608 if (
width > viewportWidth)
3610 ++columnsInViewport;
3612 if (columnCount > 0)
3613 columnsInViewport =
qMax(1, columnsInViewport);
3615 hbar->setRange(0, columnCount - columnsInViewport);
3616 hbar->setPageStep(columnsInViewport);
3617 hbar->setSingleStep(1);
3620 const QSize maxSize = q->maximumViewportSize();
3621 if (maxSize.
width() >= horizontalLength && vbar->maximum() <= 0)
3622 viewportSize = maxSize;
3623 hbar->setPageStep(viewportSize.
width());
3624 hbar->setRange(0,
qMax(horizontalLength - viewportSize.
width(), 0));
3625 hbar->setSingleStep(
qMax(viewportSize.
width() / (columnsInViewport + 1), 2));
3631 executePostedLayout();
3637 int viewItemIndex = itemAtCoordinate(pos.
y());
3638 QRect returning = itemDecorationRect(modelIndex(viewItemIndex));
3639 if (!returning.contains(pos))
3642 return viewItemIndex;
3648 if (!rootDecoration && index.
parent() == root)
3651 int viewItemIndex = viewIndex(index);
3652 if (viewItemIndex < 0 || !hasVisibleChildren(viewItems.at(viewItemIndex).index))
3655 int itemIndentation = indentationForItem(viewItemIndex);
3660 if (q->isRightToLeft())
3661 rect =
QRect(position + size - itemIndentation, coordinateForItem(viewItemIndex),
3662 indent, itemHeight(viewItemIndex));
3664 rect =
QRect(position + itemIndentation - indent, coordinateForItem(viewItemIndex),
3665 indent, itemHeight(viewItemIndex));
3678 const int start =
qMin(topVisual, bottomVisual);
3679 const int end =
qMax(topVisual, bottomVisual);
3684 for (
int c = start;
c <=
end;
c++) {
3687 logicalIndexes << logical;
3697 for(
int i = 0; i < logicalIndexes.
count(); ++i) {
3698 const int logicalColumn = logicalIndexes.
at(i);
3699 if (current.
second + 1 != logicalColumn) {
3700 if (current.
first != -2) {
3712 if (current.
first != -2) {
3720 QItemSelectionModel::SelectionFlags command)
3724 const int top = viewIndex(topIndex),
3725 bottom = viewIndex(bottomIndex);
3729 for (it = colRanges.
begin(); it != colRanges.
end(); ++
it) {
3730 const int left = (*it).first,
3731 right = (*it).second;
3736 for (
int i = top; i <= bottom; ++i) {
3740 if (previous.
isValid() && parent == previousParent) {
3742 if (
qAbs(previous.
row() - index.
row()) > 1) {
3745 selection.
append(currentRange);
3756 rangeStack.
push(currentRange);
3760 selection.
append(currentRange);
3764 currentRange = rangeStack.
pop();
3772 selection.
append(currentRange);
3773 for (
int i = 0; i < rangeStack.
count(); ++i)
3774 selection.
append(rangeStack.
at(i));
3776 q->selectionModel()->select(selection, command);
3784 if (q->isRightToLeft()) {
3785 start = (start == -1 ?
header->
count() - 1 : start);
3786 end = (end == -1 ? 0 :
end);
3788 start = (start == -1 ? 0 : start);
3791 return qMakePair<int,int>(
qMin(start, end),
qMax(start, end));
3798 if (hiddenIndexes.isEmpty())
3800 if (q->isIndexHidden(parent))
3803 for (
int i = 0; i < rowCount; ++i) {
3804 if (!q->isRowHidden(i, parent))
3828 previousRect.
setX(0);
3834 currentRect.
setX(0);
3839 #ifndef QT_NO_ACCESSIBILITY 3861 #ifndef QT_NO_ACCESSIBILITY 3897 d->executePostedLayout();
3898 return d->viewIndex(index);
3903 #include "moc_qtreeview.cpp" 3905 #endif // QT_NO_TREEVIEW bool isHeaderHidden() const
SelectionMode
This enum indicates how the view responds to user selections:
bool isIndexHidden(const QModelIndex &index) const
Reimplemented Function
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
void mousePressEvent(QMouseEvent *event)
Reimplemented Function
static int keyboardInputInterval()
The QPainter class performs low-level painting on widgets and other paint devices.
void setHeaderHidden(bool hide)
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
int itemAtCoordinate(int coordinate) const
Returns the index of the view item at the given viewport coordinate.
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
This slot is called when rows are about to be removed.
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
Move the cursor in the way described by cursorAction, using the information provided by the button mo...
void keyboardSearch(const QString &search)
Reimplemented Function
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object's accessibility information.
The QAbstractItemDelegate class is used to display and edit data items from a model.
static QAbstractItemModel * staticEmptyModel()
The QKeyEvent class describes a key event.
QPair< int, int > startAndEndColumns(const QRect &rect) const
The QItemSelectionModel class keeps track of a view's selected items.
void mouseDoubleClickEvent(QMouseEvent *event)
Reimplemented Function
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
void setHeight(int h)
Sets the height of the rectangle to the given height.
int left() const
Returns the column index corresponding to the leftmost selected column in the selection range...
static bool ancestorOf(QObject *widget, QObject *other)
move to QObject :)
virtual void clear()
Clears the selection model.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
void dragMoveEvent(QDragMoveEvent *event)
Reimplemented Function
void setRowHidden(int row, const QModelIndex &parent, bool hide)
If hide is true the row with the given parent is hidden, otherwise the row is shown.
int width() const
Returns the width of the pixmap.
QPointer< QWidget > widget
void updateGeometries()
Reimplemented Function
virtual QStyleOptionViewItem viewOptions() const
Returns a QStyleOptionViewItem structure populated with the view's palette, font, state...
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
Sets the current selection model to the given selectionModel.
void select(const QModelIndex &start, const QModelIndex &stop, QItemSelectionModel::SelectionFlags command)
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
Reimplemented Function
ScrollMode horizontalScrollMode() const
QModelIndex bottomRight() const
Returns the index for the item located at the bottom-right corner of the selection range...
void rowsRemoved(const QModelIndex &parent, int first, int last)
Informs the view that the rows from the start row to the end row inclusive have been removed from the...
void prepareAnimatedOperation(int item, QVariantAnimation::Direction d)
QModelIndexList selectedIndexes() const
Reimplemented Function
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
void setUniformRowHeights(bool uniform)
void mouseMoveEvent(QMouseEvent *event)
This function is called with the given event when a mouse move event is sent to the widget...
QStyle::State state
the style flags that are used when drawing the control
#define it(className, varName)
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
Applies the selection command to the items in or touched by the rectangle, rect.
int count(const T &t) const
Returns the number of occurrences of value in the vector.
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const =0
This pure abstract function must be reimplemented if you want to provide custom rendering.
void showColumn(int column)
Shows the given column in the tree view.
bool isValid() const
Returns true if the selection range is valid; otherwise returns false.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
QPixmap renderTreeToPixmapForAnimation(const QRect &rect) const
virtual void _q_modelDestroyed()
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
bool isRowHidden(int row, const QModelIndex &parent) const
Returns true if the item in the given row of the parent is hidden; otherwise returns false...
QModelIndexList selectedIndexes() const
Returns a list of all selected model item indexes.
static C reverse(const C &l)
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
The QHoverEvent class contains parameters that describe a mouse event.
void adjustViewOptionsForIndex(QStyleOptionViewItemV4 *option, const QModelIndex ¤t) const
void scrollContentsBy(int dx, int dy)
Scrolls the contents of the tree view by (dx, dy).
int rowHeight(const QModelIndex &index) const
Returns the height of the row indicated by the given index.
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
void restore()
Restores the current painter state (pops a saved state off the stack).
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
QRect normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
The QItemSelectionRange class manages information about a range of selected items in a model...
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
void setHeader(QHeaderView *header)
Sets the header for the tree view, to the given header.
static bool match(const uchar *found, const char *target, uint len)
int left() const
Returns the x-coordinate of the rectangle's left edge.
void _q_columnsAboutToBeRemoved(const QModelIndex &, int, int)
This slot is called when columns are about to be removed.
void timerEvent(QTimerEvent *event)
This function is called with the given event when a timer event is sent to the widget.
int width() const
Returns the width of the rectangle.
virtual QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const
bool isFirstColumnSpanned(int row, const QModelIndex &parent) const
Returns true if the item in first column in the given row of the parent is spanning all the columns; ...
int columnViewportPosition(int column) const
Returns the horizontal position of the column in the viewport.
QModelIndex indexBelow(const QModelIndex &index) const
Returns the model index of the item below index.
QModelIndex modelIndex(int i, int column=0) const
The QStack class is a template class that provides a stack.
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
int sizeHintForColumn(int column) const
Returns the size hint for the column's width or -1 if there is no model.
QRect boundingRect() const
Returns the bounding rectangle of this region.
int right() const
Returns the column index corresponding to the rightmost selected column in the selection range...
QRegion visualRegionForSelection(const QItemSelection &selection) const
Returns the rectangle from the viewport of the items in the given selection.
QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const
Reimplemented Function
void setSelectionModel(QItemSelectionModel *selectionModel)
Reimplemented Function
bool expandsOnDoubleClick() const
void layout(int item, bool recusiveExpanding=false, bool afterIsUninitialized=false)
void resizeColumnToContents(int column)
Resizes the column given to the size of its contents.
void reset()
Reimplemented Function
void setModel(QAbstractItemModel *model)
Reimplemented Function
bool isExpanded(const QModelIndex &index) const
Returns true if the model item index is expanded; otherwise returns false.
int height() const
Returns the height of the rectangle.
int bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
The QString class provides a Unicode character string.
QAbstractItemDelegate * itemDelegate() const
Returns the item delegate used by this view and model.
virtual void doItemsLayout()
This function is intended to lay out the items in the view.
ViewItemPosition
This enum is used to represent the placement of the item on a row.
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
int pageDown(int item) const
bool isColumnHidden(int column) const
Returns true if the column is hidden; otherwise returns false.
Q_DECL_CONSTEXPR T qAbs(const T &t)
void drawAnimatedOperation(QPainter *painter) const
The QObject class is the base class of all Qt objects.
void selectAll()
Reimplemented Function
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
void setBrushOrigin(int x, int y)
Sets the brush's origin to point (x, y).
QModelIndex parent() const
Returns the parent model item index of the items in the selection range.
void keyPressEvent(QKeyEvent *event)
Reimplemented Function
void dragMoveEvent(QDragMoveEvent *event)
This function is called continuously with the given event during a drag and drop operation over the w...
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QWidget * indexWidget(const QModelIndex &index) const
Returns the widget for the item at the given index.
void save()
Saves the current painter state (pushes the state onto a stack).
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
void collapse(const QModelIndex &index)
Collapses the model item specified by the index.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
void resize(int size)
Sets the size of the vector to size.
void horizontalScrollbarAction(int action)
The QStyleOptionViewItemV2 class is used to describe the parameters necessary for drawing a frame in ...
int columnAt(int x) const
QColor backgroundColor
the background color on which the focus rectangle is being drawn
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Reimplemented Function
void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)
Scroll the contents of the tree view until the given model item index is visible. ...
virtual void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Sorts the model by column in the given order.
T pop()
Removes the top item from the stack and returns it.
QModelIndex topLeft() const
Returns the index for the item located at the top-left corner of the selection range.
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
void setCurrentColorGroup(ColorGroup cg)
Set the palette's current color group to cg.
void expanded(const QModelIndex &index)
This signal is emitted when the item specified by index is expanded.
int key() const
Returns the code of the key that was pressed or released.
void calcLogicalIndices(QVector< int > *logicalIndices, QVector< QStyleOptionViewItemV4::ViewItemPosition > *itemPositions, int left, int right) const
int itemHeight(int item) const
void setFirstColumnSpanned(int row, const QModelIndex &parent, bool span)
If span is true the item in the first column in the row with the given parent is set to span all colu...
void collapseAll()
Collapses all expanded items.
int width() const
Returns the width.
void append(const T &t)
Inserts value at the end of the list.
void setColumnHidden(int column, bool hide)
If hide is true the column is hidden, otherwise the column is shown.
virtual void _q_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
This slot is called when columns are about to be removed.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Direction
This enum describes the direction of the animation when in Running state.
void rowsInserted(const QModelIndex &parent, int start, int end)
Informs the view that the rows from the start row to the end row inclusive have been inserted into th...
ViewItemFeatures features
a bitwise OR of the features that describe this view item
int coordinateForItem(int item) const
Returns the viewport y coordinate for item.
QPoint brushOrigin() const
Returns the currently set brush origin.
ScrollMode verticalScrollMode() const
qint64 internalId() const
Returns a qint64 used by the model to associate the index with the internal data structure.
void setAllColumnsShowFocus(bool enable)
The QStyleOption class stores the parameters used by QStyle functions.
virtual bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Returns true if parent has any children; otherwise returns false.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QItemSelectionModel * selectionModel() const
Returns the current selection model.
The QTreeView class provides a default model/view implementation of a tree view.
void initFrom(const QWidget *w)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
int row() const
Returns the row this model index refers to.
int horizontalOffset() const
Returns the horizontal offset of the items in the treeview.
QSize size() const
Returns the size of the rectangle.
const T & at(int i) const
Returns the item at index position i in the list.
virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
This slot is called when a new item becomes the current item.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
void mouseReleaseEvent(QMouseEvent *event)
Reimplemented Function
int viewIndex(const QModelIndex &index) const
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
void append(const T &t)
Inserts value at the end of the vector.
The QStyleOptionFocusRect class is used to describe the parameters for drawing a focus rectangle with...
const QRegion & region() const
Returns the region that needs to be updated.
const char * styleHint(const QFontDef &request)
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
bool showDecorationSelected
whether the decoration should be highlighted on selected items
int visualIndex(const QModelIndex &index) const
void expandAll()
Expands all expandable items.
void setSortingEnabled(bool enable)
virtual void reset()
Reset the internal state of the view.
QModelIndex currentIndex() const
Returns the model index of the current item.
void setRootIsDecorated(bool show)
void keyPressEvent(QKeyEvent *event)
This function is called with the given event when a key event is sent to the widget.
The QRegion class specifies a clip region for a painter.
int verticalOffset() const
Returns the vertical offset of the items in the tree view.
T value(int i) const
Returns the value at index position i in the list.
int columnWidth(int column) const
Returns the width of the column.
virtual bool canFetchMore(const QModelIndex &parent) const
Returns true if there is more data available for parent; otherwise returns false. ...
void activated(const QModelIndex &index)
This signal is emitted when the item specified by index is activated by the user. ...
QRect itemDecorationRect(const QModelIndex &index) const
QAbstractItemView::SelectionBehavior selectionBehavior() const
void setRootIndex(const QModelIndex &index)
Reimplemented Function
void push(const T &t)
Adds element t to the top of the stack.
void setX(int x)
Sets the left edge of the rectangle to the given x coordinate.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
void expand(const QModelIndex &index)
Expands the model item specified by the index.
void qSort(RandomAccessIterator start, RandomAccessIterator end)
~QTreeView()
Destroys the tree view.
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
void qSwap(T &value1, T &value2)
const T & at(int i) const
Returns the item at index position i in the vector.
The QAbstractItemModel class provides the abstract interface for item model classes.
static bool isActive()
Returns true if an accessibility implementation has been requested during the runtime of the applicat...
The QMouseEvent class contains parameters that describe a mouse event.
void columnResized(int column, int oldSize, int newSize)
This function is called whenever {column}'s size is changed in the header.
ViewItemPosition viewItemPosition
Gives the position of this view item relative to other items.
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
QTreeView(QWidget *parent=0)
Constructs a tree view with a parent to represent a model's data.
virtual void fetchMore(const QModelIndex &parent)
Fetches any available data for the items with the parent specified by the parent index.
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
QPalette palette
the palette that should be used when painting the control
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This slot is called when the selection is changed.
int firstVisibleItem(int *offset=0) const
The QAbstractItemView class provides the basic functionality for item view classes.
int pageUp(int item) const
void _q_modelAboutToBeReset()
void columnCountChanged(int oldCount, int newCount)
Informs the tree view that the number of columns in the tree view has changed from oldCount to newCou...
int top() const
Returns the y-coordinate of the rectangle's top edge.
bool isSortingEnabled() const
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction...
void setAnimated(bool enable)
The QItemSelection class manages information about selected items in a model.
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
void setColumnWidth(int column, int width)
Sets the width of the given column to the width specified.
void expandToDepth(int depth)
Expands all expandable items to the given depth.
int right() const
Returns the x-coordinate of the rectangle's right edge.
bool rootIsDecorated() const
The QTimerEvent class contains parameters that describe a timer event.
The QPersistentModelIndex class is used to locate data in a data model.
int y() const
Returns the y-coordinate of the rectangle's top edge.
bool itemsExpandable() const
int y() const
Returns the y position of the mouse cursor, relative to the widget that received the event...
void expand(int item, bool emitSignal)
void setExpandsOnDoubleClick(bool enable)
void timerEvent(QTimerEvent *event)
Reimplemented Function
void _q_endAnimatedOperation()
QObject * parent() const
Returns a pointer to the parent object.
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given widt...
QRect visualRect(const QModelIndex &index) const
Returns the rectangle on the viewport occupied by the item at index.
The QPoint class defines a point in the plane using integer precision.
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
void setIndentation(int i)
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
QHeaderView * header() const
Returns the header for the tree view.
The QModelIndex class is used to locate data in a data model.
void setItemsExpandable(bool enable)
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
void columnMoved()
This slot is called whenever a column has been moved.
void setWidth(int w)
Sets the width of the rectangle to the given width.
bool hasVisibleChildren(const QModelIndex &parent) const
int height() const
Returns the height.
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
bool uniformRowHeights() const
void edit(const QModelIndex &index)
Starts editing the item corresponding to the given index if it is editable.
virtual void _q_columnsRemoved(const QModelIndex &parent, int start, int end)
This slot is called when columns have been removed.
void paintAlternatingRowColors(QPainter *painter, QStyleOptionViewItemV4 *option, int y, int bottom) const
void paintEvent(QPaintEvent *event)
Reimplemented Function
const QObjectList & children() const
Returns a list of child objects.
void doItemsLayout()
Lays out the items in the tree view.
void mouseMoveEvent(QMouseEvent *event)
Reimplemented Function
void collapse(int item, bool emitSignal)
State state() const
Returns the item view's state.
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
void setExpanded(const QModelIndex &index, bool expand)
Sets the item referred to by index to either collapse or expanded, depending on the value of expanded...
int y() const
Returns the y coordinate of this point.
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
Informs the view that the rows from the start row to the end row inclusive are about to removed from ...
void mouseReleaseEvent(QMouseEvent *event)
This function is called with the given event when a mouse button is released, after a mouse press eve...
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
This slot is called when rows are inserted.
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This slot is called when items are changed in the model.
The QPixmap class is an off-screen image representation that can be used as a paint device...
virtual void updateGeometries()
Updates the geometry of the child widgets of the view.
int indexRowSizeHint(const QModelIndex &index) const
Returns the size hint for the row indicated by index.
int top() const
Returns the row index corresponding to the uppermost selected row in the selection range...
void drawTree(QPainter *painter, const QRegion ®ion) const
Draws the part of the tree intersecting the given region using the specified painter.
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
int height() const
Returns the height of the pixmap.
void sortByColumn(int column, Qt::SortOrder order)
Sets the model up for sorting by the values in the given column and order.
int itemDecorationAt(const QPoint &pos) const
int columnAt(int x) const
Returns the column in the tree view whose header covers the x coordinate given.
void _q_sortIndicatorChanged(int column, Qt::SortOrder order)
The QSize class defines the size of a two-dimensional object using integer point precision.
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
void removeViewItems(int pos, int count)
CursorAction
This enum describes the different ways to navigate between items,.
int x() const
Returns the x coordinate of this point.
QModelIndexList indexes() const
Returns a list of model indexes that correspond to the selected items.
void doubleClicked(const QModelIndex &index)
This signal is emitted when a mouse button is double-clicked.
The QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
void hideColumn(int column)
Hides the column given.
bool allColumnsShowFocus() const
virtual void horizontalScrollbarAction(int action)
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
void setWordWrap(bool on)
QModelIndex indexAbove(const QModelIndex &index) const
Returns the model index of the item above index.
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
int indentationForItem(int item) const
void _q_columnsRemoved(const QModelIndex &, int, int)
This slot is called when columns have been removed.
The QPaintEvent class contains event parameters for paint events.
QModelIndex indexAt(const QPoint &p) const
Reimplemented Function
QModelIndex rootIndex() const
Returns the model index of the model's root item.
QAbstractItemModel * model() const
Returns the model that this view is presenting.
static const KeyPair *const end
virtual void drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const
Draws the row in the tree view that contains the model item index, using the painter given...
void insertViewItems(int pos, int count, const QTreeViewItem &viewItem)
void collapsed(const QModelIndex &index)
This signal is emitted when the item specified by index is collapsed.
bool event(QEvent *event)
Reimplemented Function
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
Reimplemented Function
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
int size() const
Returns the number of items in the vector.
void setState(State state)
Sets the item view's state to the given state.
void mousePressEvent(QMouseEvent *event)
This function is called with the given event when a mouse button is pressed while the cursor is insid...
bool expandOrCollapseItemAtPos(const QPoint &pos)
QRect rect
the area that should be used for various calculations and painting
virtual int sizeHintForRow(int row) const
Returns the height size hint for the specified row or -1 if there is no model.
bool viewportEvent(QEvent *event)
Reimplemented Function
virtual void updateEditorGeometries()
Updates the geometry of the open editor widgets in the view.
friend class const_iterator
bool viewportEvent(QEvent *event)
This function is used to handle tool tips, and What's This? mode, if the given event is a QEvent::Too...
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
QList< QPair< int, int > > columnRanges(const QModelIndex &topIndex, const QModelIndex &bottomIndex) const
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
int column() const
Returns the column this model index refers to.
static int area(const QSize &s)
void setAutoExpandDelay(int delay)
bool isValid() const
Returns true if this persistent model index is valid; otherwise returns false.
void beginAnimatedOperation()
void killTimer(int id)
Kills the timer with timer identifier, id.
QPoint topLeft() const
Returns the position of the rectangle's top-left corner.
Qt::LayoutDirection direction
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
int autoExpandDelay() const
virtual void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
Draws the branches in the tree view on the same row as the model item index, using the painter given...