QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsskyboxsettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsskyboxsettings.cpp
3  --------------------------------------
4  Date : August 2020
5  Copyright : (C) 2020 by Belgacem Nedjima
6  Email : gb uderscore nedjima at esi dot dz
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsskyboxsettings.h"
17 
18 #include <QDomDocument>
19 
20 #include "qgsreadwritecontext.h"
21 #include "qgssymbollayerutils.h"
22 
23 void QgsSkyboxSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
24 {
25  const QgsPathResolver &pathResolver = context.pathResolver();
26  QString skyboxTypeStr = element.attribute( QStringLiteral( "skybox-type" ) );
27  if ( skyboxTypeStr == QLatin1String( "Distinct Faces" ) )
29  else if ( skyboxTypeStr == QLatin1String( "Panoramic Texture" ) )
31  mPanoramicTexturePath = pathResolver.readPath( element.attribute( QStringLiteral( "panoramic-texture-path" ) ) );
32  mCubeMapFacesPaths.clear();
33  mCubeMapFacesPaths[ QStringLiteral( "posX" ) ] = pathResolver.readPath( element.attribute( QStringLiteral( "posX-texture-path" ) ) );
34  mCubeMapFacesPaths[ QStringLiteral( "posY" ) ] = pathResolver.readPath( element.attribute( QStringLiteral( "posY-texture-path" ) ) );
35  mCubeMapFacesPaths[ QStringLiteral( "posZ" ) ] = pathResolver.readPath( element.attribute( QStringLiteral( "posZ-texture-path" ) ) );
36  mCubeMapFacesPaths[ QStringLiteral( "negX" ) ] = pathResolver.readPath( element.attribute( QStringLiteral( "negX-texture-path" ) ) );
37  mCubeMapFacesPaths[ QStringLiteral( "negY" ) ] = pathResolver.readPath( element.attribute( QStringLiteral( "negY-texture-path" ) ) );
38  mCubeMapFacesPaths[ QStringLiteral( "negZ" ) ] = pathResolver.readPath( element.attribute( QStringLiteral( "negZ-texture-path" ) ) );
39 }
40 
41 void QgsSkyboxSettings::writeXml( QDomElement &element, const QgsReadWriteContext &context ) const
42 {
43  switch ( mSkyboxType )
44  {
46  element.setAttribute( QStringLiteral( "skybox-type" ), QStringLiteral( "Distinct Faces" ) );
47  break;
49  element.setAttribute( QStringLiteral( "skybox-type" ), QStringLiteral( "Panoramic Texture" ) );
50  break;
51  }
52 
53  const QgsPathResolver &pathResolver = context.pathResolver();
54  element.setAttribute( QStringLiteral( "panoramic-texture-path" ), pathResolver.writePath( mPanoramicTexturePath ) );
55  element.setAttribute( QStringLiteral( "posX-texture-path" ), pathResolver.writePath( mCubeMapFacesPaths[ QStringLiteral( "posX" ) ] ) );
56  element.setAttribute( QStringLiteral( "posY-texture-path" ), pathResolver.writePath( mCubeMapFacesPaths[ QStringLiteral( "posY" ) ] ) );
57  element.setAttribute( QStringLiteral( "posZ-texture-path" ), pathResolver.writePath( mCubeMapFacesPaths[ QStringLiteral( "posZ" ) ] ) );
58  element.setAttribute( QStringLiteral( "negX-texture-path" ), pathResolver.writePath( mCubeMapFacesPaths[ QStringLiteral( "negX" ) ] ) );
59  element.setAttribute( QStringLiteral( "negY-texture-path" ), pathResolver.writePath( mCubeMapFacesPaths[ QStringLiteral( "negY" ) ] ) );
60  element.setAttribute( QStringLiteral( "negZ-texture-path" ), pathResolver.writePath( mCubeMapFacesPaths[ QStringLiteral( "negZ" ) ] ) );
61 }
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
qgsreadwritecontext.h
qgssymbollayerutils.h
qgsskyboxsettings.h
QgsSkyboxSettings::writeXml
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to a DOM element.
Definition: qgsskyboxsettings.cpp:41
QgsSkyboxEntity::DistinctTexturesSkybox
@ DistinctTexturesSkybox
Definition: qgsskyboxentity.h:51
QgsPathResolver::writePath
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
Definition: qgspathresolver.cpp:192
QgsSkyboxSettings::readXml
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
Definition: qgsskyboxsettings.cpp:23
QgsSkyboxEntity::PanoramicSkybox
@ PanoramicSkybox
Definition: qgsskyboxentity.h:50
QgsPathResolver::readPath
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
Definition: qgspathresolver.cpp:35
QgsPathResolver
Resolves relative paths into absolute paths and vice versa.
Definition: qgspathresolver.h:32
QgsReadWriteContext::pathResolver
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
Definition: qgsreadwritecontext.cpp:47