QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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" ) )
103  symbol = new QgsPolygon3DSymbol;
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 }
The class is used as a container of context for various read/write operations on other objects...
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads renderer's properties from given XML element.
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
Base class for all renderers that may to participate in 3D view.
QgsVectorLayer3DTilingSettings tilingSettings() const
Returns tiling settings of the renderer.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes renderer's properties to given XML element.
QgsAbstract3DRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context) override
Creates an instance of a 3D renderer based on a DOM element with renderer configuration.
QgsVectorLayer * layer() const
Returns vector layer associated with the renderer.
3 3D symbol that draws polygon geometries as planar polygons, optionally extruded (with added walls)...
void setSymbol(QgsAbstract3DSymbol *symbol)
Sets 3D symbol associated with the renderer. Takes ownership of the symbol.
3 Definition of the world
3 Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
QgsVectorLayer3DRenderer * clone() const override
Returns a cloned instance.
void copyBaseProperties(QgsAbstractVectorLayer3DRenderer *r) const
Copies common properties of this object to another object.
3 3D symbol that draws point geometries as 3D objects using one of the predefined shapes...
3 3D symbol that draws linestring geometries as planar polygons (created from lines using a buffer wi...
const QgsAbstract3DSymbol * symbol() const
Returns 3D symbol associated with the renderer.
3D renderer that renders all features of a vector layer with the same 3D symbol.
void writeXmlBaseProperties(QDomElement &elem, const QgsReadWriteContext &context) const
Writes common properties of this object to DOM element.
Qt3DCore::QEntity * createEntity(const Qgs3DMapSettings &map) const override
Returns a 3D entity that will be used to show renderer's data in 3D scene.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads symbol configuration from the given DOM element.
Base metadata class for 3D renderers.
Represents a vector layer which manages a vector based data sets.
QgsVectorLayer3DRenderer(QgsAbstract3DSymbol *s=nullptr)
Takes ownership of the symbol object.
void readXmlBaseProperties(const QDomElement &elem, const QgsReadWriteContext &context)
Reads common properties of this object from DOM element.