X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Ftreemodel.cpp;h=2a71576de2309419dce7b97d5b2f01db8668cf5c;hb=cd3dc8132fa88bd81e8aa2c9947d3540e1f56f37;hp=9a919803bd4e85d94b590d6dae7447b7fe60095e;hpb=f2e4609f070221a010eef8be98524c5ce88d228b;p=quassel.git diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index 9a919803..2a71576d 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -19,6 +19,7 @@ ***************************************************************************/ #include "treemodel.h" +#include "global.h" #include #include @@ -131,6 +132,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 +181,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 { @@ -287,7 +318,7 @@ TreeModel::TreeModel(const QList &data, QObject *parent) rootItem = new SimpleTreeItem(data, 0); connectItem(rootItem); - if(QCoreApplication::instance()->arguments().contains("--debugmodel")) { + if(Global::parser.isSet("debugmodel")) { connect(this, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), this, SLOT(debug_rowsAboutToBeInserted(const QModelIndex &, int, int))); connect(this, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), @@ -399,9 +430,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); }