equal
deleted
inserted
replaced
65 void stringListModel(); |
65 void stringListModel(); |
66 void treeWidgetModel(); |
66 void treeWidgetModel(); |
67 void standardItemModel(); |
67 void standardItemModel(); |
68 void testInsertThroughProxy(); |
68 void testInsertThroughProxy(); |
69 void moveSourceItems(); |
69 void moveSourceItems(); |
|
70 void testResetThroughProxy(); |
70 }; |
71 }; |
71 |
72 |
72 |
73 |
73 |
74 |
74 void tst_ModelTest::initTestCase() |
75 void tst_ModelTest::initTestCase() |
223 } |
224 } |
224 } |
225 } |
225 |
226 |
226 void storePersistent() |
227 void storePersistent() |
227 { |
228 { |
228 m_persistentSourceIndexes.clear(); |
229 foreach(const QModelIndex &idx, m_persistentProxyIndexes) |
229 m_persistentProxyIndexes.clear(); |
230 Q_ASSERT(idx.isValid()); // This is called from layoutAboutToBeChanged. Persistent indexes should be valid |
|
231 |
230 Q_ASSERT(m_proxy->persistent().isEmpty()); |
232 Q_ASSERT(m_proxy->persistent().isEmpty()); |
231 storePersistent(QModelIndex()); |
233 storePersistent(QModelIndex()); |
232 Q_ASSERT(!m_proxy->persistent().isEmpty()); |
234 Q_ASSERT(!m_proxy->persistent().isEmpty()); |
233 } |
235 } |
234 |
236 |
241 for (int row = 0; row < m_persistentProxyIndexes.size(); ++row) { |
243 for (int row = 0; row < m_persistentProxyIndexes.size(); ++row) { |
242 QModelIndex updatedProxy = m_persistentProxyIndexes.at(row); |
244 QModelIndex updatedProxy = m_persistentProxyIndexes.at(row); |
243 QModelIndex updatedSource = m_persistentSourceIndexes.at(row); |
245 QModelIndex updatedSource = m_persistentSourceIndexes.at(row); |
244 QCOMPARE(m_proxy->mapToSource(updatedProxy), updatedSource); |
246 QCOMPARE(m_proxy->mapToSource(updatedProxy), updatedSource); |
245 } |
247 } |
|
248 m_persistentSourceIndexes.clear(); |
|
249 m_persistentProxyIndexes.clear(); |
246 } |
250 } |
247 |
251 |
248 private: |
252 private: |
249 AccessibleProxyModel *m_proxy; |
253 AccessibleProxyModel *m_proxy; |
250 QList<QPersistentModelIndex> m_persistentSourceIndexes; |
254 QList<QPersistentModelIndex> m_persistentSourceIndexes; |
276 moveCommand->setDestAncestors(QList<int>() << 1); |
280 moveCommand->setDestAncestors(QList<int>() << 1); |
277 moveCommand->setDestRow(0); |
281 moveCommand->setDestRow(0); |
278 moveCommand->doCommand(); |
282 moveCommand->doCommand(); |
279 } |
283 } |
280 |
284 |
|
285 void tst_ModelTest::testResetThroughProxy() |
|
286 { |
|
287 DynamicTreeModel *model = new DynamicTreeModel(this); |
|
288 |
|
289 ModelInsertCommand *insertCommand = new ModelInsertCommand(model, this); |
|
290 insertCommand->setStartRow(0); |
|
291 insertCommand->setEndRow(2); |
|
292 insertCommand->doCommand(); |
|
293 |
|
294 QPersistentModelIndex persistent = model->index(0, 0); |
|
295 |
|
296 AccessibleProxyModel *proxy = new AccessibleProxyModel(this); |
|
297 proxy->setSourceModel(model); |
|
298 |
|
299 ObservingObject observer(proxy); |
|
300 observer.storePersistent(); |
|
301 |
|
302 ModelResetCommand *resetCommand = new ModelResetCommand(model, this); |
|
303 resetCommand->setNumCols(0); |
|
304 resetCommand->doCommand(); |
|
305 } |
|
306 |
281 |
307 |
282 QTEST_MAIN(tst_ModelTest) |
308 QTEST_MAIN(tst_ModelTest) |
283 #include "tst_modeltest.moc" |
309 #include "tst_modeltest.moc" |