X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Ftreemodel.cpp;h=0d6111fb5c3916f85ac6efd4717f1e54f08f8739;hb=51dc042dd59b491e45951cb9d8371a1f62857945;hp=3f264498938b6167e07b8c55316bd1baa2250571;hpb=13b2affbdccd1d52479e49affdb81a77258392a6;p=quassel.git diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index 3f264498..0d6111fb 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -162,10 +162,46 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int rol } bool TreeModel::removeRow(int row, const QModelIndex &parent) { + if(row > rowCount(parent)) + return false; + + TreeItem *item; + if(!parent.isValid()) + item = rootItem; + else + item = static_cast(parent.internalPointer()); + beginRemoveRows(parent, row, row); - TreeItem *item = static_cast(parent.internalPointer()); item->removeChild(row); endRemoveRows(); return true; } +bool TreeModel::removeRows(int row, int count, const QModelIndex &parent) { + // check if there is work to be done + if(count == 0) + return true; + + // out of range check + if(row + count - 1 > rowCount(parent) || row < 0 || count < 0) + return false; + + TreeItem *item; + if(!parent.isValid()) + item = rootItem; + else + item = static_cast(parent.internalPointer()); + + + beginRemoveRows(parent, row, row + count - 1); + + for(int i = row + count - 1; i >= 0; i--) { + item->removeChild(i); + } + endRemoveRows(); + return true; +} + +void TreeModel::clear() { + removeRows(0, rowCount()); +}