diff options
author | Jani Honkonen <jani.honkonen@digia.com> | 2012-08-17 11:25:13 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-23 21:43:15 (GMT) |
commit | 98ed9ba14a91c941d48cc5c946c4df1d7ed47945 (patch) | |
tree | 68d410993161f6daedb40fe3038ea691493cce5a /tests/auto/qlistview | |
parent | b97d1e01c9c76a1ab87fc791dfb8c5708457286c (diff) | |
download | Qt-98ed9ba14a91c941d48cc5c946c4df1d7ed47945.zip Qt-98ed9ba14a91c941d48cc5c946c4df1d7ed47945.tar.gz Qt-98ed9ba14a91c941d48cc5c946c4df1d7ed47945.tar.bz2 |
Fix a QListViewItem width when spacing is set
The listitem width was calculated incorrectly because spacing was
not considered. This fixes the second part of the reported bug where
spacing is set. Added some tests to catch the issue relating to the
reported bug.
Also added a test to check spacing in general.
Backported from Qt5 commit:
d2bba5e5535726f277e8dc67b1478168f57b24bd
Task-number: QTBUG-21804
Change-Id: I20cae3a2b9d42650052441f9f15b43f72418f58b
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'tests/auto/qlistview')
-rw-r--r-- | tests/auto/qlistview/tst_qlistview.cpp | 80 |
1 files changed, 76 insertions, 4 deletions
diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp index a97296f..155ace9 100644 --- a/tests/auto/qlistview/tst_qlistview.cpp +++ b/tests/auto/qlistview/tst_qlistview.cpp @@ -132,6 +132,8 @@ private slots: void taskQTBUG_21115_scrollToAndHiddenItems(); void taskQTBUG_21804_hiddenItemsAndScrollingWithKeys_data(); void taskQTBUG_21804_hiddenItemsAndScrollingWithKeys(); + void spacing_data(); + void spacing(); }; // Testing get/set functions @@ -2113,13 +2115,17 @@ void tst_QListView::taskQTBUG_21115_scrollToAndHiddenItems() void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys_data() { QTest::addColumn<int>("flow"); - QTest::newRow("flow TopToBottom") << static_cast<int>(QListView::TopToBottom); - QTest::newRow("flow LeftToRight") << static_cast<int>(QListView::LeftToRight); + QTest::addColumn<int>("spacing"); + QTest::newRow("flow TopToBottom no spacing") << static_cast<int>(QListView::TopToBottom) << 0; + QTest::newRow("flow TopToBottom with spacing") << static_cast<int>(QListView::TopToBottom) << 5; + QTest::newRow("flow LeftToRight no spacing") << static_cast<int>(QListView::LeftToRight) << 0; + QTest::newRow("flow LeftToRight with spacing") << static_cast<int>(QListView::LeftToRight) << 5; } void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys() { QFETCH(int, flow); + QFETCH(int, spacing); // create some items to show QStringListModel model; @@ -2131,6 +2137,7 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys() // create listview QListView lv; lv.setFlow(static_cast<QListView::Flow>(flow)); + lv.setSpacing(spacing); lv.setModel(&model); lv.show(); QTest::qWaitForWindowShown(&lv); @@ -2140,7 +2147,8 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys() lv.setRowHidden(i, true); // scroll forward and check that selected item is visible always - for (int i = 0; i < model.rowCount()/2; i++) { + int visibleItemCount = model.rowCount()/2; + for (int i = 0; i < visibleItemCount; i++) { if (flow == QListView::TopToBottom) QTest::keyClick(&lv, Qt::Key_Down); else @@ -2150,7 +2158,27 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys() } // scroll backward - for (int i = 0; i < model.rowCount()/2; i++) { + for (int i = 0; i < visibleItemCount; i++) { + if (flow == QListView::TopToBottom) + QTest::keyClick(&lv, Qt::Key_Up); + else + QTest::keyClick(&lv, Qt::Key_Left); + QTest::qWait(100); + QVERIFY(lv.rect().contains(lv.visualRect(lv.currentIndex()))); + } + + // scroll forward only half way + for (int i = 0; i < visibleItemCount/2; i++) { + if (flow == QListView::TopToBottom) + QTest::keyClick(&lv, Qt::Key_Down); + else + QTest::keyClick(&lv, Qt::Key_Right); + QTest::qWait(100); + QVERIFY(lv.rect().contains(lv.visualRect(lv.currentIndex()))); + } + + // scroll backward again + for (int i = 0; i < visibleItemCount/2; i++) { if (flow == QListView::TopToBottom) QTest::keyClick(&lv, Qt::Key_Up); else @@ -2160,5 +2188,49 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys() } } +void tst_QListView::spacing_data() +{ + QTest::addColumn<int>("flow"); + QTest::addColumn<int>("spacing"); + QTest::newRow("flow=TopToBottom spacing=0") << static_cast<int>(QListView::TopToBottom) << 0; + QTest::newRow("flow=TopToBottom spacing=10") << static_cast<int>(QListView::TopToBottom) << 10; + QTest::newRow("flow=LeftToRight spacing=0") << static_cast<int>(QListView::LeftToRight) << 0; + QTest::newRow("flow=LeftToRight spacing=10") << static_cast<int>(QListView::LeftToRight) << 10; +} + +void tst_QListView::spacing() +{ + QFETCH(int, flow); + QFETCH(int, spacing); + + // create some items to show + QStringListModel model; + QStringList list; + for (int i = 0; i < 60; i++) + list << QString::number(i); + model.setStringList(list); + + // create listview + QListView lv; + lv.setFlow(static_cast<QListView::Flow>(flow)); + lv.setModel(&model); + lv.setSpacing(spacing); + lv.show(); + QTest::qWaitForWindowShown(&lv); + + // check size and position of first two items + QRect item1 = lv.visualRect(lv.model()->index(0, 0)); + QRect item2 = lv.visualRect(lv.model()->index(1, 0)); + QCOMPARE(item1.topLeft(), QPoint(flow == QListView::TopToBottom ? spacing : 0, spacing)); + if (flow == QListView::TopToBottom) { + QCOMPARE(item1.width(), lv.viewport()->width() - 2 * spacing); + QCOMPARE(item2.topLeft(), QPoint(spacing, spacing + item1.height() + 2 * spacing)); + } + else { // QListView::LeftToRight + QCOMPARE(item1.height(), lv.viewport()->height() - 2 * spacing); + QCOMPARE(item2.topLeft(), QPoint(spacing + item1.width() + spacing, spacing)); + } +} + QTEST_MAIN(tst_QListView) #include "tst_qlistview.moc" |