diff options
author | Joni Poikelin <joni.poikelin@theqtcompany.com> | 2015-09-23 13:42:11 +0300 |
---|---|---|
committer | Joni Poikelin <joni.poikelin@theqtcompany.com> | 2015-09-24 08:13:07 +0000 |
commit | 61f2e9a9a72ba4daa96960bf3cb7a605c0b4634c (patch) | |
tree | 0233735440ded55a35313f910813bdf06c6335b0 /tests | |
parent | 7183d08095f4598fc0f7702608bd726986bf1307 (diff) | |
download | qtbase-61f2e9a9a72ba4daa96960bf3cb7a605c0b4634c.tar.gz |
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 <gabriel.dedietrich@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
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<int>("rows"); + QTest::addColumn<int>("columns"); + + QTest::addColumn<int>("selectTop"); + QTest::addColumn<int>("selectLeft"); + QTest::addColumn<int>("selectBottom"); + QTest::addColumn<int>("selectRight"); + + QTest::addColumn<int>("removeTop"); + QTest::addColumn<int>("removeBottom"); + + QTest::addColumn<int>("deselectTop"); + QTest::addColumn<int>("deselectLeft"); + QTest::addColumn<int>("deselectBottom"); + QTest::addColumn<int>("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" |