TreeModel: More API cleanup

- introduce topLevelItemCount (similar to QTreeWidget)
- squash untypedTreeLevelItems()
- rename removeItems() to clear()
- rename removeItem() to takeItem()
- rename treeLevelItems<> to itemsAtLevel<>

Change-Id: I0f1bb4110f7687b20da3d92e3d943858645a9fa2
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
hjk
2015-04-22 14:49:14 +02:00
parent b30b69bbf3
commit 2b19081cb0
15 changed files with 65 additions and 69 deletions

View File

@@ -984,6 +984,11 @@ TreeItem *TreeModel::rootItem() const
return m_root;
}
int TreeModel::topLevelItemCount() const
{
return m_root->childCount();
}
void TreeModel::setRootItem(TreeItem *item)
{
delete m_root;
@@ -1030,25 +1035,22 @@ QModelIndex TreeModel::indexForItem(const TreeItem *item) const
return createIndex(row, 0, mitem);
}
void TreeModel::removeItems()
/*!
Destroys all items in them model except the invisible root item.
*/
void TreeModel::clear()
{
if (m_root)
m_root->removeChildren();
}
UntypedTreeLevelItems TreeModel::untypedLevelItems(int level, TreeItem *start) const
{
if (start == 0)
start = m_root;
return UntypedTreeLevelItems(start, level);
}
/*!
Removes the specified item from the model.
UntypedTreeLevelItems TreeModel::untypedLevelItems(TreeItem *start) const
{
return UntypedTreeLevelItems(start, 1);
}
\note The item is not destroyed, ownership is effectively passed to the caller.
*/
void TreeModel::removeItem(TreeItem *item)
void TreeModel::takeItem(TreeItem *item)
{
#if USE_MODEL_TEST
(void) new ModelTest(this, this);