X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Ftreemodel.cpp;h=d84f0e018e0090645090f47b421b8f56fc7b2c43;hp=1505a25ed11272a72f66d5e8fed3806f2f59fa71;hb=7f22197b5318ccbe7f0b6b644127a71c025ca917;hpb=e104b220388a276a4483a45567243a8473ca5fa6 diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index 1505a25e..d84f0e01 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -162,6 +162,9 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int rol } bool TreeModel::removeRow(int row, const QModelIndex &parent) { + if(row > rowCount(parent)) + return false; + beginRemoveRows(parent, row, row); TreeItem *item = static_cast(parent.internalPointer()); item->removeChild(row); @@ -170,9 +173,17 @@ bool TreeModel::removeRow(int row, const QModelIndex &parent) { } 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; + beginRemoveRows(parent, row, row + count - 1); TreeItem *item = static_cast(parent.internalPointer()); - for(int i = row; i < row + count; i++) { + for(int i = row + count - 1; i >= 0; i--) { item->removeChild(i); } endRemoveRows();