Got rid of class Global, as promised. For now, the few global variables we still
[quassel.git] / src / client / treemodel.cpp
index 3f26449..0d6111f 100644 (file)
@@ -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<TreeItem*>(parent.internalPointer());
+  
   beginRemoveRows(parent, row, row);
-  TreeItem *item = static_cast<TreeItem*>(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<TreeItem*>(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());
+}