summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-07-26 18:51:32 (GMT)
committerSamuli Piippo <samuli.piippo@digia.com>2011-06-09 10:06:36 (GMT)
commite4a3da5e3af84e3c576718236c490feac3f31703 (patch)
tree6931b4c0b114adbed612ebbfa8da486713225e65
parent9914df6e8f032f543c153fa219a5da0911f8b952 (diff)
downloadQt-e4a3da5e3af84e3c576718236c490feac3f31703.zip
Qt-e4a3da5e3af84e3c576718236c490feac3f31703.tar.gz
Qt-e4a3da5e3af84e3c576718236c490feac3f31703.tar.bz2
Fix crash when all the items in a QListView are hidden
Calling QIconModeViewBase::initDynamicLayout() on the second and successive segments would return QPoint(-1,-1), resulting in a totally empty area rectangle for all the items while in QIconModeViewBase::doDynamicLayout(). This rectangle is used to initialize the BSP tree, and produces an arithmetic exception when empty. Furthermore, a rendering bug was also apparent when displaying the first item of a segment while the last item of the previous segment was hidden. Auto-tests included. Reviewed-by: Olivier Task-number: QTBUG-12308 (cherry picked from commit 3c7e7992461b1fef37ada68244f1b5b891015bda)
-rw-r--r--src/gui/itemviews/qlistview.cpp7
-rw-r--r--tests/auto/qlistview/tst_qlistview.cpp51
2 files changed, 57 insertions, 1 deletions
diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp
index 1dc3ff5..8f06fb7 100644
--- a/src/gui/itemviews/qlistview.cpp
+++ b/src/gui/itemviews/qlistview.cpp
@@ -2773,7 +2773,10 @@ QPoint QIconModeViewBase::initDynamicLayout(const QListViewLayoutInfo &info)
y = info.bounds.y() + info.spacing;
items.reserve(rowCount() - hiddenCount());
} else {
- const QListViewItem item = items.at(info.first - 1);
+ int idx = info.first - 1;
+ while (idx > 0 && !items.at(idx).isValid())
+ --idx;
+ const QListViewItem &item = items.at(idx);
x = item.x;
y = item.y;
if (info.flow == QListView::LeftToRight)
@@ -2899,6 +2902,8 @@ void QIconModeViewBase::doDynamicLayout(const QListViewLayoutInfo &info)
// resize the content area
if (done || !info.bounds.contains(item->rect()))
contentsSize = QSize(rect.width(), rect.height());
+ if (rect.size().isEmpty())
+ return;
// resize tree
int insertFrom = info.first;
if (done || info.first == 0) {
diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp
index c9be046..0ca254d 100644
--- a/tests/auto/qlistview/tst_qlistview.cpp
+++ b/tests/auto/qlistview/tst_qlistview.cpp
@@ -45,6 +45,7 @@
#include <qabstractitemmodel.h>
#include <qapplication.h>
#include <qlistview.h>
+#include <qlistwidget.h>
#include <qitemdelegate.h>
#include <qstandarditemmodel.h>
#include <qstringlistmodel.h>
@@ -123,6 +124,8 @@ private slots:
void taskQTBUG_435_deselectOnViewportClick();
void taskQTBUG_2678_spacingAndWrappedText();
void taskQTBUG_5877_skippingItemInPageDownUp();
+ void taskQTBUG_12308_artihmeticException();
+ void taskQTBUG_12308_wrongFlowLayout();
};
// Testing get/set functions
@@ -1941,5 +1944,53 @@ void tst_QListView::taskQTBUG_5877_skippingItemInPageDownUp()
}
}
+void tst_QListView::taskQTBUG_12308_artihmeticException()
+{
+ QListWidget lw;
+ lw.setLayoutMode(QListView::Batched);
+ lw.setViewMode(QListView::IconMode);
+ for (int i = 0; i < lw.batchSize() + 1; i++) {
+ QListWidgetItem *item = new QListWidgetItem();
+ item->setText(QString("Item %L1").arg(i));
+ lw.addItem(item);
+ item->setHidden(true);
+ }
+ lw.show();
+ QTest::qWaitForWindowShown(&lw);
+ // No crash, it's all right.
+}
+
+class Delegate12308 : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ Delegate12308(QObject *parent = 0) : QStyledItemDelegate(parent)
+ { }
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+ {
+ QVERIFY(option.rect.topLeft() != QPoint(-1, -1));
+ QStyledItemDelegate::paint(painter, option, index);
+ }
+};
+
+void tst_QListView::taskQTBUG_12308_wrongFlowLayout()
+{
+ QListWidget lw;
+ Delegate12308 delegate;
+ lw.setLayoutMode(QListView::Batched);
+ lw.setViewMode(QListView::IconMode);
+ lw.setItemDelegate(&delegate);
+ for (int i = 0; i < lw.batchSize() + 1; i++) {
+ QListWidgetItem *item = new QListWidgetItem();
+ item->setText(QString("Item %L1").arg(i));
+ lw.addItem(item);
+ if (!item->text().contains(QString::fromAscii("1")))
+ item->setHidden(true);
+ }
+ lw.show();
+ QTest::qWaitForWindowShown(&lw);
+}
+
QTEST_MAIN(tst_QListView)
#include "tst_qlistview.moc"