QGIS API Documentation 3.27.0-Master (75dc696944)
qgsprojectelevationproperties.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprojectelevationproperties.cpp
3 ---------------
4 begin : February 2022
5 copyright : (C) 2022 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18#include "qgis.h"
19#include "qgsterrainprovider.h"
20
21#include <QDomElement>
22
24 : QObject( parent )
25 , mTerrainProvider( std::make_unique< QgsFlatTerrainProvider >() )
26{
27
28}
29
31
33{
34 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
35 emit changed();
36}
37
39{
40 if ( mTerrainProvider )
41 mTerrainProvider->resolveReferences( project );
42}
43
44bool QgsProjectElevationProperties::readXml( const QDomElement &element, const QgsReadWriteContext &context )
45{
46 const QDomElement providerElement = element.firstChildElement( QStringLiteral( "terrainProvider" ) );
47 if ( !providerElement.isNull() )
48 {
49 const QString type = providerElement.attribute( QStringLiteral( "type" ) );
50 if ( type.compare( QLatin1String( "flat" ) ) == 0 )
51 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
52 else if ( type.compare( QLatin1String( "raster" ) ) == 0 )
53 mTerrainProvider = std::make_unique< QgsRasterDemTerrainProvider >();
54 else if ( type.compare( QLatin1String( "mesh" ) ) == 0 )
55 mTerrainProvider = std::make_unique< QgsMeshTerrainProvider >();
56 else
57 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
58
59 mTerrainProvider->readXml( providerElement, context );
60 }
61 else
62 {
63 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
64 }
65
66 emit changed();
67 return true;
68}
69
70QDomElement QgsProjectElevationProperties::writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const
71{
72 QDomElement element = document.createElement( QStringLiteral( "ElevationProperties" ) );
73
74 if ( mTerrainProvider )
75 {
76 QDomElement providerElement = document.createElement( QStringLiteral( "terrainProvider" ) );
77 providerElement.setAttribute( QStringLiteral( "type" ), mTerrainProvider->type() );
78 providerElement.appendChild( mTerrainProvider->writeXml( document, context ) );
79 element.appendChild( providerElement );
80 }
81 return element;
82}
83
85{
86 return mTerrainProvider.get();
87}
88
90{
91 if ( mTerrainProvider.get() == provider )
92 return;
93
94 mTerrainProvider.reset( provider );
95 emit changed();
96}
Abstract base class for terrain providers.
A terrain provider where the terrain is a simple flat surface.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads the property state from a DOM element.
void reset()
Resets the properties to a default state.
QgsProjectElevationProperties(QObject *parent=nullptr)
Constructor for QgsProjectElevationProperties with the specified parent object.
QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const
Returns a DOM element representing the properties.
~QgsProjectElevationProperties() override
QgsAbstractTerrainProvider * terrainProvider()
Returns the project's terrain provider.
void changed()
Emitted when the elevation properties change.
void resolveReferences(const QgsProject *project)
Resolves reference to layers from stored layer ID.
void setTerrainProvider(QgsAbstractTerrainProvider *provider)
Sets the project's terrain provider.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:104
The class is used as a container of context for various read/write operations on other objects.