X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Ftreemodel.cpp;h=d66cc3a9f838ac9d58c187dbd9f679eaa100e778;hp=960f7e841f9fc4032268cbb0784dab8f7c9b680a;hb=56607f81246f04db3a0e71c9a8757d7f75d6cfcf;hpb=c7a5ea8c0e5807fd0079bcb10cb88e4356526bad diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index 960f7e84..d66cc3a9 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -51,6 +51,35 @@ bool AbstractTreeItem::newChild(AbstractTreeItem *item) { return true; } +bool AbstractTreeItem::newChilds(const QList &items) { + if(items.isEmpty()) + return false; + + QList::const_iterator itemIter = items.constBegin(); + AbstractTreeItem *item; + while(itemIter != items.constEnd()) { + item = *itemIter; + if(childById(item->id()) != 0) { + qWarning() << "AbstractTreeItem::newChilds(): received child that is already attached" << item << item->id(); + return false; + } + itemIter++; + } + + int nextRow = childCount(); + int lastRow = nextRow + items.count() - 1; + + emit beginAppendChilds(nextRow, lastRow); + itemIter = items.constBegin(); + while(itemIter != items.constEnd()) { + _childItems.append(*itemIter); + itemIter++; + } + emit endAppendChilds(); + + return true; +} + bool AbstractTreeItem::removeChild(int row) { if(childCount() <= row) return false; @@ -83,13 +112,17 @@ void AbstractTreeItem::removeAllChilds() { AbstractTreeItem *child; - QList::iterator childIter = _childItems.begin(); + QList::iterator childIter; + + childIter = _childItems.begin(); while(childIter != _childItems.end()) { child = *childIter; child->removeAllChilds(); + childIter++; } emit beginRemoveChilds(0, numChilds - 1); + childIter = _childItems.begin(); while(childIter != _childItems.end()) { child = *childIter; childIter = _childItems.erase(childIter);