From 146b7a9c8bf4ca93488099a19853ca3a47df08cd Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 9 Aug 2012 14:49:38 +0200 Subject: [PATCH] Take scroll position into account when painting drag pixmap. Task-number: QTBUG-26793 Change-Id: Ic19cb6581cd5838d26713998e152772a5d12da4f Reviewed-by: David Faure Reviewed-by: Stephen Kelly --- src/widgets/itemviews/qlistview.cpp | 2 +- .../widgets/itemviews/qlistview/qlistview.pro | 2 +- .../itemviews/qlistview/tst_qlistview.cpp | 41 +++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 82792d5fef..14c6172869 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -654,7 +654,7 @@ QItemViewPaintPairs QListViewPrivate::draggablePaintPairs(const QModelIndexList QRect &rect = *r; const QRect viewportRect = viewport->rect(); QItemViewPaintPairs ret; - const QSet visibleIndexes = intersectingSet(viewportRect).toList().toSet(); + const QSet visibleIndexes = intersectingSet(viewportRect.translated(q->horizontalOffset(), q->verticalOffset())).toList().toSet(); for (int i = 0; i < indexes.count(); ++i) { const QModelIndex &index = indexes.at(i); if (visibleIndexes.contains(index)) { diff --git a/tests/auto/widgets/itemviews/qlistview/qlistview.pro b/tests/auto/widgets/itemviews/qlistview/qlistview.pro index 6820370cea..1fb5b7f767 100644 --- a/tests/auto/widgets/itemviews/qlistview/qlistview.pro +++ b/tests/auto/widgets/itemviews/qlistview/qlistview.pro @@ -1,6 +1,6 @@ CONFIG += testcase TARGET = tst_qlistview -QT += widgets gui-private testlib +QT += widgets gui-private widgets-private core-private testlib SOURCES += tst_qlistview.cpp win32:!wince*: LIBS += -luser32 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index a9169b0cbc..507a5f3308 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -133,6 +134,8 @@ private slots: void taskQTBUG_12308_wrongFlowLayout(); void taskQTBUG_21115_scrollToAndHiddenItems_data(); void taskQTBUG_21115_scrollToAndHiddenItems(); + void draggablePaintPairs_data(); + void draggablePaintPairs(); }; // Testing get/set functions @@ -2115,6 +2118,44 @@ void tst_QListView::taskQTBUG_21115_scrollToAndHiddenItems() QCOMPARE(lv.visualRect(index), firstItemRect); } +void tst_QListView::draggablePaintPairs_data() +{ + QTest::addColumn("row"); + + for (int row = 0; row < 30; ++row) + QTest::newRow("row-" + QByteArray::number(row)) << row; +} + +void tst_QListView::draggablePaintPairs() +{ + QFETCH(int, row); + + QListView view; + + QStringListModel model; + QStringList list; + for (int i = 0; i < 30; i++) + list << QString::number(i); + model.setStringList(list); + view.setModel(&model); + + view.show(); + QTest::qWaitForWindowExposed(&view); + + QModelIndex expectedIndex = model.index(row, 0); + QListViewPrivate *privateClass = static_cast(QListViewPrivate::get(&view)); + QRect rect; + QModelIndexList indexList; + indexList << expectedIndex; + view.scrollTo(expectedIndex); + QItemViewPaintPairs pairs = privateClass->draggablePaintPairs(indexList, &rect); + QCOMPARE(indexList.size(), pairs.size()); + foreach (const QItemViewPaintPair pair, pairs) { + QCOMPARE(rect, pair.first); + QCOMPARE(expectedIndex, pair.second); + } +} + QTEST_MAIN(tst_QListView) #include "tst_qlistview.moc"