summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2010-01-06 10:48:25 +0100
committerOlivier Goffart <ogoffart@trolltech.com>2010-01-06 10:48:25 +0100
commitd149a3faca9b97ce806249bc7ef73fe2f59589d5 (patch)
tree65a4f6006c240b5e048daf235043cfcff61734f3
parentdbc4a07327e0c306eb84a65ae7fa98bdb36c6ad0 (diff)
Don't call invalidate when resetting the QSortFilterProxyModel.
The invalidate connection is made before connecting the source model, which means it gets called first. If a second proxy model is used with it, the sourceLayoutAboutToBeChanged of the second proxy is therefore called before its sourceReset slot, but after the persistent indexes of the first model have been invalidated. The invalidate call is not needed because clear_mappings is called when the source model is reset anyway. Merge-request: 416 Reviewed-by: Olivier Goffart <ogoffart@trolltech.com>
-rw-r--r--src/gui/itemviews/qsortfilterproxymodel.cpp1
-rw-r--r--tests/auto/modeltest/dynamictreemodel.cpp3
-rw-r--r--tests/auto/modeltest/tst_modeltest.cpp30
3 files changed, 30 insertions, 4 deletions
diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp
index 646a3a1352..0e4af53ab9 100644
--- a/src/gui/itemviews/qsortfilterproxymodel.cpp
+++ b/src/gui/itemviews/qsortfilterproxymodel.cpp
@@ -1481,7 +1481,6 @@ QSortFilterProxyModel::QSortFilterProxyModel(QObject *parent)
d->filter_column = 0;
d->filter_role = Qt::DisplayRole;
d->dynamic_sortfilter = false;
- connect(this, SIGNAL(modelReset()), this, SLOT(invalidate()));
}
/*!
diff --git a/tests/auto/modeltest/dynamictreemodel.cpp b/tests/auto/modeltest/dynamictreemodel.cpp
index 24d3ab3ce6..b572eb16a1 100644
--- a/tests/auto/modeltest/dynamictreemodel.cpp
+++ b/tests/auto/modeltest/dynamictreemodel.cpp
@@ -160,10 +160,11 @@ QVariant DynamicTreeModel::data(const QModelIndex &index, int role) const
void DynamicTreeModel::clear()
{
+ beginResetModel();
m_items.clear();
m_childItems.clear();
nextId = 1;
- reset();
+ endResetModel();
}
diff --git a/tests/auto/modeltest/tst_modeltest.cpp b/tests/auto/modeltest/tst_modeltest.cpp
index 262b966ddd..8beeb3878a 100644
--- a/tests/auto/modeltest/tst_modeltest.cpp
+++ b/tests/auto/modeltest/tst_modeltest.cpp
@@ -67,6 +67,7 @@ private slots:
void standardItemModel();
void testInsertThroughProxy();
void moveSourceItems();
+ void testResetThroughProxy();
};
@@ -225,8 +226,9 @@ public slots:
void storePersistent()
{
- m_persistentSourceIndexes.clear();
- m_persistentProxyIndexes.clear();
+ foreach(const QModelIndex &idx, m_persistentProxyIndexes)
+ Q_ASSERT(idx.isValid()); // This is called from layoutAboutToBeChanged. Persistent indexes should be valid
+
Q_ASSERT(m_proxy->persistent().isEmpty());
storePersistent(QModelIndex());
Q_ASSERT(!m_proxy->persistent().isEmpty());
@@ -243,6 +245,8 @@ public slots:
QModelIndex updatedSource = m_persistentSourceIndexes.at(row);
QCOMPARE(m_proxy->mapToSource(updatedProxy), updatedSource);
}
+ m_persistentSourceIndexes.clear();
+ m_persistentProxyIndexes.clear();
}
private:
@@ -278,6 +282,28 @@ void tst_ModelTest::moveSourceItems()
moveCommand->doCommand();
}
+void tst_ModelTest::testResetThroughProxy()
+{
+ DynamicTreeModel *model = new DynamicTreeModel(this);
+
+ ModelInsertCommand *insertCommand = new ModelInsertCommand(model, this);
+ insertCommand->setStartRow(0);
+ insertCommand->setEndRow(2);
+ insertCommand->doCommand();
+
+ QPersistentModelIndex persistent = model->index(0, 0);
+
+ AccessibleProxyModel *proxy = new AccessibleProxyModel(this);
+ proxy->setSourceModel(model);
+
+ ObservingObject observer(proxy);
+ observer.storePersistent();
+
+ ModelResetCommand *resetCommand = new ModelResetCommand(model, this);
+ resetCommand->setNumCols(0);
+ resetCommand->doCommand();
+}
+
QTEST_MAIN(tst_ModelTest)
#include "tst_modeltest.moc"