diff options
author | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2009-10-12 12:28:33 (GMT) |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2009-10-12 14:33:34 (GMT) |
commit | 8da7252de0badb818302763cbe62c38ad699f1f3 (patch) | |
tree | c2ad6d88a1415d244f5b70ed7e7555642a6ca180 /tests | |
parent | 857b7443b1bd4311a02753bea7b8c7839f1ad311 (diff) | |
download | Qt-8da7252de0badb818302763cbe62c38ad699f1f3.zip Qt-8da7252de0badb818302763cbe62c38ad699f1f3.tar.gz Qt-8da7252de0badb818302763cbe62c38ad699f1f3.tar.bz2 |
Fixed keyboard navigation for QTableView
Keyboard navigation didn't work in the following cases:
- The last column was disabled and we pressed the tab key when at the 2nd
last column. (See ref. task).
- Spans with their anchor column or row hidden or disabled.
- Navigation would not preserve the original row/column when traversing a
span horizontally/vertically.
Auto-tests submitted with this commit.
Task-number: QTBUG-3878
Reviewed-by: Olivier
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qtableview/tst_qtableview.cpp | 166 |
1 files changed, 164 insertions, 2 deletions
diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp index bb0e226..4ea1b19 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -100,6 +100,9 @@ private slots: void moveCursor_data(); void moveCursor(); + void moveCursorStrikesBack_data(); + void moveCursorStrikesBack(); + void hideRows_data(); void hideRows(); @@ -252,12 +255,43 @@ public: row_count(rows), column_count(columns), can_fetch_more(false), - fetch_more_count(0) {} + fetch_more_count(0), + disabled_rows(), + disabled_columns() {} int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; } int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; } bool isEditable(const QModelIndex &) const { return true; } + Qt::ItemFlags flags(const QModelIndex &index) const + { + Qt::ItemFlags index_flags = QAbstractTableModel::flags(index); + if (disabled_rows.contains(index.row()) + || disabled_columns.contains(index.column())) + index_flags &= ~Qt::ItemIsEnabled; + return index_flags; + } + + void disableRow(int row) + { + disabled_rows.insert(row); + } + + void enableRow(int row) + { + disabled_rows.remove(row); + } + + void disableColumn(int column) + { + disabled_columns.insert(column); + } + + void enableColumn(int column) + { + disabled_columns.remove(column); + } + QVariant data(const QModelIndex &idx, int role) const { if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) { @@ -363,6 +397,8 @@ public: int column_count; bool can_fetch_more; int fetch_more_count; + QSet<int> disabled_rows; + QSet<int> disabled_columns; }; class QtTestTableView : public QTableView @@ -834,7 +870,7 @@ void tst_QTableView::moveCursor_data() << 4 << 4 << -1 << 2 << 0 << 2 << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) - << 1 << 0 << IntPair(0,0) << IntPair(3,0); + << 1 << 3 << IntPair(0,0) << IntPair(3,0); // MoveLeft QTest::newRow("MoveLeft (0,0)") @@ -1137,6 +1173,132 @@ void tst_QTableView::moveCursor() QCOMPARE(newIndex.column(), expectedColumn); } +void tst_QTableView::moveCursorStrikesBack_data() +{ + QTest::addColumn<int>("hideRow"); + QTest::addColumn<int>("hideColumn"); + QTest::addColumn<IntList>("disableRows"); + QTest::addColumn<IntList>("disableColumns"); + QTest::addColumn<QRect>("span"); + + QTest::addColumn<int>("startRow"); + QTest::addColumn<int>("startColumn"); + QTest::addColumn<IntList>("cursorMoveActions"); + QTest::addColumn<int>("expectedRow"); + QTest::addColumn<int>("expectedColumn"); + + QTest::newRow("Last column disabled. Task QTBUG-3878") << -1 << -1 + << IntList() + << (IntList() << 6) + << QRect() + << 0 << 5 << (IntList() << int(QtTestTableView::MoveNext)) + << 1 << 0; + + QTest::newRow("Span, anchor column hidden") << -1 << 1 + << IntList() + << IntList() + << QRect(1, 2, 2, 3) + << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext)) + << 2 << 2; + + QTest::newRow("Span, anchor column disabled") << -1 << -1 + << IntList() + << (IntList() << 1) + << QRect(1, 2, 2, 3) + << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext)) + << 2 << 2; + + QTest::newRow("Span, anchor row hidden") << 2 << -1 + << IntList() + << IntList() + << QRect(1, 2, 2, 3) + << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown)) + << 3 << 2; + + QTest::newRow("Span, anchor row disabled") << -1 << -1 + << (IntList() << 2) + << IntList() + << QRect(1, 2, 2, 3) + << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown)) + << 3 << 2; + + QTest::newRow("Move through span right") << -1 << -1 + << IntList() + << IntList() + << QRect(1, 2, 2, 3) + << 3 << 0 << (IntList() << int(QtTestTableView::MoveRight) << int(QtTestTableView::MoveRight)) + << 3 << 3; + + QTest::newRow("Move through span left") << -1 << -1 + << IntList() + << IntList() + << QRect(1, 2, 2, 3) + << 3 << 3 << (IntList() << int(QtTestTableView::MoveLeft) << int(QtTestTableView::MoveLeft)) + << 3 << 0; + + QTest::newRow("Move through span down") << -1 << -1 + << IntList() + << IntList() + << QRect(1, 2, 2, 3) + << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown) << int(QtTestTableView::MoveDown)) + << 5 << 2; + + QTest::newRow("Move through span up") << -1 << -1 + << IntList() + << IntList() + << QRect(1, 2, 2, 3) + << 5 << 2 << (IntList() << int(QtTestTableView::MoveUp) << int(QtTestTableView::MoveUp)) + << 1 << 2; +} + +void tst_QTableView::moveCursorStrikesBack() +{ + QFETCH(int, hideRow); + QFETCH(int, hideColumn); + QFETCH(IntList, disableRows); + QFETCH(IntList, disableColumns); + QFETCH(QRect, span); + + QFETCH(int, startRow); + QFETCH(int, startColumn); + QFETCH(IntList, cursorMoveActions); + QFETCH(int, expectedRow); + QFETCH(int, expectedColumn); + + QtTestTableModel model(7, 7); + QtTestTableView view; + view.setModel(&model); + view.hideRow(hideRow); + view.hideColumn(hideColumn); + + foreach (int row, disableRows) + model.disableRow(row); + foreach (int column, disableColumns) + model.disableColumn(column); + + if (span.height() && span.width()) + view.setSpan(span.top(), span.left(), span.height(), span.width()); + view.show(); + + QModelIndex index = model.index(startRow, startColumn); + view.setCurrentIndex(index); + + int newRow = -1; + int newColumn = -1; + foreach (int cursorMoveAction, cursorMoveActions) { + QModelIndex newIndex = view.moveCursor((QtTestTableView::CursorAction)cursorMoveAction, 0); + view.setCurrentIndex(newIndex); + newRow = newIndex.row(); + newColumn = newIndex.column(); + } + + // expected fails, task 119433 + if(newRow == -1) + return; + QCOMPARE(newRow, expectedRow); + QCOMPARE(newColumn, expectedColumn); +} + void tst_QTableView::hideRows_data() { QTest::addColumn<int>("rowCount"); |