QGIS API Documentation 3.37.0-Master (c2d15952569)
Loading...
Searching...
No Matches
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#include "qgsrasterbandstats.h"
21
22#include <QDomElement>
23
25 : QObject( parent )
26 , mTerrainProvider( std::make_unique< QgsFlatTerrainProvider >() )
27{
28
29}
30
32
34{
35 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
36 emit changed();
37}
38
40{
41 if ( mTerrainProvider )
42 mTerrainProvider->resolveReferences( project );
43}
44
45bool QgsProjectElevationProperties::readXml( const QDomElement &element, const QgsReadWriteContext &context )
46{
47 const QDomElement providerElement = element.firstChildElement( QStringLiteral( "terrainProvider" ) );
48 if ( !providerElement.isNull() )
49 {
50 const QString type = providerElement.attribute( QStringLiteral( "type" ) );
51 if ( type.compare( QLatin1String( "flat" ) ) == 0 )
52 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
53 else if ( type.compare( QLatin1String( "raster" ) ) == 0 )
54 mTerrainProvider = std::make_unique< QgsRasterDemTerrainProvider >();
55 else if ( type.compare( QLatin1String( "mesh" ) ) == 0 )
56 mTerrainProvider = std::make_unique< QgsMeshTerrainProvider >();
57 else
58 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
59
60 mTerrainProvider->readXml( providerElement, context );
61 }
62 else
63 {
64 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
65 }
66
67 emit changed();
68 return true;
69}
70
71QDomElement QgsProjectElevationProperties::writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const
72{
73 QDomElement element = document.createElement( QStringLiteral( "ElevationProperties" ) );
74
75 if ( mTerrainProvider )
76 {
77 QDomElement providerElement = document.createElement( QStringLiteral( "terrainProvider" ) );
78 providerElement.setAttribute( QStringLiteral( "type" ), mTerrainProvider->type() );
79 providerElement.appendChild( mTerrainProvider->writeXml( document, context ) );
80 element.appendChild( providerElement );
81 }
82 return element;
83}
84
89
91{
92 if ( mTerrainProvider.get() == provider )
93 return;
94
95 mTerrainProvider.reset( provider );
96 emit changed();
97}
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:107
The class is used as a container of context for various read/write operations on other objects.