Commit 158eb788 by Alisa Jung

delete nodes from model

parent ab86fe42
......@@ -92,31 +92,10 @@ TreeItem* MyItemModel::getItem(const QModelIndex& index) const{
}
bool MyItemModel::insertRows(int position, int rows, const QModelIndex &parent)
{
beginInsertRows(QModelIndex(), position, position+rows-1);
TreeItem* p = getItem(parent);
for (int row = 0; row < rows; ++row) {
qDebug("Add Child to item");
p->addChild(new TreeItem());
}
endInsertRows();
return true;
}
void MyItemModel::addChildToRoot(TreeItem *rbt, TreeItem* prim){
void MyItemModel::addNewTransformToRoot(TreeItem *rbt, TreeItem* prim){
beginInsertRows(QModelIndex(), 0, 0);
qDebug() << "Add child " << rbt->data(0);
root->addChild(rbt);
endInsertRows();
QModelIndex i = index(0,0,QModelIndex());
beginInsertRows(i,0,0);
......@@ -126,3 +105,20 @@ void MyItemModel::addChildToRoot(TreeItem *rbt, TreeItem* prim){
endInsertRows();
// return true;
}
void MyItemModel::removeTransformFromRoot(TreeItem *rbt){
int row = -1;
for (int i = 0; i < root->getChildren().length(); i++){
if (root->getChild(i) == rbt){
row = i;
break;
}
}
if (row < 0) qDebug("item not found");
else {
// QModelIndex i = index(row,0,QModelIndex());
beginRemoveRows(QModelIndex(),row,row);
root->removeChild(rbt);
endRemoveRows();
}
}
......@@ -22,9 +22,8 @@ public:
QModelIndex index(int row, int column, const QModelIndex &parent) const Q_DECL_OVERRIDE;
QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
void addChildToRoot(TreeItem* rbt, TreeItem* prim);
bool insertRows(int row, int count, const QModelIndex &parent);
void addNewTransformToRoot(TreeItem* rbt, TreeItem* prim);
void removeTransformFromRoot(TreeItem* rbt);
private:
TreeItem* root;
......
......@@ -93,7 +93,7 @@ RigidBodyTransformation* SceneGraph::addTorus(int tesselation){
RigidBodyTransformation* SceneGraph::addPrimitive(Primitive* p){
RigidBodyTransformation* r = new RigidBodyTransformation();
nodes.append(r);
model->addChildToRoot(r,p);
model->addNewTransformToRoot(r,p);
// model->insertRows(1,1,QModelIndex());
notifyViews();
return r;
......@@ -106,6 +106,7 @@ RigidBodyTransformation* SceneGraph::deleteNode(RigidBodyTransformation *r){
}
bool s = nodes.removeOne(r);
if (!s) qDebug("could not remove this. Delete r anyways.");
model->removeTransformFromRoot(r);
r->~RigidBodyTransformation();
notifyViews();
if (nodes.length() > 0) return nodes.back();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment