X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Ftreemodel.cpp;h=c61cf9e83366b7bcba8973acfcb69ea6c2476a4b;hb=7fe80a6d0c51374de16886c0fbc69490be2434e9;hp=6fc0c25b38a333944e46729caa3e83811e73a009;hpb=c0e4730a50f812cd3795d47561357ff221094f8c;p=quassel.git diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index 6fc0c25b..c61cf9e8 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -131,6 +131,31 @@ void AbstractTreeItem::removeAllChilds() { emit endRemoveChilds(); } +bool AbstractTreeItem::reParent(AbstractTreeItem *newParent) { + // currently we support only re parenting if the child that's about to be + // adopted does not have any children itself. + if(childCount() != 0) { + qDebug() << "AbstractTreeItem::reParent(): cannot reparent" << this << "with children."; + return false; + } + + int oldRow = row(); + if(oldRow == -1) + return false; + + emit parent()->beginRemoveChilds(oldRow, oldRow); + parent()->_childItems.removeAt(oldRow); + emit parent()->endRemoveChilds(); + + setParent(newParent); + + bool success = newParent->newChild(this); + if(!success) + qWarning() << "AbstractTreeItem::reParent(): failed to attach to new parent after removing from old parent! this:" << this << "new parent:" << newParent; + + return success; +} + AbstractTreeItem *AbstractTreeItem::child(int row) const { if(childCount() <= row) return 0; @@ -155,10 +180,15 @@ int AbstractTreeItem::childCount(int column) const { } int AbstractTreeItem::row() const { - if(!parent()) + if(!parent()) { + qWarning() << "AbstractTreeItem::row():" << this << "has no parent AbstractTreeItem as it's parent! parent is" << QObject::parent(); return -1; - else - return parent()->_childItems.indexOf(const_cast(this)); + } + + int row_ = parent()->_childItems.indexOf(const_cast(this)); + if(row_ == -1) + qWarning() << "AbstractTreeItem::row():" << this << "is not in the child list of" << QObject::parent(); + return row_; } AbstractTreeItem *AbstractTreeItem::parent() const {