From 77670c3c0fdc3021356e212e94042a0b5a4f4f8c Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 24 Feb 2010 16:55:15 +0100 Subject: Expand indicator would not be displayed after removal of a collapsed item's child While setting the hasChildren property of QTreeViewItem, "collapsed" and "not visible" were being mistaken. Auto-test included. Reviewed-by: Olivier Task-number: QTBUG-7443 --- src/gui/itemviews/qtreeview.cpp | 13 +++++++++---- tests/auto/qtreeview/tst_qtreeview.cpp | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 706d2a8..37168eb 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -3770,10 +3770,15 @@ void QTreeViewPrivate::rowsRemoved(const QModelIndex &parent, if (previousSibiling != -1 && after && model->rowCount(parent) == start) viewItems[previousSibiling].hasMoreSiblings = false; - - updateChildCount(parentItem, -removedCount); - if (parentItem != -1 && viewItems.at(parentItem).total == 0) - viewItems[parentItem].hasChildren = false; //every children have been removed; + if (parentItem != -1) { + if (viewItems.at(parentItem).expanded) { + updateChildCount(parentItem, -removedCount); + if (viewItems.at(parentItem).total == 0) + viewItems[parentItem].hasChildren = false; //every children have been removed; + } else if (viewItems[parentItem].hasChildren && !hasVisibleChildren(parent)) { + viewItems[parentItem].hasChildren = false; + } + } if (after) { q->updateGeometries(); viewport->update(); diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index fd4815e..e39cf6c 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -3083,6 +3083,20 @@ void tst_QTreeView::styleOptionViewItem() QApplication::processEvents(); QTRY_VERIFY(delegate.count >= 3); QApplication::processEvents(); + + item00->setText("OnlyOne"); + item0->insertRow(2, new QStandardItem("OnlyOne Last")); + view.collapse(item0->index()); + item0->removeRow(0); + delegate.count = 0; + QTRY_VERIFY(delegate.count >= 2); + QApplication::processEvents(); + + item0->removeRow(1); + item0->setText("OnlyOne"); + delegate.count = 0; + QTRY_VERIFY(delegate.count >= 2); + QApplication::processEvents(); } } -- cgit v0.12