Skip to content
Permalink
Browse files
remove dirtifying the project on hide & show and add proper project d…
…irtyfing when the project changes
  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 12, 2022
1 parent 73b48d4 commit 96f7c474bfb1ef36770fee1e9aa8fda90a095013
Showing with 115 additions and 6 deletions.
  1. +10 −0 python/3d/auto_generated/qgs3dmapsettings.sip.in
  2. +87 −0 src/3d/qgs3dmapsettings.cpp
  3. +16 −1 src/3d/qgs3dmapsettings.h
  4. +2 −2 src/app/3d/qgs3dmapcanvas.cpp
  5. +0 −3 src/app/3d/qgs3dviewsmanagerdialog.cpp
@@ -604,6 +604,16 @@ Sets whether the 2D terrain surface will be rendered in.
%End

signals:

void settingsChanged();
%Docstring
Emitted when one of the configuration settings has changed

.. seealso:: :py:func:`connectChangedSignalsToSettingsChanged`

.. versionadded:: 3.24
%End

void backgroundColorChanged();
%Docstring
Emitted when the background color has changed
@@ -30,6 +30,16 @@
#include "qgssymbollayerutils.h"
#include "qgsrasterlayer.h"

Qgs3DMapSettings::Qgs3DMapSettings()
: QObject( nullptr )
{
connect( this, &Qgs3DMapSettings::settingsChanged, [&]()
{
QgsProject::instance()->setDirty();
} );
connectChangedSignalsToSettingsChanged();
}

Qgs3DMapSettings::Qgs3DMapSettings( const Qgs3DMapSettings &other )
: QObject( nullptr )
, QgsTemporalRangeObject( other )
@@ -83,6 +93,12 @@ Qgs3DMapSettings::Qgs3DMapSettings( const Qgs3DMapSettings &other )
{
mRenderers << renderer->clone();
}

connect( this, &Qgs3DMapSettings::settingsChanged, [&]()
{
QgsProject::instance()->setDirty();
} );
connectChangedSignalsToSettingsChanged();
}

Qgs3DMapSettings::~Qgs3DMapSettings()
@@ -92,6 +108,7 @@ Qgs3DMapSettings::~Qgs3DMapSettings()

void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
{
disconnectChangedSignalsToSettingsChanged();
QDomElement elemOrigin = elem.firstChildElement( QStringLiteral( "origin" ) );
mOrigin = QgsVector3D(
elemOrigin.attribute( QStringLiteral( "x" ) ).toDouble(),
@@ -272,6 +289,7 @@ void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteConte
QDateTime start = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "start" ) ), Qt::ISODate );
QDateTime end = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "end" ) ), Qt::ISODate );
setTemporalRange( QgsDateTimeRange( start, end ) );
connectChangedSignalsToSettingsChanged();
}

QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
@@ -794,3 +812,72 @@ void Qgs3DMapSettings::setTerrainRenderingEnabled( bool terrainRenderingEnabled
mTerrainRenderingEnabled = terrainRenderingEnabled;
emit terrainGeneratorChanged();
}

void Qgs3DMapSettings::connectChangedSignalsToSettingsChanged()
{
connect( this, &Qgs3DMapSettings::selectionColorChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::layersChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::terrainGeneratorChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::terrainVerticalScaleChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::mapTileResolutionChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::maxTerrainScreenErrorChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::maxTerrainGroundErrorChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::terrainElevationOffsetChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::terrainShadingChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::terrainMapThemeChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::renderersChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::showTerrainBoundingBoxesChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::showTerrainTilesInfoChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::showCameraViewCenterChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::showCameraRotationCenterChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::showLightSourceOriginsChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::eyeDomeLightingEnabledChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::eyeDomeLightingStrengthChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::eyeDomeLightingDistanceChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::debugShadowMapSettingsChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::debugDepthMapSettingsChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::pointLightsChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::directionalLightsChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::fieldOfViewChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::projectionTypeChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::cameraNavigationModeChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::cameraMovementSpeedChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::skyboxSettingsChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::shadowSettingsChanged, this, &Qgs3DMapSettings::settingsChanged );
connect( this, &Qgs3DMapSettings::fpsCounterEnabledChanged, this, &Qgs3DMapSettings::settingsChanged );
}

void Qgs3DMapSettings::disconnectChangedSignalsToSettingsChanged()
{
disconnect( this, &Qgs3DMapSettings::selectionColorChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::layersChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::terrainGeneratorChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::terrainVerticalScaleChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::mapTileResolutionChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::maxTerrainScreenErrorChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::maxTerrainGroundErrorChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::terrainElevationOffsetChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::terrainShadingChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::terrainMapThemeChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::renderersChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::showTerrainBoundingBoxesChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::showTerrainTilesInfoChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::showCameraViewCenterChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::showCameraRotationCenterChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::showLightSourceOriginsChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::eyeDomeLightingEnabledChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::eyeDomeLightingStrengthChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::eyeDomeLightingDistanceChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::debugShadowMapSettingsChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::debugDepthMapSettingsChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::pointLightsChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::directionalLightsChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::fieldOfViewChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::projectionTypeChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::cameraNavigationModeChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::cameraMovementSpeedChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::skyboxSettingsChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::shadowSettingsChanged, this, &Qgs3DMapSettings::settingsChanged );
disconnect( this, &Qgs3DMapSettings::fpsCounterEnabledChanged, this, &Qgs3DMapSettings::settingsChanged );
}

@@ -59,7 +59,7 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObjec
public:

//! Constructor for Qgs3DMapSettings
Qgs3DMapSettings() = default;
Qgs3DMapSettings();
//! Copy constructor
Qgs3DMapSettings( const Qgs3DMapSettings &other );
~Qgs3DMapSettings() override;
@@ -570,6 +570,15 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObjec
void setTerrainRenderingEnabled( bool terrainRenderingEnabled );

signals:

/**
* Emitted when one of the configuration settings has changed
*
* \see connectChangedSignalsToSettingsChanged() disconnectChangedSignalsToSettingsChanged()
* \since QGIS 3.24
*/
void settingsChanged();

//! Emitted when the background color has changed
void backgroundColorChanged();
//! Emitted when the selection color has changed
@@ -733,6 +742,12 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObjec
Qgs3DMapSettings &operator=( const Qgs3DMapSettings & );
#endif

private:
//! Connects the various changed signals of this widget to the settingsChanged signal
void connectChangedSignalsToSettingsChanged();
//! Disconnects the various changed signals of this widget to the settingsChanged signal
void disconnectChangedSignalsToSettingsChanged();

private:
//! Offset in map CRS coordinates at which our 3D world has origin (0,0,0)
QgsVector3D mOrigin;
@@ -95,9 +95,9 @@ Qgs3DMapCanvas::~Qgs3DMapCanvas()
if ( mMapTool )
mMapTool->deactivate();
// make sure the scene is deleted while map settings object is still alive
delete mScene;
mScene->deleteLater();
mScene = nullptr;
delete mMap;
mMap->deleteLater();
mMap = nullptr;
}

@@ -64,7 +64,6 @@ void Qgs3DViewsManagerDialog::showClicked()
QString viewName = m3DViewsListView->selectionModel()->selectedRows().at( 0 ).data( Qt::DisplayRole ).toString();

Qgs3DMapCanvasDockWidget *widget = QgisApp::instance()->open3DMapView( viewName );
QgsProject::instance()->setDirty();
widget->show();

m3DViewsListView->selectionModel()->setCurrentIndex( m3DViewsListView->selectionModel()->currentIndex(), QItemSelectionModel::Select );
@@ -81,8 +80,6 @@ void Qgs3DViewsManagerDialog::hideClicked()
Qgs3DMapCanvasDockWidget *widget = QgisApp::instance()->get3DMapViewDock( viewName );
widget->close();

QgsProject::instance()->setDirty();

m3DViewsListView->selectionModel()->setCurrentIndex( m3DViewsListView->selectionModel()->currentIndex(), QItemSelectionModel::Select );
currentChanged( m3DViewsListView->selectionModel()->currentIndex(), m3DViewsListView->selectionModel()->currentIndex() );
}

0 comments on commit 96f7c47

Please sign in to comment.