QGIS API Documentation 4.1.0-Master (ca2ac17535b)
Loading...
Searching...
No Matches
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
19#include "qgsreadwritecontext.h"
20#include "qgssymbollayerutils.h"
21
22#include <QDomDocument>
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
28{
29 return new QgsSkyboxSettings( *this );
30}
31
32
34#if ENABLE_PANORAMIC_SKYBOX
35 : mPanoramicTexturePath( other.mPanoramicTexturePath )
36 , mCubeMapping( other.mCubeMapping )
37#else
38 : mCubeMapping( other.mCubeMapping )
39#endif
40 , mCubeMapFacesPaths( other.mCubeMapFacesPaths )
41 , mEnableEnvironmentalLighting( other.mEnableEnvironmentalLighting )
42 , mEnvironmentalLightStrength( other.mEnvironmentalLightStrength )
43{}
44
46{
47 if ( &rhs == this )
48 return *this;
49
50#if ENABLE_PANORAMIC_SKYBOX
51 this->mPanoramicTexturePath = rhs.mPanoramicTexturePath;
52#endif
53 mCubeMapFacesPaths = rhs.mCubeMapFacesPaths;
54 mCubeMapping = rhs.mCubeMapping;
55 mEnableEnvironmentalLighting = rhs.mEnableEnvironmentalLighting;
56 mEnvironmentalLightStrength = rhs.mEnvironmentalLightStrength;
57 return *this;
58}
59
60void QgsSkyboxSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
61{
62 const QgsPathResolver &pathResolver = context.pathResolver();
63#if ENABLE_PANORAMIC_SKYBOX
64 mPanoramicTexturePath = pathResolver.readPath( element.attribute( u"panoramic-texture-path"_s ) );
65#endif
66 mCubeMapFacesPaths.clear();
67 mCubeMapFacesPaths[u"posX"_s] = pathResolver.readPath( element.attribute( u"posX-texture-path"_s ) );
68 mCubeMapFacesPaths[u"posY"_s] = pathResolver.readPath( element.attribute( u"posY-texture-path"_s ) );
69 mCubeMapFacesPaths[u"posZ"_s] = pathResolver.readPath( element.attribute( u"posZ-texture-path"_s ) );
70 mCubeMapFacesPaths[u"negX"_s] = pathResolver.readPath( element.attribute( u"negX-texture-path"_s ) );
71 mCubeMapFacesPaths[u"negY"_s] = pathResolver.readPath( element.attribute( u"negY-texture-path"_s ) );
72 mCubeMapFacesPaths[u"negZ"_s] = pathResolver.readPath( element.attribute( u"negZ-texture-path"_s ) );
73 mCubeMapping = qgsEnumKeyToValue( element.attribute( u"mapping"_s ), Qgis::SkyboxCubeMapping::NativeZUp );
74
75 mEnableEnvironmentalLighting = element.attribute( u"environmental-lighting"_s, u"1"_s ).toInt();
76 mEnvironmentalLightStrength = element.attribute( u"environment-light-strength"_s, u"1"_s ).toDouble();
77}
78
79void QgsSkyboxSettings::writeXml( QDomElement &element, const QgsReadWriteContext &context ) const
80{
81 const QgsPathResolver &pathResolver = context.pathResolver();
82#if ENABLE_PANORAMIC_SKYBOX
83 element.setAttribute( u"panoramic-texture-path"_s, pathResolver.writePath( mPanoramicTexturePath ) );
84#endif
85 element.setAttribute( u"posX-texture-path"_s, pathResolver.writePath( mCubeMapFacesPaths[u"posX"_s] ) );
86 element.setAttribute( u"posY-texture-path"_s, pathResolver.writePath( mCubeMapFacesPaths[u"posY"_s] ) );
87 element.setAttribute( u"posZ-texture-path"_s, pathResolver.writePath( mCubeMapFacesPaths[u"posZ"_s] ) );
88 element.setAttribute( u"negX-texture-path"_s, pathResolver.writePath( mCubeMapFacesPaths[u"negX"_s] ) );
89 element.setAttribute( u"negY-texture-path"_s, pathResolver.writePath( mCubeMapFacesPaths[u"negY"_s] ) );
90 element.setAttribute( u"negZ-texture-path"_s, pathResolver.writePath( mCubeMapFacesPaths[u"negZ"_s] ) );
91 element.setAttribute( u"mapping"_s, qgsEnumValueToKey( mCubeMapping ) );
92 element.setAttribute( u"environmental-lighting"_s, mEnableEnvironmentalLighting ? u"1"_s : u"0"_s );
93 element.setAttribute( u"environment-light-strength"_s, mEnvironmentalLightStrength );
94}
95
97{
98 return mCubeMapping;
99}
100
102{
103 mCubeMapping = mapping;
104}
SkyboxCubeMapping
Skybox texture cube mapping for distinct texture skyboxes.
Definition qgis.h:4429
@ NativeZUp
Textures exported for Z-up (+X Right, +Y Forward, +Z Up).
Definition qgis.h:4430
Resolves relative paths into absolute paths and vice versa.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
A container for the context for various read/write operations on objects.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
void setCubeMapping(Qgis::SkyboxCubeMapping mapping)
Sets the cube face mapping scheme.
QgsSkyboxSettings()=default
void readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads settings from a DOM element.
QgsSkyboxSettings * clone() const override
Returns a deep copy of this background settings object.
QgsSkyboxSettings & operator=(QgsSkyboxSettings const &rhs)
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
Qgis::SkyboxCubeMapping cubeMapping() const
Returns the cube face mapping scheme.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition qgis.h:7437
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7418