From 9c2020c7035a22bab89bf47d199dec4f5df6c704 Mon Sep 17 00:00:00 2001 From: Withalion Date: Fri, 7 Mar 2025 20:26:06 +0100 Subject: [PATCH] Fix paintbrush editing tool movement --- src/3d/qgs3dmapcanvas.cpp | 3 +++ src/3d/qgs3dmaptool.cpp | 5 +++++ src/3d/qgs3dmaptool.h | 2 ++ src/app/3d/qgs3dmapcanvaswidget.cpp | 1 + ...aptoolpointcloudchangeattributepaintbrush.cpp | 16 ++++++++++++---- ...dmaptoolpointcloudchangeattributepaintbrush.h | 1 + 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/3d/qgs3dmapcanvas.cpp b/src/3d/qgs3dmapcanvas.cpp index dc920edafab..c45b00aef7e 100644 --- a/src/3d/qgs3dmapcanvas.cpp +++ b/src/3d/qgs3dmapcanvas.cpp @@ -300,6 +300,9 @@ bool Qgs3DMapCanvas::eventFilter( QObject *watched, QEvent *event ) case QEvent::KeyPress: mMapTool->keyPressEvent( static_cast( event ) ); break; + case QEvent::KeyRelease: + mMapTool->keyReleaseEvent( static_cast( event ) ); + break; case QEvent::Wheel: mMapTool->mouseWheelEvent( static_cast( event ) ); break; diff --git a/src/3d/qgs3dmaptool.cpp b/src/3d/qgs3dmaptool.cpp index 1a68a553a4b..f82a45af379 100644 --- a/src/3d/qgs3dmaptool.cpp +++ b/src/3d/qgs3dmaptool.cpp @@ -44,6 +44,11 @@ void Qgs3DMapTool::keyPressEvent( QKeyEvent *event ) Q_UNUSED( event ) } +void Qgs3DMapTool::keyReleaseEvent( QKeyEvent *event ) +{ + Q_UNUSED( event ) +} + void Qgs3DMapTool::mouseWheelEvent( QWheelEvent *event ) { Q_UNUSED( event ) diff --git a/src/3d/qgs3dmaptool.h b/src/3d/qgs3dmaptool.h index cc9713caba3..b15c51ff04b 100644 --- a/src/3d/qgs3dmaptool.h +++ b/src/3d/qgs3dmaptool.h @@ -50,6 +50,8 @@ class _3D_EXPORT Qgs3DMapTool : public QObject virtual void mouseMoveEvent( QMouseEvent *event ); //! Reimplement to handle key press \a event forwarded by the parent Qgs3DMapCanvas virtual void keyPressEvent( QKeyEvent *event ); + //! Reimplement to handle key release \a event forwarded by the parent Qgs3DMapCanvas + virtual void keyReleaseEvent( QKeyEvent *event ); //! Reimplement to handle mouse wheel \a event forwarded by the parent Qgs3DMapCanvas virtual void mouseWheelEvent( QWheelEvent *event ); diff --git a/src/app/3d/qgs3dmapcanvaswidget.cpp b/src/app/3d/qgs3dmapcanvaswidget.cpp index 1db55faa751..7604aa65050 100644 --- a/src/app/3d/qgs3dmapcanvaswidget.cpp +++ b/src/app/3d/qgs3dmapcanvaswidget.cpp @@ -490,6 +490,7 @@ void Qgs3DMapCanvasWidget::changePointCloudAttributeByPaintbrush() if ( !action ) return; + mCanvas->requestActivate(); mCanvas->setMapTool( nullptr ); mMapToolChangeAttribute.reset( new Qgs3DMapToolPointCloudChangeAttributePaintbrush( mCanvas ) ); onPointCloudChangeAttributeSettingsChanged(); diff --git a/src/app/3d/qgs3dmaptoolpointcloudchangeattributepaintbrush.cpp b/src/app/3d/qgs3dmaptoolpointcloudchangeattributepaintbrush.cpp index 65b84425249..2f8e12c8db1 100644 --- a/src/app/3d/qgs3dmaptoolpointcloudchangeattributepaintbrush.cpp +++ b/src/app/3d/qgs3dmaptoolpointcloudchangeattributepaintbrush.cpp @@ -157,10 +157,18 @@ void Qgs3DMapToolPointCloudChangeAttributePaintbrush::keyPressEvent( QKeyEvent * restart(); } - if ( !mIsClicked && event->key() == Qt::Key_Space ) + if ( event->key() == Qt::Key_Space && !event->isAutoRepeat() ) { - const bool newState = !mCanvas->cameraController()->hasInputHandlersEnabled(); - mCanvas->cameraController()->setInputHandlersEnabled( newState ); - mIsMoving = newState; + mCanvas->cameraController()->setInputHandlersEnabled( true ); + mIsMoving = true; + } +} + +void Qgs3DMapToolPointCloudChangeAttributePaintbrush::keyReleaseEvent( QKeyEvent *event ) +{ + if ( event->key() == Qt::Key_Space && !event->isAutoRepeat() ) + { + mCanvas->cameraController()->setInputHandlersEnabled( false ); + mIsMoving = false; } } diff --git a/src/app/3d/qgs3dmaptoolpointcloudchangeattributepaintbrush.h b/src/app/3d/qgs3dmaptoolpointcloudchangeattributepaintbrush.h index d7b6ab479da..a42fd11d142 100644 --- a/src/app/3d/qgs3dmaptoolpointcloudchangeattributepaintbrush.h +++ b/src/app/3d/qgs3dmaptoolpointcloudchangeattributepaintbrush.h @@ -42,6 +42,7 @@ class Qgs3DMapToolPointCloudChangeAttributePaintbrush : public Qgs3DMapToolPoint void mouseMoveEvent( QMouseEvent *event ) override; void mouseWheelEvent( QWheelEvent *event ) override; void keyPressEvent( QKeyEvent *event ) override; + void keyReleaseEvent( QKeyEvent *event ) override; private: void run() override;