Commit 10d649c3 by Alisa Jung

not sure what is happening. selecting items in tree view works a little.

parent 158eb788
...@@ -261,3 +261,11 @@ void Controller::selectTransform(RigidBodyTransformation *rbt){ ...@@ -261,3 +261,11 @@ void Controller::selectTransform(RigidBodyTransformation *rbt){
statusBar->showMessage("None selected"); statusBar->showMessage("None selected");
} }
} }
void Controller::itemSelected(QModelIndex q){
qDebug() << "item selected. Row: " << q.row() << ", column: " << q.column();
qDebug("try to retrieve rbt");
TreeItem* t = scene->getItem(q);
if (t->childNumber() == 0) t = t->getParent();
selectTransform(static_cast<RigidBodyTransformation*>(t));
}
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <QGridLayout> #include <QGridLayout>
#include <rigidbodytransformation.h> #include <rigidbodytransformation.h>
#include <QStatusBar> #include <QStatusBar>
#include <QModelIndex>
#include <math.h> #include <math.h>
...@@ -95,6 +96,8 @@ public slots: ...@@ -95,6 +96,8 @@ public slots:
void addTorus(); void addTorus();
void deletePrimitive(); void deletePrimitive();
void itemSelected(QModelIndex q);
}; };
#endif // CONTROLLER_H #endif // CONTROLLER_H
...@@ -254,6 +254,9 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -254,6 +254,9 @@ MainWindow::MainWindow(QWidget *parent)
dockWidget->setWidget(treeView); dockWidget->setWidget(treeView);
addDockWidget(Qt::RightDockWidgetArea, dockWidget); addDockWidget(Qt::RightDockWidgetArea, dockWidget);
connect(treeView,SIGNAL(clicked(QModelIndex)),controller, SLOT(itemSelected(QModelIndex)));
} }
......
...@@ -76,7 +76,7 @@ Qt::ItemFlags MyItemModel::flags(const QModelIndex &index) const{ ...@@ -76,7 +76,7 @@ Qt::ItemFlags MyItemModel::flags(const QModelIndex &index) const{
if (!index.isValid()){ if (!index.isValid()){
return 0; return 0;
}else{ }else{
return Qt::ItemIsEditable | QAbstractItemModel::flags(index); return Qt::ItemIsEditable | Qt::ItemIsSelectable | QAbstractItemModel::flags(index);
} }
} }
......
...@@ -24,11 +24,11 @@ public: ...@@ -24,11 +24,11 @@ public:
void addNewTransformToRoot(TreeItem* rbt, TreeItem* prim); void addNewTransformToRoot(TreeItem* rbt, TreeItem* prim);
void removeTransformFromRoot(TreeItem* rbt); void removeTransformFromRoot(TreeItem* rbt);
TreeItem* getItem(const QModelIndex &index) const;
private: private:
TreeItem* root; TreeItem* root;
TreeItem* getItem(const QModelIndex &index) const;
}; };
#endif // MYITEMMODEL_H #endif // MYITEMMODEL_H
...@@ -5,7 +5,7 @@ RigidBodyTransformation::RigidBodyTransformation() ...@@ -5,7 +5,7 @@ RigidBodyTransformation::RigidBodyTransformation()
{ {
translation = QVector3D(0,0,0); translation = QVector3D(0,0,0);
rotation = QQuaternion(); rotation = QQuaternion();
name = ""; name = "<rbt>";
// qDebug() << "new rbt " << tx << "," << ty << "," << tz << ", rot " << rotation; // qDebug() << "new rbt " << tx << "," << ty << "," << tz << ", rot " << rotation;
} }
......
...@@ -136,3 +136,7 @@ void SceneGraph::notifyViews(){ ...@@ -136,3 +136,7 @@ void SceneGraph::notifyViews(){
(*i)->modelChanged(); (*i)->modelChanged();
} }
} }
TreeItem* SceneGraph::getItem(QModelIndex q){
return model->getItem(q);
}
...@@ -34,6 +34,8 @@ public: ...@@ -34,6 +34,8 @@ public:
MyItemModel* getModel(); MyItemModel* getModel();
TreeItem* getItem(QModelIndex q);
//Hallo. Todos: //Hallo. Todos:
//Log selected name in status bar //Log selected name in status bar
//add remaining primitive types //add remaining primitive types
......
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