Merge pull request #560 from maxGimeno/Polyhedron_demo-scroll_sceneview-GF

Scrolls the sceneView when a picking is performed.
This commit is contained in:
Sébastien Loriot 2015-12-18 16:38:26 +01:00
commit b4315f4232
4 changed files with 29 additions and 1 deletions

View File

@ -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()));
@ -1736,3 +1739,14 @@ void MainWindow::on_downButton_pressed()
{
scene->moveRowDown();
}
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));
}
}

View File

@ -14,7 +14,6 @@
#include <QFileInfo>
#include <QStringList>
#include <QSet>
class Scene;
class Viewer;
class QTreeView;
@ -212,6 +211,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.

View File

@ -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)

View File

@ -235,6 +235,7 @@ public Q_SLOTS:
Q_SIGNALS:
//generated automatically by moc
void itemPicked(const QModelIndex &);
void newItem(int);
void updated_bbox();
void updated();
@ -272,6 +273,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<QModelIndex, int> index_map;