From 3c0026db71a225ff51e0572a965056ec20946fa5 Mon Sep 17 00:00:00 2001 From: Withalion Date: Fri, 22 Nov 2024 18:11:28 +0100 Subject: [PATCH 1/2] Add toolbar and debug panel into 3d sandbox --- src/app/3d/qgs3ddebugwidget.h | 3 +- tests/src/3d/sandbox/qgis_3d_sandbox.cpp | 62 +++++++++++++++++++++--- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/app/3d/qgs3ddebugwidget.h b/src/app/3d/qgs3ddebugwidget.h index 9964354d3a8f..8f073e329f00 100644 --- a/src/app/3d/qgs3ddebugwidget.h +++ b/src/app/3d/qgs3ddebugwidget.h @@ -21,8 +21,9 @@ class Qgs3DMapCanvas; #include #include "qgs3dmapsettings.h" +#include "qgis_app.h" -class Qgs3DDebugWidget : public QWidget, Ui::Q3DDebugWidget +class APP_EXPORT Qgs3DDebugWidget : public QWidget, Ui::Q3DDebugWidget { Q_OBJECT public: diff --git a/tests/src/3d/sandbox/qgis_3d_sandbox.cpp b/tests/src/3d/sandbox/qgis_3d_sandbox.cpp index d6f4f46979ca..a216ec0f3b35 100644 --- a/tests/src/3d/sandbox/qgis_3d_sandbox.cpp +++ b/tests/src/3d/sandbox/qgis_3d_sandbox.cpp @@ -17,25 +17,29 @@ #include -#include "qgsapplication.h" #include "qgs3d.h" +#include "qgs3dmapcanvas.h" +#include "qgs3dmapscene.h" +#include "qgs3dmapsettings.h" +#include "qgsapplication.h" +#include "qgsflatterraingenerator.h" #include "qgslayertree.h" #include "qgsmapsettings.h" #include "qgspointcloudlayer.h" #include "qgspointcloudlayer3drenderer.h" +#include "qgspointlightsettings.h" #include "qgsproject.h" -#include "qgsflatterraingenerator.h" -#include "qgs3dmapscene.h" -#include "qgs3dmapsettings.h" -#include "qgs3dmapcanvas.h" #include "qgsprojectelevationproperties.h" #include "qgsprojectviewsettings.h" -#include "qgspointlightsettings.h" #include "qgsterrainprovider.h" #include "qgstiledscenelayer.h" #include "qgstiledscenelayer3drenderer.h" +#include "qgs3ddebugwidget.h" +#include #include +#include +#include void initCanvas3D( Qgs3DMapCanvas *canvas ) { @@ -151,8 +155,50 @@ int main( int argc, char *argv[] ) Qgs3DMapCanvas *canvas = new Qgs3DMapCanvas; initCanvas3D( canvas ); - canvas->resize( 800, 600 ); - canvas->show(); + + // set up the UI + QWidget *windowWidget = new QWidget; + QVBoxLayout *vLayout = new QVBoxLayout; + vLayout->setContentsMargins( 0, 0, 0, 0 ); + vLayout->setSpacing( 0 ); + + QToolBar *toolBar = new QToolBar( windowWidget ); + toolBar->setIconSize( QgisApp::instance()->iconSize( true ) ); + toolBar->addAction( QIcon( QgsApplication::iconPath( "mActionZoomFullExtent.svg" ) ), QStringLiteral( "Reset camera to default position" ), windowWidget, [canvas] + { + canvas->resetView(); + } ); + QAction *toggleDebugPanel = toolBar->addAction( + QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/general.svg" ) ), + QStringLiteral( "Toggle on-screen Debug panel" ) ); + toggleDebugPanel->setCheckable( true ); + vLayout->addWidget( toolBar ); + + QWidget *container = QWidget::createWindowContainer( canvas ); + container->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); + Qgs3DDebugWidget *debugWidget = new Qgs3DDebugWidget( canvas ); + debugWidget->setMapSettings( canvas->mapSettings() ); + debugWidget->setVisible( false ); + + // Connect the camera to the debug widget. + QObject::connect( canvas->cameraController(), &QgsCameraController::cameraChanged, debugWidget, &Qgs3DDebugWidget::updateFromCamera ); + QObject::connect( canvas->cameraController()->camera(), &Qt3DRender::QCamera::nearPlaneChanged, debugWidget, &Qgs3DDebugWidget::updateFromCamera ); + QObject::connect( canvas->cameraController()->camera(), &Qt3DRender::QCamera::farPlaneChanged, debugWidget, &Qgs3DDebugWidget::updateFromCamera ); + QObject::connect( toggleDebugPanel, &QAction::toggled, windowWidget, [ = ]( const bool enabled ) + { + debugWidget->setVisible( enabled ); + } ); + + QHBoxLayout *hLayout = new QHBoxLayout; + vLayout->addLayout( hLayout ); + hLayout->setContentsMargins( 0, 0, 0, 0 ); + hLayout->addWidget( container ); + hLayout->addWidget( debugWidget ); + + + windowWidget->resize( 800, debugWidget->height() ); + windowWidget->setLayout( vLayout ); + windowWidget->show(); return myApp.exec(); } From 0931d22ae9f9da502f6ba00ae113e215f240be51 Mon Sep 17 00:00:00 2001 From: Withalion Date: Sun, 24 Nov 2024 11:32:09 +0100 Subject: [PATCH 2/2] Add config dialog to 3d sandbox with warning --- src/app/3d/qgs3dmapconfigwidget.h | 3 +- tests/src/3d/sandbox/qgis_3d_sandbox.cpp | 84 +++++++++++++++++++++++- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/src/app/3d/qgs3dmapconfigwidget.h b/src/app/3d/qgs3dmapconfigwidget.h index 4f1ac998d6eb..0ca0860e7fd1 100644 --- a/src/app/3d/qgs3dmapconfigwidget.h +++ b/src/app/3d/qgs3dmapconfigwidget.h @@ -19,6 +19,7 @@ #include #include +#include "qgis_app.h" class QCheckBox; class Qgs3DMapSettings; @@ -29,7 +30,7 @@ class QgsShadowRenderingSettingsWidget; class Qgs3DMapCanvas; class QgsSkyboxSettings; -class Qgs3DMapConfigWidget : public QWidget, private Ui::Map3DConfigWidget +class APP_EXPORT Qgs3DMapConfigWidget : public QWidget, private Ui::Map3DConfigWidget { Q_OBJECT public: diff --git a/tests/src/3d/sandbox/qgis_3d_sandbox.cpp b/tests/src/3d/sandbox/qgis_3d_sandbox.cpp index a216ec0f3b35..91ffd549c372 100644 --- a/tests/src/3d/sandbox/qgis_3d_sandbox.cpp +++ b/tests/src/3d/sandbox/qgis_3d_sandbox.cpp @@ -18,13 +18,20 @@ #include #include "qgs3d.h" +#include "qgs3ddebugwidget.h" #include "qgs3dmapcanvas.h" +#include "qgs3dmapconfigwidget.h" #include "qgs3dmapscene.h" #include "qgs3dmapsettings.h" +#include "qgs3dutils.h" #include "qgsapplication.h" #include "qgsflatterraingenerator.h" +#include "qgsgui.h" +#include "qgshelp.h" #include "qgslayertree.h" +#include "qgsmapcanvas.h" #include "qgsmapsettings.h" +#include "qgsmessagebaritem.h" #include "qgspointcloudlayer.h" #include "qgspointcloudlayer3drenderer.h" #include "qgspointlightsettings.h" @@ -34,11 +41,9 @@ #include "qgsterrainprovider.h" #include "qgstiledscenelayer.h" #include "qgstiledscenelayer3drenderer.h" -#include "qgs3ddebugwidget.h" #include #include -#include #include void initCanvas3D( Qgs3DMapCanvas *canvas ) @@ -110,6 +115,69 @@ void initCanvas3D( Qgs3DMapCanvas *canvas ) qDebug() << "pending jobs:" << canvas->scene()->totalPendingJobsCount(); } +QPointer createConfigDialog( Qgs3DMapCanvas *canvas ) +{ + const QPointer configDialog = new QDialog; + configDialog->setWindowTitle( QStringLiteral( "3D Configuration" ) ); + configDialog->setObjectName( QStringLiteral( "3DConfigurationDialog" ) ); + configDialog->setMinimumSize( 600, 460 ); + QgsGui::enableAutoGeometryRestore( configDialog ); + + Qgs3DMapSettings *map = canvas->mapSettings(); + Qgs3DMapConfigWidget *w = new Qgs3DMapConfigWidget( map, new QgsMapCanvas, canvas, configDialog ); + QDialogButtonBox *buttons = new QDialogButtonBox( QDialogButtonBox::Apply | QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, configDialog ); + + auto applyConfig = [ = ] + { + const QgsVector3D oldOrigin = map->origin(); + const QgsCoordinateReferenceSystem oldCrs = map->crs(); + const QgsCameraPose oldCameraPose = canvas->cameraController()->cameraPose(); + const QgsVector3D oldLookingAt = oldCameraPose.centerPoint(); + + // update map + w->apply(); + + const QgsVector3D p = Qgs3DUtils::transformWorldCoordinates( + oldLookingAt, + oldOrigin, oldCrs, + map->origin(), map->crs(), QgsProject::instance()->transformContext() ); + + if ( p != oldLookingAt ) + { + // apply() call has moved origin of the world so let's move camera so we look still at the same place + QgsCameraPose newCameraPose = oldCameraPose; + newCameraPose.setCenterPoint( p ); + canvas->cameraController()->setCameraPose( newCameraPose ); + } + }; + + QObject::connect( buttons, &QDialogButtonBox::rejected, configDialog, &QDialog::reject ); + QObject::connect( buttons, &QDialogButtonBox::clicked, configDialog, [ = ]( const QAbstractButton * button ) + { + if ( button == buttons->button( QDialogButtonBox::Apply ) || button == buttons->button( QDialogButtonBox::Ok ) ) + applyConfig(); + if ( button == buttons->button( QDialogButtonBox::Ok ) ) + configDialog->accept(); + } ); + QObject::connect( buttons, &QDialogButtonBox::helpRequested, w, []() { QgsHelp::openHelp( QStringLiteral( "map_views/3d_map_view.html#scene-configuration" ) ); } ); + + QObject::connect( w, &Qgs3DMapConfigWidget::isValidChanged, configDialog, [ = ]( const bool valid ) + { + buttons->button( QDialogButtonBox::Apply )->setEnabled( valid ); + buttons->button( QDialogButtonBox::Ok )->setEnabled( valid ); + } ); + + QgsMessageBar *messageBar = new QgsMessageBar; + QgsMessageBarItem *warningWidget = QgsMessageBar::createMessage( QString(), "Some settings are unavailable in sandbox" ); + messageBar->pushWidget( warningWidget, Qgis::MessageLevel::Warning, 0 ); + + QVBoxLayout *layout = new QVBoxLayout( configDialog ); + layout->addWidget( messageBar ); + layout->addWidget( w, 1 ); + layout->addWidget( buttons ); + return configDialog; +} + int main( int argc, char *argv[] ) { QgsApplication myApp( argc, argv, true, QString(), QStringLiteral( "desktop" ) ); @@ -172,6 +240,14 @@ int main( int argc, char *argv[] ) QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/general.svg" ) ), QStringLiteral( "Toggle on-screen Debug panel" ) ); toggleDebugPanel->setCheckable( true ); + QAction *configureAction = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "mActionOptions.svg" ) ), + QStringLiteral( "Configureā€¦" ), windowWidget ); + QPointer configDialog = createConfigDialog( canvas ); + QObject::connect( configureAction, &QAction::triggered, windowWidget, [configDialog] + { + configDialog->setVisible( true ); + } ); + toolBar->addAction( configureAction ); vLayout->addWidget( toolBar ); QWidget *container = QWidget::createWindowContainer( canvas ); @@ -179,6 +255,10 @@ int main( int argc, char *argv[] ) Qgs3DDebugWidget *debugWidget = new Qgs3DDebugWidget( canvas ); debugWidget->setMapSettings( canvas->mapSettings() ); debugWidget->setVisible( false ); + QObject::connect( canvas->mapSettings(), &Qgs3DMapSettings::showDebugPanelChanged, windowWidget, [ = ]( const bool enabled ) + { + debugWidget->setVisible( enabled ); + } ); // Connect the camera to the debug widget. QObject::connect( canvas->cameraController(), &QgsCameraController::cameraChanged, debugWidget, &Qgs3DDebugWidget::updateFromCamera );