From 61f2e9a9a72ba4daa96960bf3cb7a605c0b4634c Mon Sep 17 00:00:00 2001 From: Joni Poikelin Date: Wed, 23 Sep 2015 13:42:11 +0300 Subject: Fix QItemSelectionModel deselection range Left and right were swapped which caused invalid selection ranges to be emitted through selectionChanged. Task-number: QTBUG-48402 Change-Id: I18692c2b50c49ab39065f9b360b37b7615227ee9 Reviewed-by: Gabriel de Dietrich --- .../tst_qitemselectionmodel.cpp | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index 23cd254477..888ffba282 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -94,6 +94,9 @@ private slots: void testChainedSelectionClear(); void testClearCurrentIndex(); + void QTBUG48402_data(); + void QTBUG48402(); + private: QAbstractItemModel *model; QItemSelectionModel *selection; @@ -2756,5 +2759,96 @@ void tst_QItemSelectionModel::testClearCurrentIndex() QVERIFY(currentIndexSpy.size() == 2); } +void tst_QItemSelectionModel::QTBUG48402_data() +{ + QTest::addColumn("rows"); + QTest::addColumn("columns"); + + QTest::addColumn("selectTop"); + QTest::addColumn("selectLeft"); + QTest::addColumn("selectBottom"); + QTest::addColumn("selectRight"); + + QTest::addColumn("removeTop"); + QTest::addColumn("removeBottom"); + + QTest::addColumn("deselectTop"); + QTest::addColumn("deselectLeft"); + QTest::addColumn("deselectBottom"); + QTest::addColumn("deselectRight"); + + QTest::newRow("4x4 top intersection") + << 4 << 4 + << 0 << 2 << 1 << 3 + << 1 << 1 + << 1 << 2 << 1 << 3; + + QTest::newRow("4x4 bottom intersection") + << 4 << 4 + << 0 << 2 << 1 << 3 + << 0 << 0 + << 0 << 2 << 0 << 3; + + QTest::newRow("4x4 middle intersection") + << 4 << 4 + << 0 << 2 << 2 << 3 + << 1 << 1 + << 1 << 2 << 1 << 3; + + QTest::newRow("4x4 full inclusion") + << 4 << 4 + << 0 << 2 << 1 << 3 + << 0 << 1 + << 0 << 2 << 1 << 3; +} +class QTBUG48402_helper : public QObject +{ + Q_OBJECT +public: + QModelIndex tl; + QModelIndex br; +public slots: + void changed(const QItemSelection &selected, const QItemSelection &deselected) + { + tl = deselected.first().topLeft(); + br = deselected.first().bottomRight(); + } +}; + +void tst_QItemSelectionModel::QTBUG48402() +{ + QFETCH(int, rows); + QFETCH(int, columns); + QFETCH(int, selectTop); + QFETCH(int, selectLeft); + QFETCH(int, selectBottom); + QFETCH(int, selectRight); + QFETCH(int, removeTop); + QFETCH(int, removeBottom); + QFETCH(int, deselectTop); + QFETCH(int, deselectLeft); + QFETCH(int, deselectBottom); + QFETCH(int, deselectRight); + + MyStandardItemModel model(rows, columns); + QItemSelectionModel selections(&model); + + QModelIndex stl = model.index(selectTop, selectLeft); + QModelIndex sbr = model.index(selectBottom, selectRight); + QModelIndex dtl = model.index(deselectTop, deselectLeft); + QModelIndex dbr = model.index(deselectBottom, deselectRight); + + selections.select(QItemSelection(stl, sbr), QItemSelectionModel::ClearAndSelect); + QTBUG48402_helper helper; + helper.connect(&selections, &QItemSelectionModel::selectionChanged, &helper, &QTBUG48402_helper::changed); + QVERIFY(selections.isSelected(stl)); + QVERIFY(selections.isSelected(sbr)); + QVERIFY(selections.hasSelection()); + + model.removeRows(removeTop, removeBottom - removeTop + 1); + + QCOMPARE(QItemSelectionRange(helper.tl, helper.br), QItemSelectionRange(dtl, dbr)); +} + QTEST_MAIN(tst_QItemSelectionModel) #include "tst_qitemselectionmodel.moc" -- cgit v1.2.3