Take scroll position into account when painting drag pixmap.

Task-number: QTBUG-26793

Change-Id: Ic19cb6581cd5838d26713998e152772a5d12da4f
Reviewed-by: David Faure <faure@kde.org>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Stephen Kelly 2012-08-09 14:49:38 +02:00 committed by Qt by Nokia
parent 59cd316d6c
commit 146b7a9c8b
3 changed files with 43 additions and 2 deletions

View File

@ -654,7 +654,7 @@ QItemViewPaintPairs QListViewPrivate::draggablePaintPairs(const QModelIndexList
QRect &rect = *r;
const QRect viewportRect = viewport->rect();
QItemViewPaintPairs ret;
const QSet<QModelIndex> visibleIndexes = intersectingSet(viewportRect).toList().toSet();
const QSet<QModelIndex> 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)) {

View File

@ -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

View File

@ -45,6 +45,7 @@
#include <qabstractitemmodel.h>
#include <qapplication.h>
#include <qlistview.h>
#include <private/qlistview_p.h>
#include <qlistwidget.h>
#include <qitemdelegate.h>
#include <qstandarditemmodel.h>
@ -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<int>("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 *>(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"