void ThreadList::updateThreads(const std::list<ThreadInfo>& threads) { // reset flag in all items for (QTreeWidgetItemIterator i(this); *i; ++i) static_cast<ThreadEntry*>(*i)->m_delete = true; for (std::list<ThreadInfo>::const_iterator i = threads.begin(); i != threads.end(); ++i) { // look up this thread by id ThreadEntry* te = threadById(i->id); if (te == 0) { te = new ThreadEntry(this, *i); } else { te->m_delete = false; te->setFunction(i->function); } // set focus icon te->hasFocus = i->hasFocus; te->setIcon(0, i->hasFocus ? QIcon(m_focusIcon) : QIcon(m_noFocusIcon)); } // delete all entries that have not been seen for (QTreeWidgetItemIterator i(this); *i;) { ThreadEntry* te = static_cast<ThreadEntry*>(*i); ++i; // step ahead before deleting it ;-) if (te->m_delete) { delete te; } } }
void ThreadList::updateThreads(QList<ThreadInfo>& threads) { // reset flag in all items for (QListViewItem* e = firstChild(); e != 0; e = e->nextSibling()) { static_cast<ThreadEntry*>(e)->m_delete = true; } for (ThreadInfo* i = threads.first(); i != 0; i = threads.next()) { // look up this thread by id ThreadEntry* te = threadById(i->id); if (te == 0) { te = new ThreadEntry(this, i); } else { te->m_delete = false; te->setFunction(i->function); } // set focus icon te->hasFocus = i->hasFocus; te->setPixmap(0, i->hasFocus ? m_focusIcon : m_noFocusIcon); } // delete all entries that have not been seen for (QListViewItem* e = firstChild(); e != 0;) { ThreadEntry* te = static_cast<ThreadEntry*>(e); e = e->nextSibling(); /* step ahead before deleting it ;-) */ if (te->m_delete) { delete te; } } }