X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Ftreemodel.cpp;h=0dc19b77da8adc9e8821f5237ed82064a2e0d4ed;hp=2983e5ff4c3afde3675b9ce92c217ae23b070dc5;hb=2a04cb443a50e37165fc2d5447cc705a813efd3e;hpb=c4507cf512b6fd04e5c75a7ac00b9c2888fb646f diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index 2983e5ff..0dc19b77 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -86,15 +86,32 @@ void AbstractTreeItem::removeChild(int row) { removeChild(defaultColumn(), row); } +void AbstractTreeItem::removeChildById(int column, const quint64 &id) { + if(!_childHash[column].contains(id)) + return; + + AbstractTreeItem *treeItem = _childHash[column][id]; + int row = _childItems[column].indexOf(treeItem); + Q_ASSERT(row >= 0); + removeChild(column, row); +} + +void AbstractTreeItem::removeChildById(const quint64 &id) { + removeChildById(defaultColumn(), id); +} + void AbstractTreeItem::removeAllChilds() { - emit beginRemoveChilds(0, childCount() - 1); + if(childCount() == 0) + return; + emit beginRemoveChilds(0, childCount() - 1); AbstractTreeItem *child; - foreach(int key, _childItems.keys()) { - QList::iterator iter = _childItems[key].begin(); - while(iter != _childItems[key].end()) { + foreach(int column, _childItems.keys()) { + QList::iterator iter = _childItems[column].begin(); + while(iter != _childItems[column].end()) { child = *iter; - iter = _childItems[key].erase(iter); + _childHash[column].remove(_childHash[column].key(child)); + iter = _childItems[column].erase(iter); disconnect(child, 0, this, 0); child->removeAllChilds(); child->deleteLater(); @@ -271,6 +288,19 @@ TreeModel::TreeModel(const QList &data, QObject *parent) : QAbstractItemModel(parent) { rootItem = new SimpleTreeItem(data, 0); + + connect(rootItem, SIGNAL(dataChanged(int)), + this, SLOT(itemDataChanged(int))); + + connect(rootItem, SIGNAL(newChild(AbstractTreeItem *)), + this, SLOT(newChild(AbstractTreeItem *))); + + connect(rootItem, SIGNAL(beginRemoveChilds(int, int)), + this, SLOT(beginRemoveChilds(int, int))); + + connect(rootItem, SIGNAL(endRemoveChilds()), + this, SLOT(endRemoveChilds())); + } TreeModel::~TreeModel() { @@ -411,7 +441,7 @@ void TreeModel::itemDataChanged(int column) { } void TreeModel::appendChild(AbstractTreeItem *parent, AbstractTreeItem *child) { - if(parent == 0 or child == 0) { + if(parent == 0 || child == 0) { qWarning() << "TreeModel::appendChild(parent, child) parent and child have to be valid pointers!" << parent << child; return; } @@ -427,9 +457,6 @@ void TreeModel::appendChild(AbstractTreeItem *parent, AbstractTreeItem *child) { connect(child, SIGNAL(newChild(AbstractTreeItem *)), this, SLOT(newChild(AbstractTreeItem *))); -// connect(child, SIGNAL(childRemoved(int)), -// this, SLOT(childRemoved(int))); - connect(child, SIGNAL(beginRemoveChilds(int, int)), this, SLOT(beginRemoveChilds(int, int))); @@ -450,19 +477,6 @@ void TreeModel::endRemoveChilds() { endRemoveRows(); } -void TreeModel::childRemoved(int row) { - QModelIndex parent = indexByItem(static_cast(sender())); - beginRemoveRows(parent, row, row); - endRemoveRows(); -} - -void TreeModel::childsRemoved(int firstRow, int lastRow) { - QModelIndex parent = indexByItem(static_cast(sender())); - beginRemoveRows(parent, firstRow, lastRow); - endRemoveRows(); - -} - bool TreeModel::removeRow(int row, const QModelIndex &parent) { if(row > rowCount(parent)) return false; @@ -505,6 +519,5 @@ bool TreeModel::removeRows(int row, int count, const QModelIndex &parent) { } void TreeModel::clear() { - removeRows(0, rowCount()); - reset(); + rootItem->removeAllChilds(); }