summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2009-11-26 11:41:58 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2009-11-26 15:24:05 (GMT)
commite8d7d2172627dd3cac8b0cc3165ed371b524feb4 (patch)
treeef5f02e12ba9f301fafd489d3157d96f1ad6c6cb /tests/auto
parent88b9c6eb3f1dde9997d5e824450c9eaa2a36f8d5 (diff)
downloadQt-e8d7d2172627dd3cac8b0cc3165ed371b524feb4.zip
Qt-e8d7d2172627dd3cac8b0cc3165ed371b524feb4.tar.gz
Qt-e8d7d2172627dd3cac8b0cc3165ed371b524feb4.tar.bz2
QSortProxyModel: Crash when changing model with 2-level proxy and selected items
The index mapping to the base model was being cleared before the persistant model indices. Reviewed-by: Olivier Task-number: QTBUG-6237
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index e99e9d6..b7839f7 100644
--- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -135,6 +135,7 @@ private slots:
void task251296_hiddenChildren();
void task252507_mapFromToSource();
void task255652_removeRowsRecursive();
+ void taskQTBUG_6205_doubleProxySelectionSetSourceModel();
protected:
void buildHierarchy(const QStringList &data, QAbstractItemModel *model);
@@ -2815,5 +2816,41 @@ void tst_QSortFilterProxyModel::task255652_removeRowsRecursive()
delete pItem11;
}
+void tst_QSortFilterProxyModel::taskQTBUG_6205_doubleProxySelectionSetSourceModel()
+{
+ QStandardItemModel *model1 = new QStandardItemModel;
+ QStandardItem *parentItem = model1->invisibleRootItem();
+ for (int i = 0; i < 4; ++i) {
+ QStandardItem *item = new QStandardItem(QString("model1 item %0").arg(i));
+ parentItem->appendRow(item);
+ parentItem = item;
+ }
+
+ QStandardItemModel *model2 = new QStandardItemModel;
+ QStandardItem *parentItem2 = model2->invisibleRootItem();
+ for (int i = 0; i < 4; ++i) {
+ QStandardItem *item = new QStandardItem(QString("model2 item %0").arg(i));
+ parentItem2->appendRow(item);
+ parentItem2 = item;
+ }
+
+ QSortFilterProxyModel *toggleProxy = new QSortFilterProxyModel;
+ toggleProxy->setSourceModel(model1);
+
+ QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel;
+ proxyModel->setSourceModel(toggleProxy);
+
+ QModelIndex mi = proxyModel->index(0, 0, proxyModel->index(0, 0, proxyModel->index(0, 0)));
+ QItemSelectionModel ism(proxyModel);
+ ism.select(mi, QItemSelectionModel::Select);
+ QModelIndexList mil = ism.selectedIndexes();
+ QCOMPARE(mil.count(), 1);
+ QCOMPARE(mil.first(), mi);
+
+ toggleProxy->setSourceModel(model2);
+ // No crash, it's good news!
+ QVERIFY(ism.selection().isEmpty());
+}
+
QTEST_MAIN(tst_QSortFilterProxyModel)
#include "tst_qsortfilterproxymodel.moc"