Commit 158eb788 by Alisa Jung

delete nodes from model

parent ab86fe42
...@@ -92,31 +92,10 @@ TreeItem* MyItemModel::getItem(const QModelIndex& index) const{ ...@@ -92,31 +92,10 @@ TreeItem* MyItemModel::getItem(const QModelIndex& index) const{
} }
bool MyItemModel::insertRows(int position, int rows, const QModelIndex &parent) void MyItemModel::addNewTransformToRoot(TreeItem *rbt, TreeItem* prim){
{
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){
beginInsertRows(QModelIndex(), 0, 0); beginInsertRows(QModelIndex(), 0, 0);
qDebug() << "Add child " << rbt->data(0); qDebug() << "Add child " << rbt->data(0);
root->addChild(rbt); root->addChild(rbt);
endInsertRows(); endInsertRows();
QModelIndex i = index(0,0,QModelIndex()); QModelIndex i = index(0,0,QModelIndex());
beginInsertRows(i,0,0); beginInsertRows(i,0,0);
...@@ -126,3 +105,20 @@ void MyItemModel::addChildToRoot(TreeItem *rbt, TreeItem* prim){ ...@@ -126,3 +105,20 @@ void MyItemModel::addChildToRoot(TreeItem *rbt, TreeItem* prim){
endInsertRows(); endInsertRows();
// return true; // 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: ...@@ -22,9 +22,8 @@ public:
QModelIndex index(int row, int column, const QModelIndex &parent) const Q_DECL_OVERRIDE; QModelIndex index(int row, int column, const QModelIndex &parent) const Q_DECL_OVERRIDE;
QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
void addChildToRoot(TreeItem* rbt, TreeItem* prim); void addNewTransformToRoot(TreeItem* rbt, TreeItem* prim);
void removeTransformFromRoot(TreeItem* rbt);
bool insertRows(int row, int count, const QModelIndex &parent);
private: private:
TreeItem* root; TreeItem* root;
......
...@@ -93,7 +93,7 @@ RigidBodyTransformation* SceneGraph::addTorus(int tesselation){ ...@@ -93,7 +93,7 @@ RigidBodyTransformation* SceneGraph::addTorus(int tesselation){
RigidBodyTransformation* SceneGraph::addPrimitive(Primitive* p){ RigidBodyTransformation* SceneGraph::addPrimitive(Primitive* p){
RigidBodyTransformation* r = new RigidBodyTransformation(); RigidBodyTransformation* r = new RigidBodyTransformation();
nodes.append(r); nodes.append(r);
model->addChildToRoot(r,p); model->addNewTransformToRoot(r,p);
// model->insertRows(1,1,QModelIndex()); // model->insertRows(1,1,QModelIndex());
notifyViews(); notifyViews();
return r; return r;
...@@ -106,6 +106,7 @@ RigidBodyTransformation* SceneGraph::deleteNode(RigidBodyTransformation *r){ ...@@ -106,6 +106,7 @@ RigidBodyTransformation* SceneGraph::deleteNode(RigidBodyTransformation *r){
} }
bool s = nodes.removeOne(r); bool s = nodes.removeOne(r);
if (!s) qDebug("could not remove this. Delete r anyways."); if (!s) qDebug("could not remove this. Delete r anyways.");
model->removeTransformFromRoot(r);
r->~RigidBodyTransformation(); r->~RigidBodyTransformation();
notifyViews(); notifyViews();
if (nodes.length() > 0) return nodes.back(); 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