+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());
+}