QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgspolygon3dsymbol.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspolygon3dsymbol.cpp
3  --------------------------------------
4  Date : July 2017
5  Copyright : (C) 2017 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 "qgspolygon3dsymbol.h"
17 
18 #include "qgs3dutils.h"
19 #include "qgssymbollayerutils.h"
20 
22 {
23  return new QgsPolygon3DSymbol( *this );
24 }
25 
26 void QgsPolygon3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
27 {
28  Q_UNUSED( context )
29 
30  QDomDocument doc = elem.ownerDocument();
31 
32  QDomElement elemDataProperties = doc.createElement( QStringLiteral( "data" ) );
33  elemDataProperties.setAttribute( QStringLiteral( "alt-clamping" ), Qgs3DUtils::altClampingToString( mAltClamping ) );
34  elemDataProperties.setAttribute( QStringLiteral( "alt-binding" ), Qgs3DUtils::altBindingToString( mAltBinding ) );
35  elemDataProperties.setAttribute( QStringLiteral( "height" ), mHeight );
36  elemDataProperties.setAttribute( QStringLiteral( "extrusion-height" ), mExtrusionHeight );
37  elemDataProperties.setAttribute( QStringLiteral( "culling-mode" ), Qgs3DUtils::cullingModeToString( mCullingMode ) );
38  elemDataProperties.setAttribute( QStringLiteral( "invert-normals" ), mInvertNormals ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
39  elemDataProperties.setAttribute( QStringLiteral( "add-back-faces" ), mAddBackFaces ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
40  elem.appendChild( elemDataProperties );
41 
42  QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
43  mMaterial.writeXml( elemMaterial );
44  elem.appendChild( elemMaterial );
45 
46  QDomElement elemDDP = doc.createElement( QStringLiteral( "data-defined-properties" ) );
48  elem.appendChild( elemDDP );
49 
50  QDomElement elemEdges = doc.createElement( QStringLiteral( "edges" ) );
51  elemEdges.setAttribute( QStringLiteral( "enabled" ), mEdgesEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
52  elemEdges.setAttribute( QStringLiteral( "width" ), mEdgeWidth );
53  elemEdges.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mEdgeColor ) );
54  elem.appendChild( elemEdges );
55 }
56 
57 void QgsPolygon3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
58 {
59  Q_UNUSED( context )
60 
61  QDomElement elemDataProperties = elem.firstChildElement( QStringLiteral( "data" ) );
62  mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( QStringLiteral( "alt-clamping" ) ) );
63  mAltBinding = Qgs3DUtils::altBindingFromString( elemDataProperties.attribute( QStringLiteral( "alt-binding" ) ) );
64  mHeight = elemDataProperties.attribute( QStringLiteral( "height" ) ).toFloat();
65  mExtrusionHeight = elemDataProperties.attribute( QStringLiteral( "extrusion-height" ) ).toFloat();
66  mCullingMode = Qgs3DUtils::cullingModeFromString( elemDataProperties.attribute( QStringLiteral( "culling-mode" ) ) );
67  mInvertNormals = elemDataProperties.attribute( QStringLiteral( "invert-normals" ) ).toInt();
68  mAddBackFaces = elemDataProperties.attribute( QStringLiteral( "add-back-faces" ) ).toInt();
69 
70  QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
71  mMaterial.readXml( elemMaterial );
72 
73  QDomElement elemDDP = elem.firstChildElement( QStringLiteral( "data-defined-properties" ) );
74  if ( !elemDDP.isNull() )
76 
77  QDomElement elemEdges = elem.firstChildElement( QStringLiteral( "edges" ) );
78  if ( !elemEdges.isNull() )
79  {
80  mEdgesEnabled = elemEdges.attribute( QStringLiteral( "enabled" ) ).toInt();
81  mEdgeWidth = elemEdges.attribute( QStringLiteral( "width" ) ).toFloat();
82  mEdgeColor = QgsSymbolLayerUtils::decodeColor( elemEdges.attribute( QStringLiteral( "color" ) ) );
83  }
84 }
QgsSymbolLayerUtils::encodeColor
static QString encodeColor(const QColor &color)
Definition: qgssymbollayerutils.cpp:52
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
qgssymbollayerutils.h
QgsAbstractPropertyCollection::readXml
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
Definition: qgspropertycollection.cpp:108
Qgs3DUtils::altBindingFromString
static Qgs3DTypes::AltitudeBinding altBindingFromString(const QString &str)
Converts a string to a value from AltitudeBinding enum.
Definition: qgs3dutils.cpp:218
QgsSymbolLayerUtils::decodeColor
static QColor decodeColor(const QString &str)
Definition: qgssymbollayerutils.cpp:57
QgsPolygon3DSymbol::QgsPolygon3DSymbol
QgsPolygon3DSymbol()=default
Constructor for QgsPolygon3DSymbol.
QgsAbstract3DSymbol
Definition: qgsabstract3dsymbol.h:41
qgs3dutils.h
Qgs3DUtils::altBindingToString
static QString altBindingToString(Qgs3DTypes::AltitudeBinding altBind)
Converts a value from AltitudeBinding enum to a string.
Definition: qgs3dutils.cpp:207
QgsAbstract3DSymbol::propertyDefinitions
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
Definition: qgsabstract3dsymbol.cpp:22
QgsAbstract3DSymbol::mDataDefinedProperties
QgsPropertyCollection mDataDefinedProperties
Definition: qgsabstract3dsymbol.h:76
Qgs3DUtils::altClampingToString
static QString altClampingToString(Qgs3DTypes::AltitudeClamping altClamp)
Converts a value from AltitudeClamping enum to a string.
Definition: qgs3dutils.cpp:184
Qgs3DUtils::cullingModeFromString
static Qgs3DTypes::CullingMode cullingModeFromString(const QString &str)
Converts a string to a value from CullingMode enum.
Definition: qgs3dutils.cpp:238
QgsPhongMaterialSettings::readXml
void readXml(const QDomElement &elem)
Reads settings from a DOM element.
Definition: qgsphongmaterialsettings.cpp:21
QgsPolygon3DSymbol::clone
QgsAbstract3DSymbol * clone() const override
Returns a new instance of the symbol with the same settings.
Definition: qgspolygon3dsymbol.cpp:21
QgsPolygon3DSymbol::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads symbol configuration from the given DOM element.
Definition: qgspolygon3dsymbol.cpp:57
qgspolygon3dsymbol.h
Qgs3DUtils::altClampingFromString
static Qgs3DTypes::AltitudeClamping altClampingFromString(const QString &str)
Converts a string to a value from AltitudeClamping enum.
Definition: qgs3dutils.cpp:196
Qgs3DUtils::cullingModeToString
static QString cullingModeToString(Qgs3DTypes::CullingMode mode)
Converts a value from CullingMode enum to a string.
Definition: qgs3dutils.cpp:226
QgsPhongMaterialSettings::writeXml
void writeXml(QDomElement &elem) const
Writes settings to a DOM element.
Definition: qgsphongmaterialsettings.cpp:29
QgsPolygon3DSymbol::writeXml
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes symbol configuration to the given DOM element.
Definition: qgspolygon3dsymbol.cpp:26
QgsAbstractPropertyCollection::writeXml
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
Definition: qgspropertycollection.cpp:99