QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "qgs3dsymbolregistry.h"
19#include "qgs3dutils.h"
20#include "qgsapplication.h"
21#include "qgsvectorlayer.h"
23#include "qgsxmlutils.h"
24
29
31{
33 r->readXml( elem, context );
34 return r;
35}
36
37
38// ---------
39
40
45
47{
48 QgsVectorLayer3DRenderer *r = new QgsVectorLayer3DRenderer( mSymbol ? mSymbol->clone() : nullptr );
50 return r;
51}
52
57
59{
60 return mSymbol.get();
61}
62
64{
65 QgsVectorLayer *vl = layer();
66
67 if ( !mSymbol || !vl )
68 return nullptr;
69
70 // we start with a maximal z range because we can't know this upfront. There's too many
71 // factors to consider eg vertex z data, terrain heights, data defined offsets and extrusion heights,...
72 // This range will be refined after populating the nodes to the actual z range of the generated chunks nodes.
73 // Assuming the vertical height is in meter, then it's extremely unlikely that a real vertical
74 // height will exceed this amount!
75 constexpr double MINIMUM_VECTOR_Z_ESTIMATE = -100000;
76 constexpr double MAXIMUM_VECTOR_Z_ESTIMATE = 100000;
77 return new QgsVectorLayerChunkedEntity( map, vl, MINIMUM_VECTOR_Z_ESTIMATE, MAXIMUM_VECTOR_Z_ESTIMATE, tilingSettings(), mSymbol.get() );
78}
79
80void 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
95void QgsVectorLayer3DRenderer::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
96{
97 readXmlBaseProperties( elem, context );
98
99 const QDomElement elemSymbol = elem.firstChildElement( QStringLiteral( "symbol" ) );
100 const QString symbolType = elemSymbol.attribute( QStringLiteral( "type" ) );
101 mSymbol.reset( QgsApplication::symbol3DRegistry()->createSymbol( symbolType ) );
102 if ( mSymbol )
103 mSymbol->readXml( elemSymbol, context );
104}
Definition of the world.
Qgs3DRendererAbstractMetadata(const QString &type)
Constructor of the base class.
Base class for all renderers that participate in 3D views.
Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
QgsVectorLayer3DTilingSettings tilingSettings() const
Returns tiling settings of the renderer.
void writeXmlBaseProperties(QDomElement &elem, const QgsReadWriteContext &context) const
Writes common properties of this object to DOM element.
void readXmlBaseProperties(const QDomElement &elem, const QgsReadWriteContext &context)
Reads common properties of this object from DOM element.
void copyBaseProperties(QgsAbstractVectorLayer3DRenderer *r) const
Copies common properties of this object to another object.
QgsVectorLayer * layer() const
Returns vector layer associated with the renderer.
static Qgs3DSymbolRegistry * symbol3DRegistry()
Returns registry of available 3D symbols.
A container for the context for various read/write operations on objects.
QgsAbstract3DRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context) override
Creates an instance of a 3D renderer based on a DOM element with renderer configuration.
3D renderer that renders all features of a vector layer with the same 3D symbol.
void setSymbol(QgsAbstract3DSymbol *symbol)
Sets 3D symbol associated with the renderer. Takes ownership of the symbol.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads renderer's properties from given XML element.
Qt3DCore::QEntity * createEntity(Qgs3DMapSettings *map) const override
Returns a 3D entity that will be used to show renderer's data in 3D scene.
QgsVectorLayer3DRenderer * clone() const override
Returns a cloned instance.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes renderer's properties to given XML element.
const QgsAbstract3DSymbol * symbol() const
Returns 3D symbol associated with the renderer.
QgsVectorLayer3DRenderer(QgsAbstract3DSymbol *s=nullptr)
Takes ownership of the symbol object.
Represents a vector layer which manages a vector based dataset.