Skip to content

Commit

Permalink
qgs3dmapconfigwidget: Live extent change
Browse files Browse the repository at this point in the history
With this change, the 3D scene extent is updated as soon as one of the
parameter from the extent configuration dialog is changed.
  • Loading branch information
ptitjano committed May 29, 2024
1 parent 2a0dee9 commit 85f0a39
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/app/3d/qgs3dmapcanvaswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,11 @@ void Qgs3DMapCanvasWidget::configure()
|| map->terrainGenerator()->type() == QgsTerrainGenerator::Mesh );
};

connect( buttons, &QDialogButtonBox::rejected, mConfigureDialog, &QDialog::reject );
connect( buttons, &QDialogButtonBox::rejected, mConfigureDialog, [ = ]()
{
configWidget->reject();
mConfigureDialog->reject();
} );
connect( buttons, &QDialogButtonBox::clicked, mConfigureDialog, [ = ]( QAbstractButton * button )
{
if ( button == buttons->button( QDialogButtonBox::Apply ) || button == buttons->button( QDialogButtonBox::Ok ) )
Expand Down
32 changes: 32 additions & 0 deletions src/app/3d/qgs3dmapconfigwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "qgs3dmapsettings.h"
#include "qgsdemterraingenerator.h"
#include "qgsextent3dwidget.h"
#include "qgsflatterraingenerator.h"
#include "qgsonlineterraingenerator.h"
#include "qgsmeshterraingenerator.h"
Expand Down Expand Up @@ -244,11 +245,31 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas
// ==================
// Page: General

mOldRotation = mMap->zRotation();
mOldExtent = mMap->extent();

mExtent3D->setDefaultExtent( mMap->extent(), mMap->crs() );
mExtent3D->setMapCanvas( mMainCanvas );
mExtent3D->setRotation( mMap->zRotation() );
mExtent3D->setShowIn2DView( mMap->showExtentIn2DView() );

connect( mExtent3D, &QgsExtent3DWidget::extentChanged, this, [ = ]
{
mMap->setExtent( mExtent3D->extent() );
updateTerrain();
} );

connect( mExtent3D, &QgsExtent3DWidget::rotationChanged, this, [ = ]
{
mMap->setZRotation( mExtent3D->rotation() );
updateTerrain();
} );

connect( mExtent3D, &QgsExtent3DWidget::showIn2DViewChanged, this, [ = ]
{
mMap->setShowExtentIn2DView( mExtent3D->showIn2DView() );
} );

onTerrainTypeChanged();
}

Expand Down Expand Up @@ -335,6 +356,17 @@ void Qgs3DMapConfigWidget::updateTerrain()
}
}

void Qgs3DMapConfigWidget::reject()
{
if ( mExtent3D->extent() == mOldExtent && mExtent3D->rotation() == mOldRotation )
return;

mMap->setExtent( mOldExtent );
mMap->setZRotation( mOldRotation );

updateTerrain();
}

void Qgs3DMapConfigWidget::apply()
{
mMap->setExtent( mExtent3D->extent() );
Expand Down
5 changes: 5 additions & 0 deletions src/app/3d/qgs3dmapconfigwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class Qgs3DMapConfigWidget : public QWidget, private Ui::Map3DConfigWidget

void apply();

void reject();

signals:

void isValidChanged( bool valid );
Expand All @@ -60,6 +62,9 @@ class Qgs3DMapConfigWidget : public QWidget, private Ui::Map3DConfigWidget
QgsShadowRenderingSettingsWidget *mShadowSettingsWidget = nullptr;
QCheckBox *mShowExtentIn2DViewCheckbox = nullptr;

double mOldRotation;
QgsRectangle mOldExtent;

void init3DAxisPage();
void updateTerrain();
};
Expand Down
3 changes: 3 additions & 0 deletions src/app/3d/qgsextent3dwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ QgsExtent3DWidget::QgsExtent3DWidget( QWidget *parent )

connect( mRotationSpinBox, qOverload<int>( &QgsSpinBox::valueChanged ), this, &QgsExtent3DWidget::onRotationChanged );
connect( mRotationSlider, &QSlider::valueChanged, this, &QgsExtent3DWidget::onRotationChanged );
connect( mPreviewExtentCheckBox, &QCheckBox::toggled, this, [ = ] { emit showIn2DViewChanged(); } );
}

void QgsExtent3DWidget::setMapCanvas( QgsMapCanvas *canvas )
Expand Down Expand Up @@ -320,6 +321,7 @@ void QgsExtent3DWidget::setOutputExtent( const QgsRectangle &rectangle, const Qg
}

updateTitle( state );
emit extentChanged();
}

void QgsExtent3DWidget::updateTitle( const QgsExtentWidget::ExtentState &state )
Expand Down Expand Up @@ -359,6 +361,7 @@ QgsRectangle QgsExtent3DWidget::extent() const
void QgsExtent3DWidget::onRotationChanged( int rotation )
{
setRotation( rotation );
emit rotationChanged();
}

void QgsExtent3DWidget::setRotation( double rotation )
Expand Down
3 changes: 3 additions & 0 deletions src/app/3d/qgsextent3dwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class QgsExtent3DWidget : public QgsCollapsibleGroupBox, private Ui::QgsExtent3D
signals:

void toggleDialogVisibility( bool visible );
void extentChanged();
void rotationChanged();
void showIn2DViewChanged();

private slots:

Expand Down

0 comments on commit 85f0a39

Please sign in to comment.