diff options
-rw-r--r-- | src/gui/itemviews/qtreeview.cpp | 17 | ||||
-rw-r--r-- | src/gui/itemviews/qtreeview_p.h | 3 | ||||
-rw-r--r-- | tests/auto/qtreeview/tst_qtreeview.cpp | 15 |
3 files changed, 21 insertions, 14 deletions
diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 49c8e34..e74ecfc 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -1423,7 +1423,8 @@ void QTreeView::drawTree(QPainter *painter, const QRegion ®ion) const const int itemHeight = d->itemHeight(i); option.rect.setRect(0, y, viewportWidth, itemHeight); option.state = state | (viewItems.at(i).expanded ? QStyle::State_Open : QStyle::State_None) - | (viewItems.at(i).hasChildren ? QStyle::State_Children : QStyle::State_None ); + | (viewItems.at(i).hasChildren ? QStyle::State_Children : QStyle::State_None) + | (viewItems.at(i).hasMoreSiblings ? QStyle::State_Sibling : QStyle::State_None); d->current = i; d->spanning = viewItems.at(i).spanning; if (!multipleRects || !drawn.contains(i)) { @@ -1749,12 +1750,7 @@ void QTreeView::drawBranches(QPainter *painter, const QRect &rect, const bool expanded = viewItem.expanded; const bool children = viewItem.hasChildren; - bool moreSiblings = false; - if (d->hiddenIndexes.isEmpty()) - moreSiblings = (d->model->rowCount(parent) - 1 > index.row()); - else - moreSiblings = ((d->viewItems.size() > item +1) - && (d->viewItems.at(item + 1).index.parent() == parent)); + bool moreSiblings = viewItem.hasMoreSiblings; opt.state = QStyle::State_Item | extraFlags | (moreSiblings ? QStyle::State_Sibling : QStyle::State_None) @@ -3126,7 +3122,7 @@ void QTreeViewPrivate::layout(int i) int hidden = 0; int last = 0; int children = 0; - + QTreeViewItem *item = 0; for (int j = first; j < first + count; ++j) { current = model->index(j - first, 0, parent); if (isRowHidden(current)) { @@ -3134,13 +3130,16 @@ void QTreeViewPrivate::layout(int i) last = j - hidden + children; } else { last = j - hidden + children; - QTreeViewItem *item = &viewItems[last]; + if (item) + item->hasMoreSiblings = true; + item = &viewItems[last]; item->index = current; item->level = level; item->height = 0; item->spanning = q->isFirstColumnSpanned(current.row(), parent); item->expanded = false; item->total = 0; + item->hasMoreSiblings = false; if (isIndexExpanded(current)) { item->expanded = true; layout(last); diff --git a/src/gui/itemviews/qtreeview_p.h b/src/gui/itemviews/qtreeview_p.h index f89c328..62676d8 100644 --- a/src/gui/itemviews/qtreeview_p.h +++ b/src/gui/itemviews/qtreeview_p.h @@ -67,7 +67,8 @@ struct QTreeViewItem uint expanded : 1; uint spanning : 1; uint hasChildren : 1; // if the item has visible children (even if collapsed) - uint total : 29; // total number of children visible + uint hasMoreSiblings : 1; + uint total : 28; // total number of children visible uint level : 16; // indentation int height : 16; // row height }; diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index 8d824cb..cbc999f 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -2913,6 +2913,7 @@ void tst_QTreeView::styleOptionViewItem() QCOMPARE(opt.checkState, Qt::Unchecked); QCOMPARE(!(opt.state & QStyle::State_Children) , !opt.text.contains("HasChildren")); + QCOMPARE(!!(opt.state & QStyle::State_Sibling) , !opt.text.contains("Last")); QVERIFY(!opt.text.contains("Assert")); @@ -2942,6 +2943,8 @@ void tst_QTreeView::styleOptionViewItem() checked->setCheckState(Qt::Checked); model.appendRow(QList<QStandardItem*>() << new QStandardItem("Beginning") << checkable << checked << new QStandardItem("End") ); + model.appendRow(QList<QStandardItem*>() + << new QStandardItem("Beginning Last") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") ); par1->appendRow(QList<QStandardItem*>() << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); @@ -2949,14 +2952,18 @@ void tst_QTreeView::styleOptionViewItem() par1->appendRow(QList<QStandardItem*>() << par2 << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") ); par2->appendRow(QList<QStandardItem*>() - << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); + << new QStandardItem("Beginning Last") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") ); - QStandardItem *par3 = new QStandardItem("Beginning"); + QStandardItem *par3 = new QStandardItem("Beginning Last"); par1->appendRow(QList<QStandardItem*>() - << par3 << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); + << par3 << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") ); par3->appendRow(QList<QStandardItem*>() - << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); + << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") ); view.setRowHidden(0, par3->index(), true); + par1->appendRow(QList<QStandardItem*>() + << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") ); + view.setRowHidden(3, par1->index(), true); + view.setFirstColumnSpanned(2, QModelIndex(), true); view.setAlternatingRowColors(true); |