forked from qt-creator/qt-creator
TreeModel: Rework tree iteration
Use function objects to apply directly during a depth-first walk of the tree instead of faking a flat container of tree nodes. Less code, and allows even some non-const operations. Change-Id: I804ab11df358fe937b40809cbcb772e6f3ff8dc5 Reviewed-by: David Schulz <david.schulz@theqtcompany.com> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -321,6 +321,11 @@ void ThreadsHandler::notifyGroupCreated(const QByteArray &groupId, const QByteAr
|
||||
m_pidForGroupId[groupId] = pid;
|
||||
}
|
||||
|
||||
void ThreadsHandler::foreachThread(const std::function<void (ThreadItem *)> &func)
|
||||
{
|
||||
forEachItemAtLevel<ThreadItem *>(1, func);
|
||||
}
|
||||
|
||||
void ThreadsHandler::updateThread(const ThreadData &threadData)
|
||||
{
|
||||
if (ThreadItem *item = itemForThreadId(this, threadData.id))
|
||||
@@ -349,9 +354,9 @@ void ThreadsHandler::setThreads(const Threads &threads)
|
||||
void ThreadsHandler::updateThreadBox()
|
||||
{
|
||||
QStringList list;
|
||||
auto items = itemsAtLevel<ThreadItem *>(1);
|
||||
foreach (ThreadItem *item, items)
|
||||
foreachThread([&list](ThreadItem *item) {
|
||||
list.append(QString::fromLatin1("#%1 %2").arg(item->threadData.id.raw()).arg(item->threadData.name));
|
||||
});
|
||||
Internal::setThreadBoxContents(list, indexForThreadId(this, m_currentId));
|
||||
}
|
||||
|
||||
@@ -370,10 +375,10 @@ void ThreadsHandler::removeAll()
|
||||
bool ThreadsHandler::notifyGroupExited(const QByteArray &groupId)
|
||||
{
|
||||
QList<ThreadItem *> list;
|
||||
auto items = itemsAtLevel<ThreadItem *>(1);
|
||||
foreach (ThreadItem *item, items)
|
||||
foreachThread([&list, groupId](ThreadItem *item) {
|
||||
if (item->threadData.groupId == groupId)
|
||||
list.append(item);
|
||||
});
|
||||
foreach (ThreadItem *item, list)
|
||||
delete takeItem(item);
|
||||
|
||||
@@ -397,9 +402,7 @@ void ThreadsHandler::notifyRunning(const QByteArray &data)
|
||||
|
||||
void ThreadsHandler::notifyAllRunning()
|
||||
{
|
||||
auto items = itemsAtLevel<ThreadItem *>(1);
|
||||
foreach (ThreadItem *item, items)
|
||||
item->notifyRunning();
|
||||
foreachThread([](ThreadItem *item) { item->notifyRunning(); });
|
||||
}
|
||||
|
||||
void ThreadsHandler::notifyRunning(ThreadId threadId)
|
||||
@@ -424,9 +427,7 @@ void ThreadsHandler::notifyStopped(const QByteArray &data)
|
||||
|
||||
void ThreadsHandler::notifyAllStopped()
|
||||
{
|
||||
auto items = itemsAtLevel<ThreadItem *>(1);
|
||||
foreach (ThreadItem *item, items)
|
||||
item->notifyStopped();
|
||||
foreachThread([](ThreadItem *item) { item->notifyStopped(); });
|
||||
}
|
||||
|
||||
void ThreadsHandler::notifyStopped(ThreadId threadId)
|
||||
|
||||
Reference in New Issue
Block a user