summaryrefslogtreecommitdiffstats
path: root/sigmodr/tree/TreeModel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sigmodr/tree/TreeModel.cpp')
-rw-r--r--sigmodr/tree/TreeModel.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/sigmodr/tree/TreeModel.cpp b/sigmodr/tree/TreeModel.cpp
index 024b27e9..1be6d00d 100644
--- a/sigmodr/tree/TreeModel.cpp
+++ b/sigmodr/tree/TreeModel.cpp
@@ -106,6 +106,42 @@ bool TreeModel::hasChildren(const QModelIndex& parent) const
return (0 < static_cast<TreeItem*>(parent.internalPointer())->childCount());
}
+bool TreeModel::insertRows(const int row, const int count, const QModelIndex& parent)
+{
+ if (!parent.isValid())
+ return false;
+ TreeItem* item = static_cast<TreeItem*>(parent.internalPointer());
+ if (!item->canAddTo() || (item == m_root) || (row != item->childCount()))
+ return false;
+ beginInsertRows(parent, row, row + count - 1);
+ for (int i = 0; i < count; ++i)
+ item->addChild();
+ endInsertRows();
+ emit(layoutAboutToBeChanged());
+ emit(layoutChanged());
+ return true;
+}
+
+bool TreeModel::removeRows(const int row, const int count, const QModelIndex& parent)
+{
+ if (!parent.isValid())
+ return false;
+ TreeItem* item = static_cast<TreeItem*>(parent.internalPointer());
+ if (item == m_root)
+ return false;
+ for (int i = 0; i < count; ++i)
+ {
+ TreeItem* child = item->childAt(row + i);
+ if (!child || !child->canRemove())
+ return false;
+ }
+ beginRemoveRows(parent, row, row + count - 1);
+ for (int i = 0; i < count; ++i)
+ item->removeChild(row + i);
+ endRemoveRows();
+ return true;
+}
+
int TreeModel::rowCount(const QModelIndex& parent) const
{
if (!parent.isValid())