From 75607c05f8aefee825e5b4f0d5428626da52fe48 Mon Sep 17 00:00:00 2001 From: uclaros Date: Fri, 12 Jan 2024 16:59:49 +0200 Subject: [PATCH] Qgs3DMapCanvas + Qgs3DWindow = <3 --- python/3d/3d_auto.sip | 3 +- .../3d/auto_generated/qgs3dmapcanvas.sip.in | 191 ++++++++++++++++++ python/3d/auto_generated/qgs3dmaptool.sip.in | 64 ++++++ python/3d/auto_generated/qgs3dwindow.sip.in | 69 ------- python/PyQt6/3d/3d_auto.sip | 3 +- .../3d/auto_generated/qgs3dmapcanvas.sip.in | 191 ++++++++++++++++++ .../3d/auto_generated/qgs3dmaptool.sip.in | 64 ++++++ .../3d/auto_generated/qgs3dwindow.sip.in | 69 ------- src/3d/CMakeLists.txt | 6 +- src/3d/qgs3daxis.cpp | 6 +- src/3d/qgs3daxis.h | 6 +- src/3d/qgs3dmapcanvas.cpp | 133 ++++++++++-- src/3d/qgs3dmapcanvas.h | 153 ++++++++++++-- src/3d/qgs3dmapscene.cpp | 2 +- src/3d/qgs3dwindow.cpp | 119 ----------- src/3d/qgs3dwindow.h | 151 -------------- src/3d/qgswindow3dengine.cpp | 6 +- src/3d/qgswindow3dengine.h | 6 +- src/app/3d/qgs3dmapcanvaswidget.cpp | 19 +- src/app/3d/qgs3dmaptoolidentify.cpp | 4 +- src/app/3d/qgs3dmeasuredialog.cpp | 2 +- src/app/3d/qgs3dnavigationwidget.cpp | 20 -- src/app/3d/qgs3dnavigationwidget.h | 12 -- src/app/3d/qgs3dviewsmanagerdialog.cpp | 1 - 24 files changed, 789 insertions(+), 511 deletions(-) create mode 100644 python/3d/auto_generated/qgs3dmapcanvas.sip.in create mode 100644 python/3d/auto_generated/qgs3dmaptool.sip.in delete mode 100644 python/3d/auto_generated/qgs3dwindow.sip.in create mode 100644 python/PyQt6/3d/auto_generated/qgs3dmapcanvas.sip.in create mode 100644 python/PyQt6/3d/auto_generated/qgs3dmaptool.sip.in delete mode 100644 python/PyQt6/3d/auto_generated/qgs3dwindow.sip.in delete mode 100644 src/3d/qgs3dwindow.cpp delete mode 100644 src/3d/qgs3dwindow.h diff --git a/python/3d/3d_auto.sip b/python/3d/3d_auto.sip index 86c92bd2a54..465a9b57088 100644 --- a/python/3d/3d_auto.sip +++ b/python/3d/3d_auto.sip @@ -1,10 +1,11 @@ // Include auto-generated SIP files %Include auto_generated/processing/qgs3dalgorithms.sip %Include auto_generated/qgs3d.sip +%Include auto_generated/qgs3dmapcanvas.sip %Include auto_generated/qgs3dmapscene.sip %Include auto_generated/qgs3dmapsettings.sip +%Include auto_generated/qgs3dmaptool.sip %Include auto_generated/qgs3dtypes.sip -%Include auto_generated/qgs3dwindow.sip %Include auto_generated/qgsabstractvectorlayer3drenderer.sip %Include auto_generated/qgscameracontroller.sip %Include auto_generated/qgscamerapose.sip diff --git a/python/3d/auto_generated/qgs3dmapcanvas.sip.in b/python/3d/auto_generated/qgs3dmapcanvas.sip.in new file mode 100644 index 00000000000..5d13955e5b1 --- /dev/null +++ b/python/3d/auto_generated/qgs3dmapcanvas.sip.in @@ -0,0 +1,191 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/3d/qgs3dmapcanvas.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + + + + +class Qgs3DMapCanvas : QWindow +{ +%Docstring(signature="appended") +Qgs3DMapCanvas is a convenience wrapper to simplify the creation of a 3D window ready to be used with QGIS. + +.. note:: + + This is a port of qtwindow3d which does not set the default surface when initialized. + +.. note:: + + The default surface must be set before the construction of the QApplication when using shared OpenGL context. + +.. note:: + + This is required in order to use QT3d and QtWebEngine at the same time. + +.. versionadded:: 3.36 +%End + +%TypeHeaderCode +#include "qgs3dmapcanvas.h" +%End + public: + + Qgs3DMapCanvas(); +%Docstring +Constructor for Qgs3DMapCanvas. +%End + + ~Qgs3DMapCanvas(); + + + + + + + + void setMap( Qgs3DMapSettings *map ); +%Docstring +Configure map scene being displayed. Takes ownership. +%End + + Qgs3DMapSettings *map(); +%Docstring +Returns access to the 3D scene configuration +%End + + Qgs3DMapScene *scene(); +%Docstring +Returns access to the 3D scene (root 3D entity) +%End + + QgsCameraController *cameraController(); +%Docstring +Returns access to the view's camera controller. Returns ``None`` if the scene has not been initialized yet with :py:func:`~Qgs3DMapCanvas.setMap` +%End + + void resetView(); +%Docstring +Resets camera position to the default: looking down at the origin of world coordinates +%End + + void setViewFromTop( const QgsPointXY ¢er, float distance, float rotation = 0 ); +%Docstring +Sets camera position to look down at the given point (in map coordinates) in given distance from plane with zero elevation +%End + + void saveAsImage( const QString &fileName, const QString &fileFormat ); +%Docstring +Saves the current scene as an image +%End + + void setMapTool( Qgs3DMapTool *tool ); +%Docstring +Sets the active map tool that will receive events from the 3D canvas. Does not transfer ownership. +If the tool is ``None``, events will be used for camera manipulation. +%End + + Qgs3DMapTool *mapTool() const; +%Docstring +Returns the active map tool that will receive events from the 3D canvas. +If the tool is ``None``, events will be used for camera manipulation. +%End + + + void setTemporalController( QgsTemporalController *temporalController ); +%Docstring +Sets the temporal controller +%End + + QSize windowSize() const; +%Docstring +Returns the size of the 3D canvas window + +.. versionadded:: 3.18 +%End + + void setViewFrom2DExtent( const QgsRectangle &extent ); +%Docstring +Resets camera view to show the extent ``extent`` (top view) + +.. versionadded:: 3.26 +%End + + QVector viewFrustum2DExtent(); +%Docstring +Calculates the 2D extent viewed by the 3D camera as the vertices of the viewed trapezoid + +.. versionadded:: 3.26 +%End + + signals: + void savedAsImage( const QString &fileName ); +%Docstring +Emitted when the 3D map canvas was successfully saved as image +%End + + void mapSettingsChanged(); +%Docstring +Emitted when the the map setting is changed +%End + + void fpsCountChanged( float fpsCount ); +%Docstring +Emitted when the FPS count changes (at most every frame) +%End + void fpsCounterEnabledChanged( bool enabled ); +%Docstring +Emitted when the FPS counter is enabled or disabeld +%End + + void viewed2DExtentFrom3DChanged( QVector extent ); +%Docstring +Emitted when the viewed 2D extent seen by the 3D camera has changed + +.. versionadded:: 3.26 +%End + + void cameraNavigationSpeedChanged( double speed ); +%Docstring +Emitted when the camera navigation ``speed`` is changed. + +.. versionadded:: 3.18 +%End + public slots: + void captureDepthBuffer(); + + protected: + + virtual void showEvent( QShowEvent *e ); + +%Docstring +Manages the display events specified in e. +%End + + virtual void resizeEvent( QResizeEvent * ); + +%Docstring +Resets the aspect ratio of the 3D window. +%End + + + + virtual bool eventFilter( QObject *watched, QEvent *event ); + + +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/3d/qgs3dmapcanvas.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/3d/auto_generated/qgs3dmaptool.sip.in b/python/3d/auto_generated/qgs3dmaptool.sip.in new file mode 100644 index 00000000000..7a855673e6c --- /dev/null +++ b/python/3d/auto_generated/qgs3dmaptool.sip.in @@ -0,0 +1,64 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/3d/qgs3dmaptool.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + +class Qgs3DMapTool : QObject +{ +%Docstring(signature="appended") +Base class for map tools operating on 3D map canvas. +%End + +%TypeHeaderCode +#include "qgs3dmaptool.h" +%End + public: + Qgs3DMapTool( Qgs3DMapCanvas *canvas ); + + virtual void mousePressEvent( QMouseEvent *event ); + virtual void mouseReleaseEvent( QMouseEvent *event ); + virtual void mouseMoveEvent( QMouseEvent *event ); + virtual void keyPressEvent( QKeyEvent *event ); + + virtual void activate(); +%Docstring +Called when set as currently active map tool +%End + + virtual void deactivate(); +%Docstring +Called when map tool is being deactivated +%End + + virtual QCursor cursor() const; +%Docstring +Mouse cursor to be used when the tool is active +%End + + virtual bool allowsCameraControls() const; +%Docstring +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``. +%End + + Qgs3DMapCanvas *canvas(); + + protected: +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/3d/qgs3dmaptool.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/3d/auto_generated/qgs3dwindow.sip.in b/python/3d/auto_generated/qgs3dwindow.sip.in deleted file mode 100644 index dff9b2d8162..00000000000 --- a/python/3d/auto_generated/qgs3dwindow.sip.in +++ /dev/null @@ -1,69 +0,0 @@ -/************************************************************************ - * This file has been generated automatically from * - * * - * src/3d/qgs3dwindow.h * - * * - * Do not edit manually ! Edit header and run scripts/sipify.pl again * - ************************************************************************/ - - - - - - -class Qgs3DWindow : QWindow -{ -%Docstring(signature="appended") -qgs3dWindow is a convenience wrapper to simplify the creation of a 3D window ready to be used with QGIS. - -.. note:: - - This is a port of qtwindow3d which does not set the default surface when initialized. - -.. note:: - - The default surface must be set before the construction of the QApplication when using shared OpenGL context. - -.. note:: - - This is required in order to use QT3d and QtWebEngine at the same time. - -.. versionadded:: 3.36 -%End - -%TypeHeaderCode -#include "qgs3dwindow.h" -%End - public: - - Qgs3DWindow(); -%Docstring -Constructor for Qgs3DWindow. -%End - - ~Qgs3DWindow(); - - - protected: - - virtual void showEvent( QShowEvent *e ); - -%Docstring -Manages the display events specified in e. -%End - - virtual void resizeEvent( QResizeEvent * ); - -%Docstring -Resets the aspect ratio of the 3D window. -%End - -}; - -/************************************************************************ - * This file has been generated automatically from * - * * - * src/3d/qgs3dwindow.h * - * * - * Do not edit manually ! Edit header and run scripts/sipify.pl again * - ************************************************************************/ diff --git a/python/PyQt6/3d/3d_auto.sip b/python/PyQt6/3d/3d_auto.sip index 86c92bd2a54..465a9b57088 100644 --- a/python/PyQt6/3d/3d_auto.sip +++ b/python/PyQt6/3d/3d_auto.sip @@ -1,10 +1,11 @@ // Include auto-generated SIP files %Include auto_generated/processing/qgs3dalgorithms.sip %Include auto_generated/qgs3d.sip +%Include auto_generated/qgs3dmapcanvas.sip %Include auto_generated/qgs3dmapscene.sip %Include auto_generated/qgs3dmapsettings.sip +%Include auto_generated/qgs3dmaptool.sip %Include auto_generated/qgs3dtypes.sip -%Include auto_generated/qgs3dwindow.sip %Include auto_generated/qgsabstractvectorlayer3drenderer.sip %Include auto_generated/qgscameracontroller.sip %Include auto_generated/qgscamerapose.sip diff --git a/python/PyQt6/3d/auto_generated/qgs3dmapcanvas.sip.in b/python/PyQt6/3d/auto_generated/qgs3dmapcanvas.sip.in new file mode 100644 index 00000000000..5d13955e5b1 --- /dev/null +++ b/python/PyQt6/3d/auto_generated/qgs3dmapcanvas.sip.in @@ -0,0 +1,191 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/3d/qgs3dmapcanvas.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + + + + +class Qgs3DMapCanvas : QWindow +{ +%Docstring(signature="appended") +Qgs3DMapCanvas is a convenience wrapper to simplify the creation of a 3D window ready to be used with QGIS. + +.. note:: + + This is a port of qtwindow3d which does not set the default surface when initialized. + +.. note:: + + The default surface must be set before the construction of the QApplication when using shared OpenGL context. + +.. note:: + + This is required in order to use QT3d and QtWebEngine at the same time. + +.. versionadded:: 3.36 +%End + +%TypeHeaderCode +#include "qgs3dmapcanvas.h" +%End + public: + + Qgs3DMapCanvas(); +%Docstring +Constructor for Qgs3DMapCanvas. +%End + + ~Qgs3DMapCanvas(); + + + + + + + + void setMap( Qgs3DMapSettings *map ); +%Docstring +Configure map scene being displayed. Takes ownership. +%End + + Qgs3DMapSettings *map(); +%Docstring +Returns access to the 3D scene configuration +%End + + Qgs3DMapScene *scene(); +%Docstring +Returns access to the 3D scene (root 3D entity) +%End + + QgsCameraController *cameraController(); +%Docstring +Returns access to the view's camera controller. Returns ``None`` if the scene has not been initialized yet with :py:func:`~Qgs3DMapCanvas.setMap` +%End + + void resetView(); +%Docstring +Resets camera position to the default: looking down at the origin of world coordinates +%End + + void setViewFromTop( const QgsPointXY ¢er, float distance, float rotation = 0 ); +%Docstring +Sets camera position to look down at the given point (in map coordinates) in given distance from plane with zero elevation +%End + + void saveAsImage( const QString &fileName, const QString &fileFormat ); +%Docstring +Saves the current scene as an image +%End + + void setMapTool( Qgs3DMapTool *tool ); +%Docstring +Sets the active map tool that will receive events from the 3D canvas. Does not transfer ownership. +If the tool is ``None``, events will be used for camera manipulation. +%End + + Qgs3DMapTool *mapTool() const; +%Docstring +Returns the active map tool that will receive events from the 3D canvas. +If the tool is ``None``, events will be used for camera manipulation. +%End + + + void setTemporalController( QgsTemporalController *temporalController ); +%Docstring +Sets the temporal controller +%End + + QSize windowSize() const; +%Docstring +Returns the size of the 3D canvas window + +.. versionadded:: 3.18 +%End + + void setViewFrom2DExtent( const QgsRectangle &extent ); +%Docstring +Resets camera view to show the extent ``extent`` (top view) + +.. versionadded:: 3.26 +%End + + QVector viewFrustum2DExtent(); +%Docstring +Calculates the 2D extent viewed by the 3D camera as the vertices of the viewed trapezoid + +.. versionadded:: 3.26 +%End + + signals: + void savedAsImage( const QString &fileName ); +%Docstring +Emitted when the 3D map canvas was successfully saved as image +%End + + void mapSettingsChanged(); +%Docstring +Emitted when the the map setting is changed +%End + + void fpsCountChanged( float fpsCount ); +%Docstring +Emitted when the FPS count changes (at most every frame) +%End + void fpsCounterEnabledChanged( bool enabled ); +%Docstring +Emitted when the FPS counter is enabled or disabeld +%End + + void viewed2DExtentFrom3DChanged( QVector extent ); +%Docstring +Emitted when the viewed 2D extent seen by the 3D camera has changed + +.. versionadded:: 3.26 +%End + + void cameraNavigationSpeedChanged( double speed ); +%Docstring +Emitted when the camera navigation ``speed`` is changed. + +.. versionadded:: 3.18 +%End + public slots: + void captureDepthBuffer(); + + protected: + + virtual void showEvent( QShowEvent *e ); + +%Docstring +Manages the display events specified in e. +%End + + virtual void resizeEvent( QResizeEvent * ); + +%Docstring +Resets the aspect ratio of the 3D window. +%End + + + + virtual bool eventFilter( QObject *watched, QEvent *event ); + + +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/3d/qgs3dmapcanvas.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/PyQt6/3d/auto_generated/qgs3dmaptool.sip.in b/python/PyQt6/3d/auto_generated/qgs3dmaptool.sip.in new file mode 100644 index 00000000000..7a855673e6c --- /dev/null +++ b/python/PyQt6/3d/auto_generated/qgs3dmaptool.sip.in @@ -0,0 +1,64 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/3d/qgs3dmaptool.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + +class Qgs3DMapTool : QObject +{ +%Docstring(signature="appended") +Base class for map tools operating on 3D map canvas. +%End + +%TypeHeaderCode +#include "qgs3dmaptool.h" +%End + public: + Qgs3DMapTool( Qgs3DMapCanvas *canvas ); + + virtual void mousePressEvent( QMouseEvent *event ); + virtual void mouseReleaseEvent( QMouseEvent *event ); + virtual void mouseMoveEvent( QMouseEvent *event ); + virtual void keyPressEvent( QKeyEvent *event ); + + virtual void activate(); +%Docstring +Called when set as currently active map tool +%End + + virtual void deactivate(); +%Docstring +Called when map tool is being deactivated +%End + + virtual QCursor cursor() const; +%Docstring +Mouse cursor to be used when the tool is active +%End + + virtual bool allowsCameraControls() const; +%Docstring +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``. +%End + + Qgs3DMapCanvas *canvas(); + + protected: +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/3d/qgs3dmaptool.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/PyQt6/3d/auto_generated/qgs3dwindow.sip.in b/python/PyQt6/3d/auto_generated/qgs3dwindow.sip.in deleted file mode 100644 index dff9b2d8162..00000000000 --- a/python/PyQt6/3d/auto_generated/qgs3dwindow.sip.in +++ /dev/null @@ -1,69 +0,0 @@ -/************************************************************************ - * This file has been generated automatically from * - * * - * src/3d/qgs3dwindow.h * - * * - * Do not edit manually ! Edit header and run scripts/sipify.pl again * - ************************************************************************/ - - - - - - -class Qgs3DWindow : QWindow -{ -%Docstring(signature="appended") -qgs3dWindow is a convenience wrapper to simplify the creation of a 3D window ready to be used with QGIS. - -.. note:: - - This is a port of qtwindow3d which does not set the default surface when initialized. - -.. note:: - - The default surface must be set before the construction of the QApplication when using shared OpenGL context. - -.. note:: - - This is required in order to use QT3d and QtWebEngine at the same time. - -.. versionadded:: 3.36 -%End - -%TypeHeaderCode -#include "qgs3dwindow.h" -%End - public: - - Qgs3DWindow(); -%Docstring -Constructor for Qgs3DWindow. -%End - - ~Qgs3DWindow(); - - - protected: - - virtual void showEvent( QShowEvent *e ); - -%Docstring -Manages the display events specified in e. -%End - - virtual void resizeEvent( QResizeEvent * ); - -%Docstring -Resets the aspect ratio of the 3D window. -%End - -}; - -/************************************************************************ - * This file has been generated automatically from * - * * - * src/3d/qgs3dwindow.h * - * * - * Do not edit manually ! Edit header and run scripts/sipify.pl again * - ************************************************************************/ diff --git a/src/3d/CMakeLists.txt b/src/3d/CMakeLists.txt index e28d2b01ee7..cebfa2d930e 100644 --- a/src/3d/CMakeLists.txt +++ b/src/3d/CMakeLists.txt @@ -11,13 +11,12 @@ set(QGIS_3D_SRCS qgs3danimationsettings.cpp qgs3dexportobject.cpp qgs3dmapexportsettings.cpp - qgs3dmapcanvas.cpp qgs3dmapscene.cpp qgs3dmapsettings.cpp qgs3dmaptool.cpp + qgs3dmapcanvas.cpp qgs3dsceneexporter.cpp qgs3dutils.cpp - qgs3dwindow.cpp qgscameracontroller.cpp qgscamerapose.cpp qgsfeature3dhandler_p.cpp @@ -115,14 +114,13 @@ set(QGIS_3D_HDRS qgs3danimationsettings.h qgs3daxis.h qgs3daxissettings.h - qgs3dmapcanvas.h qgs3dmapscene.h qgs3dmapsettings.h qgs3dmaptool.h qgs3dsceneexporter.h qgs3dtypes.h qgs3dutils.h - qgs3dwindow.h + qgs3dmapcanvas.h qgsaabb.h qgsabstract3dengine.h qgsabstractvectorlayer3drenderer.h diff --git a/src/3d/qgs3daxis.cpp b/src/3d/qgs3daxis.cpp index 501d4f96b14..3c6aa0cb776 100644 --- a/src/3d/qgs3daxis.cpp +++ b/src/3d/qgs3daxis.cpp @@ -55,7 +55,7 @@ typedef Qt3DCore::QBuffer Qt3DQBuffer; #include "qgswindow3dengine.h" #include "qgsraycastingutils_p.h" -Qgs3DAxis::Qgs3DAxis( Qgs3DWindow *parentWindow, +Qgs3DAxis::Qgs3DAxis( Qgs3DMapCanvas *parentWindow, Qt3DCore::QEntity *parent3DScene, Qgs3DMapScene *mapScene, QgsCameraController *cameraCtrl, @@ -74,8 +74,8 @@ Qgs3DAxis::Qgs3DAxis( Qgs3DWindow *parentWindow, mTwoDLabelViewport->setParent( mParentWindow->activeFrameGraph() ); connect( cameraCtrl, &QgsCameraController::cameraChanged, this, &Qgs3DAxis::onCameraUpdate ); - connect( mParentWindow, &Qgs3DWindow::widthChanged, this, &Qgs3DAxis::onAxisViewportSizeUpdate ); - connect( mParentWindow, &Qgs3DWindow::heightChanged, this, &Qgs3DAxis::onAxisViewportSizeUpdate ); + connect( mParentWindow, &Qgs3DMapCanvas::widthChanged, this, &Qgs3DAxis::onAxisViewportSizeUpdate ); + connect( mParentWindow, &Qgs3DMapCanvas::heightChanged, this, &Qgs3DAxis::onAxisViewportSizeUpdate ); createAxisScene(); onAxisViewportSizeUpdate(); diff --git a/src/3d/qgs3daxis.h b/src/3d/qgs3daxis.h index 521bee6293d..54c964d91e0 100644 --- a/src/3d/qgs3daxis.h +++ b/src/3d/qgs3daxis.h @@ -17,7 +17,7 @@ #define QGS3DAXIS_H #include "qgis_3d.h" -#include "qgs3dwindow.h" +#include "qgs3dmapcanvas.h" #include "qgscoordinatereferencesystem.h" #include @@ -70,7 +70,7 @@ class _3D_EXPORT Qgs3DAxis : public QObject * @param camera camera controller used to track camera movements * @param map 3D map settings */ - Qgs3DAxis( Qgs3DWindow *parentWindow, Qt3DCore::QEntity *parent3DScene, + Qgs3DAxis( Qgs3DMapCanvas *parentWindow, Qt3DCore::QEntity *parent3DScene, Qgs3DMapScene *mapScene, QgsCameraController *camera, Qgs3DMapSettings *map ); ~Qgs3DAxis() override; @@ -143,7 +143,7 @@ class _3D_EXPORT Qgs3DAxis : public QObject void displayMenuAt( const QPoint &position ); Qgs3DMapSettings *mMapSettings = nullptr; - Qgs3DWindow *mParentWindow = nullptr; + Qgs3DMapCanvas *mParentWindow = nullptr; Qgs3DMapScene *mMapScene = nullptr; QgsCameraController *mCameraController = nullptr; diff --git a/src/3d/qgs3dmapcanvas.cpp b/src/3d/qgs3dmapcanvas.cpp index 31ec2a9b383..fd50adb9d21 100644 --- a/src/3d/qgs3dmapcanvas.cpp +++ b/src/3d/qgs3dmapcanvas.cpp @@ -13,24 +13,60 @@ * * ***************************************************************************/ +#include +#include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#endif +#include +#include +#include +#include +#include +#include +#include + #include "qgs3dmapcanvas.h" -#include -#include #include -#include - -#include "qgscameracontroller.h" -#include "qgs3dmapsettings.h" #include "qgs3dmapscene.h" -#include "qgs3dmaptool.h" #include "qgswindow3dengine.h" -#include "qgssettings.h" +#include "qgs3dmapsettings.h" +#include "qgs3dmaptool.h" #include "qgstemporalcontroller.h" -Qgs3DMapCanvas::Qgs3DMapCanvas( QWidget *parent ) - : QWidget( parent ) +Qgs3DMapCanvas::Qgs3DMapCanvas() + : m_aspectEngine( new Qt3DCore::QAspectEngine ) + , m_renderAspect( new Qt3DRender::QRenderAspect ) + , m_inputAspect( new Qt3DInput::QInputAspect ) + , m_logicAspect( new Qt3DLogic::QLogicAspect ) + , m_renderSettings( new Qt3DRender::QRenderSettings ) + , m_forwardRenderer( new Qt3DExtras::QForwardRenderer ) + , m_defaultCamera( new Qt3DRender::QCamera ) + , m_inputSettings( new Qt3DInput::QInputSettings ) + , m_root( new Qt3DCore::QEntity ) + , m_userRoot( nullptr ) + , m_initialized( false ) { + setSurfaceType( QSurface::OpenGLSurface ); + + // register aspects +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + m_aspectEngine->registerAspect( new Qt3DCore::QCoreAspect ); +#endif + m_aspectEngine->registerAspect( m_renderAspect ); + m_aspectEngine->registerAspect( m_inputAspect ); + m_aspectEngine->registerAspect( m_logicAspect ); + + m_defaultCamera->setParent( m_root ); + m_forwardRenderer->setCamera( m_defaultCamera ); + m_forwardRenderer->setSurface( this ); + m_renderSettings->setActiveFrameGraph( m_forwardRenderer ); + m_inputSettings->setEventSource( this ); + + + + const QgsSettings setting; mEngine = new QgsWindow3DEngine( this ); @@ -41,8 +77,8 @@ Qgs3DMapCanvas::Qgs3DMapCanvas( QWidget *parent ) emit savedAsImage( mCaptureFileName ); } ); - mEngine->window()->setCursor( Qt::OpenHandCursor ); - mEngine->window()->installEventFilter( this ); + setCursor( Qt::OpenHandCursor ); + installEventFilter( this ); } Qgs3DMapCanvas::~Qgs3DMapCanvas() @@ -54,18 +90,77 @@ Qgs3DMapCanvas::~Qgs3DMapCanvas() mScene = nullptr; mMap->deleteLater(); mMap = nullptr; + + + delete m_aspectEngine; } -void Qgs3DMapCanvas::resizeEvent( QResizeEvent *ev ) +void Qgs3DMapCanvas::setRootEntity( Qt3DCore::QEntity *root ) { - QWidget::resizeEvent( ev ); + if ( m_userRoot != root ) + { + if ( m_userRoot != nullptr ) + m_userRoot->setParent( static_cast( nullptr ) ); + if ( root != nullptr ) + root->setParent( m_root ); + m_userRoot = root; + } +} - if ( !mScene ) - return; +void Qgs3DMapCanvas::setActiveFrameGraph( Qt3DRender::QFrameGraphNode *activeFrameGraph ) +{ + m_renderSettings->setActiveFrameGraph( activeFrameGraph ); +} + +Qt3DRender::QFrameGraphNode *Qgs3DMapCanvas::activeFrameGraph() const +{ + return m_renderSettings->activeFrameGraph(); +} + +Qt3DExtras::QForwardRenderer *Qgs3DMapCanvas::defaultFrameGraph() const +{ + return m_forwardRenderer; +} + +Qt3DRender::QCamera *Qgs3DMapCanvas::camera() const +{ + return m_defaultCamera; +} + +Qt3DRender::QRenderSettings *Qgs3DMapCanvas::renderSettings() const +{ + return m_renderSettings; +} + +void Qgs3DMapCanvas::showEvent( QShowEvent *e ) +{ + if ( !m_initialized ) + { + m_root->addComponent( m_renderSettings ); + m_root->addComponent( m_inputSettings ); + m_aspectEngine->setRootEntity( Qt3DCore::QEntityPtr( m_root ) ); + + m_initialized = true; + } + QWindow::showEvent( e ); +} + +void Qgs3DMapCanvas::resizeEvent( QResizeEvent * ) +{ + m_defaultCamera->setAspectRatio( float( width() ) / std::max( 1.f, static_cast( height() ) ) ); mEngine->setSize( size() ); } + + + + + + + + + void Qgs3DMapCanvas::setMap( Qgs3DMapSettings *map ) { // TODO: eventually we want to get rid of this @@ -177,7 +272,7 @@ void Qgs3DMapCanvas::setMapTool( Qgs3DMapTool *tool ) if ( mMapTool && !tool ) { mScene->cameraController()->setEnabled( true ); - mEngine->window()->setCursor( Qt::OpenHandCursor ); + setCursor( Qt::OpenHandCursor ); } else if ( !mMapTool && tool ) { @@ -192,14 +287,14 @@ void Qgs3DMapCanvas::setMapTool( Qgs3DMapTool *tool ) if ( mMapTool ) { mMapTool->activate(); - mEngine->window()->setCursor( mMapTool->cursor() ); + setCursor( mMapTool->cursor() ); } } bool Qgs3DMapCanvas::eventFilter( QObject *watched, QEvent *event ) { - if ( watched != mEngine->window() ) + if ( watched != this ) return false; if ( event->type() == QEvent::ShortcutOverride ) diff --git a/src/3d/qgs3dmapcanvas.h b/src/3d/qgs3dmapcanvas.h index 99f6ad2d543..661aff1899e 100644 --- a/src/3d/qgs3dmapcanvas.h +++ b/src/3d/qgs3dmapcanvas.h @@ -16,34 +16,118 @@ #ifndef QGS3DMAPCANVAS_H #define QGS3DMAPCANVAS_H -#include -#include - #include "qgis_3d.h" +#include "qgis.h" #include "qgsrange.h" -#include "qgscameracontroller.h" -#include "qgsrectangle.h" + +#include + +#ifndef SIP_RUN +namespace Qt3DCore +{ + class QAspectEngine; + class QAbstractAspect; + class QEntity; +} + +namespace Qt3DRender +{ + class QCamera; + class QFrameGraphNode; + class QRenderAspect; + class QRenderSettings; +} + +namespace Qt3DExtras +{ + class QForwardRenderer; +} + +namespace Qt3DInput +{ + class QInputAspect; + class QInputSettings; +} namespace Qt3DLogic { - class QFrameAction; + class QLogicAspect; } +#endif -class Qgs3DMapSettings; -class Qgs3DMapScene; -class Qgs3DMapTool; +class QgsRectangle; class QgsWindow3DEngine; +class Qgs3DMapTool; class QgsPointXY; +class QgsCameraController; class QgsTemporalController; -class QgsRubberBand; +class Qgs3DMapScene; +class Qgs3DMapSettings; -class _3D_EXPORT Qgs3DMapCanvas : public QWidget + +/** + * \ingroup 3d + * \brief Qgs3DMapCanvas is a convenience wrapper to simplify the creation of a 3D window ready to be used with QGIS. + * + * \note This is a port of qtwindow3d which does not set the default surface when initialized. + * \note The default surface must be set before the construction of the QApplication when using shared OpenGL context. + * \note This is required in order to use QT3d and QtWebEngine at the same time. + * + * \since QGIS 3.36 + */ +class _3D_EXPORT Qgs3DMapCanvas : public QWindow { Q_OBJECT public: - Qgs3DMapCanvas( QWidget *parent = nullptr ); - ~Qgs3DMapCanvas() override; + + /** + * Constructor for Qgs3DMapCanvas. + */ + Qgs3DMapCanvas(); + + /** + * Destructor for Qgs3DMapCanvas. + */ + ~Qgs3DMapCanvas(); + +#ifndef SIP_RUN + + /** + * Sets the specified root entity of the scene. + */ + void setRootEntity( Qt3DCore::QEntity *root ); + + /** + * Activates the specified activeFrameGraph. + */ + void setActiveFrameGraph( Qt3DRender::QFrameGraphNode *activeFrameGraph ); + + /** + * Returns the node of the active frame graph. + */ + Qt3DRender::QFrameGraphNode *activeFrameGraph() const; + + /** + * Returns the node of the default framegraph + */ + Qt3DExtras::QForwardRenderer *defaultFrameGraph() const; + + /** + * Returns the default camera of the 3D Window. + */ + Qt3DRender::QCamera *camera() const; + + /** + * Returns the render settings of the 3D Window. + */ + Qt3DRender::QRenderSettings *renderSettings() const; +#endif + + + + + //! Configure map scene being displayed. Takes ownership. void setMap( Qgs3DMapSettings *map ); @@ -81,7 +165,7 @@ class _3D_EXPORT Qgs3DMapCanvas : public QWidget /** * Returns the 3D engine. */ - QgsWindow3DEngine *engine() const { return mEngine; } + QgsWindow3DEngine *engine() const SIP_SKIP { return mEngine; } /** * Sets the temporal controller @@ -142,10 +226,47 @@ class _3D_EXPORT Qgs3DMapCanvas : public QWidget void onNavigationModeChanged( Qgis::NavigationMode mode ); protected: - void resizeEvent( QResizeEvent *ev ) override; + + /** + * Manages the display events specified in e. + */ + void showEvent( QShowEvent *e ) override; + + /** + * Resets the aspect ratio of the 3D window. + */ + void resizeEvent( QResizeEvent * ) override; + + + bool eventFilter( QObject *watched, QEvent *event ) override; private: + + Qt3DCore::QAspectEngine *m_aspectEngine; + + // Aspects + Qt3DRender::QRenderAspect *m_renderAspect; + Qt3DInput::QInputAspect *m_inputAspect; + Qt3DLogic::QLogicAspect *m_logicAspect; + + // Renderer configuration + Qt3DRender::QRenderSettings *m_renderSettings; + Qt3DExtras::QForwardRenderer *m_forwardRenderer; + Qt3DRender::QCamera *m_defaultCamera; + + // Input configuration + Qt3DInput::QInputSettings *m_inputSettings; + + // Scene + Qt3DCore::QEntity *m_root; + Qt3DCore::QEntity *m_userRoot; + + bool m_initialized; + + + + QgsWindow3DEngine *mEngine = nullptr; //! Description of the 3D scene @@ -162,4 +283,4 @@ class _3D_EXPORT Qgs3DMapCanvas : public QWidget QgsTemporalController *mTemporalController = nullptr; }; -#endif // QGS3DMAPCANVAS_H +#endif //QGS3DMAPCANVAS_H diff --git a/src/3d/qgs3dmapscene.cpp b/src/3d/qgs3dmapscene.cpp index 69088a95c30..0f4e2dce3eb 100644 --- a/src/3d/qgs3dmapscene.cpp +++ b/src/3d/qgs3dmapscene.cpp @@ -1193,7 +1193,7 @@ void Qgs3DMapScene::on3DAxisSettingsChanged() { if ( QgsWindow3DEngine *engine = dynamic_cast( mEngine ) ) { - m3DAxis = new Qgs3DAxis( static_cast( engine->window() ), + m3DAxis = new Qgs3DAxis( static_cast( engine->window() ), engine->root(), this, mCameraController, diff --git a/src/3d/qgs3dwindow.cpp b/src/3d/qgs3dwindow.cpp deleted file mode 100644 index 4e9c9b1c8e6..00000000000 --- a/src/3d/qgs3dwindow.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/*************************************************************************** - qgs3dwindow.cpp - -------------------------------------- - Date : May 2023 - Copyright : (C) 2023 by Jean-Baptiste Peter - Email : jbpeter at outlook dot com - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#include -#include -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) -#include -#endif -#include -#include -#include -#include -#include -#include -#include - -#include "qgs3dwindow.h" - -Qgs3DWindow::Qgs3DWindow() - : m_aspectEngine( new Qt3DCore::QAspectEngine ) - , m_renderAspect( new Qt3DRender::QRenderAspect ) - , m_inputAspect( new Qt3DInput::QInputAspect ) - , m_logicAspect( new Qt3DLogic::QLogicAspect ) - , m_renderSettings( new Qt3DRender::QRenderSettings ) - , m_forwardRenderer( new Qt3DExtras::QForwardRenderer ) - , m_defaultCamera( new Qt3DRender::QCamera ) - , m_inputSettings( new Qt3DInput::QInputSettings ) - , m_root( new Qt3DCore::QEntity ) - , m_userRoot( nullptr ) - , m_initialized( false ) -{ - setSurfaceType( QSurface::OpenGLSurface ); - - // register aspects -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - m_aspectEngine->registerAspect( new Qt3DCore::QCoreAspect ); -#endif - m_aspectEngine->registerAspect( m_renderAspect ); - m_aspectEngine->registerAspect( m_inputAspect ); - m_aspectEngine->registerAspect( m_logicAspect ); - - m_defaultCamera->setParent( m_root ); - m_forwardRenderer->setCamera( m_defaultCamera ); - m_forwardRenderer->setSurface( this ); - m_renderSettings->setActiveFrameGraph( m_forwardRenderer ); - m_inputSettings->setEventSource( this ); -} - -Qgs3DWindow::~Qgs3DWindow() -{ - delete m_aspectEngine; -} - -void Qgs3DWindow::setRootEntity( Qt3DCore::QEntity *root ) -{ - if ( m_userRoot != root ) - { - if ( m_userRoot != nullptr ) - m_userRoot->setParent( static_cast( nullptr ) ); - if ( root != nullptr ) - root->setParent( m_root ); - m_userRoot = root; - } -} - -void Qgs3DWindow::setActiveFrameGraph( Qt3DRender::QFrameGraphNode *activeFrameGraph ) -{ - m_renderSettings->setActiveFrameGraph( activeFrameGraph ); -} - -Qt3DRender::QFrameGraphNode *Qgs3DWindow::activeFrameGraph() const -{ - return m_renderSettings->activeFrameGraph(); -} - -Qt3DExtras::QForwardRenderer *Qgs3DWindow::defaultFrameGraph() const -{ - return m_forwardRenderer; -} - -Qt3DRender::QCamera *Qgs3DWindow::camera() const -{ - return m_defaultCamera; -} - -Qt3DRender::QRenderSettings *Qgs3DWindow::renderSettings() const -{ - return m_renderSettings; -} - -void Qgs3DWindow::showEvent( QShowEvent *e ) -{ - if ( !m_initialized ) - { - m_root->addComponent( m_renderSettings ); - m_root->addComponent( m_inputSettings ); - m_aspectEngine->setRootEntity( Qt3DCore::QEntityPtr( m_root ) ); - - m_initialized = true; - } - QWindow::showEvent( e ); -} - -void Qgs3DWindow::resizeEvent( QResizeEvent * ) -{ - m_defaultCamera->setAspectRatio( float( width() ) / std::max( 1.f, static_cast( height() ) ) ); -} diff --git a/src/3d/qgs3dwindow.h b/src/3d/qgs3dwindow.h deleted file mode 100644 index 3948e7ee28d..00000000000 --- a/src/3d/qgs3dwindow.h +++ /dev/null @@ -1,151 +0,0 @@ -/*************************************************************************** - qgs3dwindow.h - -------------------------------------- - Date : May 2023 - Copyright : (C) 2023 by Jean-Baptiste Peter - Email : jbpeter at outlook dot com - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - -#ifndef QGS3DWINDOW_H -#define QGS3DWINDOW_H - -#include "qgis_3d.h" - -#include - -#ifndef SIP_RUN -namespace Qt3DCore -{ - class QAspectEngine; - class QAbstractAspect; - class QEntity; -} - -namespace Qt3DRender -{ - class QCamera; - class QFrameGraphNode; - class QRenderAspect; - class QRenderSettings; -} - -namespace Qt3DExtras -{ - class QForwardRenderer; -} - -namespace Qt3DInput -{ - class QInputAspect; - class QInputSettings; -} - -namespace Qt3DLogic -{ - class QLogicAspect; -} -#endif - - -/** - * \ingroup 3d - * \brief qgs3dWindow is a convenience wrapper to simplify the creation of a 3D window ready to be used with QGIS. - * - * \note This is a port of qtwindow3d which does not set the default surface when initialized. - * \note The default surface must be set before the construction of the QApplication when using shared OpenGL context. - * \note This is required in order to use QT3d and QtWebEngine at the same time. - * - * \since QGIS 3.36 - */ -class _3D_EXPORT Qgs3DWindow : public QWindow -{ - Q_OBJECT - public: - - /** - * Constructor for Qgs3DWindow. - */ - Qgs3DWindow(); - - /** - * Destructor for Qgs3DWindow. - */ - ~Qgs3DWindow(); - -#ifndef SIP_RUN - - /** - * Sets the specified root entity of the scene. - */ - void setRootEntity( Qt3DCore::QEntity *root ); - - /** - * Activates the specified activeFrameGraph. - */ - void setActiveFrameGraph( Qt3DRender::QFrameGraphNode *activeFrameGraph ); - - /** - * Returns the node of the active frame graph. - */ - Qt3DRender::QFrameGraphNode *activeFrameGraph() const; - - /** - * Returns the node of the default framegraph - */ - Qt3DExtras::QForwardRenderer *defaultFrameGraph() const; - - /** - * Returns the default camera of the 3D Window. - */ - Qt3DRender::QCamera *camera() const; - - /** - * Returns the render settings of the 3D Window. - */ - Qt3DRender::QRenderSettings *renderSettings() const; -#endif - - protected: - - /** - * Manages the display events specified in e. - */ - void showEvent( QShowEvent *e ) override; - - /** - * Resets the aspect ratio of the 3D window. - */ - void resizeEvent( QResizeEvent * ) override; - - private: - - Qt3DCore::QAspectEngine *m_aspectEngine; - - // Aspects - Qt3DRender::QRenderAspect *m_renderAspect; - Qt3DInput::QInputAspect *m_inputAspect; - Qt3DLogic::QLogicAspect *m_logicAspect; - - // Renderer configuration - Qt3DRender::QRenderSettings *m_renderSettings; - Qt3DExtras::QForwardRenderer *m_forwardRenderer; - Qt3DRender::QCamera *m_defaultCamera; - - // Input configuration - Qt3DInput::QInputSettings *m_inputSettings; - - // Scene - Qt3DCore::QEntity *m_root; - Qt3DCore::QEntity *m_userRoot; - - bool m_initialized; -}; - -#endif //QGS3DWINDOW_H diff --git a/src/3d/qgswindow3dengine.cpp b/src/3d/qgswindow3dengine.cpp index da08d501915..d9c780e0363 100644 --- a/src/3d/qgswindow3dengine.cpp +++ b/src/3d/qgswindow3dengine.cpp @@ -20,12 +20,12 @@ #include #include "qgspreviewquad.h" -#include "qgs3dwindow.h" +#include "qgs3dmapcanvas.h" -QgsWindow3DEngine::QgsWindow3DEngine( QObject *parent ) +QgsWindow3DEngine::QgsWindow3DEngine( Qgs3DMapCanvas *parent ) : QgsAbstract3DEngine( parent ) { - mWindow3D = new Qgs3DWindow; + mWindow3D = parent; mRoot = new Qt3DCore::QEntity; mWindow3D->setRootEntity( mRoot ); diff --git a/src/3d/qgswindow3dengine.h b/src/3d/qgswindow3dengine.h index ae12f3f73ad..095dbe6f9bf 100644 --- a/src/3d/qgswindow3dengine.h +++ b/src/3d/qgswindow3dengine.h @@ -32,7 +32,7 @@ namespace Qt3DExtras } -class Qgs3DWindow; +class Qgs3DMapCanvas; class QWindow; @@ -55,7 +55,7 @@ class _3D_EXPORT QgsWindow3DEngine : public QgsAbstract3DEngine /** * Constructor for QgsWindow3DEngine with the specified \a parent object. */ - QgsWindow3DEngine( QObject *parent = nullptr ); + QgsWindow3DEngine( Qgs3DMapCanvas *parent = nullptr ); //! Returns the internal 3D window where all the rendered output is displayed QWindow *window(); @@ -80,7 +80,7 @@ class _3D_EXPORT QgsWindow3DEngine : public QgsAbstract3DEngine void setSize( QSize s ) override; private: //! 3D window with all the 3D magic inside - Qgs3DWindow *mWindow3D = nullptr; + Qgs3DMapCanvas *mWindow3D = nullptr; //! Frame graph node for render capture bool mShadowRenderingEnabled = false; Qt3DCore::QEntity *mRoot = nullptr; diff --git a/src/app/3d/qgs3dmapcanvaswidget.cpp b/src/app/3d/qgs3dmapcanvaswidget.cpp index ed843eab213..c87cb764901 100644 --- a/src/app/3d/qgs3dmapcanvaswidget.cpp +++ b/src/app/3d/qgs3dmapcanvaswidget.cpp @@ -208,9 +208,8 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( const QString &name, bool isDocked ) connect( configureAction, &QAction::triggered, this, &Qgs3DMapCanvasWidget::configure ); mOptionsMenu->addAction( configureAction ); - mCanvas = new Qgs3DMapCanvas( this ); + mCanvas = new Qgs3DMapCanvas; mCanvas->setMinimumSize( QSize( 200, 200 ) ); - mCanvas->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); connect( mCanvas, &Qgs3DMapCanvas::savedAsImage, this, [ = ]( const QString & fileName ) { @@ -263,7 +262,8 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( const QString &name, bool isDocked ) layout->addLayout( topLayout ); layout->addWidget( mMessageBar ); - mContainer = QWidget::createWindowContainer( mCanvas->engine()->window() ); + // mContainer takes ownership of Qgs3DMapCanvas + mContainer = QWidget::createWindowContainer( mCanvas ); mContainer->setMinimumSize( QSize( 200, 200 ) ); mContainer->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); mNavigationWidget = new Qgs3DNavigationWidget( mCanvas ); @@ -277,17 +277,6 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( const QString &name, bool isDocked ) QRect viewportRect( QPoint( 0, 0 ), mContainer->size() ); mCanvas->engine()->setSize( viewportRect.size() ); - // Connect the camera to the navigation widget. - connect( mCanvas->cameraController(), &QgsCameraController::cameraChanged, mNavigationWidget, &Qgs3DNavigationWidget::updateFromCamera ); - - connect( mNavigationWidget, &Qgs3DNavigationWidget::sizeChanged, this, [&]( const QSize & newSize ) - { - QSize widgetSize = size(); - QRect viewportRect( QPoint( 0, 0 ), QSize( widgetSize.width() - newSize.width(), widgetSize.height() ) ); - mCanvas->engine()->setSize( viewportRect.size() ); - } ); - - toggleNavigationWidget( setting.value( QStringLiteral( "/3D/navigationWidget/visibility" ), false, QgsSettings::Gui ).toBool() ); @@ -402,6 +391,8 @@ void Qgs3DMapCanvasWidget::setMapSettings( Qgs3DMapSettings *map ) mCanvas->setMap( map ); + // Connect the camera to the navigation widget. + connect( mCanvas->cameraController(), &QgsCameraController::cameraChanged, mNavigationWidget, &Qgs3DNavigationWidget::updateFromCamera ); connect( mCanvas->scene(), &Qgs3DMapScene::totalPendingJobsCountChanged, this, &Qgs3DMapCanvasWidget::onTotalPendingJobsCountChanged ); connect( mCanvas->scene(), &Qgs3DMapScene::gpuMemoryLimitReached, this, &Qgs3DMapCanvasWidget::onGpuMemoryLimitReached ); diff --git a/src/app/3d/qgs3dmaptoolidentify.cpp b/src/app/3d/qgs3dmaptoolidentify.cpp index ef12ac63d38..65770ab01d4 100644 --- a/src/app/3d/qgs3dmaptoolidentify.cpp +++ b/src/app/3d/qgs3dmaptoolidentify.cpp @@ -15,6 +15,8 @@ #include "qgs3dmaptoolidentify.h" +#include + #include "qgsapplication.h" #include "qgs3dmapcanvas.h" #include "qgs3dmapscene.h" @@ -107,7 +109,7 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event ) // estimate search radius Qgs3DMapScene *scene = mCanvas->scene(); const double searchRadiusMM = QgsMapTool::searchRadiusMM(); - const double pixelsPerMM = mCanvas->logicalDpiX() / 25.4; + const double pixelsPerMM = mCanvas->screen()->logicalDotsPerInchX(); // mCanvas->logicalDpiX() / 25.4; const double searchRadiusPx = searchRadiusMM * pixelsPerMM; const double searchRadiusMapUnits = scene->worldSpaceError( searchRadiusPx, hit.distance ); diff --git a/src/app/3d/qgs3dmeasuredialog.cpp b/src/app/3d/qgs3dmeasuredialog.cpp index 36a866eae02..08893e957bd 100644 --- a/src/app/3d/qgs3dmeasuredialog.cpp +++ b/src/app/3d/qgs3dmeasuredialog.cpp @@ -24,7 +24,7 @@ #include "qgshelp.h" Qgs3DMeasureDialog::Qgs3DMeasureDialog( Qgs3DMapToolMeasureLine *tool, Qt::WindowFlags f ) - : QDialog( tool->canvas()->topLevelWidget(), f ) + : QDialog( nullptr, f ) //TODO: parent? , mTool( tool ) { setupUi( this ); diff --git a/src/app/3d/qgs3dnavigationwidget.cpp b/src/app/3d/qgs3dnavigationwidget.cpp index 14aa8446fd2..339935f5003 100644 --- a/src/app/3d/qgs3dnavigationwidget.cpp +++ b/src/app/3d/qgs3dnavigationwidget.cpp @@ -171,23 +171,3 @@ void Qgs3DNavigationWidget::updateFromCamera() mCameraInfoItemModel->setData( mCameraInfoItemModel->index( 6, 1 ), QStringLiteral( "%1" ).arg( m3DMapCanvas->cameraController()->lookingAtPoint().y() ) ); mCameraInfoItemModel->setData( mCameraInfoItemModel->index( 7, 1 ), QStringLiteral( "%1" ).arg( m3DMapCanvas->cameraController()->lookingAtPoint().z() ) ); } - -void Qgs3DNavigationWidget::resizeEvent( QResizeEvent *ev ) -{ - QWidget::resizeEvent( ev ); - - QSize size = ev->size(); - emit sizeChanged( size ); -} - -void Qgs3DNavigationWidget::hideEvent( QHideEvent *ev ) -{ - QWidget::hideEvent( ev ); - emit sizeChanged( QSize( 0, 0 ) ); -} - -void Qgs3DNavigationWidget::showEvent( QShowEvent *ev ) -{ - QWidget::showEvent( ev ); - emit sizeChanged( size() ); -} diff --git a/src/app/3d/qgs3dnavigationwidget.h b/src/app/3d/qgs3dnavigationwidget.h index 946371f5580..49266632d1d 100644 --- a/src/app/3d/qgs3dnavigationwidget.h +++ b/src/app/3d/qgs3dnavigationwidget.h @@ -16,10 +16,6 @@ #ifndef QGS3DNAVIGATIONWIDGET_H #define QGS3DNAVIGATIONWIDGET_H -class QHideEvent; -class QResizeEvent; -class QShowEvent; -class QSize; class QStandardItemModel; class Qgs3DMapCanvas; @@ -40,14 +36,6 @@ class Qgs3DNavigationWidget : public QWidget, private Ui::Q3DNavigationWidget */ void updateFromCamera(); - signals: - void sizeChanged( const QSize &newSize ); - - protected: - void resizeEvent( QResizeEvent *event ) override; - void hideEvent( QHideEvent *event ) override; - void showEvent( QShowEvent *event ) override; - private: Qgs3DMapCanvas *m3DMapCanvas = nullptr; QStandardItemModel *mCameraInfoItemModel = nullptr; diff --git a/src/app/3d/qgs3dviewsmanagerdialog.cpp b/src/app/3d/qgs3dviewsmanagerdialog.cpp index 2772dc95aeb..1b2cbd5785b 100644 --- a/src/app/3d/qgs3dviewsmanagerdialog.cpp +++ b/src/app/3d/qgs3dviewsmanagerdialog.cpp @@ -17,7 +17,6 @@ #include "qgisapp.h" #include "qgsnewnamedialog.h" -#include "qgs3dmapcanvas.h" #include "qgsmapviewsmanager.h" #include "qgs3dmapcanvaswidget.h" #include "qgsdockablewidgethelper.h"