Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use path resolver's read/writePath()
Remove QSkyboxEntity include
Use deleteLater() instead of delete
Remove unneeded todo
Add \since to skyboxSettings in qgs3dmapsettings.h
  • Loading branch information
NEDJIMAbelgacem committed Aug 6, 2020
1 parent 5be696d commit d7787f2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
2 changes: 2 additions & 0 deletions python/3d/auto_generated/qgs3dmapsettings.sip.in
Expand Up @@ -605,6 +605,8 @@ Emitted when the camera lens field of view changes
void skyboxSettingsChanged();
%Docstring
Emitted when skybox settings are changed

.. versionadded:: 3.16
%End

private:
Expand Down
3 changes: 1 addition & 2 deletions src/3d/qgs3dmapscene.cpp
Expand Up @@ -27,7 +27,6 @@
#include <Qt3DRender/QSceneLoader>
#include <Qt3DExtras/QForwardRenderer>
#include <Qt3DExtras/QPhongMaterial>
#include <Qt3DExtras/QSkyboxEntity>
#include <Qt3DExtras/QSphereMesh>
#include <Qt3DLogic/QFrameAction>
#include <Qt3DRender/QEffect>
Expand Down Expand Up @@ -860,7 +859,7 @@ void Qgs3DMapScene::onSkyboxSettingsChanged()
QgsSkyboxSettings skyboxSettings = mMap.skyboxSettings();
if ( mSkybox != nullptr )
{
delete mSkybox;
mSkybox->deleteLater();
mSkybox = nullptr;
}

Expand Down
1 change: 0 additions & 1 deletion src/3d/qgs3dmapsettings.cpp
Expand Up @@ -325,7 +325,6 @@ QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteCon
elem.appendChild( elemRenderers );

QDomElement elemSkybox = doc.createElement( QStringLiteral( "skybox" ) );
// TODO: use context for relative paths, maybe explicitly list all files(?)
mSkyboxSettings.writeXml( elemSkybox, context );
elem.appendChild( elemSkybox );

Expand Down
3 changes: 3 additions & 0 deletions src/3d/qgs3dmapsettings.h
Expand Up @@ -414,11 +414,13 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObjec

/**
* Returns the current configuration of the skybox
* \since QGIS 3.16
*/
QgsSkyboxSettings skyboxSettings() const SIP_SKIP { return mSkyboxSettings; }

/**
* Sets the current configuration of the skybox
* \since QGIS 3.16
*/
void setSkyboxSettings( const QgsSkyboxSettings &skyboxSettings ) SIP_SKIP;

Expand Down Expand Up @@ -517,6 +519,7 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObjec

/**
* Emitted when skybox settings are changed
* \since QGIS 3.16
*/
void skyboxSettingsChanged();

Expand Down
33 changes: 17 additions & 16 deletions src/3d/qgsskyboxsettings.cpp
Expand Up @@ -22,7 +22,7 @@

void QgsSkyboxSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
{
Q_UNUSED( context );
const QgsPathResolver &pathResolver = context.pathResolver();
mIsSkyboxEnabled = element.attribute( QStringLiteral( "skybox-enabled" ) ).toInt();
QString skyboxTypeStr = element.attribute( QStringLiteral( "skybox-type" ) );
if ( skyboxTypeStr == QStringLiteral( "Textures collection" ) )
Expand All @@ -33,19 +33,18 @@ void QgsSkyboxSettings::readXml( const QDomElement &element, const QgsReadWriteC
mSkyboxType = QgsSkyboxEntity::HDRSkybox;
mSkyboxBaseName = element.attribute( QStringLiteral( "base-name" ) );
mSkyboxExt = element.attribute( QStringLiteral( "extension" ) );
mHDRTexturePath = element.attribute( QStringLiteral( "HDR-texture-path" ) );
mHDRTexturePath = element.attribute( pathResolver.readPath( QStringLiteral( "HDR-texture-path" ) ) );
mCubeMapFacesPaths.clear();
mCubeMapFacesPaths[ QStringLiteral( "posX" ) ] = element.attribute( QStringLiteral( "posX-texture-path" ) );
mCubeMapFacesPaths[ QStringLiteral( "posY" ) ] = element.attribute( QStringLiteral( "posY-texture-path" ) );
mCubeMapFacesPaths[ QStringLiteral( "posZ" ) ] = element.attribute( QStringLiteral( "posZ-texture-path" ) );
mCubeMapFacesPaths[ QStringLiteral( "negX" ) ] = element.attribute( QStringLiteral( "negX-texture-path" ) );
mCubeMapFacesPaths[ QStringLiteral( "negY" ) ] = element.attribute( QStringLiteral( "negY-texture-path" ) );
mCubeMapFacesPaths[ QStringLiteral( "negZ" ) ] = element.attribute( QStringLiteral( "negZ-texture-path" ) );
mCubeMapFacesPaths[ QStringLiteral( "posX" ) ] = element.attribute( pathResolver.readPath( QStringLiteral( "posX-texture-path" ) ) );
mCubeMapFacesPaths[ QStringLiteral( "posY" ) ] = element.attribute( pathResolver.readPath( QStringLiteral( "posY-texture-path" ) ) );
mCubeMapFacesPaths[ QStringLiteral( "posZ" ) ] = element.attribute( pathResolver.readPath( QStringLiteral( "posZ-texture-path" ) ) );
mCubeMapFacesPaths[ QStringLiteral( "negX" ) ] = element.attribute( pathResolver.readPath( QStringLiteral( "negX-texture-path" ) ) );
mCubeMapFacesPaths[ QStringLiteral( "negY" ) ] = element.attribute( pathResolver.readPath( QStringLiteral( "negY-texture-path" ) ) );
mCubeMapFacesPaths[ QStringLiteral( "negZ" ) ] = element.attribute( pathResolver.readPath( QStringLiteral( "negZ-texture-path" ) ) );
}

void QgsSkyboxSettings::writeXml( QDomElement &element, const QgsReadWriteContext &context ) const
{
Q_UNUSED( context );
element.setAttribute( QStringLiteral( "skybox-enabled" ), mIsSkyboxEnabled );
switch ( mSkyboxType )
{
Expand All @@ -59,13 +58,15 @@ void QgsSkyboxSettings::writeXml( QDomElement &element, const QgsReadWriteContex
element.setAttribute( QStringLiteral( "skybox-type" ), QStringLiteral( "HDR texture" ) );
break;
}

const QgsPathResolver &pathResolver = context.pathResolver();
element.setAttribute( QStringLiteral( "base-name" ), mSkyboxBaseName );
element.setAttribute( QStringLiteral( "extension" ), mSkyboxExt );
element.setAttribute( QStringLiteral( "HDR-texture-path" ), mHDRTexturePath );
element.setAttribute( QStringLiteral( "posX-texture-path" ), mCubeMapFacesPaths[ QStringLiteral( "posX" ) ] );
element.setAttribute( QStringLiteral( "posY-texture-path" ), mCubeMapFacesPaths[ QStringLiteral( "posY" ) ] );
element.setAttribute( QStringLiteral( "posZ-texture-path" ), mCubeMapFacesPaths[ QStringLiteral( "posZ" ) ] );
element.setAttribute( QStringLiteral( "negX-texture-path" ), mCubeMapFacesPaths[ QStringLiteral( "negX" ) ] );
element.setAttribute( QStringLiteral( "negY-texture-path" ), mCubeMapFacesPaths[ QStringLiteral( "negY" ) ] );
element.setAttribute( QStringLiteral( "negZ-texture-path" ), mCubeMapFacesPaths[ QStringLiteral( "negZ" ) ] );
element.setAttribute( QStringLiteral( "HDR-texture-path" ), pathResolver.writePath( mHDRTexturePath ) );
element.setAttribute( QStringLiteral( "posX-texture-path" ), pathResolver.writePath( mCubeMapFacesPaths[ QStringLiteral( "posX" ) ] ) );
element.setAttribute( QStringLiteral( "posY-texture-path" ), pathResolver.writePath( mCubeMapFacesPaths[ QStringLiteral( "posY" ) ] ) );
element.setAttribute( QStringLiteral( "posZ-texture-path" ), pathResolver.writePath( mCubeMapFacesPaths[ QStringLiteral( "posZ" ) ] ) );
element.setAttribute( QStringLiteral( "negX-texture-path" ), pathResolver.writePath( mCubeMapFacesPaths[ QStringLiteral( "negX" ) ] ) );
element.setAttribute( QStringLiteral( "negY-texture-path" ), pathResolver.writePath( mCubeMapFacesPaths[ QStringLiteral( "negY" ) ] ) );
element.setAttribute( QStringLiteral( "negZ-texture-path" ), pathResolver.writePath( mCubeMapFacesPaths[ QStringLiteral( "negZ" ) ] ) );
}

0 comments on commit d7787f2

Please sign in to comment.