18#include "moc_qgsprojectelevationproperties.cpp"
35 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
43 if ( mTerrainProvider )
44 mTerrainProvider->resolveReferences( project );
49 const QDomElement providerElement = element.firstChildElement( QStringLiteral(
"terrainProvider" ) );
50 if ( !providerElement.isNull() )
52 const QString type = providerElement.attribute( QStringLiteral(
"type" ) );
53 if ( type.compare( QLatin1String(
"flat" ) ) == 0 )
54 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
55 else if ( type.compare( QLatin1String(
"raster" ) ) == 0 )
56 mTerrainProvider = std::make_unique< QgsRasterDemTerrainProvider >();
57 else if ( type.compare( QLatin1String(
"mesh" ) ) == 0 )
58 mTerrainProvider = std::make_unique< QgsMeshTerrainProvider >();
60 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
62 mTerrainProvider->readXml( providerElement, context );
66 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
70 double rangeLower = std::numeric_limits< double >::lowest();
71 const double storedRangeLower = element.attribute( QStringLiteral(
"RangeLower" ) ).toDouble( &ok );
73 rangeLower = storedRangeLower;
74 double rangeUpper = std::numeric_limits< double >::max();
75 const double storedRangeUpper = element.attribute( QStringLiteral(
"RangeUpper" ) ).toDouble( &ok );
77 rangeUpper = storedRangeUpper;
80 mElevationFilterRangeSize = element.attribute( QStringLiteral(
"FilterRangeSize" ) ).toDouble( &ok );
82 mElevationFilterRangeSize = -1;
84 mInvertElevationFilter = element.attribute( QStringLiteral(
"FilterInvertSlider" ), QStringLiteral(
"0" ) ).toInt();
93 QDomElement element = document.createElement( QStringLiteral(
"ElevationProperties" ) );
95 if ( mTerrainProvider )
97 QDomElement providerElement = document.createElement( QStringLiteral(
"terrainProvider" ) );
98 providerElement.setAttribute( QStringLiteral(
"type" ), mTerrainProvider->type() );
99 providerElement.appendChild( mTerrainProvider->writeXml( document, context ) );
100 element.appendChild( providerElement );
103 if ( mElevationRange.
lower() != std::numeric_limits< double >::lowest() )
105 if ( mElevationRange.
upper() != std::numeric_limits< double >::max() )
108 if ( mElevationFilterRangeSize >= 0 )
110 element.setAttribute( QStringLiteral(
"FilterRangeSize" ), mElevationFilterRangeSize );
112 element.setAttribute( QStringLiteral(
"FilterInvertSlider" ), mInvertElevationFilter ?
"1" :
"0" );
119 return mTerrainProvider.get();
124 if ( mTerrainProvider.get() == provider )
127 const bool hasChanged = ( provider && mTerrainProvider ) ? !mTerrainProvider->equals( provider ) : (
static_cast< bool >( provider ) !=
static_cast< bool >( mTerrainProvider.get() ) );
129 mTerrainProvider.reset( provider );
136 if ( mElevationFilterRangeSize == size )
139 mElevationFilterRangeSize = size;
145 if ( mInvertElevationFilter == invert )
148 mInvertElevationFilter = invert;
154 if ( mElevationRange == range )
157 mElevationRange = range;
Abstract base class for terrain providers.
QgsRange which stores a range of double values.
A terrain provider where the terrain is a simple flat surface.
void setElevationFilterRangeSize(double size)
Sets the fixed size for elevation range filtering in the project, used when interactively filtering b...
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
void setElevationRange(const QgsDoubleRange &range)
Sets the project's elevation range, which indicates the upper and lower elevation limits associated w...
QgsAbstractTerrainProvider * terrainProvider()
Returns the project's terrain provider.
void elevationRangeChanged(const QgsDoubleRange &range)
Emitted when the project's elevation is changed.
void changed()
Emitted when the elevation properties change.
void resolveReferences(const QgsProject *project)
Resolves reference to layers from stored layer ID.
void setInvertElevationFilter(bool invert)
Sets whether the elevation range filter slider should be inverted for this project.
void setTerrainProvider(QgsAbstractTerrainProvider *provider)
Sets the project's terrain provider.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
T lower() const
Returns the lower bound of the range.
T upper() const
Returns the upper bound of the range.
The class is used as a container of context for various read/write operations on other objects.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.