Commit 8c583cb3 authored by hjk's avatar hjk

TreeModel: Add a few more soft asserts

This establishes an additional invariant, namely that items
that are not part of a model have m_model == 0, even if their
destruction is imminent.

Change-Id: I0bad7fff57d21ddcefe06953cd0da8c2897baa4a
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 9553309a
...@@ -622,6 +622,8 @@ TreeItem::TreeItem(const QStringList &displays, int flags) ...@@ -622,6 +622,8 @@ TreeItem::TreeItem(const QStringList &displays, int flags)
TreeItem::~TreeItem() TreeItem::~TreeItem()
{ {
QTC_CHECK(m_parent == 0);
QTC_CHECK(m_model == 0);
removeChildren(); removeChildren();
delete m_displays; delete m_displays;
} }
...@@ -851,6 +853,10 @@ TreeModel::TreeModel(TreeItem *root, QObject *parent) ...@@ -851,6 +853,10 @@ TreeModel::TreeModel(TreeItem *root, QObject *parent)
TreeModel::~TreeModel() TreeModel::~TreeModel()
{ {
QTC_ASSERT(m_root, return);
QTC_ASSERT(m_root->m_parent == 0, return);
QTC_ASSERT(m_root->m_model == this, return);
m_root->m_model = 0;
delete m_root; delete m_root;
} }
...@@ -966,7 +972,13 @@ int TreeModel::topLevelItemCount() const ...@@ -966,7 +972,13 @@ int TreeModel::topLevelItemCount() const
void TreeModel::setRootItem(TreeItem *item) void TreeModel::setRootItem(TreeItem *item)
{ {
delete m_root; QTC_CHECK(m_root);
if (m_root) {
QTC_CHECK(m_root->m_parent == 0);
QTC_CHECK(m_root->m_model == this);
m_root->m_model = 0;
delete m_root;
}
m_root = item; m_root = item;
item->setModel(this); item->setModel(this);
emit layoutChanged(); emit layoutChanged();
...@@ -1049,6 +1061,7 @@ TreeItem *TreeModel::takeItem(TreeItem *item) ...@@ -1049,6 +1061,7 @@ TreeItem *TreeModel::takeItem(TreeItem *item)
QModelIndex idx = indexForItem(parent); QModelIndex idx = indexForItem(parent);
beginRemoveRows(idx, pos, pos); beginRemoveRows(idx, pos, pos);
item->m_parent = 0; item->m_parent = 0;
item->m_model = 0;
parent->m_children.removeAt(pos); parent->m_children.removeAt(pos);
endRemoveRows(); endRemoveRows();
return item; return item;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment