QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsquantizedmeshterrainsettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsquantizedmeshterrainsettings.cpp
3 --------------------------------------
4 Date : August 2024
5 Copyright : (C) 2024 by Nyall Dawson
6 Email : nyall dot dawson 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#include "qgstiledscenelayer.h"
19#include "qgs3drendercontext.h"
20
25
30
32{
33 return QStringLiteral( "quantizedmesh" );
34}
35
36void QgsQuantizedMeshTerrainSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
37{
38 if ( element.hasAttribute( QStringLiteral( "layer" ) ) )
39 {
40 mLayer = QgsMapLayerRef( element.attribute( QStringLiteral( "layer" ) ) );
41 }
42 else
43 {
44 // restore old project
45 const QDomElement elemTerrainGenerator = element.firstChildElement( QStringLiteral( "generator" ) );
46 mLayer = QgsMapLayerRef( elemTerrainGenerator.attribute( QStringLiteral( "layer" ) ) );
47 }
48
49 readCommonProperties( element, context );
50}
51
52void QgsQuantizedMeshTerrainSettings::writeXml( QDomElement &element, const QgsReadWriteContext &context ) const
53{
54 element.setAttribute( QStringLiteral( "layer" ), mLayer.layerId );
55 writeCommonProperties( element, context );
56}
57
59{
60 mLayer.resolve( project );
61}
62
64{
65 const QgsQuantizedMeshTerrainSettings *otherMeshTerrain = dynamic_cast<const QgsQuantizedMeshTerrainSettings *>( other );
66 if ( !otherMeshTerrain )
67 return false;
68
69 if ( !equalsCommon( otherMeshTerrain ) )
70 return false;
71
72 return mLayer.layerId == otherMeshTerrain->mLayer.layerId;
73}
74
75std::unique_ptr<QgsTerrainGenerator> QgsQuantizedMeshTerrainSettings::createTerrainGenerator( const Qgs3DRenderContext &context ) const
76{
77 std::unique_ptr<QgsQuantizedMeshTerrainGenerator> generator = std::make_unique<QgsQuantizedMeshTerrainGenerator>();
78 generator->setLayer( layer() );
79 generator->setCrs( context.crs(), context.transformContext() );
80 generator->setExtent( context.extent() );
81 return generator;
82}
83
88
90{
91 return qobject_cast<QgsTiledSceneLayer *>( mLayer.layer.data() );
92}
QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system used in the 3D scene.
QgsRectangle extent() const
Returns the 3D scene's 2D extent in the 3D scene's CRS.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
void writeCommonProperties(QDomElement &element, const QgsReadWriteContext &context) const
Writes common properties from the base class into an XML element.
bool equalsCommon(const QgsAbstractTerrainSettings *other) const
Returns true if common base class settings from other match this object.
void readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Reads common properties from the base class from the given DOM element.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
bool equals(const QgsAbstractTerrainSettings *other) const final
Returns true if this settings is exactly equal to another other settings.
void resolveReferences(const QgsProject *project) final
After reading settings from XML, resolves references to any layers in a project that have been read a...
QgsTiledSceneLayer * layer() const
Returns the quantized mesh tile layer with elevation model to be used for terrain generation.
QString type() const final
Returns the unique type name for the terrain generator.
static QgsAbstractTerrainSettings * create()
Creates a new instance of a QgsQuantizedMeshTerrainSettings object.
QgsQuantizedMeshTerrainSettings * clone() const final
Returns a copy of the terrain settings.
void readXml(const QDomElement &element, const QgsReadWriteContext &context) final
Reads settings from a DOM element.
std::unique_ptr< QgsTerrainGenerator > createTerrainGenerator(const Qgs3DRenderContext &context) const override
Creates a new instance of a terrain generator which matches the terrain settings.
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const final
Writes settings to a DOM element.
void setLayer(QgsTiledSceneLayer *layer)
Sets the quantized mesh tile layer with elevation model to be used for terrain generation.
The class is used as a container of context for various read/write operations on other objects.
Represents a map layer supporting display of tiled scene objects.
_LayerRef< QgsMapLayer > QgsMapLayerRef
QPointer< TYPE > layer
Weak pointer to map layer.
TYPE * resolve(const QgsProject *project)
Resolves the map layer by attempting to find a layer with matching ID within a project.
QString layerId
Original layer ID.