From 77f055ab9474ec4d3311884c293af7ee4a2a7cb3 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 20 Oct 2009 15:52:38 +0200 Subject: Fixed QTreeView trying to animate when parent item has no child We now check that the item has children before animating. Reviewed-by: Alexis --- src/gui/itemviews/qtreeview.cpp | 6 +++--- tests/auto/qtreeview/tst_qtreeview.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 210534e..d597f5c 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -2908,15 +2908,15 @@ void QTreeViewPrivate::expand(int item, bool emitSignal) layout(item); q->setState(oldState); + if (model->canFetchMore(index)) + model->fetchMore(index); if (emitSignal) { emit q->expanded(index); #ifndef QT_NO_ANIMATION - if (animationsEnabled) + if (animationsEnabled && model->hasChildren(index)) beginAnimatedOperation(); #endif //QT_NO_ANIMATION } - if (model->canFetchMore(index)) - model->fetchMore(index); } void QTreeViewPrivate::collapse(int item, bool emitSignal) diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index 91b2cc5..da58725 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -172,6 +172,7 @@ private slots: void expandAndCollapse_data(); void expandAndCollapse(); void expandAndCollapseAll(); + void expandWithNoChildren(); void keyboardNavigation(); void headerSections(); void moveCursor_data(); @@ -1548,6 +1549,19 @@ void tst_QTreeView::expandAndCollapseAll() // QCOMPARE(collapsedSpy.count(), count); } +void tst_QTreeView::expandWithNoChildren() +{ + QTreeView tree; + QStandardItemModel model(1,1); + tree.setModel(&model); + tree.setAnimated(true); + tree.doItemsLayout(); + //this test should not output warnings + tree.expand(model.index(0,0)); +} + + + void tst_QTreeView::keyboardNavigation() { const int rows = 10; -- cgit v0.12