summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-05-04 16:15:35 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-05-05 13:38:03 (GMT)
commit78660bf18ec11e043f1c88d711f62d32237bd0e5 (patch)
tree545f1205a9aaa9cdf71d71a9020963d18a883909
parentc1c7dbf2a066868503dfabcd7113856fa6d2e457 (diff)
downloadQt-78660bf18ec11e043f1c88d711f62d32237bd0e5.zip
Qt-78660bf18ec11e043f1c88d711f62d32237bd0e5.tar.gz
Qt-78660bf18ec11e043f1c88d711f62d32237bd0e5.tar.bz2
QSortFilterProxyModel: Warning or assert failure
A mapping was being created after QStandardItem::dataChanged() signal, even though one of the item's ancestors was being filtered out by the filter proxy. This let the QSortFilterProxyModel in a unstable state, triggering warnings and failing asserts. This patch partialy reverts commit f4bce41c10988. Auto-test included. Reviewed-by: mbm Task-number: QTBUG-10287
-rw-r--r--src/gui/itemviews/qsortfilterproxymodel.cpp2
-rw-r--r--tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp61
2 files changed, 62 insertions, 1 deletions
diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp
index dce5c6a..b12cd45 100644
--- a/src/gui/itemviews/qsortfilterproxymodel.cpp
+++ b/src/gui/itemviews/qsortfilterproxymodel.cpp
@@ -1099,7 +1099,7 @@ void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &sourc
if (!source_top_left.isValid() || !source_bottom_right.isValid())
return;
QModelIndex source_parent = source_top_left.parent();
- IndexMap::const_iterator it = create_mapping(source_parent);
+ IndexMap::const_iterator it = source_index_mapping.find(source_parent);
if (it == source_index_mapping.constEnd()) {
// Don't care, since we don't have mapping for this index
return;
diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index 2339b21..992c95e 100644
--- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -138,6 +138,7 @@ private slots:
void taskQTBUG_6205_doubleProxySelectionSetSourceModel();
void taskQTBUG_7537_appearsAndSort();
void taskQTBUG_7716_unnecessaryDynamicSorting();
+ void taskQTBUG_10287_unnecessaryMapCreation();
void testMultipleProxiesWithSelection();
@@ -3038,5 +3039,65 @@ void tst_QSortFilterProxyModel::testMultipleProxiesWithSelection()
}
+class Model10287 : public QStandardItemModel
+{
+ Q_OBJECT
+
+public:
+ Model10287(QObject *parent = 0)
+ : QStandardItemModel(0, 1, parent)
+ {
+ parentItem = new QStandardItem("parent");
+ parentItem->setData(false, Qt::UserRole);
+ appendRow(parentItem);
+
+ childItem = new QStandardItem("child");
+ childItem->setData(true, Qt::UserRole);
+ parentItem->appendRow(childItem);
+
+ childItem2 = new QStandardItem("child2");
+ childItem2->setData(true, Qt::UserRole);
+ parentItem->appendRow(childItem2);
+ }
+
+ void removeChild()
+ {
+ childItem2->setData(false, Qt::UserRole);
+ parentItem->removeRow(0);
+ }
+
+private:
+ QStandardItem *parentItem, *childItem, *childItem2;
+};
+
+class Proxy10287 : public QSortFilterProxyModel
+{
+ Q_OBJECT
+
+public:
+ Proxy10287(QAbstractItemModel *model, QObject *parent = 0)
+ : QSortFilterProxyModel(parent)
+ {
+ setSourceModel(model);
+ setDynamicSortFilter(true);
+ }
+
+protected:
+ virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
+ {
+ // Filter based on UserRole in model
+ QModelIndex i = sourceModel()->index(source_row, 0, source_parent);
+ return i.data(Qt::UserRole).toBool();
+ }
+};
+
+void tst_QSortFilterProxyModel::taskQTBUG_10287_unnecessaryMapCreation()
+{
+ Model10287 m;
+ Proxy10287 p(&m);
+ m.removeChild();
+ // No assert failure, it passes.
+}
+
QTEST_MAIN(tst_QSortFilterProxyModel)
#include "tst_qsortfilterproxymodel.moc"