QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 "qgstiledscenelayer.h"
20
25
27{
28 return true;
29}
30
31QDomElement QgsTiledSceneLayerElevationProperties::writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context )
32{
33 QDomElement element = document.createElement( QStringLiteral( "elevation" ) );
34 writeCommonProperties( element, document, context );
35
36 parentElement.appendChild( element );
37 return element;
38}
39
40bool QgsTiledSceneLayerElevationProperties::readXml( const QDomElement &element, const QgsReadWriteContext &context )
41{
42 const QDomElement elevationElement = element.firstChildElement( QStringLiteral( "elevation" ) ).toElement();
43 readCommonProperties( elevationElement, context );
44
45 return true;
46}
47
49{
50 std::unique_ptr< QgsTiledSceneLayerElevationProperties > res = std::make_unique< QgsTiledSceneLayerElevationProperties >( nullptr );
51 res->copyCommonProperties( this );
52
53 return res.release();
54}
55
57{
58 QStringList properties;
59 properties << tr( "Scale: %1" ).arg( mZScale );
60 properties << tr( "Offset: %1" ).arg( mZOffset );
61 return QStringLiteral( "<ul><li>%1</li></ul>" ).arg( properties.join( QLatin1String( "</li><li>" ) ) );
62}
63
65{
66 if ( QgsTiledSceneLayer *tiledSceneLayer = qobject_cast< QgsTiledSceneLayer * >( layer ) )
67 {
68 if ( QgsTiledSceneDataProvider *dp = tiledSceneLayer->dataProvider() )
69 {
70 const QgsDoubleRange providerRange = dp->zRange();
71 if ( providerRange.isInfinite() || providerRange.isEmpty() )
72 return QgsDoubleRange();
73
74 return QgsDoubleRange( dp->zRange().lower() * mZScale + mZOffset, dp->zRange().upper() * mZScale + mZOffset );
75 }
76 }
77
78 return QgsDoubleRange();
79}
80
82{
83 const QgsDoubleRange range = calculateZRange( layer );
84 if ( !range.isInfinite() && range.lower() != range.upper() )
85 return {range.lower(), range.upper() };
86 else if ( !range.isInfinite() )
87 return {range.lower() };
88 else
89 return {};
90}
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.