X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Ftreemodel.cpp;h=ace9d3d7a73ee1eee3b14eeada69bc6b2c62f08b;hb=2ef12747a748a78311ee51b4bf833e1664347d47;hp=960f7e841f9fc4032268cbb0784dab8f7c9b680a;hpb=c7a5ea8c0e5807fd0079bcb10cb88e4356526bad;p=quassel.git diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index 960f7e84..ace9d3d7 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); @@ -495,7 +528,7 @@ void TreeModel::clear() { } void TreeModel::debug_rowsAboutToBeInserted(const QModelIndex &parent, int start, int end) { - // qDebug() << "debug_rowsAboutToBeInserted" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end; + qDebug() << "debug_rowsAboutToBeInserted" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end; } void TreeModel::debug_rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) { @@ -533,5 +566,5 @@ void TreeModel::debug_rowsInserted(const QModelIndex &parent, int start, int end } void TreeModel::debug_rowsRemoved(const QModelIndex &parent, int start, int end) { - // qDebug() << "debug_rowsRemoved" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end; + qDebug() << "debug_rowsRemoved" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end; }