Skip to content

Commit

Permalink
3D view: allow usual camera controls while the identify tool is active
Browse files Browse the repository at this point in the history
A small usability improvement... until now one would need to disable
identify tool before being able to move/zoom/rotate the camera in 3D view
and then enable identify tool again. Now camera can be controlled
while the tool is active and the tool is easier to use.
  • Loading branch information
wonder-sk committed Sep 28, 2018
1 parent 68426d6 commit 1a61885
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/3d/qgs3dmapscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void Qgs3DMapScene::registerPickHandler( Qgs3DMapScenePickHandler *pickHandler )
{
Qt3DRender::QObjectPicker *picker = new Qt3DRender::QObjectPicker( entity );
entity->addComponent( picker );
connect( picker, &Qt3DRender::QObjectPicker::pressed, this, &Qgs3DMapScene::onLayerEntityPickEvent );
connect( picker, &Qt3DRender::QObjectPicker::clicked, this, &Qgs3DMapScene::onLayerEntityPickEvent );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/3d/qgs3dmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void Qgs3DMapCanvas::setMapTool( Qgs3DMapTool *tool )
else if ( !mMapTool && tool )
{
mEngine->window()->installEventFilter( this );
mScene->cameraController()->setEnabled( false );
mScene->cameraController()->setEnabled( tool->allowsCameraControls() );
mEngine->window()->setCursor( tool->cursor() );
}

Expand Down
8 changes: 8 additions & 0 deletions src/app/3d/qgs3dmaptool.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class Qgs3DMapTool : public QObject
//! Mouse cursor to be used when the tool is active
virtual QCursor cursor() const;

/**
* Whether the default mouse controls to zoom/pan/rotate camera can stay enabled
* while the tool is active. This may be useful for some basic tools using just
* mouse clicks (e.g. identify, measure), but it could be creating conflicts when used
* with more advanced tools. Default implementation returns true.
*/
virtual bool allowsCameraControls() const { return true; }

protected:
Qgs3DMapCanvas *mCanvas = nullptr;
};
Expand Down
6 changes: 3 additions & 3 deletions src/app/3d/qgs3dmaptoolidentify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ void Qgs3DMapToolIdentify::mousePressEvent( QMouseEvent *event )
void Qgs3DMapToolIdentify::activate()
{
Qt3DRender::QObjectPicker *picker = mCanvas->scene()->terrainEntity()->terrainPicker();
connect( picker, &Qt3DRender::QObjectPicker::pressed, this, &Qgs3DMapToolIdentify::onTerrainPicked );
connect( picker, &Qt3DRender::QObjectPicker::clicked, this, &Qgs3DMapToolIdentify::onTerrainPicked );

mCanvas->scene()->registerPickHandler( mPickHandler.get() );
}

void Qgs3DMapToolIdentify::deactivate()
{
Qt3DRender::QObjectPicker *picker = mCanvas->scene()->terrainEntity()->terrainPicker();
disconnect( picker, &Qt3DRender::QObjectPicker::pressed, this, &Qgs3DMapToolIdentify::onTerrainPicked );
disconnect( picker, &Qt3DRender::QObjectPicker::clicked, this, &Qgs3DMapToolIdentify::onTerrainPicked );

mCanvas->scene()->unregisterPickHandler( mPickHandler.get() );
}
Expand Down Expand Up @@ -132,5 +132,5 @@ void Qgs3DMapToolIdentify::onTerrainEntityChanged()
// no need to disconnect from the previous entity: it has been destroyed
// start listening to the new terrain entity
Qt3DRender::QObjectPicker *picker = mCanvas->scene()->terrainEntity()->terrainPicker();
connect( picker, &Qt3DRender::QObjectPicker::pressed, this, &Qgs3DMapToolIdentify::onTerrainPicked );
connect( picker, &Qt3DRender::QObjectPicker::clicked, this, &Qgs3DMapToolIdentify::onTerrainPicked );
}

0 comments on commit 1a61885

Please sign in to comment.