From bb80d1877a8474ed60d4d0d41c587347fb521c95 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Wed, 10 Aug 2011 10:38:24 +0200 Subject: Update the anchor item when items are added or removed If items are added or removed in the model, not only the current item, but also the anchor item, which is the starting point for any selections via Shift+Click or Shift+Key, needs to be updated. BUG: 262638 FIXED-IN: 4.8.0 --- src/tests/kitemlistselectionmanagertest.cpp | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/tests') diff --git a/src/tests/kitemlistselectionmanagertest.cpp b/src/tests/kitemlistselectionmanagertest.cpp index 3d0c318ff..6b0059a5c 100644 --- a/src/tests/kitemlistselectionmanagertest.cpp +++ b/src/tests/kitemlistselectionmanagertest.cpp @@ -121,6 +121,42 @@ void KItemListSelectionManagerTest::testCurrentItemAnchorItem() QCOMPARE(qvariant_cast(spyAnchor.at(0).at(0)), 5); QCOMPARE(qvariant_cast(spyAnchor.at(0).at(1)), 3); spyAnchor.takeFirst(); + + // Inserting items should update current item and anchor item. + m_selectionManager->itemsInserted(KItemRangeList() << + KItemRange(0, 1) << + KItemRange(2, 2) << + KItemRange(6, 3)); + + QCOMPARE(m_selectionManager->currentItem(), 5); + QCOMPARE(spyCurrent.count(), 1); + QCOMPARE(qvariant_cast(spyCurrent.at(0).at(0)), 5); + QCOMPARE(qvariant_cast(spyCurrent.at(0).at(1)), 2); + spyCurrent.takeFirst(); + + QCOMPARE(m_selectionManager->anchorItem(), 8); + QCOMPARE(spyAnchor.count(), 1); + QCOMPARE(qvariant_cast(spyAnchor.at(0).at(0)), 8); + QCOMPARE(qvariant_cast(spyAnchor.at(0).at(1)), 5); + spyAnchor.takeFirst(); + + // Removing items should update current item and anchor item. + m_selectionManager->itemsRemoved(KItemRangeList() << + KItemRange(0, 2) << + KItemRange(2, 1) << + KItemRange(9, 2)); + + QCOMPARE(m_selectionManager->currentItem(), 2); + QCOMPARE(spyCurrent.count(), 1); + QCOMPARE(qvariant_cast(spyCurrent.at(0).at(0)), 2); + QCOMPARE(qvariant_cast(spyCurrent.at(0).at(1)), 5); + spyCurrent.takeFirst(); + + QCOMPARE(m_selectionManager->anchorItem(), 5); + QCOMPARE(spyAnchor.count(), 1); + QCOMPARE(qvariant_cast(spyAnchor.at(0).at(0)), 5); + QCOMPARE(qvariant_cast(spyAnchor.at(0).at(1)), 8); + spyAnchor.takeFirst(); } void KItemListSelectionManagerTest::testSetSelected_data() -- cgit v1.3