QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsdirectionallightsettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsdirectionallightsettings.cpp
3 --------------------------------------
4 Date : June 2020
5 Copyright : (C) 2020 by Belgacem Nedjima
6 Email : gb underscore 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
17#include "qgssymbollayerutils.h"
18#include "qgscolorutils.h"
19
20#include <QDomDocument>
21#include <Qt3DRender/QDirectionalLight>
22#include <Qt3DCore/QEntity>
23
25{
27}
28
30{
31 return new QgsDirectionalLightSettings( *this );
32}
33
34Qt3DCore::QEntity *QgsDirectionalLightSettings::createEntity( const Qgs3DMapSettings &, Qt3DCore::QEntity *parent ) const
35{
36 Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity( parent );
37 Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform;
38
39 Qt3DRender::QDirectionalLight *light = new Qt3DRender::QDirectionalLight;
40 light->setColor( color() );
41 light->setIntensity( intensity() );
43 light->setWorldDirection( QVector3D( direction.x(), direction.y(), direction.z() ) );
44
45 lightEntity->addComponent( light );
46 lightEntity->addComponent( lightTransform );
47
48 return lightEntity;
49}
50
51QDomElement QgsDirectionalLightSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext & ) const
52{
53 QDomElement elemLight = doc.createElement( QStringLiteral( "directional-light" ) );
54 elemLight.setAttribute( QStringLiteral( "x" ), mDirection.x() );
55 elemLight.setAttribute( QStringLiteral( "y" ), mDirection.y() );
56 elemLight.setAttribute( QStringLiteral( "z" ), mDirection.z() );
57 elemLight.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) );
58 elemLight.setAttribute( QStringLiteral( "intensity" ), mIntensity );
59 return elemLight;
60}
61
62void QgsDirectionalLightSettings::readXml( const QDomElement &elem, const QgsReadWriteContext & )
63{
64 mDirection.set( elem.attribute( QStringLiteral( "x" ) ).toFloat(),
65 elem.attribute( QStringLiteral( "y" ) ).toFloat(),
66 elem.attribute( QStringLiteral( "z" ) ).toFloat() );
67 mColor = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "color" ) ) );
68 mIntensity = elem.attribute( QStringLiteral( "intensity" ) ).toFloat();
69}
70
72{
73 return mDirection == other.mDirection && mColor == other.mColor && mIntensity == other.mIntensity;
74}
LightSourceType
Light source types for 3D scenes.
Definition: qgis.h:3398
@ Directional
Directional light source.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
bool operator==(const QgsDirectionalLightSettings &other)
QgsDirectionalLightSettings * clone() const override
Returns a copy of the light source.
float intensity() const
Returns intensity of the light.
QColor color() const
Returns color of the light.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const override
Writes the light source's configuration to a new DOM element and returns it.
QgsDirectionalLightSettings()=default
Construct a directional light with default values.
Qt3DCore::QEntity * createEntity(const Qgs3DMapSettings &map, Qt3DCore::QEntity *parent) const override
Creates an entity representing the light source.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context=QgsReadWriteContext()) override
Reads configuration from a DOM element previously written using writeXml().
QgsVector3D direction() const
Returns the direction of the light in degrees.
Qgis::LightSourceType type() const override
Returns the light source type.
The class is used as a container of context for various read/write operations on other objects.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition: qgsvector3d.h:31
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:50
double z() const
Returns Z coordinate.
Definition: qgsvector3d.h:52
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:48
void set(double x, double y, double z)
Sets vector coordinates.
Definition: qgsvector3d.h:73