diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 4b249927209..65640091a2d 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -194,6 +194,9 @@ MainWindow::MainWindow(QWidget* parent) connect(scene, SIGNAL(selectionChanged(int)), this, SLOT(selectSceneItem(int))); + connect(scene, SIGNAL(itemPicked(const QModelIndex &)), + this, SLOT(recenterSceneView(const QModelIndex &))); + connect(sceneView->selectionModel(), SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & ) ), this, SLOT(updateInfo())); @@ -1726,3 +1729,14 @@ void MainWindow::make_new_group() Scene_group_item * group = new Scene_group_item("New group"); scene->add_group(group); } + +void MainWindow::recenterSceneView(const QModelIndex &id) +{ + if(id.isValid()) + { + // mapFromSource is necessary to convert the QModelIndex received + // from the Scene into a valid QModelIndex in the view, beacuse of + // the proxymodel + sceneView->scrollTo(proxyModel->mapFromSource(id)); + } +} diff --git a/Polyhedron/demo/Polyhedron/MainWindow.h b/Polyhedron/demo/Polyhedron/MainWindow.h index 53f58c2352e..aed8e451855 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.h +++ b/Polyhedron/demo/Polyhedron/MainWindow.h @@ -14,7 +14,6 @@ #include #include #include - class Scene; class Viewer; class QTreeView; @@ -211,6 +210,9 @@ protected Q_SLOTS: * frame of the viewer to the new selected item's and calls updateGL(). */ void selectionChanged(); + //! Scrolls to the new selected item. + void recenterSceneView(const QModelIndex &id); + /*! * Invoques a context menu for the currently selected item at the requested * position. diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index d570ade1c71..da2149772a1 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -43,6 +43,7 @@ Scene::Scene(QObject* parent) if(ms_splatting==0) ms_splatting = new GlSplat::SplatRenderer(); ms_splattingCounter++; + picked = false; } @@ -480,6 +481,15 @@ glDepthFunc(GL_LEQUAL); ms_splatting->finalize(); } + + //scrolls the sceneView to the selected item's line. + if(picked) + Q_EMIT(itemPicked(index_map.key(mainSelectionIndex()))); + if(with_names) + picked = true; + else + picked = false; + } // workaround for Qt-4.2 (see above) diff --git a/Polyhedron/demo/Polyhedron/Scene.h b/Polyhedron/demo/Polyhedron/Scene.h index f257b45bd17..4c92cfc4de2 100644 --- a/Polyhedron/demo/Polyhedron/Scene.h +++ b/Polyhedron/demo/Polyhedron/Scene.h @@ -233,6 +233,7 @@ public Q_SLOTS: Q_SIGNALS: //generated automatically by moc + void itemPicked(const QModelIndex &); void newItem(int); void updated_bbox(); void updated(); @@ -270,6 +271,7 @@ private: int item_A; //!Index of the item_B. int item_B; + bool picked; static GlSplat::SplatRenderer* ms_splatting; static int ms_splattingCounter; QMap index_map;