Commit b1393d47 authored by Eike Ziller's avatar Eike Ziller

TreeModel: takeItem should return the item

The usual Qt API for "takeXyz()" methods is to return the item that was
"taken".

Change-Id: Ie144051801487a301b3f13e2857735b65f58150b
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent 5309e217
......@@ -1027,23 +1027,24 @@ void TreeModel::clear()
\note The item is not destroyed, ownership is effectively passed to the caller.
*/
void TreeModel::takeItem(TreeItem *item)
TreeItem *TreeModel::takeItem(TreeItem *item)
{
#if USE_MODEL_TEST
(void) new ModelTest(this, this);
#endif
QTC_ASSERT(item, return);
QTC_ASSERT(item, return item);
TreeItem *parent = item->parent();
QTC_ASSERT(parent, return);
QTC_ASSERT(parent, return item);
int pos = parent->m_children.indexOf(item);
QTC_ASSERT(pos != -1, return);
QTC_ASSERT(pos != -1, return item);
QModelIndex idx = indexForItem(parent);
beginRemoveRows(idx, pos, pos);
item->m_parent = 0;
parent->m_children.removeAt(pos);
endRemoveRows();
return item;
}
//
......
......@@ -291,7 +291,7 @@ public:
return Utils::findOrDefault(itemsAtLevel<T>(level, start), f);
}
void takeItem(TreeItem *item); // item is not destroyed.
TreeItem *takeItem(TreeItem *item); // item is not destroyed.
signals:
void requestExpansion(QModelIndex);
......
......@@ -265,8 +265,7 @@ void GdbServerProviderModel::removeProvider(GdbServerProvider *provider)
}
n = findNode(rootItem()->children(), provider);
takeItem(n);
delete n;
delete takeItem(n);
emit providerStateChanged();
}
......
......@@ -237,10 +237,8 @@ void CMakeToolItemModel::removeCMakeTool(const Core::Id &id)
CMakeToolTreeItem *treeItem = cmakeToolItem(id);
QTC_ASSERT(treeItem, return);
takeItem(treeItem);
delete takeItem(treeItem);
m_removedItems.append(id);
delete treeItem;
}
void CMakeToolItemModel::apply()
......
......@@ -412,8 +412,7 @@ void BreakHandler::deletionHelper(BreakpointModelId id)
{
Breakpoint b = breakpointById(id);
QTC_ASSERT(b, return);
takeItem(b.b);
delete b.b;
delete takeItem(b.b);
}
Breakpoint BreakHandler::findWatchpoint(const BreakpointParameters &params) const
......@@ -1235,8 +1234,7 @@ void BreakHandler::changeLineNumberFromMarkerHelper(BreakpointModelId id)
Breakpoint b = breakpointById(id);
QTC_ASSERT(b, return);
BreakpointParameters params = b.parameters();
takeItem(b.b);
delete b.b;
delete takeItem(b.b);
appendBreakpoint(params);
}
......
......@@ -165,8 +165,7 @@ void DebuggerItemModel::removeCurrentDebugger()
QVariant id = m_currentTreeItem->m_item.id();
DebuggerTreeItem *treeItem = m_currentTreeItem;
m_currentTreeItem = 0;
takeItem(treeItem);
delete treeItem;
delete takeItem(treeItem);
m_removedItems.append(id);
}
......
......@@ -1251,8 +1251,7 @@ void WatchHandler::removeItemByIName(const QByteArray &iname)
theWatcherNames.remove(item->exp);
saveWatchers();
}
m_model->takeItem(item);
delete item;
delete m_model->takeItem(item);
updateWatchersWindow();
}
......
......@@ -359,8 +359,7 @@ void KitModel::removeKit(Kit *k)
if (node == m_defaultNode)
setDefaultNode(findItemAtLevel<KitNode *>(2, [node](KitNode *kn) { return kn != node; }));
takeItem(node);
delete node;
delete takeItem(node);
validateKitNames();
emit kitStateChanged();
......
......@@ -259,8 +259,7 @@ void ToolChainOptionsWidget::removeToolChain(ToolChain *tc)
TreeItem *parent = m_model.rootItem()->child(tc->isAutoDetected() ? 0 : 1);
foreach (ToolChainTreeItem *item, m_model.itemsAtLevel<ToolChainTreeItem *>(1, parent)) {
if (item->toolChain == tc) {
m_model.takeItem(item);
delete item;
delete m_model.takeItem(item);
break;
}
}
......
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