summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2009-08-11 11:36:48 +0200
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2009-08-11 11:51:56 +0200
commitdadb7b7ad36c43757d96b540b40cc3d81dca69d2 (patch)
treebba28e1c731d76b0613b8424449b3fa6102959ca
parentec82f4fee841cc312a2d3517de36941ad8bee158 (diff)
QTableView with swapped headers PageUp/PageDown bug
QTableView with header-swapped rows wouldn't scroll correctly when PageUp or PageDown pressed. Simplified calculation for next currentIndex provided in QTableView::moveCursor. Task-number: 259308 Reviewed-by: olivier
-rw-r--r--src/gui/itemviews/qtableview.cpp17
-rw-r--r--tests/auto/qtableview/tst_qtableview.cpp33
2 files changed, 41 insertions, 9 deletions
diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp
index 2009499271..8fc99a0dc2 100644
--- a/src/gui/itemviews/qtableview.cpp
+++ b/src/gui/itemviews/qtableview.cpp
@@ -1197,17 +1197,16 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi
visualRow = bottom;
break;
case MovePageUp: {
- int top = 0;
- while (top < bottom && d->isVisualRowHiddenOrDisabled(top, visualColumn))
- ++top;
- int newRow = qMax(rowAt(visualRect(current).top() - d->viewport->height()), top);
- return d->model->index(qBound(0, newRow, bottom), current.column(), d->root);
+ int newRow = rowAt(visualRect(current).top() - d->viewport->height());
+ if (newRow == -1)
+ newRow = d->logicalRow(0);
+ return d->model->index(newRow, current.column(), d->root);
}
case MovePageDown: {
- int newRow = qMin(rowAt(visualRect(current).bottom() + d->viewport->height()), bottom);
- if (newRow < 0)
- newRow = bottom;
- return d->model->index(qBound(0, newRow, bottom), current.column(), d->root);
+ int newRow = rowAt(visualRect(current).bottom() + d->viewport->height());
+ if (newRow == -1)
+ newRow = d->logicalRow(bottom);
+ return d->model->index(newRow, current.column(), d->root);
}}
int logicalRow = d->logicalRow(visualRow);
diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp
index eb39dd73e3..597e24a066 100644
--- a/tests/auto/qtableview/tst_qtableview.cpp
+++ b/tests/auto/qtableview/tst_qtableview.cpp
@@ -42,6 +42,7 @@
#include <QtGui/QtGui>
#include <QtTest/QtTest>
+#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=
@@ -177,6 +178,7 @@ private slots:
void task227953_setRootIndex();
void task240266_veryBigColumn();
void task248688_autoScrollNavigation();
+ void task259308_scrollVerticalHeaderSwappedSections();
void mouseWheel_data();
void mouseWheel();
@@ -3253,6 +3255,37 @@ void tst_QTableView::addColumnWhileEditing()
QCOMPARE(editor->geometry(), view.visualRect(last));
}
+void tst_QTableView::task259308_scrollVerticalHeaderSwappedSections()
+{
+ QStandardItemModel model;
+ model.setRowCount(50);
+ model.setColumnCount(2);
+ for (int row = 0; row < model.rowCount(); ++row)
+ for (int col = 0; col < model.columnCount(); ++col) {
+ const QModelIndex &idx = model.index(row, col);
+ model.setData(idx, QVariant(row), Qt::EditRole);
+ }
+
+ QTableView tv;
+ tv.setModel(&model);
+ tv.show();
+ tv.verticalHeader()->swapSections(0, model.rowCount() - 1);
+
+ QTest::qWait(60);
+ QTest::keyClick(&tv, Qt::Key_PageUp); // PageUp won't scroll when at top
+ QTRY_COMPARE(tv.rowAt(0), tv.verticalHeader()->logicalIndex(0));
+
+ int newRow = tv.rowAt(tv.viewport()->height());
+ if (newRow == tv.rowAt(tv.viewport()->height() - 1)) // Overlapping row
+ newRow++;
+ QTest::keyClick(&tv, Qt::Key_PageDown); // Scroll down and check current
+ QTRY_COMPARE(tv.currentIndex().row(), newRow);
+
+ tv.setCurrentIndex(model.index(0, 0));
+ QTest::qWait(60);
+ QTest::keyClick(&tv, Qt::Key_PageDown); // PageDown won't scroll when at the bottom
+ QTRY_COMPARE(tv.rowAt(tv.viewport()->height() - 1), tv.verticalHeader()->logicalIndex(model.rowCount() - 1));
+}
QTEST_MAIN(tst_QTableView)
#include "tst_qtableview.moc"