summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-04-16 15:29:36 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-04-16 15:40:35 (GMT)
commitd1221d84714a169e12192cfa073af11db61bfbcc (patch)
tree2ba6b2185a0b843271cbd7db8723e9c325575d33
parent139265031939d676f049edd2c91918040e0659b4 (diff)
downloadQt-d1221d84714a169e12192cfa073af11db61bfbcc.zip
Qt-d1221d84714a169e12192cfa073af11db61bfbcc.tar.gz
Qt-d1221d84714a169e12192cfa073af11db61bfbcc.tar.bz2
QSortFilterProxyModel: In dynamic filter model, childs of temporarly
filtered items are not correctly updated. when filtering away a row, we should remove all the mapping of the children Task-number: 251296 Reviewed-by: Marius Bugge Monsen
-rw-r--r--src/gui/itemviews/qsortfilterproxymodel.cpp14
-rw-r--r--tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp42
2 files changed, 55 insertions, 1 deletions
diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp
index 2c9eeea..a1d35b0 100644
--- a/src/gui/itemviews/qsortfilterproxymodel.cpp
+++ b/src/gui/itemviews/qsortfilterproxymodel.cpp
@@ -1032,9 +1032,21 @@ void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &sourc
}
}
- if (!source_rows_remove.isEmpty())
+ if (!source_rows_remove.isEmpty()) {
remove_source_items(m->proxy_rows, m->source_rows,
source_rows_remove, source_parent, Qt::Vertical);
+ QSet<int> source_rows_remove_set = source_rows_remove.toSet();
+ QVector<QModelIndex>::iterator it = m->mapped_children.begin();
+ while (it != m->mapped_children.end()) {
+ const QModelIndex source_child_index = *it;
+ if (source_rows_remove_set.contains(source_child_index.row())) {
+ it = m->mapped_children.erase(it);
+ remove_from_mapping(source_child_index);
+ } else {
+ ++it;
+ }
+ }
+ }
if (!source_rows_resort.isEmpty()) {
// Re-sort the rows
diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index 4a749f0..18aa5fc 100644
--- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -132,6 +132,7 @@ private slots:
void task248868_staticSorting();
void task248868_dynamicSorting();
void task250023_fetchMore();
+ void task251296_hiddenChildren();
protected:
void buildHierarchy(const QStringList &data, QAbstractItemModel *model);
@@ -2675,6 +2676,47 @@ void tst_QSortFilterProxyModel::task250023_fetchMore()
QCOMPARE(proxy.columnCount(idx), 10);
}
+void tst_QSortFilterProxyModel::task251296_hiddenChildren()
+{
+ QStandardItemModel model;
+ QSortFilterProxyModel proxy;
+ proxy.setSourceModel(&model);
+ proxy.setDynamicSortFilter(true);
+
+ QStandardItem *itemA = new QStandardItem("A VISIBLE");
+ model.appendRow(itemA);
+ QStandardItem *itemB = new QStandardItem("B VISIBLE");
+ itemA->appendRow(itemB);
+ QStandardItem *itemC = new QStandardItem("C");
+ itemA->appendRow(itemC);
+ proxy.setFilterRegExp("VISIBLE");
+
+ QCOMPARE(proxy.rowCount(QModelIndex()) , 1);
+ QPersistentModelIndex indexA = proxy.index(0,0);
+ QCOMPARE(proxy.data(indexA).toString(), QString::fromLatin1("A VISIBLE"));
+
+ QCOMPARE(proxy.rowCount(indexA) , 1);
+ QPersistentModelIndex indexB = proxy.index(0, 0, indexA);
+ QCOMPARE(proxy.data(indexB).toString(), QString::fromLatin1("B VISIBLE"));
+
+ itemA->setText("A");
+ QCOMPARE(proxy.rowCount(QModelIndex()), 0);
+ QVERIFY(!indexA.isValid());
+ QVERIFY(!indexB.isValid());
+
+ itemB->setText("B");
+ itemA->setText("A VISIBLE");
+ itemC->setText("C VISIBLE");
+
+ QCOMPARE(proxy.rowCount(QModelIndex()), 1);
+ indexA = proxy.index(0,0);
+ QCOMPARE(proxy.data(indexA).toString(), QString::fromLatin1("A VISIBLE"));
+
+ QCOMPARE(proxy.rowCount(indexA) , 1);
+ QModelIndex indexC = proxy.index(0, 0, indexA);
+ QCOMPARE(proxy.data(indexC).toString(), QString::fromLatin1("C VISIBLE"));
+}
+
QTEST_MAIN(tst_QSortFilterProxyModel)
#include "tst_qsortfilterproxymodel.moc"