QGIS API Documentation  3.6.0-Noosa (5873452)
qgspointlightsettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspointlightsettings.cpp
3  --------------------------------------
4  Date : November 2018
5  Copyright : (C) 2018 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
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 "qgspointlightsettings.h"
17 
18 #include <QDomDocument>
19 
20 #include "qgssymbollayerutils.h"
21 
22 
23 QDomElement QgsPointLightSettings::writeXml( QDomDocument &doc ) const
24 {
25  QDomElement elemLight = doc.createElement( QStringLiteral( "point-light" ) );
26  elemLight.setAttribute( QStringLiteral( "x" ), mPosition.x() );
27  elemLight.setAttribute( QStringLiteral( "y" ), mPosition.y() );
28  elemLight.setAttribute( QStringLiteral( "z" ), mPosition.z() );
29  elemLight.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mColor ) );
30  elemLight.setAttribute( QStringLiteral( "intensity" ), mIntensity );
31  elemLight.setAttribute( QStringLiteral( "attenuation-0" ), mConstantAttenuation );
32  elemLight.setAttribute( QStringLiteral( "attenuation-1" ), mLinearAttenuation );
33  elemLight.setAttribute( QStringLiteral( "attenuation-2" ), mQuadraticAttenuation );
34  return elemLight;
35 }
36 
37 void QgsPointLightSettings::readXml( const QDomElement &elem )
38 {
39  mPosition.set( elem.attribute( QStringLiteral( "x" ) ).toDouble(),
40  elem.attribute( QStringLiteral( "y" ) ).toDouble(),
41  elem.attribute( QStringLiteral( "z" ) ).toDouble() );
42  mColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "color" ) ) );
43  mIntensity = elem.attribute( QStringLiteral( "intensity" ) ).toFloat();
44  mConstantAttenuation = elem.attribute( QStringLiteral( "attenuation-0" ) ).toDouble();
45  mLinearAttenuation = elem.attribute( QStringLiteral( "attenuation-1" ) ).toDouble();
46  mQuadraticAttenuation = elem.attribute( QStringLiteral( "attenuation-2" ) ).toDouble();
47 }
48 
50 {
51  return mPosition == other.mPosition && mColor == other.mColor && mIntensity == other.mIntensity &&
52  mConstantAttenuation == other.mConstantAttenuation && mLinearAttenuation == other.mLinearAttenuation &&
53  mQuadraticAttenuation == other.mQuadraticAttenuation;
54 }
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
void set(double x, double y, double z)
Sets vector coordinates.
Definition: qgsvector3d.h:56
static QString encodeColor(const QColor &color)
3 Definition of a point light in a 3D map scene
double z() const
Returns Z coordinate.
Definition: qgsvector3d.h:53
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element and returns it.
bool operator==(const QgsPointLightSettings &other)
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49
static QColor decodeColor(const QString &str)
void readXml(const QDomElement &elem)
Reads configuration from a DOM element previously written using writeXml()