summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2013-04-16 17:53:46 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-23 14:03:07 +0200
commite36e83b5e65a703058ec5a4e4418fe6a49d73e2c (patch)
tree1dc62cdb9be3b05fcc47dfd884d78c72127f394f
parentdc5db85ca4f95a0cfe682d90693d05a74af63f55 (diff)
downloadqt4-tools-e36e83b5e65a703058ec5a4e4418fe6a49d73e2c.tar.gz
Fix QTableView::doItemsLayout()
Keep the content aligned to the bottom when the view has been scrolled to the bottom and the content is relayouted (for example due to sorting). Task-number: QTBUG-30653 (cherry-picked from qtbase commit 00b11ccdead05d77589d4ec5ebb3b376c6ae2ca1) Change-Id: I183145fbd84339e82d2d1d0bc39cea33d9cc9734 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com> Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
-rw-r--r--src/gui/itemviews/qtableview.cpp11
-rw-r--r--tests/auto/qtableview/tst_qtableview.cpp34
2 files changed, 42 insertions, 3 deletions
diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp
index 13ce309a73..63036b2680 100644
--- a/src/gui/itemviews/qtableview.cpp
+++ b/src/gui/itemviews/qtableview.cpp
@@ -1108,10 +1108,15 @@ void QTableView::doItemsLayout()
{
Q_D(QTableView);
QAbstractItemView::doItemsLayout();
- if (verticalScrollMode() == QAbstractItemView::ScrollPerItem)
- d->verticalHeader->setOffsetToSectionPosition(verticalScrollBar()->value());
- else
+ if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
+ const int max = verticalScrollBar()->maximum();
+ if (max > 0 && verticalScrollBar()->value() == max)
+ d->verticalHeader->setOffsetToLastSection();
+ else
+ d->verticalHeader->setOffsetToSectionPosition(verticalScrollBar()->value());
+ } else {
d->verticalHeader->setOffset(verticalScrollBar()->value());
+ }
if (!d->verticalHeader->updatesEnabled())
d->verticalHeader->setUpdatesEnabled(true);
}
diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp
index 73cb3792a8..1939b61622 100644
--- a/tests/auto/qtableview/tst_qtableview.cpp
+++ b/tests/auto/qtableview/tst_qtableview.cpp
@@ -203,6 +203,7 @@ private slots:
void taskQTBUG_7774_RtoLVisualRegionForSelection();
void taskQTBUG_8777_scrollToSpans();
void taskQTBUG_10169_sizeHintForRow();
+ void taskQTBUG_30653_doItemsLayout();
void mouseWheel_data();
void mouseWheel();
@@ -4069,5 +4070,38 @@ void tst_QTableView::taskQTBUG_10169_sizeHintForRow()
QCOMPARE(orderedHeight, reorderedHeight);
}
+void tst_QTableView::taskQTBUG_30653_doItemsLayout()
+{
+ QWidget topLevel;
+ QtTestTableView view(&topLevel);
+
+ QtTestTableModel model(5, 5);
+ view.setModel(&model);
+
+ QtTestItemDelegate delegate;
+ delegate.hint = QSize(50, 50);
+ view.setItemDelegate(&delegate);
+
+ view.resizeRowsToContents();
+ view.resizeColumnsToContents();
+
+ // show two and half rows/cols
+ int extraWidth = view.verticalHeader()->sizeHint().width() + view.verticalScrollBar()->sizeHint().width();
+ int extraHeight = view.horizontalHeader()->sizeHint().height() + view.horizontalScrollBar()->sizeHint().height();
+ view.resize(125 + extraWidth, 125 + extraHeight);
+
+ topLevel.show();
+ QVERIFY(QTest::qWaitForWindowShown(&topLevel));
+
+ // the offset after scrollToBottom() and doItemsLayout() should not differ
+ // as the view content should stay aligned to the last section
+ view.scrollToBottom();
+ int scrollToBottomOffset = view.verticalHeader()->offset();
+ view.doItemsLayout();
+ int doItemsLayoutOffset = view.verticalHeader()->offset();
+
+ QCOMPARE(scrollToBottomOffset, doItemsLayoutOffset);
+}
+
QTEST_MAIN(tst_QTableView)
#include "tst_qtableview.moc"