From f1e90768095be37419ba4bf3c69ec5c860bdbcb6 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Tue, 10 Mar 2015 23:05:22 +0100 Subject: Fix problems with extended selection after changing the model contents Storing the position of the first selected item in the view can lead to wrong extended selections if the contents of the model change. Future Shift-clicks will always use the previous position of the first selected item, which may not be correct any more, to calculate the current selection. To fix this problem, a QPersistentModelIndex is used to keep track of the first selected item. A new unit test is added. Moreover, one function of the QTableView unit test is changed such that it shows the view prior to performing the test. Without this change, this test may fail. That the test, which simulates mouse presses without showing the view, worked at all seems to be a coincidence, as pointed out in QTBUG-18009. Task-number: QTBUG-18009 Change-Id: I0d844fbd1a994c279a7c8ee5d9b5b9fccecd25bf Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp') diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index a11d423896..75f77f8107 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -4288,6 +4288,9 @@ void tst_QTableView::taskQTBUG_4516_clickOnRichTextLabel() QLabel label("rich text"); label.setTextFormat(Qt::RichText); view.setIndexWidget(model.index(1,1), &label); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + view.setCurrentIndex(model.index(0,0)); QCOMPARE(view.currentIndex(), model.index(0,0)); -- cgit v1.2.3