QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsonlinedemterrainsettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsonlinedemterrainsettings.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
18#include "qgis.h"
19#include "qgs3drendercontext.h"
20
21#include <QDomElement>
22
27
32
34{
35 return QStringLiteral( "online" );
36}
37
38void QgsOnlineDemTerrainSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
39{
40 if ( element.hasAttribute( QStringLiteral( "resolution" ) ) )
41 {
42 mResolution = element.attribute( QStringLiteral( "resolution" ) ).toInt();
43 mSkirtHeight = element.attribute( QStringLiteral( "skirt-height" ) ).toDouble();
44 }
45 else
46 {
47 // restore old project
48 const QDomElement elemTerrainGenerator = element.firstChildElement( QStringLiteral( "generator" ) );
49 mResolution = elemTerrainGenerator.attribute( QStringLiteral( "resolution" ) ).toInt();
50 mSkirtHeight = elemTerrainGenerator.attribute( QStringLiteral( "skirt-height" ) ).toDouble();
51 }
52
53 readCommonProperties( element, context );
54}
55
56void QgsOnlineDemTerrainSettings::writeXml( QDomElement &element, const QgsReadWriteContext &context ) const
57{
58 element.setAttribute( QStringLiteral( "resolution" ), mResolution );
59 element.setAttribute( QStringLiteral( "skirt-height" ), mSkirtHeight );
60
61 writeCommonProperties( element, context );
62}
63
65{
66 const QgsOnlineDemTerrainSettings *otherTerrain = dynamic_cast<const QgsOnlineDemTerrainSettings *>( other );
67 if ( !otherTerrain )
68 return false;
69
70 if ( !equalsCommon( other ) )
71 return false;
72
73 return mResolution == otherTerrain->mResolution
74 && qgsDoubleNear( mSkirtHeight, otherTerrain->mSkirtHeight );
75}
76
77std::unique_ptr<QgsTerrainGenerator> QgsOnlineDemTerrainSettings::createTerrainGenerator( const Qgs3DRenderContext &context ) const
78{
79 std::unique_ptr<QgsOnlineTerrainGenerator> generator = std::make_unique<QgsOnlineTerrainGenerator>();
80 generator->setResolution( mResolution );
81 generator->setSkirtHeight( static_cast<float>( mSkirtHeight ) );
82 generator->setCrs( context.crs(), context.transformContext() );
83 generator->setExtent( context.extent() );
84 return generator;
85}
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.
bool equals(const QgsAbstractTerrainSettings *other) const final
Returns true if this settings is exactly equal to another other settings.
void readXml(const QDomElement &element, const QgsReadWriteContext &context) final
Reads settings from a DOM element.
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const final
Writes settings to a DOM element.
static QgsAbstractTerrainSettings * create()
Creates a new instance of a QgsOnlineDemTerrainSettings object.
std::unique_ptr< QgsTerrainGenerator > createTerrainGenerator(const Qgs3DRenderContext &context) const override
Creates a new instance of a terrain generator which matches the terrain settings.
QgsOnlineDemTerrainSettings * clone() const final
Returns a copy of the terrain settings.
QString type() const final
Returns the unique type name for the terrain generator.
The class is used as a container of context for various read/write operations on other objects.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:6024