QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgsmeshlayer3drenderer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshlayer3drenderer.cpp
3  --------------------------
4  Date : January 2019
5  Copyright : (C) 2019 by Peter Petrik
6  Email : zilolv 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 
16 #include "qgsmeshlayer3drenderer.h"
17 
18 #include "qgsmeshlayer3drenderer.h"
19 #include "qgsmesh3dsymbol.h"
20 #include "qgsmesh3dsymbol_p.h"
21 
22 #include "qgsmeshlayer.h"
23 #include "qgsxmlutils.h"
24 
25 
27  : Qgs3DRendererAbstractMetadata( QStringLiteral( "mesh" ) )
28 {
29 }
30 
32 {
34  r->readXml( elem, context );
35  return r;
36 }
37 
38 
39 // ---------
40 
41 
43  : mSymbol( s )
44 {
45 }
46 
48 {
49  QgsMeshLayer3DRenderer *r = new QgsMeshLayer3DRenderer( mSymbol ? ( QgsMesh3DSymbol * )mSymbol->clone() : nullptr );
50  r->mLayerRef = mLayerRef;
51  return r;
52 }
53 
55 {
56  mLayerRef = QgsMapLayerRef( layer );
57 }
58 
60 {
61  return qobject_cast<QgsMeshLayer *>( mLayerRef.layer );
62 }
63 
65 {
66  mSymbol.reset( symbol );
67 }
68 
70 {
71  return mSymbol.get();
72 }
73 
74 Qt3DCore::QEntity *QgsMeshLayer3DRenderer::createEntity( const Qgs3DMapSettings &map ) const
75 {
76  QgsMeshLayer *vl = layer();
77 
78  if ( !mSymbol || !vl )
79  return nullptr;
80 
81  return new QgsMesh3DSymbolEntity( map, vl, *static_cast<QgsMesh3DSymbol *>( mSymbol.get() ) );
82 }
83 
84 void QgsMeshLayer3DRenderer::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
85 {
86  QDomDocument doc = elem.ownerDocument();
87 
88  elem.setAttribute( QStringLiteral( "layer" ), mLayerRef.layerId );
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 QgsMeshLayer3DRenderer::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
100 {
101  mLayerRef = QgsMapLayerRef( elem.attribute( QStringLiteral( "layer" ) ) );
102 
103  QDomElement elemSymbol = elem.firstChildElement( QStringLiteral( "symbol" ) );
105  symbol->readXml( elemSymbol, context );
106  mSymbol.reset( symbol );
107 }
108 
110 {
111  mLayerRef.setLayer( project.mapLayer( mLayerRef.layerId ) );
112 }
The class is used as a container of context for various read/write operations on other objects...
Qt3DCore::QEntity * createEntity(const Qgs3DMapSettings &map) const override
Returns a 3D entity that will be used to show renderer&#39;s data in 3D scene.
3 3D symbol that draws mesh geometry as planar triangles.
_LayerRef< QgsMapLayer > QgsMapLayerRef
Base class for all renderers that may to participate in 3D view.
void resolveReferences(const QgsProject &project) override
Resolves references to other objects - second phase of loading - after readXml()
3D renderer that renders all mesh triangles of a mesh layer.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes renderer&#39;s properties to given XML element.
3 Definition of the world
QgsMeshLayer3DRenderer * clone() const override
Returns a cloned instance.
QgsMeshLayer * layer() const
Returns mesh layer associated with the renderer.
QString layerId
Original layer ID.
QPointer< TYPE > layer
Weak pointer to map layer.
const QgsMesh3DSymbol * symbol() const
Returns 3D symbol associated with the renderer.
void setSymbol(QgsMesh3DSymbol *symbol)
Sets 3D symbol associated with the renderer.
Reads and writes project states.
Definition: qgsproject.h:89
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
void setLayer(QgsMeshLayer *layer)
Sets vector layer associated with the renderer.
QgsAbstract3DRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context) override
Creates an instance of a 3D renderer based on a DOM element with renderer configuration.
QgsMeshLayer3DRenderer(QgsMesh3DSymbol *s=nullptr)
Takes ownership of the symbol object.
QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:90
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads renderer&#39;s properties from given XML element.
Base metadata class for 3D renderers.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads symbol configuration from the given DOM element.