43 #include <QtTest/QtTest> |
43 #include <QtTest/QtTest> |
44 |
44 |
45 #include <qabstractitemmodel.h> |
45 #include <qabstractitemmodel.h> |
46 #include <qapplication.h> |
46 #include <qapplication.h> |
47 #include <qlistview.h> |
47 #include <qlistview.h> |
|
48 #include <qlistwidget.h> |
48 #include <qitemdelegate.h> |
49 #include <qitemdelegate.h> |
49 #include <qstandarditemmodel.h> |
50 #include <qstandarditemmodel.h> |
50 #include <qstringlistmodel.h> |
51 #include <qstringlistmodel.h> |
51 #ifndef Q_OS_SYMBIAN |
52 #ifndef Q_OS_SYMBIAN |
52 #include <cmath> |
53 #include <cmath> |
123 void taskQTBUG_435_deselectOnViewportClick(); |
124 void taskQTBUG_435_deselectOnViewportClick(); |
124 void taskQTBUG_2678_spacingAndWrappedText(); |
125 void taskQTBUG_2678_spacingAndWrappedText(); |
125 void taskQTBUG_5877_skippingItemInPageDownUp(); |
126 void taskQTBUG_5877_skippingItemInPageDownUp(); |
126 void taskQTBUG_9455_wrongScrollbarRanges(); |
127 void taskQTBUG_9455_wrongScrollbarRanges(); |
127 void styleOptionViewItem(); |
128 void styleOptionViewItem(); |
|
129 void taskQTBUG_12308_artihmeticException(); |
|
130 void taskQTBUG_12308_wrongFlowLayout(); |
128 }; |
131 }; |
129 |
132 |
130 // Testing get/set functions |
133 // Testing get/set functions |
131 void tst_QListView::getSetCheck() |
134 void tst_QListView::getSetCheck() |
132 { |
135 { |
1651 list.setPositionForIndex(topLeft, index); |
1654 list.setPositionForIndex(topLeft, index); |
1652 |
1655 |
1653 //we'll make sure the item is repainted |
1656 //we'll make sure the item is repainted |
1654 delegate.numPaints = 0; |
1657 delegate.numPaints = 0; |
1655 QApplication::processEvents(); |
1658 QApplication::processEvents(); |
|
1659 QTRY_COMPARE(delegate.numPaints, 1); |
1656 QCOMPARE(list.visualRect(index).topLeft(), topLeft); |
1660 QCOMPARE(list.visualRect(index).topLeft(), topLeft); |
1657 QCOMPARE(delegate.numPaints, 1); |
|
1658 } |
1661 } |
1659 |
1662 |
1660 |
1663 |
1661 void tst_QListView::keyboardSearch() |
1664 void tst_QListView::keyboardSearch() |
1662 { |
1665 { |
2000 // Run test |
2003 // Run test |
2001 view.showMaximized(); |
2004 view.showMaximized(); |
2002 QApplication::processEvents(); |
2005 QApplication::processEvents(); |
2003 } |
2006 } |
2004 |
2007 |
|
2008 void tst_QListView::taskQTBUG_12308_artihmeticException() |
|
2009 { |
|
2010 QListWidget lw; |
|
2011 lw.setLayoutMode(QListView::Batched); |
|
2012 lw.setViewMode(QListView::IconMode); |
|
2013 for (int i = 0; i < lw.batchSize() + 1; i++) { |
|
2014 QListWidgetItem *item = new QListWidgetItem(); |
|
2015 item->setText(QString("Item %L1").arg(i)); |
|
2016 lw.addItem(item); |
|
2017 item->setHidden(true); |
|
2018 } |
|
2019 lw.show(); |
|
2020 QTest::qWaitForWindowShown(&lw); |
|
2021 // No crash, it's all right. |
|
2022 } |
|
2023 |
|
2024 class Delegate12308 : public QStyledItemDelegate |
|
2025 { |
|
2026 Q_OBJECT |
|
2027 public: |
|
2028 Delegate12308(QObject *parent = 0) : QStyledItemDelegate(parent) |
|
2029 { } |
|
2030 |
|
2031 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
|
2032 { |
|
2033 QVERIFY(option.rect.topLeft() != QPoint(-1, -1)); |
|
2034 QStyledItemDelegate::paint(painter, option, index); |
|
2035 } |
|
2036 }; |
|
2037 |
|
2038 void tst_QListView::taskQTBUG_12308_wrongFlowLayout() |
|
2039 { |
|
2040 QListWidget lw; |
|
2041 Delegate12308 delegate; |
|
2042 lw.setLayoutMode(QListView::Batched); |
|
2043 lw.setViewMode(QListView::IconMode); |
|
2044 lw.setItemDelegate(&delegate); |
|
2045 for (int i = 0; i < lw.batchSize() + 1; i++) { |
|
2046 QListWidgetItem *item = new QListWidgetItem(); |
|
2047 item->setText(QString("Item %L1").arg(i)); |
|
2048 lw.addItem(item); |
|
2049 if (!item->text().contains(QString::fromAscii("1"))) |
|
2050 item->setHidden(true); |
|
2051 } |
|
2052 lw.show(); |
|
2053 QTest::qWaitForWindowShown(&lw); |
|
2054 } |
|
2055 |
2005 QTEST_MAIN(tst_QListView) |
2056 QTEST_MAIN(tst_QListView) |
2006 #include "tst_qlistview.moc" |
2057 #include "tst_qlistview.moc" |