void tst_QColumnView::moveCursor() { QFETCH(bool, reverse); if (reverse) qApp->setLayoutDirection(Qt::RightToLeft); ColumnView view; // don't crash view.MoveCursor(ColumnView::MoveUp, Qt::NoModifier); // don't do anything QCOMPARE(view.MoveCursor(ColumnView::MoveEnd, Qt::NoModifier), QModelIndex()); QDirModel model; view.setModel(&model); QModelIndex home = model.index(QDir::homePath()); QModelIndex ci = view.currentIndex(); QCOMPARE(view.MoveCursor(ColumnView::MoveUp, Qt::NoModifier), QModelIndex()); QCOMPARE(view.MoveCursor(ColumnView::MoveDown, Qt::NoModifier), QModelIndex()); // left at root view.setCurrentIndex(model.index(0,0)); ColumnView::PublicCursorAction action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft; QCOMPARE(view.MoveCursor(action, Qt::NoModifier), model.index(0,0)); // left shouldn't move up int i = 0; ci = model.index(0, 0); while (i < model.rowCount() - 1 && !model.hasChildren(ci)) ci = model.index(++i, 0); QVERIFY(model.hasChildren(ci)); view.setCurrentIndex(ci); action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft; QCOMPARE(view.MoveCursor(action, Qt::NoModifier), ci); // now move to the left (i.e. move over one column) view.setCurrentIndex(home); QCOMPARE(view.MoveCursor(action, Qt::NoModifier), home.parent()); // right action = reverse ? ColumnView::MoveLeft : ColumnView::MoveRight; view.setCurrentIndex(ci); QModelIndex mc = view.MoveCursor(action, Qt::NoModifier); QCOMPARE(mc, model.index(0,0, ci)); // next one should move down QModelIndex idx = model.index(0, 0, ci); while (model.hasChildren(idx) && model.rowCount(ci) > idx.row() + 1) idx = idx.sibling(idx.row() + 1, idx.column()); view.setCurrentIndex(idx); mc = view.MoveCursor(action, Qt::NoModifier); QCOMPARE(mc, idx.sibling(idx.row() + 1, idx.column())); }
void tst_QColumnView::selectAll() { ColumnView view; view.selectAll(); QDirModel model; view.setModel(&model); view.selectAll(); QVERIFY(view.selectionModel()->selectedIndexes().count() >= 0); QModelIndex home = model.index(QDir::homePath()); view.setCurrentIndex(home); view.selectAll(); QVERIFY(view.selectionModel()->selectedIndexes().count() > 0); QModelIndex file; for (int i = 0; i < model.rowCount(home); ++i) if (!model.hasChildren(model.index(i, 0, home))) { file = model.index(i, 0, home); break; } view.setCurrentIndex(file); view.selectAll(); QVERIFY(view.selectionModel()->selectedIndexes().count() > 0); view.setCurrentIndex(QModelIndex()); QVERIFY(view.selectionModel()->selectedIndexes().count() == 0); }