QGIS API Documentation 4.1.0-Master (376402f9aeb)
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"
22#include "qgsvectorlayer.h"
24#include "qgsxmlutils.h"
25
26#include <QString>
27
28using namespace Qt::StringLiterals;
29
33
35{
37 r->readXml( elem, context );
38 return r;
39}
40
41
42// ---------
43
44
48
50{
51 QgsVectorLayer3DRenderer *r = new QgsVectorLayer3DRenderer( mSymbol ? mSymbol->clone() : nullptr );
53 return r;
54}
55
60
62{
63 return mSymbol.get();
64}
65
67{
68 QgsVectorLayer *vl = layer();
69
70 if ( !mSymbol || !vl )
71 return nullptr;
72
73 return new QgsVectorLayerChunkedEntity( map, vl, Qgs3DUtils::MINIMUM_VECTOR_Z_ESTIMATE, Qgs3DUtils::MAXIMUM_VECTOR_Z_ESTIMATE, tilingSettings(), mSymbol.get() );
74}
75
76void QgsVectorLayer3DRenderer::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
77{
78 QDomDocument doc = elem.ownerDocument();
79
80 writeXmlBaseProperties( elem, context );
81
82 QDomElement elemSymbol = doc.createElement( u"symbol"_s );
83 if ( mSymbol )
84 {
85 elemSymbol.setAttribute( u"type"_s, mSymbol->type() );
86 mSymbol->writeXml( elemSymbol, context );
87 }
88 elem.appendChild( elemSymbol );
89}
90
91void QgsVectorLayer3DRenderer::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
92{
93 readXmlBaseProperties( elem, context );
94
95 const QDomElement elemSymbol = elem.firstChildElement( u"symbol"_s );
96 const QString symbolType = elemSymbol.attribute( u"type"_s );
97 mSymbol.reset( QgsApplication::symbol3DRegistry()->createSymbol( symbolType ) );
98 if ( mSymbol )
99 mSymbol->readXml( elemSymbol, context );
100}
101
102std::unique_ptr<QgsVectorLayer3DRenderer> QgsVectorLayer3DRenderer::convertFromRenderer( const QgsAbstractVectorLayer3DRenderer *renderer, QgsVectorLayer * )
103{
104 std::unique_ptr< QgsVectorLayer3DRenderer > r;
105 if ( renderer->type() == "vector"_L1 )
106 {
107 r.reset( dynamic_cast<const QgsVectorLayer3DRenderer *>( renderer )->clone() );
108 }
109 else if ( renderer->type() == "rulebased"_L1 )
110 {
111 const QgsRuleBased3DRenderer *ruleBasedRenderer = dynamic_cast<const QgsRuleBased3DRenderer *>( renderer );
112 if ( !ruleBasedRenderer->rootRule()->children().isEmpty() )
113 {
114 std::unique_ptr< QgsAbstract3DSymbol > origSymbol;
115 const QList< QgsRuleBased3DRenderer::Rule * > children = ruleBasedRenderer->rootRule()->children();
116 for ( const QgsRuleBased3DRenderer::Rule *child : children )
117 {
118 if ( child->symbol() )
119 {
120 origSymbol.reset( child->symbol()->clone() );
121 break;
122 }
123 }
124 if ( origSymbol )
125 {
126 r = std::make_unique< QgsVectorLayer3DRenderer >( origSymbol.release() );
127 }
128 }
129 }
130
131 if ( r )
132 {
133 renderer->copyBaseProperties( r.get() );
134 }
135
136 return r;
137}
Definition of the world.
Qgs3DRendererAbstractMetadata(const QString &type)
Constructor of the base class.
static constexpr double MINIMUM_VECTOR_Z_ESTIMATE
Definition qgs3dutils.h:455
static constexpr double MAXIMUM_VECTOR_Z_ESTIMATE
Definition qgs3dutils.h:456
Base class for all renderers that participate in 3D views.
virtual QString type() const =0
Returns unique identifier of the renderer class (used to identify subclass).
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.
A child rule for a QgsRuleBased3DRenderer.
const QgsRuleBased3DRenderer::RuleList & children() const
Returns all children rules of this rule.
Rule-based 3D renderer.
QgsRuleBased3DRenderer::Rule * rootRule()
Returns pointer to the root rule.
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.
static std::unique_ptr< QgsVectorLayer3DRenderer > convertFromRenderer(const QgsAbstractVectorLayer3DRenderer *renderer, QgsVectorLayer *layer=nullptr)
Creates a new QgsVectorLayer3DRenderer from an existing renderer.
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.