34 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
42 if ( mTerrainProvider )
43 mTerrainProvider->resolveReferences( project );
48 const QDomElement providerElement = element.firstChildElement( QStringLiteral(
"terrainProvider" ) );
49 if ( !providerElement.isNull() )
51 const QString type = providerElement.attribute( QStringLiteral(
"type" ) );
52 if ( type.compare( QLatin1String(
"flat" ) ) == 0 )
53 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
54 else if ( type.compare( QLatin1String(
"raster" ) ) == 0 )
55 mTerrainProvider = std::make_unique< QgsRasterDemTerrainProvider >();
56 else if ( type.compare( QLatin1String(
"mesh" ) ) == 0 )
57 mTerrainProvider = std::make_unique< QgsMeshTerrainProvider >();
59 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
61 mTerrainProvider->readXml( providerElement, context );
65 mTerrainProvider = std::make_unique< QgsFlatTerrainProvider >();
69 double rangeLower = std::numeric_limits< double >::lowest();
70 const double storedRangeLower = element.attribute( QStringLiteral(
"RangeLower" ) ).toDouble( &ok );
72 rangeLower = storedRangeLower;
73 double rangeUpper = std::numeric_limits< double >::max();
74 const double storedRangeUpper = element.attribute( QStringLiteral(
"RangeUpper" ) ).toDouble( &ok );
76 rangeUpper = storedRangeUpper;
79 mElevationFilterRangeSize = element.attribute( QStringLiteral(
"FilterRangeSize" ) ).toDouble( &ok );
81 mElevationFilterRangeSize = -1;
83 mInvertElevationFilter = element.attribute( QStringLiteral(
"FilterInvertSlider" ), QStringLiteral(
"0" ) ).toInt();
92 QDomElement element = document.createElement( QStringLiteral(
"ElevationProperties" ) );
94 if ( mTerrainProvider )
96 QDomElement providerElement = document.createElement( QStringLiteral(
"terrainProvider" ) );
97 providerElement.setAttribute( QStringLiteral(
"type" ), mTerrainProvider->type() );
98 providerElement.appendChild( mTerrainProvider->writeXml( document, context ) );
99 element.appendChild( providerElement );
102 if ( mElevationRange.
lower() != std::numeric_limits< double >::lowest() )
104 if ( mElevationRange.
upper() != std::numeric_limits< double >::max() )
107 if ( mElevationFilterRangeSize >= 0 )
109 element.setAttribute( QStringLiteral(
"FilterRangeSize" ), mElevationFilterRangeSize );
111 element.setAttribute( QStringLiteral(
"FilterInvertSlider" ), mInvertElevationFilter ?
"1" :
"0" );
118 return mTerrainProvider.get();
123 if ( mTerrainProvider.get() == provider )
126 const bool hasChanged = ( provider && mTerrainProvider ) ? !mTerrainProvider->equals( provider ) : (
static_cast< bool >( provider ) !=
static_cast< bool >( mTerrainProvider.get() ) );
128 mTerrainProvider.reset( provider );
135 if ( mElevationFilterRangeSize == size )
138 mElevationFilterRangeSize = size;
144 if ( mInvertElevationFilter == invert )
147 mInvertElevationFilter = invert;
153 if ( mElevationRange == range )
156 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.