Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement Qt3DWindow to work with Qt Webengine #53255

Merged
merged 21 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/3d/3d_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
%Include auto_generated/qgs3dmapscene.sip
%Include auto_generated/qgs3dmapsettings.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
Expand Down
69 changes: 69 additions & 0 deletions python/3d/auto_generated/qgs3dwindow.sip.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/************************************************************************
* 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 *
************************************************************************/
1 change: 1 addition & 0 deletions python/PyQt6/3d/3d_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
%Include auto_generated/qgs3dmapscene.sip
%Include auto_generated/qgs3dmapsettings.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
Expand Down
69 changes: 69 additions & 0 deletions python/PyQt6/3d/auto_generated/qgs3dwindow.sip.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/************************************************************************
* 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 *
************************************************************************/
2 changes: 2 additions & 0 deletions src/3d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(QGIS_3D_SRCS
qgs3dmapsettings.cpp
qgs3dsceneexporter.cpp
qgs3dutils.cpp
qgs3dwindow.cpp
qgscameracontroller.cpp
qgscamerapose.cpp
qgsfeature3dhandler_p.cpp
Expand Down Expand Up @@ -115,6 +116,7 @@ set(QGIS_3D_HDRS
qgs3dsceneexporter.h
qgs3dtypes.h
qgs3dutils.h
qgs3dwindow.h
qgsaabb.h
qgsabstract3dengine.h
qgsabstractvectorlayer3drenderer.h
Expand Down
6 changes: 3 additions & 3 deletions src/3d/qgs3daxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ typedef Qt3DCore::QBuffer Qt3DQBuffer;
#include "qgswindow3dengine.h"
#include "qgsraycastingutils_p.h"

Qgs3DAxis::Qgs3DAxis( Qt3DExtras::Qt3DWindow *parentWindow,
Qgs3DAxis::Qgs3DAxis( Qgs3DWindow *parentWindow,
Qt3DCore::QEntity *parent3DScene,
Qgs3DMapScene *mapScene,
QgsCameraController *cameraCtrl,
Expand All @@ -74,8 +74,8 @@ Qgs3DAxis::Qgs3DAxis( Qt3DExtras::Qt3DWindow *parentWindow,
mTwoDLabelViewport->setParent( mParentWindow->activeFrameGraph() );

connect( cameraCtrl, &QgsCameraController::cameraChanged, this, &Qgs3DAxis::onCameraUpdate );
connect( mParentWindow, &Qt3DExtras::Qt3DWindow::widthChanged, this, &Qgs3DAxis::onAxisViewportSizeUpdate );
connect( mParentWindow, &Qt3DExtras::Qt3DWindow::heightChanged, this, &Qgs3DAxis::onAxisViewportSizeUpdate );
connect( mParentWindow, &Qgs3DWindow::widthChanged, this, &Qgs3DAxis::onAxisViewportSizeUpdate );
connect( mParentWindow, &Qgs3DWindow::heightChanged, this, &Qgs3DAxis::onAxisViewportSizeUpdate );

createAxisScene();
onAxisViewportSizeUpdate();
Expand Down
6 changes: 3 additions & 3 deletions src/3d/qgs3daxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#define QGS3DAXIS_H

#include "qgis_3d.h"
#include "qgs3dwindow.h"

#include "qgscoordinatereferencesystem.h"
#include <Qt3DCore/QEntity>
#include <Qt3DExtras/Qt3DWindow>
#include <Qt3DExtras/QText2DEntity>
#include <Qt3DRender/QCamera>
#include <Qt3DRender/QViewport>
Expand Down Expand Up @@ -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( Qt3DExtras::Qt3DWindow *parentWindow, Qt3DCore::QEntity *parent3DScene,
Qgs3DAxis( Qgs3DWindow *parentWindow, Qt3DCore::QEntity *parent3DScene,
Qgs3DMapScene *mapScene, QgsCameraController *camera, Qgs3DMapSettings *map );
~Qgs3DAxis() override;

Expand Down Expand Up @@ -143,7 +143,7 @@ class _3D_EXPORT Qgs3DAxis : public QObject
void displayMenuAt( const QPoint &position );

Qgs3DMapSettings *mMapSettings = nullptr;
Qt3DExtras::Qt3DWindow *mParentWindow = nullptr;
Qgs3DWindow *mParentWindow = nullptr;
Qgs3DMapScene *mMapScene = nullptr;
QgsCameraController *mCameraController = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion src/3d/qgs3dmapscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ void Qgs3DMapScene::on3DAxisSettingsChanged()
{
if ( QgsWindow3DEngine *engine = dynamic_cast<QgsWindow3DEngine *>( mEngine ) )
{
m3DAxis = new Qgs3DAxis( static_cast<Qt3DExtras::Qt3DWindow *>( engine->window() ),
m3DAxis = new Qgs3DAxis( static_cast<Qgs3DWindow *>( engine->window() ),
engine->root(),
this,
mCameraController,
Expand Down
119 changes: 119 additions & 0 deletions src/3d/qgs3dwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/***************************************************************************
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 <Qt3DCore/QAspectEngine>
#include <Qt3DCore/QEntity>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <Qt3DCore/QCoreAspect>
#endif
#include <Qt3DExtras/QForwardRenderer>
#include <Qt3DRender/QRenderSettings>
#include <Qt3DRender/QRenderAspect>
#include <Qt3DInput/QInputAspect>
#include <Qt3DInput/QInputSettings>
#include <Qt3DLogic/QLogicAspect>
#include <Qt3DRender/QCamera>

#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 );

jbp35 marked this conversation as resolved.
Show resolved Hide resolved
// register aspects
jbp35 marked this conversation as resolved.
Show resolved Hide resolved
#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<Qt3DCore::QNode *>( 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<float>( height() ) ) );
}
jbp35 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading