QGIS API Documentation 4.1.0-Master (9af12b5a203)
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{}
42
44{
45 if ( &rhs == this )
46 return *this;
47
48#if ENABLE_PANORAMIC_SKYBOX
49 this->mPanoramicTexturePath = rhs.mPanoramicTexturePath;
50#endif
51 this->mCubeMapFacesPaths = rhs.mCubeMapFacesPaths;
52 this->mCubeMapping = rhs.mCubeMapping;
53 return *this;
54}
55
56void QgsSkyboxSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
57{
58 const QgsPathResolver &pathResolver = context.pathResolver();
59#if ENABLE_PANORAMIC_SKYBOX
60 mPanoramicTexturePath = pathResolver.readPath( element.attribute( u"panoramic-texture-path"_s ) );
61#endif
62 mCubeMapFacesPaths.clear();
63 mCubeMapFacesPaths[u"posX"_s] = pathResolver.readPath( element.attribute( u"posX-texture-path"_s ) );
64 mCubeMapFacesPaths[u"posY"_s] = pathResolver.readPath( element.attribute( u"posY-texture-path"_s ) );
65 mCubeMapFacesPaths[u"posZ"_s] = pathResolver.readPath( element.attribute( u"posZ-texture-path"_s ) );
66 mCubeMapFacesPaths[u"negX"_s] = pathResolver.readPath( element.attribute( u"negX-texture-path"_s ) );
67 mCubeMapFacesPaths[u"negY"_s] = pathResolver.readPath( element.attribute( u"negY-texture-path"_s ) );
68 mCubeMapFacesPaths[u"negZ"_s] = pathResolver.readPath( element.attribute( u"negZ-texture-path"_s ) );
69 mCubeMapping = qgsEnumKeyToValue( element.attribute( u"mapping"_s ), Qgis::SkyboxCubeMapping::NativeZUp );
70}
71
72void QgsSkyboxSettings::writeXml( QDomElement &element, const QgsReadWriteContext &context ) const
73{
74 const QgsPathResolver &pathResolver = context.pathResolver();
75#if ENABLE_PANORAMIC_SKYBOX
76 element.setAttribute( u"panoramic-texture-path"_s, pathResolver.writePath( mPanoramicTexturePath ) );
77#endif
78 element.setAttribute( u"posX-texture-path"_s, pathResolver.writePath( mCubeMapFacesPaths[u"posX"_s] ) );
79 element.setAttribute( u"posY-texture-path"_s, pathResolver.writePath( mCubeMapFacesPaths[u"posY"_s] ) );
80 element.setAttribute( u"posZ-texture-path"_s, pathResolver.writePath( mCubeMapFacesPaths[u"posZ"_s] ) );
81 element.setAttribute( u"negX-texture-path"_s, pathResolver.writePath( mCubeMapFacesPaths[u"negX"_s] ) );
82 element.setAttribute( u"negY-texture-path"_s, pathResolver.writePath( mCubeMapFacesPaths[u"negY"_s] ) );
83 element.setAttribute( u"negZ-texture-path"_s, pathResolver.writePath( mCubeMapFacesPaths[u"negZ"_s] ) );
84 element.setAttribute( u"mapping"_s, qgsEnumValueToKey( mCubeMapping ) );
85}
86
88{
89 return mCubeMapping;
90}
91
93{
94 mCubeMapping = mapping;
95}
SkyboxCubeMapping
Skybox texture cube mapping for distinct texture skyboxes.
Definition qgis.h:4428
@ NativeZUp
Textures exported for Z-up (+X Right, +Y Forward, +Z Up).
Definition qgis.h:4429
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:7423
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7404