Changeset View
Changeset View
Standalone View
Standalone View
src/tests/kitemlistcontrollertest.cpp
Show First 20 Lines • Show All 118 Lines • ▼ Show 20 Line(s) | 118 | { | |||
---|---|---|---|---|---|
119 | qRegisterMetaType<KItemSet>("KItemSet"); | 119 | qRegisterMetaType<KItemSet>("KItemSet"); | ||
120 | 120 | | |||
121 | m_testDir = new TestDir(); | 121 | m_testDir = new TestDir(); | ||
122 | m_model = new KFileItemModel(); | 122 | m_model = new KFileItemModel(); | ||
123 | m_view = new KFileItemListView(); | 123 | m_view = new KFileItemListView(); | ||
124 | m_controller = new KItemListController(m_model, m_view, this); | 124 | m_controller = new KItemListController(m_model, m_view, this); | ||
125 | m_container = new KItemListContainer(m_controller); | 125 | m_container = new KItemListContainer(m_controller); | ||
126 | m_controller = m_container->controller(); | 126 | m_controller = m_container->controller(); | ||
127 | m_controller->setSelectionBehavior(KItemListController::MultiSelection); | 127 | m_controller->setSelectionBehavior(KItemListController::SelectionBehavior::MultiSelection); | ||
128 | m_selectionManager = m_controller->selectionManager(); | 128 | m_selectionManager = m_controller->selectionManager(); | ||
129 | m_testStyle = new KItemListControllerTestStyle(m_view->style()); | 129 | m_testStyle = new KItemListControllerTestStyle(m_view->style()); | ||
130 | m_view->setStyle(m_testStyle); | 130 | m_view->setStyle(m_testStyle); | ||
131 | 131 | | |||
132 | QStringList files; | 132 | QStringList files; | ||
133 | files | 133 | files | ||
134 | << "a1" << "a2" << "a3" | 134 | << "a1" << "a2" << "a3" | ||
135 | << "b1" | 135 | << "b1" | ||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 224 | { | |||
225 | QTest::addColumn<KFileItemListView::ItemLayout>("layout"); | 225 | QTest::addColumn<KFileItemListView::ItemLayout>("layout"); | ||
226 | QTest::addColumn<Qt::Orientation>("scrollOrientation"); | 226 | QTest::addColumn<Qt::Orientation>("scrollOrientation"); | ||
227 | QTest::addColumn<int>("columnCount"); | 227 | QTest::addColumn<int>("columnCount"); | ||
228 | QTest::addColumn<KItemListController::SelectionBehavior>("selectionBehavior"); | 228 | QTest::addColumn<KItemListController::SelectionBehavior>("selectionBehavior"); | ||
229 | QTest::addColumn<bool>("groupingEnabled"); | 229 | QTest::addColumn<bool>("groupingEnabled"); | ||
230 | QTest::addColumn<QList<QPair<KeyPress, ViewState> > >("testList"); | 230 | QTest::addColumn<QList<QPair<KeyPress, ViewState> > >("testList"); | ||
231 | 231 | | |||
232 | QList<KFileItemListView::ItemLayout> layoutList; | 232 | QList<KFileItemListView::ItemLayout> layoutList; | ||
233 | QHash<KFileItemListView::ItemLayout, QString> layoutNames; | 233 | QHash<int, QString> layoutNames; | ||
234 | layoutList.append(KFileItemListView::IconsLayout); | 234 | layoutList.append(KFileItemListView::ItemLayout::Icons); | ||
235 | layoutNames[KFileItemListView::IconsLayout] = "Icons"; | 235 | layoutNames[static_cast<int>(KFileItemListView::ItemLayout::Icons)] = "Icons"; | ||
236 | layoutList.append(KFileItemListView::CompactLayout); | 236 | layoutList.append(KFileItemListView::ItemLayout::Compact); | ||
237 | layoutNames[KFileItemListView::CompactLayout] = "Compact"; | 237 | layoutNames[static_cast<int>(KFileItemListView::ItemLayout::Compact)] = "Compact"; | ||
238 | layoutList.append(KFileItemListView::DetailsLayout); | 238 | layoutList.append(KFileItemListView::ItemLayout::Details); | ||
239 | layoutNames[KFileItemListView::DetailsLayout] = "Details"; | 239 | layoutNames[static_cast<int>(KFileItemListView::ItemLayout::Details)] = "Details"; | ||
240 | 240 | | |||
241 | QList<KItemListController::SelectionBehavior> selectionBehaviorList; | 241 | QList<KItemListController::SelectionBehavior> selectionBehaviorList; | ||
242 | QHash<KItemListController::SelectionBehavior, QString> selectionBehaviorNames; | 242 | QHash<int, QString> selectionBehaviorNames; | ||
243 | selectionBehaviorList.append(KItemListController::NoSelection); | 243 | selectionBehaviorList.append(KItemListController::SelectionBehavior::NoSelection); | ||
244 | selectionBehaviorNames[KItemListController::NoSelection] = "NoSelection"; | 244 | selectionBehaviorNames[static_cast<int>(KItemListController::SelectionBehavior::NoSelection)] = "NoSelection"; | ||
245 | selectionBehaviorList.append(KItemListController::SingleSelection); | 245 | selectionBehaviorList.append(KItemListController::SelectionBehavior::SingleSelection); | ||
246 | selectionBehaviorNames[KItemListController::SingleSelection] = "SingleSelection"; | 246 | selectionBehaviorNames[static_cast<int>(KItemListController::SelectionBehavior::SingleSelection)] = "SingleSelection"; | ||
247 | selectionBehaviorList.append(KItemListController::MultiSelection); | 247 | selectionBehaviorList.append(KItemListController::SelectionBehavior::MultiSelection); | ||
248 | selectionBehaviorNames[KItemListController::MultiSelection] = "MultiSelection"; | 248 | selectionBehaviorNames[static_cast<int>(KItemListController::SelectionBehavior::MultiSelection)] = "MultiSelection"; | ||
249 | 249 | | |||
250 | QList<bool> groupingEnabledList; | 250 | QList<bool> groupingEnabledList; | ||
251 | QHash<bool, QString> groupingEnabledNames; | 251 | QHash<bool, QString> groupingEnabledNames; | ||
252 | groupingEnabledList.append(false); | 252 | groupingEnabledList.append(false); | ||
253 | groupingEnabledNames[false] = "ungrouped"; | 253 | groupingEnabledNames[false] = "ungrouped"; | ||
254 | groupingEnabledList.append(true); | 254 | groupingEnabledList.append(true); | ||
255 | groupingEnabledNames[true] = "grouping enabled"; | 255 | groupingEnabledNames[true] = "grouping enabled"; | ||
256 | 256 | | |||
257 | foreach (const KFileItemListView::ItemLayout& layout, layoutList) { | 257 | foreach (const KFileItemListView::ItemLayout& layout, layoutList) { | ||
258 | // The following settings depend on the layout. | 258 | // The following settings depend on the layout. | ||
259 | // Note that 'columns' are actually 'rows' in | 259 | // Note that 'columns' are actually 'rows' in | ||
260 | // Compact layout. | 260 | // Compact layout. | ||
261 | Qt::Orientation scrollOrientation; | 261 | Qt::Orientation scrollOrientation; | ||
262 | QList<int> columnCountList; | 262 | QList<int> columnCountList; | ||
263 | Qt::Key nextItemKey; | 263 | Qt::Key nextItemKey; | ||
264 | Qt::Key previousItemKey; | 264 | Qt::Key previousItemKey; | ||
265 | Qt::Key nextRowKey; | 265 | Qt::Key nextRowKey; | ||
266 | Qt::Key previousRowKey; | 266 | Qt::Key previousRowKey; | ||
267 | 267 | | |||
268 | switch (layout) { | 268 | switch (layout) { | ||
269 | case KFileItemListView::IconsLayout: | 269 | case KFileItemListView::ItemLayout::Icons: | ||
270 | scrollOrientation = Qt::Vertical; | 270 | scrollOrientation = Qt::Vertical; | ||
271 | columnCountList << 1 << 3 << 5; | 271 | columnCountList << 1 << 3 << 5; | ||
272 | nextItemKey = Qt::Key_Right; | 272 | nextItemKey = Qt::Key_Right; | ||
273 | previousItemKey = Qt::Key_Left; | 273 | previousItemKey = Qt::Key_Left; | ||
274 | nextRowKey = Qt::Key_Down; | 274 | nextRowKey = Qt::Key_Down; | ||
275 | previousRowKey = Qt::Key_Up; | 275 | previousRowKey = Qt::Key_Up; | ||
276 | break; | 276 | break; | ||
277 | case KFileItemListView::CompactLayout: | 277 | case KFileItemListView::ItemLayout::Compact: | ||
278 | scrollOrientation = Qt::Horizontal; | 278 | scrollOrientation = Qt::Horizontal; | ||
279 | columnCountList << 1 << 3 << 5; | 279 | columnCountList << 1 << 3 << 5; | ||
280 | nextItemKey = Qt::Key_Down; | 280 | nextItemKey = Qt::Key_Down; | ||
281 | previousItemKey = Qt::Key_Up; | 281 | previousItemKey = Qt::Key_Up; | ||
282 | nextRowKey = Qt::Key_Right; | 282 | nextRowKey = Qt::Key_Right; | ||
283 | previousRowKey = Qt::Key_Left; | 283 | previousRowKey = Qt::Key_Left; | ||
284 | break; | 284 | break; | ||
285 | case KFileItemListView::DetailsLayout: | 285 | case KFileItemListView::ItemLayout::Details: | ||
286 | scrollOrientation = Qt::Vertical; | 286 | scrollOrientation = Qt::Vertical; | ||
287 | columnCountList << 1; | 287 | columnCountList << 1; | ||
288 | nextItemKey = Qt::Key_Down; | 288 | nextItemKey = Qt::Key_Down; | ||
289 | previousItemKey = Qt::Key_Up; | 289 | previousItemKey = Qt::Key_Up; | ||
290 | nextRowKey = Qt::Key_Down; | 290 | nextRowKey = Qt::Key_Down; | ||
291 | previousRowKey = Qt::Key_Up; | 291 | previousRowKey = Qt::Key_Up; | ||
292 | break; | 292 | break; | ||
293 | } | 293 | } | ||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Line(s) | 442 | testList | |||
451 | << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) | 451 | << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) | ||
452 | << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) | 452 | << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) | ||
453 | << qMakePair(KeyPress(Qt::Key_End, Qt::ShiftModifier), ViewState(19, KItemSet() << 17 << 18 << 19)) | 453 | << qMakePair(KeyPress(Qt::Key_End, Qt::ShiftModifier), ViewState(19, KItemSet() << 17 << 18 << 19)) | ||
454 | << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(14, KItemSet() << 14 << 15 << 16 << 17)) | 454 | << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(14, KItemSet() << 14 << 15 << 16 << 17)) | ||
455 | << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); | 455 | << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); | ||
456 | } | 456 | } | ||
457 | 457 | | |||
458 | const QString testName = | 458 | const QString testName = | ||
459 | layoutNames[layout] + ", " + | 459 | layoutNames[static_cast<int>(layout)] + ", " + | ||
460 | QString("%1 columns, ").arg(columnCount) + | 460 | QString("%1 columns, ").arg(columnCount) + | ||
461 | selectionBehaviorNames[selectionBehavior] + ", " + | 461 | selectionBehaviorNames[static_cast<int>(selectionBehavior)] + ", " + | ||
462 | groupingEnabledNames[groupingEnabled]; | 462 | groupingEnabledNames[groupingEnabled]; | ||
463 | 463 | | |||
464 | const QByteArray testNameAscii = testName.toLatin1(); | 464 | const QByteArray testNameAscii = testName.toLatin1(); | ||
465 | 465 | | |||
466 | QTest::newRow(testNameAscii.data()) | 466 | QTest::newRow(testNameAscii.data()) | ||
467 | << layout | 467 | << layout | ||
468 | << scrollOrientation | 468 | << scrollOrientation | ||
469 | << columnCount | 469 | << columnCount | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 513 | while (!testList.isEmpty()) { | |||
517 | const int current = test.second.m_current; | 517 | const int current = test.second.m_current; | ||
518 | const KItemSet selection = test.second.m_selection; | 518 | const KItemSet selection = test.second.m_selection; | ||
519 | const bool activated = test.second.m_activated; | 519 | const bool activated = test.second.m_activated; | ||
520 | 520 | | |||
521 | QTest::keyClick(m_container, key, modifier); | 521 | QTest::keyClick(m_container, key, modifier); | ||
522 | 522 | | |||
523 | QCOMPARE(m_selectionManager->currentItem(), current); | 523 | QCOMPARE(m_selectionManager->currentItem(), current); | ||
524 | switch (selectionBehavior) { | 524 | switch (selectionBehavior) { | ||
525 | case KItemListController::NoSelection: QVERIFY(m_selectionManager->selectedItems().isEmpty()); break; | 525 | case KItemListController::SelectionBehavior::NoSelection: QVERIFY(m_selectionManager->selectedItems().isEmpty()); break; | ||
526 | case KItemListController::SingleSelection: QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << current); break; | 526 | case KItemListController::SelectionBehavior::SingleSelection: QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << current); break; | ||
527 | case KItemListController::MultiSelection: QCOMPARE(m_selectionManager->selectedItems(), selection); break; | 527 | case KItemListController::SelectionBehavior::MultiSelection: QCOMPARE(m_selectionManager->selectedItems(), selection); break; | ||
528 | } | 528 | } | ||
529 | 529 | | |||
530 | if (activated) { | 530 | if (activated) { | ||
531 | switch (selectionBehavior) { | 531 | switch (selectionBehavior) { | ||
532 | case KItemListController::MultiSelection: | 532 | case KItemListController::SelectionBehavior::MultiSelection: | ||
533 | if (!selection.isEmpty()) { | 533 | if (!selection.isEmpty()) { | ||
534 | // The selected items should be activated. | 534 | // The selected items should be activated. | ||
535 | if (selection.count() == 1) { | 535 | if (selection.count() == 1) { | ||
536 | QVERIFY(!spySingleItemActivated.isEmpty()); | 536 | QVERIFY(!spySingleItemActivated.isEmpty()); | ||
537 | QCOMPARE(qvariant_cast<int>(spySingleItemActivated.takeFirst().at(0)), selection.first()); | 537 | QCOMPARE(qvariant_cast<int>(spySingleItemActivated.takeFirst().at(0)), selection.first()); | ||
538 | QVERIFY(spyMultipleItemsActivated.isEmpty()); | 538 | QVERIFY(spyMultipleItemsActivated.isEmpty()); | ||
539 | } else { | 539 | } else { | ||
540 | QVERIFY(spySingleItemActivated.isEmpty()); | 540 | QVERIFY(spySingleItemActivated.isEmpty()); | ||
541 | QVERIFY(!spyMultipleItemsActivated.isEmpty()); | 541 | QVERIFY(!spyMultipleItemsActivated.isEmpty()); | ||
542 | QCOMPARE(qvariant_cast<KItemSet>(spyMultipleItemsActivated.takeFirst().at(0)), selection); | 542 | QCOMPARE(qvariant_cast<KItemSet>(spyMultipleItemsActivated.takeFirst().at(0)), selection); | ||
543 | } | 543 | } | ||
544 | break; | 544 | break; | ||
545 | } | 545 | } | ||
546 | // No items are selected. Therefore, the current item should be activated. | 546 | // No items are selected. Therefore, the current item should be activated. | ||
547 | // This is handled by falling through to the NoSelection/SingleSelection case. | 547 | // This is handled by falling through to the NoSelection/SingleSelection case. | ||
548 | case KItemListController::NoSelection: | 548 | case KItemListController::SelectionBehavior::NoSelection: | ||
549 | case KItemListController::SingleSelection: | 549 | case KItemListController::SelectionBehavior::SingleSelection: | ||
550 | // In NoSelection and SingleSelection mode, the current item should be activated. | 550 | // In NoSelection and SingleSelection mode, the current item should be activated. | ||
551 | QVERIFY(!spySingleItemActivated.isEmpty()); | 551 | QVERIFY(!spySingleItemActivated.isEmpty()); | ||
552 | QCOMPARE(qvariant_cast<int>(spySingleItemActivated.takeFirst().at(0)), current); | 552 | QCOMPARE(qvariant_cast<int>(spySingleItemActivated.takeFirst().at(0)), current); | ||
553 | QVERIFY(spyMultipleItemsActivated.isEmpty()); | 553 | QVERIFY(spyMultipleItemsActivated.isEmpty()); | ||
554 | break; | 554 | break; | ||
555 | } | 555 | } | ||
556 | } | 556 | } | ||
557 | } | 557 | } | ||
558 | } | 558 | } | ||
559 | 559 | | |||
560 | void KItemListControllerTest::testMouseClickActivation() | 560 | void KItemListControllerTest::testMouseClickActivation() | ||
561 | { | 561 | { | ||
562 | m_view->setItemLayout(KFileItemListView::IconsLayout); | 562 | m_view->setItemLayout(KFileItemListView::ItemLayout::Icons); | ||
563 | 563 | | |||
564 | // Make sure that we have a large window, such that | 564 | // Make sure that we have a large window, such that | ||
565 | // the items are visible and clickable. | 565 | // the items are visible and clickable. | ||
566 | adjustGeometryForColumnCount(5); | 566 | adjustGeometryForColumnCount(5); | ||
567 | 567 | | |||
568 | // Make sure that the first item is visible in the view. | 568 | // Make sure that the first item is visible in the view. | ||
569 | m_view->setScrollOffset(0); | 569 | m_view->setScrollOffset(0); | ||
570 | QCOMPARE(m_view->firstVisibleIndex(), 0); | 570 | QCOMPARE(m_view->firstVisibleIndex(), 0); | ||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |