X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Ftreemodel.cpp;h=c61cf9e83366b7bcba8973acfcb69ea6c2476a4b;hp=9a919803bd4e85d94b590d6dae7447b7fe60095e;hb=e8a5c49548759045b49c208c250c6f61c7fdfcd5;hpb=997a62b68d7469a93f373476dd955c44eb051be0 diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index 9a919803..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 { @@ -399,9 +429,6 @@ QVariant TreeModel::data(const QModelIndex &index, int role) const { return QVariant(); AbstractTreeItem *item = static_cast(index.internalPointer()); - if(role == Qt::DisplayRole && !item->data(index.column(), role).isValid()) { - qDebug() << item->data(0, role) << item->columnCount(); - } return item->data(index.column(), role); }