Changeset View
Changeset View
Standalone View
Standalone View
src/tests/kitemlistselectionmanagertest.cpp
Show First 20 Lines • Show All 307 Lines • ▼ Show 20 Line(s) | 275 | { | |||
---|---|---|---|---|---|
308 | QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 5 << 6 << 7 << 9 << 10); | 308 | QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 5 << 6 << 7 << 9 << 10); | ||
309 | 309 | | |||
310 | m_selectionManager->endAnchoredSelection(); | 310 | m_selectionManager->endAnchoredSelection(); | ||
311 | QVERIFY(!m_selectionManager->isAnchoredSelectionActive()); | 311 | QVERIFY(!m_selectionManager->isAnchoredSelectionActive()); | ||
312 | QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 5 << 6 << 7 << 9 << 10); | 312 | QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 5 << 6 << 7 << 9 << 10); | ||
313 | } | 313 | } | ||
314 | 314 | | |||
315 | namespace { | 315 | namespace { | ||
316 | enum ChangeType { | 316 | enum class ChangeType { | ||
317 | NoChange, | 317 | NoChange, | ||
318 | InsertItems, | 318 | InsertItems, | ||
319 | RemoveItems, | 319 | RemoveItems, | ||
320 | MoveItems, | 320 | MoveItems, | ||
321 | EndAnchoredSelection, | 321 | EndAnchoredSelection, | ||
322 | SetSelected | 322 | SetSelected | ||
323 | }; | 323 | }; | ||
324 | } | 324 | } | ||
Show All 39 Lines | 359 | { | |||
364 | QTest::addColumn<ChangeType>("changeType"); | 364 | QTest::addColumn<ChangeType>("changeType"); | ||
365 | QTest::addColumn<QList<QVariant> >("data"); | 365 | QTest::addColumn<QList<QVariant> >("data"); | ||
366 | QTest::addColumn<KItemSet>("finalSelection"); | 366 | QTest::addColumn<KItemSet>("finalSelection"); | ||
367 | 367 | | |||
368 | QTest::newRow("No change") | 368 | QTest::newRow("No change") | ||
369 | << (KItemSet() << 5 << 6) | 369 | << (KItemSet() << 5 << 6) | ||
370 | << 2 << 3 | 370 | << 2 << 3 | ||
371 | << (KItemSet() << 2 << 3 << 5 << 6) | 371 | << (KItemSet() << 2 << 3 << 5 << 6) | ||
372 | << NoChange | 372 | << ChangeType::NoChange | ||
373 | << QList<QVariant>{} | 373 | << QList<QVariant>{} | ||
374 | << (KItemSet() << 2 << 3 << 5 << 6); | 374 | << (KItemSet() << 2 << 3 << 5 << 6); | ||
375 | 375 | | |||
376 | QTest::newRow("Insert Items") | 376 | QTest::newRow("Insert Items") | ||
377 | << (KItemSet() << 5 << 6) | 377 | << (KItemSet() << 5 << 6) | ||
378 | << 2 << 3 | 378 | << 2 << 3 | ||
379 | << (KItemSet() << 2 << 3 << 5 << 6) | 379 | << (KItemSet() << 2 << 3 << 5 << 6) | ||
380 | << InsertItems | 380 | << ChangeType::InsertItems | ||
381 | << QList<QVariant>{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 2) << KItemRange(10, 5))} | 381 | << QList<QVariant>{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 2) << KItemRange(10, 5))} | ||
382 | << (KItemSet() << 3 << 4 << 8 << 9); | 382 | << (KItemSet() << 3 << 4 << 8 << 9); | ||
383 | 383 | | |||
384 | QTest::newRow("Remove Items") | 384 | QTest::newRow("Remove Items") | ||
385 | << (KItemSet() << 5 << 6) | 385 | << (KItemSet() << 5 << 6) | ||
386 | << 2 << 3 | 386 | << 2 << 3 | ||
387 | << (KItemSet() << 2 << 3 << 5 << 6) | 387 | << (KItemSet() << 2 << 3 << 5 << 6) | ||
388 | << RemoveItems | 388 | << ChangeType::RemoveItems | ||
389 | << QList<QVariant>{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(3, 1) << KItemRange(10, 5))} | 389 | << QList<QVariant>{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(3, 1) << KItemRange(10, 5))} | ||
390 | << (KItemSet() << 1 << 2 << 3 << 4); | 390 | << (KItemSet() << 1 << 2 << 3 << 4); | ||
391 | 391 | | |||
392 | QTest::newRow("Empty Anchored Selection") | 392 | QTest::newRow("Empty Anchored Selection") | ||
393 | << KItemSet() | 393 | << KItemSet() | ||
394 | << 2 << 2 | 394 | << 2 << 2 | ||
395 | << KItemSet() | 395 | << KItemSet() | ||
396 | << EndAnchoredSelection | 396 | << ChangeType::EndAnchoredSelection | ||
397 | << QList<QVariant>{} | 397 | << QList<QVariant>{} | ||
398 | << KItemSet(); | 398 | << KItemSet(); | ||
399 | 399 | | |||
400 | QTest::newRow("Toggle selection") | 400 | QTest::newRow("Toggle selection") | ||
401 | << (KItemSet() << 1 << 3 << 4) | 401 | << (KItemSet() << 1 << 3 << 4) | ||
402 | << 6 << 8 | 402 | << 6 << 8 | ||
403 | << (KItemSet() << 1 << 3 << 4 << 6 << 7 << 8) | 403 | << (KItemSet() << 1 << 3 << 4 << 6 << 7 << 8) | ||
404 | << SetSelected | 404 | << ChangeType::SetSelected | ||
405 | << QList<QVariant>{0, 10, QVariant::fromValue(KItemListSelectionManager::Toggle)} | 405 | << QList<QVariant>{0, 10, QVariant::fromValue(KItemListSelectionManager::SelectionMode::Toggle)} | ||
406 | << (KItemSet() << 0 << 2 << 5 << 9); | 406 | << (KItemSet() << 0 << 2 << 5 << 9); | ||
407 | 407 | | |||
408 | // Swap items 2, 3 and 4, 5 | 408 | // Swap items 2, 3 and 4, 5 | ||
409 | QTest::newRow("Move items") | 409 | QTest::newRow("Move items") | ||
410 | << (KItemSet() << 0 << 1 << 2 << 3) | 410 | << (KItemSet() << 0 << 1 << 2 << 3) | ||
411 | << -1 << -1 | 411 | << -1 << -1 | ||
412 | << (KItemSet() << 0 << 1 << 2 << 3) | 412 | << (KItemSet() << 0 << 1 << 2 << 3) | ||
413 | << MoveItems | 413 | << ChangeType::MoveItems | ||
414 | << QList<QVariant>{QVariant::fromValue(KItemRange(2, 4)), | 414 | << QList<QVariant>{QVariant::fromValue(KItemRange(2, 4)), | ||
415 | QVariant::fromValue(QList<int>{4, 5, 2, 3})} | 415 | QVariant::fromValue(QList<int>{4, 5, 2, 3})} | ||
416 | << (KItemSet() << 0 << 1 << 4 << 5); | 416 | << (KItemSet() << 0 << 1 << 4 << 5); | ||
417 | 417 | | |||
418 | QTest::newRow("Move items with active anchored selection") | 418 | QTest::newRow("Move items with active anchored selection") | ||
419 | << KItemSet() | 419 | << KItemSet() | ||
420 | << 0 << 3 | 420 | << 0 << 3 | ||
421 | << (KItemSet() << 0 << 1 << 2 << 3) | 421 | << (KItemSet() << 0 << 1 << 2 << 3) | ||
422 | << MoveItems | 422 | << ChangeType::MoveItems | ||
423 | << QList<QVariant>{QVariant::fromValue(KItemRange(2, 4)), | 423 | << QList<QVariant>{QVariant::fromValue(KItemRange(2, 4)), | ||
424 | QVariant::fromValue(QList<int>{4, 5, 2, 3})} | 424 | QVariant::fromValue(QList<int>{4, 5, 2, 3})} | ||
425 | << (KItemSet() << 0 << 1 << 4 << 5); | 425 | << (KItemSet() << 0 << 1 << 4 << 5); | ||
426 | 426 | | |||
427 | // Revert sort order | 427 | // Revert sort order | ||
428 | QTest::newRow("Revert sort order") | 428 | QTest::newRow("Revert sort order") | ||
429 | << (KItemSet() << 0 << 1) | 429 | << (KItemSet() << 0 << 1) | ||
430 | << 3 << 4 | 430 | << 3 << 4 | ||
431 | << (KItemSet() << 0 << 1 << 3 << 4) | 431 | << (KItemSet() << 0 << 1 << 3 << 4) | ||
432 | << MoveItems | 432 | << ChangeType::MoveItems | ||
433 | << QList<QVariant>{QVariant::fromValue(KItemRange(0, 10)), | 433 | << QList<QVariant>{QVariant::fromValue(KItemRange(0, 10)), | ||
434 | QVariant::fromValue(QList<int>{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})} | 434 | QVariant::fromValue(QList<int>{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})} | ||
435 | << (KItemSet() << 5 << 6 << 8 << 9); | 435 | << (KItemSet() << 5 << 6 << 8 << 9); | ||
436 | } | 436 | } | ||
437 | 437 | | |||
438 | void KItemListSelectionManagerTest::testChangeSelection() | 438 | void KItemListSelectionManagerTest::testChangeSelection() | ||
439 | { | 439 | { | ||
440 | QFETCH(KItemSet, initialSelection); | 440 | QFETCH(KItemSet, initialSelection); | ||
Show All 23 Lines | |||||
464 | m_selectionManager->setCurrentItem(current); | 464 | m_selectionManager->setCurrentItem(current); | ||
465 | QCOMPARE(m_selectionManager->m_anchorItem, anchor); | 465 | QCOMPARE(m_selectionManager->m_anchorItem, anchor); | ||
466 | QCOMPARE(m_selectionManager->currentItem(), current); | 466 | QCOMPARE(m_selectionManager->currentItem(), current); | ||
467 | 467 | | |||
468 | verifySelectionChange(spySelectionChanged, expectedSelection, initialSelection); | 468 | verifySelectionChange(spySelectionChanged, expectedSelection, initialSelection); | ||
469 | 469 | | |||
470 | // Change the model by inserting or removing items. | 470 | // Change the model by inserting or removing items. | ||
471 | switch (changeType) { | 471 | switch (changeType) { | ||
472 | case InsertItems: | 472 | case ChangeType::InsertItems: | ||
473 | m_selectionManager->itemsInserted(data.at(0).value<KItemRangeList>()); | 473 | m_selectionManager->itemsInserted(data.at(0).value<KItemRangeList>()); | ||
474 | break; | 474 | break; | ||
475 | case RemoveItems: | 475 | case ChangeType::RemoveItems: | ||
476 | m_selectionManager->itemsRemoved(data.at(0).value<KItemRangeList>()); | 476 | m_selectionManager->itemsRemoved(data.at(0).value<KItemRangeList>()); | ||
477 | break; | 477 | break; | ||
478 | case MoveItems: | 478 | case ChangeType::MoveItems: | ||
479 | m_selectionManager->itemsMoved(data.at(0).value<KItemRange>(), | 479 | m_selectionManager->itemsMoved(data.at(0).value<KItemRange>(), | ||
480 | data.at(1).value<QList<int>>()); | 480 | data.at(1).value<QList<int>>()); | ||
481 | break; | 481 | break; | ||
482 | case EndAnchoredSelection: | 482 | case ChangeType::EndAnchoredSelection: | ||
483 | m_selectionManager->endAnchoredSelection(); | 483 | m_selectionManager->endAnchoredSelection(); | ||
484 | QVERIFY(!m_selectionManager->isAnchoredSelectionActive()); | 484 | QVERIFY(!m_selectionManager->isAnchoredSelectionActive()); | ||
485 | break; | 485 | break; | ||
486 | case SetSelected: | 486 | case ChangeType::SetSelected: | ||
487 | m_selectionManager->setSelected(data.at(0).value<int>(), // index | 487 | m_selectionManager->setSelected(data.at(0).value<int>(), // index | ||
488 | data.at(1).value<int>(), // count | 488 | data.at(1).value<int>(), // count | ||
489 | data.at(2).value<KItemListSelectionManager::SelectionMode>()); | 489 | data.at(2).value<KItemListSelectionManager::SelectionMode>()); | ||
490 | break; | 490 | break; | ||
491 | case NoChange: | 491 | case ChangeType::NoChange: | ||
492 | break; | 492 | break; | ||
493 | } | 493 | } | ||
494 | 494 | | |||
495 | verifySelectionChange(spySelectionChanged, finalSelection, expectedSelection); | 495 | verifySelectionChange(spySelectionChanged, finalSelection, expectedSelection); | ||
496 | 496 | | |||
497 | // Finally, clear the selection | 497 | // Finally, clear the selection | ||
498 | m_selectionManager->clearSelection(); | 498 | m_selectionManager->clearSelection(); | ||
499 | 499 | | |||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |