QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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"
21 
22 #include "qgsvectorlayer.h"
23 #include "qgsxmlutils.h"
24 #include "qgsapplication.h"
25 #include "qgs3dsymbolregistry.h"
26 
27 
29  : Qgs3DRendererAbstractMetadata( QStringLiteral( "vector" ) )
30 {
31 }
32 
34 {
36  r->readXml( elem, context );
37  return r;
38 }
39 
40 
41 // ---------
42 
43 
45  : mSymbol( s )
46 {
47 }
48 
50 {
51  QgsVectorLayer3DRenderer *r = new QgsVectorLayer3DRenderer( mSymbol ? mSymbol->clone() : nullptr );
52  copyBaseProperties( r );
53  return r;
54 }
55 
57 {
58  mSymbol.reset( symbol );
59 }
60 
62 {
63  return mSymbol.get();
64 }
65 
66 Qt3DCore::QEntity *QgsVectorLayer3DRenderer::createEntity( const Qgs3DMapSettings &map ) const
67 {
68  QgsVectorLayer *vl = layer();
69 
70  if ( !mSymbol || !vl )
71  return nullptr;
72 
73  // we start with a maximal z range (based on a number similar to the radius of the Earth),
74  // because we can't know this upfront. There's too many
75  // factors to consider eg vertex z data, terrain heights, data defined offsets and extrusion heights,...
76  // This range will be refined after populating the nodes to the actual z range of the generated chunks nodes.
77  // Assuming the vertical height is in meter, then it's extremely unlikely that a real vertical
78  // height will exceed this amount!
79  constexpr double MINIMUM_VECTOR_Z_ESTIMATE = -5000000;
80  constexpr double MAXIMUM_VECTOR_Z_ESTIMATE = 5000000;
81  return new QgsVectorLayerChunkedEntity( vl, MINIMUM_VECTOR_Z_ESTIMATE, MAXIMUM_VECTOR_Z_ESTIMATE, tilingSettings(), mSymbol.get(), map );
82 }
83 
84 void QgsVectorLayer3DRenderer::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
85 {
86  QDomDocument doc = elem.ownerDocument();
87 
88  writeXmlBaseProperties( elem, context );
89 
90  QDomElement elemSymbol = doc.createElement( QStringLiteral( "symbol" ) );
91  if ( mSymbol )
92  {
93  elemSymbol.setAttribute( QStringLiteral( "type" ), mSymbol->type() );
94  mSymbol->writeXml( elemSymbol, context );
95  }
96  elem.appendChild( elemSymbol );
97 }
98 
99 void QgsVectorLayer3DRenderer::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
100 {
101  readXmlBaseProperties( elem, context );
102 
103  const QDomElement elemSymbol = elem.firstChildElement( QStringLiteral( "symbol" ) );
104  const QString symbolType = elemSymbol.attribute( QStringLiteral( "type" ) );
105  mSymbol.reset( QgsApplication::symbol3DRegistry()->createSymbol( symbolType ) );
106  if ( mSymbol )
107  mSymbol->readXml( elemSymbol, context );
108 }
QgsVectorLayer3DRenderer
3D renderer that renders all features of a vector layer with the same 3D symbol. The appearance is co...
Definition: qgsvectorlayer3drenderer.h:59
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
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:66
QgsAbstract3DRenderer
Base class for all renderers that may to participate in 3D view.
Definition: qgsabstract3drenderer.h:48
QgsApplication::symbol3DRegistry
static Qgs3DSymbolRegistry * symbol3DRegistry()
Returns registry of available 3D symbols.
Definition: qgsapplication.cpp:2490
qgsvectorlayerchunkloader_p.h
Qgs3DRendererAbstractMetadata
Base metadata class for 3D renderers.
Definition: qgs3drendererregistry.h:34
QgsAbstractVectorLayer3DRenderer::copyBaseProperties
void copyBaseProperties(QgsAbstractVectorLayer3DRenderer *r) const
Copies common properties of this object to another object.
Definition: qgsabstractvectorlayer3drenderer.cpp:58
qgs3dsymbolregistry.h
qgsapplication.h
QgsAbstractVectorLayer3DRenderer::readXmlBaseProperties
void readXmlBaseProperties(const QDomElement &elem, const QgsReadWriteContext &context)
Reads common properties of this object from DOM element.
Definition: qgsabstractvectorlayer3drenderer.cpp:71
QgsAbstract3DSymbol
Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
Definition: qgsabstract3dsymbol.h:46
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
Qgs3DMapSettings
Definition of the world.
Definition: qgs3dmapsettings.h:57
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:49
qgsxmlutils.h
qgsvectorlayer.h
QgsVectorLayer3DRenderer::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads renderer's properties from given XML element.
Definition: qgsvectorlayer3drenderer.cpp:99
QgsVectorLayer3DRenderer::setSymbol
void setSymbol(QgsAbstract3DSymbol *symbol)
Sets 3D symbol associated with the renderer. Takes ownership of the symbol.
Definition: qgsvectorlayer3drenderer.cpp:56
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsVectorLayer3DRendererMetadata::QgsVectorLayer3DRendererMetadata
QgsVectorLayer3DRendererMetadata()
Definition: qgsvectorlayer3drenderer.cpp:28
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:33
QgsVectorLayer3DRenderer::symbol
const QgsAbstract3DSymbol * symbol() const
Returns 3D symbol associated with the renderer.
Definition: qgsvectorlayer3drenderer.cpp:61
QgsVectorLayer3DRenderer::QgsVectorLayer3DRenderer
QgsVectorLayer3DRenderer(QgsAbstract3DSymbol *s=nullptr)
Takes ownership of the symbol object.
Definition: qgsvectorlayer3drenderer.cpp:44
QgsVectorLayer3DRenderer::writeXml
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes renderer's properties to given XML element.
Definition: qgsvectorlayer3drenderer.cpp:84