QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsvectorlayer3drenderer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayer3drenderer.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 
17 
18 #include "qgs3dutils.h"
19 #include "qgschunkedentity_p.h"
20 #include "qgsline3dsymbol.h"
21 #include "qgspoint3dsymbol.h"
22 #include "qgspolygon3dsymbol.h"
24 
25 #include "qgsvectorlayer.h"
26 #include "qgsxmlutils.h"
27 
28 
30  : Qgs3DRendererAbstractMetadata( QStringLiteral( "vector" ) )
31 {
32 }
33 
35 {
37  r->readXml( elem, context );
38  return r;
39 }
40 
41 
42 // ---------
43 
44 
46  : mSymbol( s )
47 {
48 }
49 
51 {
52  QgsVectorLayer3DRenderer *r = new QgsVectorLayer3DRenderer( mSymbol ? mSymbol->clone() : nullptr );
53  copyBaseProperties( r );
54  return r;
55 }
56 
58 {
59  mSymbol.reset( symbol );
60 }
61 
63 {
64  return mSymbol.get();
65 }
66 
67 Qt3DCore::QEntity *QgsVectorLayer3DRenderer::createEntity( const Qgs3DMapSettings &map ) const
68 {
69  QgsVectorLayer *vl = layer();
70 
71  if ( !mSymbol || !vl )
72  return nullptr;
73 
74  double zMin, zMax;
75  Qgs3DUtils::estimateVectorLayerZRange( vl, zMin, zMax );
76 
77  return new QgsVectorLayerChunkedEntity( vl, zMin, zMax, tilingSettings(), mSymbol.get(), map );
78 }
79 
80 void QgsVectorLayer3DRenderer::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
81 {
82  QDomDocument doc = elem.ownerDocument();
83 
84  writeXmlBaseProperties( elem, context );
85 
86  QDomElement elemSymbol = doc.createElement( QStringLiteral( "symbol" ) );
87  if ( mSymbol )
88  {
89  elemSymbol.setAttribute( QStringLiteral( "type" ), mSymbol->type() );
90  mSymbol->writeXml( elemSymbol, context );
91  }
92  elem.appendChild( elemSymbol );
93 }
94 
95 void QgsVectorLayer3DRenderer::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
96 {
97  readXmlBaseProperties( elem, context );
98 
99  QDomElement elemSymbol = elem.firstChildElement( QStringLiteral( "symbol" ) );
100  QString symbolType = elemSymbol.attribute( QStringLiteral( "type" ) );
101  QgsAbstract3DSymbol *symbol = nullptr;
102  if ( symbolType == QLatin1String( "polygon" ) )
104  else if ( symbolType == QLatin1String( "point" ) )
105  symbol = new QgsPoint3DSymbol;
106  else if ( symbolType == QLatin1String( "line" ) )
107  symbol = new QgsLine3DSymbol;
108 
109  if ( symbol )
110  symbol->readXml( elemSymbol, context );
111  mSymbol.reset( symbol );
112 }
QgsVectorLayer3DRenderer
Definition: qgsvectorlayer3drenderer.h:60
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsVectorLayer3DRenderer::createEntity
Qt3DCore::QEntity * createEntity(const Qgs3DMapSettings &map) const override
Returns a 3D entity that will be used to show renderer's data in 3D scene.
Definition: qgsvectorlayer3drenderer.cpp:67
qgsline3dsymbol.h
QgsAbstract3DRenderer
Definition: qgsabstract3drenderer.h:48
QgsAbstract3DSymbol::readXml
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads symbol configuration from the given DOM element.
qgsvectorlayerchunkloader_p.h
Qgs3DRendererAbstractMetadata
Base metadata class for 3D renderers.
Definition: qgs3drendererregistry.h:34
QgsPolygon3DSymbol
Definition: qgspolygon3dsymbol.h:36
QgsAbstractVectorLayer3DRenderer::copyBaseProperties
void copyBaseProperties(QgsAbstractVectorLayer3DRenderer *r) const
Copies common properties of this object to another object.
Definition: qgsabstractvectorlayer3drenderer.cpp:58
QgsAbstractVectorLayer3DRenderer::readXmlBaseProperties
void readXmlBaseProperties(const QDomElement &elem, const QgsReadWriteContext &context)
Reads common properties of this object from DOM element.
Definition: qgsabstractvectorlayer3drenderer.cpp:71
QgsAbstract3DSymbol
Definition: qgsabstract3dsymbol.h:41
QgsAbstractVectorLayer3DRenderer::tilingSettings
QgsVectorLayer3DTilingSettings tilingSettings() const
Returns tiling settings of the renderer.
Definition: qgsabstractvectorlayer3drenderer.h:90
qgs3dutils.h
QgsAbstractVectorLayer3DRenderer::layer
QgsVectorLayer * layer() const
Returns vector layer associated with the renderer.
Definition: qgsabstractvectorlayer3drenderer.cpp:53
qgschunkedentity_p.h
QgsLine3DSymbol
Definition: qgsline3dsymbol.h:35
Qgs3DMapSettings
Definition: qgs3dmapsettings.h:51
QgsAbstractVectorLayer3DRenderer::writeXmlBaseProperties
void writeXmlBaseProperties(QDomElement &elem, const QgsReadWriteContext &context) const
Writes common properties of this object to DOM element.
Definition: qgsabstractvectorlayer3drenderer.cpp:64
QgsVectorLayer3DRenderer::clone
QgsVectorLayer3DRenderer * clone() const override
Returns a cloned instance.
Definition: qgsvectorlayer3drenderer.cpp:50
qgsxmlutils.h
Qgs3DUtils::estimateVectorLayerZRange
static void estimateVectorLayerZRange(QgsVectorLayer *layer, double &zMin, double &zMax)
Try to estimate range of Z values used in the given vector layer and store that in zMin and zMax.
Definition: qgs3dutils.cpp:519
qgsvectorlayer.h
qgspolygon3dsymbol.h
QgsVectorLayer3DRenderer::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads renderer's properties from given XML element.
Definition: qgsvectorlayer3drenderer.cpp:95
QgsVectorLayer3DRenderer::setSymbol
void setSymbol(QgsAbstract3DSymbol *symbol)
Sets 3D symbol associated with the renderer. Takes ownership of the symbol.
Definition: qgsvectorlayer3drenderer.cpp:57
QgsVectorLayer
Definition: qgsvectorlayer.h:385
qgspoint3dsymbol.h
QgsVectorLayer3DRendererMetadata::QgsVectorLayer3DRendererMetadata
QgsVectorLayer3DRendererMetadata()
Definition: qgsvectorlayer3drenderer.cpp:29
qgsvectorlayer3drenderer.h
QgsVectorLayer3DRendererMetadata::createRenderer
QgsAbstract3DRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context) override
Creates an instance of a 3D renderer based on a DOM element with renderer configuration.
Definition: qgsvectorlayer3drenderer.cpp:34
QgsVectorLayer3DRenderer::symbol
const QgsAbstract3DSymbol * symbol() const
Returns 3D symbol associated with the renderer.
Definition: qgsvectorlayer3drenderer.cpp:62
QgsVectorLayer3DRenderer::QgsVectorLayer3DRenderer
QgsVectorLayer3DRenderer(QgsAbstract3DSymbol *s=nullptr)
Takes ownership of the symbol object.
Definition: qgsvectorlayer3drenderer.cpp:45
QgsPoint3DSymbol
Definition: qgspoint3dsymbol.h:37
QgsVectorLayer3DRenderer::writeXml
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes renderer's properties to given XML element.
Definition: qgsvectorlayer3drenderer.cpp:80