Utils: Avoid accessing null pointer...

...and make sure model is propagated when using copy constructor.

Change-Id: I95b95ebb7f6058adc73bc6e73b4f23a87012a2b2
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
Christian Stenger
2015-02-09 14:44:43 +01:00
committed by hjk
parent bca7015ce8
commit d24fab71eb

View File

@@ -851,7 +851,7 @@ TreeModel::TreeModel(TreeItem *root, QObject *parent)
m_root(root) m_root(root)
{ {
m_columnCount = 1; m_columnCount = 1;
m_root->m_model = this; m_root->propagateModel(this);
} }
TreeModel::~TreeModel() TreeModel::~TreeModel()
@@ -866,6 +866,7 @@ QModelIndex TreeModel::parent(const QModelIndex &idx) const
return QModelIndex(); return QModelIndex();
const TreeItem *item = itemFromIndex(idx); const TreeItem *item = itemFromIndex(idx);
QTC_ASSERT(item, return QModelIndex());
const TreeItem *parent = item->parent(); const TreeItem *parent = item->parent();
if (!parent || parent == m_root) if (!parent || parent == m_root)
return QModelIndex(); return QModelIndex();
@@ -888,7 +889,9 @@ int TreeModel::rowCount(const QModelIndex &idx) const
return m_root->rowCount(); return m_root->rowCount();
if (idx.column() > 0) if (idx.column() > 0)
return 0; return 0;
return itemFromIndex(idx)->rowCount(); const TreeItem *item = itemFromIndex(idx);
QTC_ASSERT(item, return 0);
return item->rowCount();
} }
int TreeModel::columnCount(const QModelIndex &idx) const int TreeModel::columnCount(const QModelIndex &idx) const