TreeModel: Ensure that proxy models or views get notified...

...when the root item is exchanged.

Change-Id: Ic854259902bcfdcf5ec5776ad40b56bca3820bf5
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
Christian Stenger
2015-09-25 13:38:43 +02:00
parent e57b0db0f9
commit 133af73b2a

View File

@@ -967,9 +967,14 @@ void TreeModel::setRootItem(TreeItem *item)
QTC_ASSERT(item->m_model == 0, return); QTC_ASSERT(item->m_model == 0, return);
QTC_ASSERT(item->m_parent == 0, return); QTC_ASSERT(item->m_parent == 0, return);
QTC_CHECK(m_root); QTC_CHECK(m_root);
emit layoutAboutToBeChanged();
if (m_root) { if (m_root) {
QTC_CHECK(m_root->m_parent == 0); QTC_CHECK(m_root->m_parent == 0);
QTC_CHECK(m_root->m_model == this); QTC_CHECK(m_root->m_model == this);
// needs to be done explicitly before setting the model to 0, otherwise it might lead to a
// crash inside a view or proxy model, especially if there are selected items
m_root->removeChildren();
m_root->m_model = 0; m_root->m_model = 0;
delete m_root; delete m_root;
} }