Skip to content
Permalink
Browse files
3D view: allow usual camera controls while the identify tool is active
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 1a61885254aa91bcb3cd1169767e8e9246de7faf
Showing with 13 additions and 5 deletions.
  1. +1 −1 src/3d/qgs3dmapscene.cpp
  2. +1 −1 src/app/3d/qgs3dmapcanvas.cpp
  3. +8 −0 src/app/3d/qgs3dmaptool.h
  4. +3 −3 src/app/3d/qgs3dmaptoolidentify.cpp
@@ -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 );
}
}

@@ -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() );
}

@@ -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;
};
@@ -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() );
}
@@ -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.