tests/auto/qlistview/tst_qlistview.cpp
branchRCL_3
changeset 8 3f74d0d4af4c
parent 4 3b1da2848fc7
equal deleted inserted replaced
6:dee5afe5301f 8:3f74d0d4af4c
   604     view2.setFlow(QListView::TopToBottom);
   604     view2.setFlow(QListView::TopToBottom);
   605     view2.setViewMode(QListView::ListMode);
   605     view2.setViewMode(QListView::ListMode);
   606     view2.setWrapping(true);
   606     view2.setWrapping(true);
   607     // We really want to make sure it is shown, because the layout won't be known until it is shown
   607     // We really want to make sure it is shown, because the layout won't be known until it is shown
   608     view2.show();
   608     view2.show();
   609     for (int i = 0; i < 5 && !view2.m_shown; ++i) {
   609     QTest::qWaitForWindowShown(&view2);
   610         QTest::qWait(500);
   610     QTRY_VERIFY(view2.m_shown);
   611     }
       
   612 
   611 
   613     QVERIFY(view2.m_index.isValid());
   612     QVERIFY(view2.m_index.isValid());
   614     QVERIFY(view2.m_index.row() != 0);
   613     QVERIFY(view2.m_index.row() != 0);
   615 }
   614 }
   616 
   615 
   758     QListView view;
   757     QListView view;
   759     view.setModel(&model);
   758     view.setModel(&model);
   760     view.setUniformItemSizes(true);
   759     view.setUniformItemSizes(true);
   761     view.setRowHidden(0,true);
   760     view.setRowHidden(0,true);
   762     view.show();
   761     view.show();
   763     QTest::qWait(100);
   762     QTest::qWaitForWindowShown(&view);
       
   763     QTest::qWait(10);
   764 }
   764 }
   765 
   765 
   766 void tst_QListView::batchedMode()
   766 void tst_QListView::batchedMode()
   767 {
   767 {
   768     QStringList items;
   768     QStringList items;
   776     view.setViewMode(QListView::ListMode);
   776     view.setViewMode(QListView::ListMode);
   777     view.setLayoutMode(QListView::Batched);
   777     view.setLayoutMode(QListView::Batched);
   778     view.setBatchSize(2);
   778     view.setBatchSize(2);
   779     view.resize(200,400);
   779     view.resize(200,400);
   780     view.show();
   780     view.show();
   781 
   781     QTest::qWaitForWindowShown(&view);
   782 #if !defined(Q_OS_WINCE)
       
   783     QTest::qWait(100);
   782     QTest::qWait(100);
   784 #else
   783 
       
   784 #if defined(Q_OS_WINCE)
   785     QTest::qWait(2000);
   785     QTest::qWait(2000);
   786 #endif
   786 #endif
   787     QBitArray ba;
   787     QBitArray ba;
   788     for (int y = 0; y < view.height(); ++y) {
   788     for (int y = 0; y < view.height(); ++y) {
   789         QModelIndex idx = view.indexAt( QPoint(1, y) );
   789         QModelIndex idx = view.indexAt( QPoint(1, y) );
  1201     QVERIFY(itemsize.width() > lv.width());
  1201     QVERIFY(itemsize.width() > lv.width());
  1202 
  1202 
  1203     //we click the item
  1203     //we click the item
  1204     QPoint p = lv.visualRect(index).center();
  1204     QPoint p = lv.visualRect(index).center();
  1205     QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
  1205     QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
  1206     //let's wait 1 second because the scrolling is delayed
  1206     //let's wait because the scrolling is delayed
  1207     QTest::qWait(1000);
  1207     QTest::qWait(QApplication::doubleClickInterval() + 150);
  1208     QCOMPARE(lv.visualRect(index).y(),0);
  1208     QTRY_COMPARE(lv.visualRect(index).y(),0);
  1209 
  1209 
  1210     //we scroll down. As the item is to tall for the view, it will disappear
  1210     //we scroll down. As the item is to tall for the view, it will disappear
  1211     QTest::keyClick(lv.viewport(), Qt::Key_Down, Qt::NoModifier);
  1211     QTest::keyClick(lv.viewport(), Qt::Key_Down, Qt::NoModifier);
  1212     QCOMPARE(lv.visualRect(index).y(), -itemsize.height());
  1212     QCOMPARE(lv.visualRect(index).y(), -itemsize.height());
  1213 
  1213 
  1220     lv.horizontalScrollBar()->setValue(0); //let's scroll to the beginning
  1220     lv.horizontalScrollBar()->setValue(0); //let's scroll to the beginning
  1221 
  1221 
  1222     //we click the item
  1222     //we click the item
  1223     p = lv.visualRect(index).center();
  1223     p = lv.visualRect(index).center();
  1224     QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
  1224     QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
  1225     //let's wait 1 second because the scrolling is delayed
  1225     //let's wait because the scrolling is delayed
  1226     QTest::qWait(1000);
  1226     QTest::qWait(QApplication::doubleClickInterval() + 150);
  1227     QCOMPARE(lv.visualRect(index).x(),0);
  1227     QTRY_COMPARE(lv.visualRect(index).x(),0);
  1228 
  1228 
  1229     //we scroll right. As the item is too wide for the view, it will disappear
  1229     //we scroll right. As the item is too wide for the view, it will disappear
  1230     QTest::keyClick(lv.viewport(), Qt::Key_Right, Qt::NoModifier);
  1230     QTest::keyClick(lv.viewport(), Qt::Key_Right, Qt::NoModifier);
  1231     QCOMPARE(lv.visualRect(index).x(), -itemsize.width());
  1231     QCOMPARE(lv.visualRect(index).x(), -itemsize.width());
  1232 
  1232 
  1241     lv.verticalScrollBar()->setValue(0); //scrolls back to the first item
  1241     lv.verticalScrollBar()->setValue(0); //scrolls back to the first item
  1242 
  1242 
  1243     //we click the item
  1243     //we click the item
  1244     p = lv.visualRect(index).center();
  1244     p = lv.visualRect(index).center();
  1245     QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
  1245     QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
  1246     //let's wait 1 second because the scrolling is delayed
  1246     //let's wait because the scrolling is delayed
  1247     QTest::qWait(1000);
  1247     QTest::qWait(QApplication::doubleClickInterval() + 150);
  1248     QCOMPARE(lv.visualRect(index).y(),0);
  1248     QTRY_COMPARE(lv.visualRect(index).y(),0);
  1249 
  1249 
  1250     //we scroll down. As the item is too tall for the view, it will partially disappear
  1250     //we scroll down. As the item is too tall for the view, it will partially disappear
  1251     QTest::keyClick(lv.viewport(), Qt::Key_Down, Qt::NoModifier);
  1251     QTest::keyClick(lv.viewport(), Qt::Key_Down, Qt::NoModifier);
  1252     QVERIFY(lv.visualRect(index).y()<0);
  1252     QVERIFY(lv.visualRect(index).y()<0);
  1253 
  1253 
  1275     lv.setItemDelegate(delegate);
  1275     lv.setItemDelegate(delegate);
  1276     lv.show();
  1276     lv.show();
  1277 
  1277 
  1278     for (int h = 30; h <= 210; ++h) {
  1278     for (int h = 30; h <= 210; ++h) {
  1279         lv.resize(250, h);
  1279         lv.resize(250, h);
  1280         QTest::qWait(100); // wait for the layout to be done
  1280         QApplication::processEvents(); // wait for the layout to be done
  1281         int visibleRowCount = lv.viewport()->size().height() / rowHeight;
  1281         int visibleRowCount = lv.viewport()->size().height() / rowHeight;
  1282         int invisibleRowCount = rowCount - visibleRowCount;
  1282         int invisibleRowCount = rowCount - visibleRowCount;
  1283         QCOMPARE(lv.verticalScrollBar()->maximum(), invisibleRowCount);
  1283         QCOMPARE(lv.verticalScrollBar()->maximum(), invisibleRowCount);
  1284     }
  1284     }
  1285 }
  1285 }
  1364         for (i = 0; i < rowCounts[r]; ++i)
  1364         for (i = 0; i < rowCounts[r]; ++i)
  1365             list << QString::fromAscii("Item %1").arg(i);
  1365             list << QString::fromAscii("Item %1").arg(i);
  1366 
  1366 
  1367         model.setStringList(list);
  1367         model.setStringList(list);
  1368         QApplication::processEvents();
  1368         QApplication::processEvents();
  1369         QTest::qWait(100);
  1369         QTest::qWait(50);
  1370 
  1370 
  1371         QStringList replacement;
  1371         QStringList replacement;
  1372         for (i = 0; i < itemCount; ++i) {
  1372         for (i = 0; i < itemCount; ++i) {
  1373             replacement << QString::fromAscii("Item %1").arg(i);
  1373             replacement << QString::fromAscii("Item %1").arg(i);
  1374         }
  1374         }
  1375         model.setStringList(replacement);
  1375         model.setStringList(replacement);
  1376 
  1376 
  1377         QApplication::processEvents();
  1377         QApplication::processEvents();
  1378         QTest::qWait(100);
  1378 
  1379 
  1379         QTRY_COMPARE(lv.horizontalScrollBar()->isVisible(), horizontalScrollBarVisible);
  1380         QCOMPARE(lv.horizontalScrollBar()->isVisible(), horizontalScrollBarVisible);
  1380         QTRY_COMPARE(lv.verticalScrollBar()->isVisible(), verticalScrollBarVisible);
  1381         QCOMPARE(lv.verticalScrollBar()->isVisible(), verticalScrollBarVisible);
       
  1382     }
  1381     }
  1383 }
  1382 }
  1384 
  1383 
  1385 void tst_QListView::moveItems()
  1384 void tst_QListView::moveItems()
  1386 {
  1385 {
  1431     lv.setModel(&model);
  1430     lv.setModel(&model);
  1432     lv.setWordWrap(true);
  1431     lv.setWordWrap(true);
  1433     lv.setFixedSize(150, 150);
  1432     lv.setFixedSize(150, 150);
  1434     lv.show();
  1433     lv.show();
  1435     QApplication::processEvents();
  1434     QApplication::processEvents();
  1436     QTest::qWait(100);
  1435 
  1437 
  1436     QTRY_COMPARE(lv.horizontalScrollBar()->isVisible(), false);
  1438     QCOMPARE(lv.horizontalScrollBar()->isVisible(), false);
  1437     QTRY_COMPARE(lv.verticalScrollBar()->isVisible(), true);
  1439     QCOMPARE(lv.verticalScrollBar()->isVisible(), true);
       
  1440 }
  1438 }
  1441 
  1439 
  1442 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
  1440 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
  1443 class SetCurrentIndexAfterAppendRowCrashDialog : public QDialog
  1441 class SetCurrentIndexAfterAppendRowCrashDialog : public QDialog
  1444 {
  1442 {
  1555     QListView view;
  1553     QListView view;
  1556     view.setViewMode(QListView::IconMode);
  1554     view.setViewMode(QListView::IconMode);
  1557     QStringListModel model(QStringList() << QLatin1String("item1") << QString());
  1555     QStringListModel model(QStringList() << QLatin1String("item1") << QString());
  1558     view.setModel(&model);
  1556     view.setModel(&model);
  1559     view.show();
  1557     view.show();
  1560     QTest::qWait(100);
  1558     QTest::qWaitForWindowShown(&view);
       
  1559     QTest::qWait(20);
  1561 }
  1560 }
  1562 
  1561 
  1563 void tst_QListView::task250446_scrollChanged()
  1562 void tst_QListView::task250446_scrollChanged()
  1564 {
  1563 {
  1565     QStandardItemModel model(200, 1);
  1564     QStandardItemModel model(200, 1);
  1567     view.setModel(&model);
  1566     view.setModel(&model);
  1568     QModelIndex index = model.index(0, 0);
  1567     QModelIndex index = model.index(0, 0);
  1569     QVERIFY(index.isValid());
  1568     QVERIFY(index.isValid());
  1570     view.setCurrentIndex(index);
  1569     view.setCurrentIndex(index);
  1571     view.show();
  1570     view.show();
  1572     QTest::qWait(100);
  1571     QTest::qWaitForWindowShown(&view);
  1573     const int scrollValue = view.verticalScrollBar()->maximum();
  1572     const int scrollValue = view.verticalScrollBar()->maximum();
  1574     view.verticalScrollBar()->setValue(scrollValue);
  1573     view.verticalScrollBar()->setValue(scrollValue);
  1575     QCOMPARE(view.verticalScrollBar()->value(), scrollValue);
  1574     QCOMPARE(view.verticalScrollBar()->value(), scrollValue);
  1576     QCOMPARE(view.currentIndex(), index);
  1575     QCOMPARE(view.currentIndex(), index);
  1577 
  1576 
  1578     view.showMinimized();
  1577     view.showMinimized();
  1579     QTest::qWait(100);
  1578     QTest::qWait(50);
  1580     QCOMPARE(view.verticalScrollBar()->value(), scrollValue);
  1579     QTRY_COMPARE(view.verticalScrollBar()->value(), scrollValue);
  1581     QCOMPARE(view.currentIndex(), index);
  1580     QTRY_COMPARE(view.currentIndex(), index);
  1582 
  1581 
  1583     view.showNormal();
  1582     view.showNormal();
  1584     QTest::qWait(100);
  1583     QTest::qWait(50);
  1585     QCOMPARE(view.verticalScrollBar()->value(), scrollValue);
  1584     QTRY_COMPARE(view.verticalScrollBar()->value(), scrollValue);
  1586     QCOMPARE(view.currentIndex(), index);
  1585     QTRY_COMPARE(view.currentIndex(), index);
  1587 }
  1586 }
  1588 
  1587 
  1589 void tst_QListView::task196118_visualRegionForSelection()
  1588 void tst_QListView::task196118_visualRegionForSelection()
  1590 {
  1589 {
  1591     class MyListView : public QListView
  1590     class MyListView : public QListView
  1697         view.setGridSize(QSize(100, 100));
  1696         view.setGridSize(QSize(100, 100));
  1698         view.setSelectionMode(QListView::ExtendedSelection);
  1697         view.setSelectionMode(QListView::ExtendedSelection);
  1699         view.setViewMode(QListView::IconMode);
  1698         view.setViewMode(QListView::IconMode);
  1700         view.setModel(&model);
  1699         view.setModel(&model);
  1701         view.show();
  1700         view.show();
  1702         QTest::qWait(30);
  1701         QTest::qWaitForWindowShown(&view);
  1703 
  1702 
  1704         // Verfify that item sizes are non-uniform
  1703         // Verfify that item sizes are non-uniform
  1705         QVERIFY(view.sizeHintForIndex(model.index(0, 0)).height() > view.sizeHintForIndex(model.index(1, 0)).height());
  1704         QVERIFY(view.sizeHintForIndex(model.index(0, 0)).height() > view.sizeHintForIndex(model.index(1, 0)).height());
  1706 
  1705 
  1707         QModelIndex index = model.index(3, 0);
  1706         QModelIndex index = model.index(3, 0);
  1727         view.setGridSize(QSize(100, 100));
  1726         view.setGridSize(QSize(100, 100));
  1728         view.setSelectionMode(QListView::ExtendedSelection);
  1727         view.setSelectionMode(QListView::ExtendedSelection);
  1729         view.setViewMode(QListView::IconMode);
  1728         view.setViewMode(QListView::IconMode);
  1730         view.setModel(&model);
  1729         view.setModel(&model);
  1731         view.show();
  1730         view.show();
  1732         QTest::qWait(30);
  1731         QTest::qWaitForWindowShown(&view);
  1733 
  1732 
  1734         // Verfify that item sizes are non-uniform
  1733         // Verfify that item sizes are non-uniform
  1735         QVERIFY(view.sizeHintForIndex(model.index(0, 0)).width() > view.sizeHintForIndex(model.index(1, 0)).width());
  1734         QVERIFY(view.sizeHintForIndex(model.index(0, 0)).width() > view.sizeHintForIndex(model.index(1, 0)).width());
  1736 
  1735 
  1737         QModelIndex index = model.index(3, 0);
  1736         QModelIndex index = model.index(3, 0);
  1787     view.setModelColumn(1);
  1786     view.setModelColumn(1);
  1788 
  1787 
  1789     view.show();
  1788     view.show();
  1790     QApplication::setActiveWindow(&view);
  1789     QApplication::setActiveWindow(&view);
  1791     QTest::qWaitForWindowShown(&view);
  1790     QTest::qWaitForWindowShown(&view);
  1792     QTest::qWait(30);
       
  1793     QTRY_COMPARE(static_cast<QWidget *>(&view), QApplication::activeWindow());
  1791     QTRY_COMPARE(static_cast<QWidget *>(&view), QApplication::activeWindow());
  1794     QTest::keyClick(&view, Qt::Key_Down);
  1792     QTest::keyClick(&view, Qt::Key_Down);
  1795     QTest::qWait(30);
  1793     QTest::qWait(30);
  1796     QTRY_COMPARE(view.currentIndex(), model.index(1,1));
  1794     QTRY_COMPARE(view.currentIndex(), model.index(1,1));
  1797     QTest::keyClick(&view, Qt::Key_Down);
  1795     QTest::keyClick(&view, Qt::Key_Down);
  1832             : view.horizontalScrollBar())->setValue(i);
  1830             : view.horizontalScrollBar())->setValue(i);
  1833         QModelIndex index = view.indexAt(QPoint(0,0));
  1831         QModelIndex index = view.indexAt(QPoint(0,0));
  1834         QVERIFY(index.isValid());
  1832         QVERIFY(index.isValid());
  1835         QCOMPARE(index.row(), 2 * i + 1);
  1833         QCOMPARE(index.row(), 2 * i + 1);
  1836     }
  1834     }
       
  1835 
       
  1836     //QTBUG-7929  should not crash
       
  1837     view.show();
       
  1838     QTest::qWaitForWindowShown(&view);
       
  1839     QScrollBar *bar = view.flow() == QListView::TopToBottom
       
  1840             ? view.verticalScrollBar() : view.horizontalScrollBar();
       
  1841 
       
  1842     int nbVisibleItem = rowCount / 2 - bar->maximum();
       
  1843 
       
  1844     bar->setValue(bar->maximum());
       
  1845     QApplication::processEvents();
       
  1846     for (int i = rowCount; i > rowCount / 2; i--) {
       
  1847         view.setRowHidden(i, true);
       
  1848     }
       
  1849     QApplication::processEvents();
       
  1850     QTest::qWait(50);
       
  1851     QCOMPARE(bar->value(), bar->maximum());
       
  1852     QCOMPARE(bar->maximum(), rowCount/4 - nbVisibleItem);
  1837 }
  1853 }
  1838 
  1854 
  1839 void tst_QListView::taskQTBUG_633_changeModelData()
  1855 void tst_QListView::taskQTBUG_633_changeModelData()
  1840 {
  1856 {
  1841     QListView view;
  1857     QListView view;