QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgstiledscenelayerelevationproperties.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgstiledscenelayerelevationproperties.cpp
3 ---------------
4 begin : August 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson 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 ***************************************************************************/
17
19#include "moc_qgstiledscenelayerelevationproperties.cpp"
20#include "qgstiledscenelayer.h"
21
26
28{
29 return true;
30}
31
32QDomElement QgsTiledSceneLayerElevationProperties::writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context )
33{
34 QDomElement element = document.createElement( QStringLiteral( "elevation" ) );
35 writeCommonProperties( element, document, context );
36
37 parentElement.appendChild( element );
38 return element;
39}
40
41bool QgsTiledSceneLayerElevationProperties::readXml( const QDomElement &element, const QgsReadWriteContext &context )
42{
43 const QDomElement elevationElement = element.firstChildElement( QStringLiteral( "elevation" ) ).toElement();
44 readCommonProperties( elevationElement, context );
45
46 return true;
47}
48
50{
51 std::unique_ptr< QgsTiledSceneLayerElevationProperties > res = std::make_unique< QgsTiledSceneLayerElevationProperties >( nullptr );
52 res->copyCommonProperties( this );
53
54 return res.release();
55}
56
58{
59 QStringList properties;
60 properties << tr( "Scale: %1" ).arg( mZScale );
61 properties << tr( "Offset: %1" ).arg( mZOffset );
62 return QStringLiteral( "<ul><li>%1</li></ul>" ).arg( properties.join( QLatin1String( "</li><li>" ) ) );
63}
64
66{
67 if ( QgsTiledSceneLayer *tiledSceneLayer = qobject_cast< QgsTiledSceneLayer * >( layer ) )
68 {
69 if ( QgsTiledSceneDataProvider *dp = tiledSceneLayer->dataProvider() )
70 {
71 const QgsDoubleRange providerRange = dp->zRange();
72 if ( providerRange.isInfinite() || providerRange.isEmpty() )
73 return QgsDoubleRange();
74
75 return QgsDoubleRange( dp->zRange().lower() * mZScale + mZOffset, dp->zRange().upper() * mZScale + mZOffset );
76 }
77 }
78
79 return QgsDoubleRange();
80}
81
83{
84 const QgsDoubleRange range = calculateZRange( layer );
85 if ( !range.isInfinite() && range.lower() != range.upper() )
86 return {range.lower(), range.upper() };
87 else if ( !range.isInfinite() )
88 return {range.lower() };
89 else
90 return {};
91}
QgsRange which stores a range of double values.
Definition qgsrange.h:231
bool isInfinite() const
Returns true if the range consists of all possible values.
Definition qgsrange.h:285
Base class for storage of map layer elevation properties.
void writeCommonProperties(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context)
Writes common class properties to a DOM element, to be used later with readXml().
void readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Reads common class properties from a DOM element previously written by writeXml().
Base class for all map layer types.
Definition qgsmaplayer.h:76
T lower() const
Returns the lower bound of the range.
Definition qgsrange.h:78
T upper() const
Returns the upper bound of the range.
Definition qgsrange.h:85
bool isEmpty() const
Returns true if the range is empty, ie the lower bound equals (or exceeds) the upper bound and either...
Definition qgsrange.h:125
The class is used as a container of context for various read/write operations on other objects.
Base class for data providers for QgsTiledSceneLayer.
Tiled scene layer specific subclass of QgsMapLayerElevationProperties.
QString htmlSummary() const override
Returns a HTML formatted summary of the properties.
QgsTiledSceneLayerElevationProperties(QObject *parent)
Constructor for QgsTiledSceneLayerElevationProperties, with the specified parent object.
bool hasElevation() const override
Returns true if the layer has an elevation or z component.
QList< double > significantZValues(QgsMapLayer *layer) const override
Returns a list of significant elevation/z-values for the specified layer, using the settings defined ...
QgsDoubleRange calculateZRange(QgsMapLayer *layer) const override
Attempts to calculate the overall elevation or z range for the specified layer, using the settings de...
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the elevation properties from a DOM element previously written by writeXml().
QgsTiledSceneLayerElevationProperties * clone() const override
Creates a clone of the properties.
QDomElement writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) override
Writes the properties to a DOM element, to be used later with readXml().
Represents a map layer supporting display of tiled scene objects.