QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
20#include "qgstiledscenelayer.h"
21
22#include "moc_qgstiledscenelayerelevationproperties.cpp"
23
28
30{
31 return true;
32}
33
34QDomElement QgsTiledSceneLayerElevationProperties::writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context )
35{
36 QDomElement element = document.createElement( QStringLiteral( "elevation" ) );
37 writeCommonProperties( element, document, context );
38
39 parentElement.appendChild( element );
40 return element;
41}
42
43bool QgsTiledSceneLayerElevationProperties::readXml( const QDomElement &element, const QgsReadWriteContext &context )
44{
45 const QDomElement elevationElement = element.firstChildElement( QStringLiteral( "elevation" ) ).toElement();
46 readCommonProperties( elevationElement, context );
47
48 return true;
49}
50
52{
53 auto res = std::make_unique< QgsTiledSceneLayerElevationProperties >( nullptr );
54 res->copyCommonProperties( this );
55
56 return res.release();
57}
58
60{
61 QStringList properties;
62 properties << tr( "Scale: %1" ).arg( mZScale );
63 properties << tr( "Offset: %1" ).arg( mZOffset );
64 return QStringLiteral( "<ul><li>%1</li></ul>" ).arg( properties.join( QLatin1String( "</li><li>" ) ) );
65}
66
68{
69 if ( QgsTiledSceneLayer *tiledSceneLayer = qobject_cast< QgsTiledSceneLayer * >( layer ) )
70 {
71 if ( QgsTiledSceneDataProvider *dp = tiledSceneLayer->dataProvider() )
72 {
73 const QgsDoubleRange providerRange = dp->zRange();
74 if ( providerRange.isInfinite() || providerRange.isEmpty() )
75 return QgsDoubleRange();
76
77 return QgsDoubleRange( dp->zRange().lower() * mZScale + mZOffset, dp->zRange().upper() * mZScale + mZOffset );
78 }
79 }
80
81 return QgsDoubleRange();
82}
83
85{
86 const QgsDoubleRange range = calculateZRange( layer );
87 if ( !range.isInfinite() && range.lower() != range.upper() )
88 return {range.lower(), range.upper() };
89 else if ( !range.isInfinite() )
90 return {range.lower() };
91 else
92 return {};
93}
QgsRange which stores a range of double values.
Definition qgsrange.h:233
bool isInfinite() const
Returns true if the range consists of all possible values.
Definition qgsrange.h:287
void writeCommonProperties(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context)
Writes common class properties to a DOM element, to be used later with readXml().
QgsMapLayerElevationProperties(QObject *parent)
Constructor for QgsMapLayerElevationProperties, with the specified parent object.
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:80
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
A container for the context for various read/write operations on objects.
Base class for data providers for QgsTiledSceneLayer.
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.