From 991b6bc973238a6fd73c4c71e7c642b8cc455df3 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 4 Sep 2009 11:06:08 +0200 Subject: Fix a regression with QListView::setRowHidden() when a root index is set When setRowHidden() was called after a root index was set then it would not actually hide the row, if a root index is not set then it worked fine. Task-number: 260879 Reviewed-by: Jan-Arve --- src/gui/itemviews/qlistview.cpp | 8 ++++---- tests/auto/qlistview/tst_qlistview.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp index 35b44b4..1212194 100644 --- a/src/gui/itemviews/qlistview.cpp +++ b/src/gui/itemviews/qlistview.cpp @@ -549,16 +549,16 @@ void QListView::setRowHidden(int row, bool hide) const bool hidden = d->isHidden(row); if (d->viewMode == ListMode) { if (hide && !hidden) - d->hiddenRows.append(d->model->index(row, 0)); + d->hiddenRows.append(d->model->index(row, 0, rootIndex())); else if (!hide && hidden) - d->hiddenRows.remove(d->hiddenRows.indexOf(d->model->index(row, 0))); + d->hiddenRows.remove(d->hiddenRows.indexOf(d->model->index(row, 0, rootIndex()))); d->doDelayedItemsLayout(); } else { if (hide && !hidden) { d->dynamicListView->removeItem(row); - d->hiddenRows.append(d->model->index(row, 0)); + d->hiddenRows.append(d->model->index(row, 0, rootIndex())); } else if (!hide && hidden) { - d->hiddenRows.remove(d->hiddenRows.indexOf(d->model->index(row, 0))); + d->hiddenRows.remove(d->hiddenRows.indexOf(d->model->index(row, 0, rootIndex()))); d->dynamicListView->insertItem(row); } if (d->resizeMode == Adjust) diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp index b52bef0..27c6a05 100644 --- a/tests/auto/qlistview/tst_qlistview.cpp +++ b/tests/auto/qlistview/tst_qlistview.cpp @@ -417,6 +417,18 @@ void tst_QListView::hideRows() view.setRowHidden(0, false); QVERIFY(!view.isRowHidden(0)); + QStandardItemModel sim(0); + QStandardItem *root = new QStandardItem("Root row"); + for (int i=0;i<5;i++) + root->appendRow(new QStandardItem(QString("Row %1").arg(i))); + sim.appendRow(root); + view.setModel(&sim); + view.setRootIndex(root->index()); + QVERIFY(!view.isRowHidden(0)); + view.setRowHidden(0, true); + QVERIFY(view.isRowHidden(0)); + view.setRowHidden(0, false); + QVERIFY(!view.isRowHidden(0)); } -- cgit v0.12