From 91aeceb7132f4afae0996443a162a5783d8f17aa Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 14 Apr 2009 10:02:42 +0200 Subject: Fix crash in QTreeView Discovered in Kopete trunk BT: yes Reviewed-by: Thierry --- src/gui/itemviews/qtreeview.cpp | 1 + tests/auto/qtreeview/tst_qtreeview.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 0117db2..62c1277 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -2019,6 +2019,7 @@ int QTreeView::verticalOffset() const // If we are scrolling per item and have non-uniform row heights, // finding the vertical offset in pixels is going to be relatively slow. // ### find a faster way to do this + d->executePostedLayout(); int offset = 0; for (int i = 0; i < d->viewItems.count(); ++i) { if (i == verticalScrollBar()->value()) diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index e1d405d..dfccd9e 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -209,6 +209,8 @@ private slots: void indexRowSizeHint(); void addRowsWhileSectionsAreHidden(); + void filterProxyModelCrash(); + // task-specific tests: void task174627_moveLeftToRoot(); void task171902_expandWith1stColHidden(); @@ -2829,6 +2831,29 @@ void tst_QTreeView::indexRowSizeHint() QCOMPARE(view.indexRowSizeHint(index), w->sizeHint().height()); } +void tst_QTreeView::filterProxyModelCrash() +{ + QStandardItemModel model; + QList items; + for (int i = 0; i < 100; i++) + items << new QStandardItem(QString::fromLatin1("item %1").arg(i)); + model.appendColumn(items); + + QSortFilterProxyModel proxy; + proxy.setSourceModel(&model); + + QTreeView view; + view.setModel(&proxy); + view.show(); + QTest::qWait(30); + proxy.invalidate(); + view.verticalScrollBar()->setValue(15); + QTest::qWait(20); + + proxy.invalidate(); + view.repaint(); //used to crash +} + class task174627_TreeView : public QTreeView { Q_OBJECT @@ -3254,6 +3279,5 @@ void tst_QTreeView::task246536_scrollbarsNotWorking() QVERIFY(o.count > 0); } - QTEST_MAIN(tst_QTreeView) #include "tst_qtreeview.moc" -- cgit v0.12