QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
44 bool 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 
70 QDomElement 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 }
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsProjectElevationProperties::resolveReferences
void resolveReferences(const QgsProject *project)
Resolves reference to layers from stored layer ID.
Definition: qgsprojectelevationproperties.cpp:38
qgis.h
QgsProjectElevationProperties::setTerrainProvider
void setTerrainProvider(QgsAbstractTerrainProvider *provider)
Sets the project's terrain provider.
Definition: qgsprojectelevationproperties.cpp:89
QgsProjectElevationProperties::~QgsProjectElevationProperties
~QgsProjectElevationProperties() override
QgsProjectElevationProperties::changed
void changed()
Emitted when the elevation properties change.
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsProjectElevationProperties::QgsProjectElevationProperties
QgsProjectElevationProperties(QObject *parent=nullptr)
Constructor for QgsProjectElevationProperties with the specified parent object.
Definition: qgsprojectelevationproperties.cpp:23
QgsProjectElevationProperties::terrainProvider
QgsAbstractTerrainProvider * terrainProvider()
Returns the project's terrain provider.
Definition: qgsprojectelevationproperties.cpp:84
QgsProjectElevationProperties::reset
void reset()
Resets the properties to a default state.
Definition: qgsprojectelevationproperties.cpp:32
qgsterrainprovider.h
QgsAbstractTerrainProvider
Abstract base class for terrain providers.
Definition: qgsterrainprovider.h:40
QgsProjectElevationProperties::readXml
bool readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads the property state from a DOM element.
Definition: qgsprojectelevationproperties.cpp:44
QgsProjectElevationProperties::writeXml
QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const
Returns a DOM element representing the properties.
Definition: qgsprojectelevationproperties.cpp:70
qgsprojectelevationproperties.h
QgsFlatTerrainProvider
A terrain provider where the terrain is a simple flat surface.
Definition: qgsterrainprovider.h:205