Commit 7b4c7d49 authored by hjk's avatar hjk Committed by hjk

TreeModel: Introduce a destroyItem() convenience function

Shorthand for delete takeItem(...).

Change-Id: Icb7b60e5c19aa0d21650eefff65f7eb55e9f90b0
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent 4c5ee0c0
......@@ -1049,6 +1049,11 @@ TreeItem *TreeModel::takeItem(TreeItem *item)
return item;
}
void TreeModel::destroyItem(TreeItem *item)
{
delete takeItem(item);
}
StaticTreeItem::StaticTreeItem(const QStringList &displays)
: m_displays(displays)
{
......
......@@ -230,6 +230,7 @@ public:
void fetchMore(const QModelIndex &idx) override;
TreeItem *takeItem(TreeItem *item); // item is not destroyed.
void destroyItem(TreeItem *item); // item is destroyed.
signals:
void requestExpansion(QModelIndex);
......
......@@ -209,7 +209,7 @@ void TestResultModel::removeCurrentTestMessage()
for (int row = topLevelItems.size() - 1; row >= 0; --row) {
TestResultItem *current = static_cast<TestResultItem *>(topLevelItems.at(row));
if (current->testResult()->result() == Result::MessageCurrentTest) {
delete takeItem(current);
destroyItem(current);
break;
}
}
......
......@@ -257,14 +257,14 @@ bool TestTreeModel::sweepChildren(TestTreeItem *item)
TestTreeItem *child = item->childItem(row);
if (child->parentItem()->type() != TestTreeItem::Root && child->markedForRemoval()) {
delete takeItem(child);
destroyItem(child);
hasChanged = true;
continue;
}
if (bool noEndNode = child->hasChildren()) {
hasChanged |= sweepChildren(child);
if (noEndNode && child->childCount() == 0) {
delete takeItem(child);
destroyItem(child);
hasChanged = true;
continue;
}
......
......@@ -184,7 +184,7 @@ void GdbServerProviderModel::markForRemoval(GdbServerProvider *provider)
{
GdbServerProviderNode *n = findNode(provider);
QTC_ASSERT(n, return);
delete takeItem(n);
destroyItem(n);
if (m_providersToAdd.contains(provider)) {
m_providersToAdd.removeOne(provider);
......@@ -233,7 +233,7 @@ void GdbServerProviderModel::removeProvider(GdbServerProvider *provider)
{
m_providersToRemove.removeAll(provider);
if (GdbServerProviderNode *n = findNode(provider))
delete takeItem(n);
destroyItem(n);
emit providerStateChanged();
}
......
......@@ -242,7 +242,7 @@ void CMakeToolItemModel::removeCMakeTool(const Core::Id &id)
CMakeToolTreeItem *treeItem = cmakeToolItem(id);
QTC_ASSERT(treeItem, return);
delete takeItem(treeItem);
destroyItem(treeItem);
m_removedItems.append(id);
}
......
......@@ -359,7 +359,7 @@ void LocatorSettingsPage::removeCustomFilter()
QTC_ASSERT(item, return);
ILocatorFilter *filter = item->filter();
QTC_ASSERT(m_customFilters.contains(filter), return);
delete m_model->takeItem(item);
m_model->destroyItem(item);
m_filters.removeAll(filter);
m_customFilters.removeAll(filter);
m_refreshFilters.removeAll(filter);
......
......@@ -348,7 +348,7 @@ void BreakHandler::deletionHelper(BreakpointModelId id)
{
Breakpoint b = breakpointById(id);
QTC_ASSERT(b, return);
delete takeItem(b.b);
destroyItem(b.b);
}
Breakpoint BreakHandler::findWatchpoint(const BreakpointParameters &params) const
......@@ -1169,7 +1169,7 @@ void BreakHandler::changeLineNumberFromMarkerHelper(BreakpointModelId id)
Breakpoint b = breakpointById(id);
QTC_ASSERT(b, return);
BreakpointParameters params = b.parameters();
delete takeItem(b.b);
destroyItem(b.b);
appendBreakpoint(params);
}
......
......@@ -169,7 +169,7 @@ void DebuggerItemModel::removeCurrentDebugger()
QVariant id = m_currentTreeItem->m_item.id();
DebuggerTreeItem *treeItem = m_currentTreeItem;
m_currentTreeItem = 0;
delete takeItem(treeItem);
destroyItem(treeItem);
m_removedItems.append(id);
}
......
......@@ -207,7 +207,7 @@ Modules ModulesHandler::modules() const
void ModulesHandler::removeModule(const QString &modulePath)
{
if (ModuleItem *item = moduleFromPath(m_model->rootItem(), modulePath))
delete m_model->takeItem(item);
m_model->destroyItem(item);
}
void ModulesHandler::updateModule(const Module &module)
......@@ -249,7 +249,7 @@ void ModulesHandler::endUpdateAll()
for (int i = root->rowCount(); --i >= 0; ) {
auto item = static_cast<ModuleItem *>(root->child(i));
if (!item->updated)
delete m_model->takeItem(item);
m_model->destroyItem(item);
}
}
......
......@@ -320,7 +320,7 @@ void ThreadsHandler::updateThread(const ThreadData &threadData)
void ThreadsHandler::removeThread(ThreadId threadId)
{
if (ThreadItem *item = itemForThreadId(this, threadId))
delete takeItem(item);
destroyItem(item);
}
void ThreadsHandler::setThreads(const Threads &threads)
......@@ -363,7 +363,7 @@ bool ThreadsHandler::notifyGroupExited(const QString &groupId)
list.append(item);
});
foreach (ThreadItem *item, list)
delete takeItem(item);
destroyItem(item);
m_pidForGroupId.remove(groupId);
return m_pidForGroupId.isEmpty();
......
......@@ -1289,7 +1289,7 @@ bool WatchHandler::insertItem(WatchItem *item)
const QVector<TreeItem *> siblings = parent->children();
for (int row = 0, n = siblings.size(); row < n; ++row) {
if (static_cast<WatchItem *>(siblings.at(row))->iname == item->iname) {
delete m_model->takeItem(parent->children().at(row));
m_model->destroyItem(parent->children().at(row));
parent->insertChild(row, item);
found = true;
break;
......@@ -1377,7 +1377,7 @@ void WatchHandler::notifyUpdateFinished()
});
foreach (auto item, toRemove)
delete m_model->takeItem(item);
m_model->destroyItem(item);
m_model->m_contentsValid = true;
updateWatchersWindow();
......@@ -1400,7 +1400,7 @@ void WatchHandler::removeItemByIName(const QString &iname)
theWatcherNames.remove(item->exp);
saveWatchers();
}
delete m_model->takeItem(item);
m_model->destroyItem(item);
updateWatchersWindow();
}
......
......@@ -345,7 +345,7 @@ void KitModel::removeKit(Kit *k)
if (node == m_defaultNode)
setDefaultNode(findSecondLevelItem([node](KitNode *kn) { return kn != node; }));
delete takeItem(node);
destroyItem(node);
validateKitNames();
emit kitStateChanged();
......
......@@ -255,7 +255,7 @@ void ToolChainOptionsWidget::removeToolChain(ToolChain *tc)
auto item = m_model.findSecondLevelItem([tc](ToolChainTreeItem *item) {
return tc->isAutoDetected() && item->toolChain == tc;
});
delete m_model.takeItem(item);
m_model.destroyItem(item);
updateState();
}
......
......@@ -328,10 +328,8 @@ void QtOptionsPageWidget::cleanUpQtVersions()
QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
return;
foreach (QtVersionItem *item, toRemove) {
m_model->takeItem(item);
delete item;
}
foreach (QtVersionItem *item, toRemove)
m_model->destroyItem(item);
updateCleanUpButton();
}
......@@ -526,10 +524,8 @@ void QtOptionsPageWidget::updateQtVersions(const QList<int> &additions, const QL
});
// Remove changed/removed items:
foreach (QtVersionItem *item, toRemove) {
m_model->takeItem(item);
delete item;
}
foreach (QtVersionItem *item, toRemove)
m_model->destroyItem(item);
// Add changed/added items:
foreach (int a, toAdd) {
......@@ -620,8 +616,7 @@ void QtOptionsPageWidget::removeQtDir()
if (!item)
return;
m_model->takeItem(item);
delete item;
m_model->destroyItem(item);
updateCleanUpButton();
}
......
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