TreeModel: Add function to remove all children of an item

Just convenience.

Change-Id: Ieff2291ca63584cfa113a24cc2930adc3e764d08
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
hjk
2015-01-09 10:50:33 +01:00
parent 82c2f51a29
commit 3d0537fa8a
2 changed files with 12 additions and 0 deletions

View File

@@ -326,6 +326,17 @@ void TreeModel::removeItem(TreeItem *item)
endRemoveRows();
}
void TreeModel::removeAllSubItems(TreeItem *item)
{
QTC_ASSERT(item, return);
if (item->rowCount() == 0)
return;
QModelIndex idx = indexFromItem(item);
beginRemoveRows(idx, 0, item->rowCount() - 1);
item->clear();
endRemoveRows();
}
QModelIndex TreeModel::indexFromItemHelper(const TreeItem *needle,
TreeItem *parentItem, const QModelIndex &parentIndex) const
{

View File

@@ -177,6 +177,7 @@ public:
void appendItem(TreeItem *parent, TreeItem *item);
void removeItem(TreeItem *item); // item is not destroyed.
void removeAllSubItems(TreeItem *item); // item is not destroyed.
void updateItem(TreeItem *item); // call to trigger dataChanged
UntypedTreeLevelItems untypedLevelItems(int level = 0, TreeItem *start = 0) const;