QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsmaplayerelevationproperties.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayerelevationproperties.cpp
3 ---------------
4 begin : November 2020
5 copyright : (C) 2020 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_qgsmaplayerelevationproperties.cpp"
20#include <mutex>
21
22
24
26 : QObject( parent )
27{
28}
29
31{
32 return false;
33}
34
39
41{
42 return QString();
43}
44
45void QgsMapLayerElevationProperties::writeCommonProperties( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext & )
46{
47 QDomElement elemDataDefinedProperties = doc.createElement( QStringLiteral( "data-defined-properties" ) );
48 mDataDefinedProperties.writeXml( elemDataDefinedProperties, propertyDefinitions() );
49 element.appendChild( elemDataDefinedProperties );
50
51 element.setAttribute( QStringLiteral( "zoffset" ), qgsDoubleToString( mZOffset ) );
52 element.setAttribute( QStringLiteral( "zscale" ), qgsDoubleToString( mZScale ) );
53}
54
56{
57 const QDomElement elemDataDefinedProperties = element.firstChildElement( QStringLiteral( "data-defined-properties" ) );
58 if ( !elemDataDefinedProperties.isNull() )
59 mDataDefinedProperties.readXml( elemDataDefinedProperties, propertyDefinitions() );
60
61 mZOffset = element.attribute( QStringLiteral( "zoffset" ), QStringLiteral( "0" ) ).toDouble();
62 mZScale = element.attribute( QStringLiteral( "zscale" ), QStringLiteral( "1" ) ).toDouble();
63}
64
71
73{
74 return true;
75}
76
81
83{
84 return {};
85}
86
91
93{
94 if ( qgsDoubleNear( offset, mZOffset ) )
95 return;
96
97 mZOffset = offset;
98 emit changed();
99 emit zOffsetChanged();
101}
102
104{
105 if ( qgsDoubleNear( scale, mZScale ) )
106 return;
107
108 mZScale = scale;
109 emit changed();
110 emit zScaleChanged();
112}
113
115{
116 if ( mDataDefinedProperties == collection )
117 return;
118
119 mDataDefinedProperties = collection;
120 emit changed();
122}
123
125{
126 static std::once_flag initialized;
127 std::call_once( initialized, [ = ]( )
128 {
129 initPropertyDefinitions();
130 } );
132}
133
134void QgsMapLayerElevationProperties::initPropertyDefinitions()
135{
136 const QString origin = QStringLiteral( "elevation" );
137
139 {
140 { static_cast< int >( QgsMapLayerElevationProperties::Property::ZOffset ), QgsPropertyDefinition( "ZOffset", QObject::tr( "Offset" ), QgsPropertyDefinition::Double, origin ) },
141 { static_cast< int >( QgsMapLayerElevationProperties::Property::ExtrusionHeight ), QgsPropertyDefinition( "ExtrusionHeight", QObject::tr( "Extrusion height" ), QgsPropertyDefinition::DoublePositive, origin ) },
142 { static_cast< int >( QgsMapLayerElevationProperties::Property::RasterPerBandLowerElevation ), QgsPropertyDefinition( "RasterPerBandLowerElevation", QObject::tr( "Lower elevation for band" ), QgsPropertyDefinition::Double, origin ) },
143 { static_cast< int >( QgsMapLayerElevationProperties::Property::RasterPerBandUpperElevation ), QgsPropertyDefinition( "RasterPerBandUpperElevation", QObject::tr( "Upper elevation for band" ), QgsPropertyDefinition::Double, origin ) },
144 };
145}
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
QgsRange which stores a range of double values.
Definition qgsrange.h:231
Base class for storage of map layer elevation properties.
virtual QList< double > significantZValues(QgsMapLayer *layer) const
Returns a list of significant elevation/z-values for the specified layer, using the settings defined ...
void zScaleChanged()
Emitted when the z scale changes.
QgsPropertyCollection mDataDefinedProperties
Property collection for data defined elevation settings.
void writeCommonProperties(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context)
Writes common class properties to a DOM element, to be used later with readXml().
void profileGenerationPropertyChanged()
Emitted when any of the elevation properties which relate solely to generation of elevation profiles ...
virtual bool isVisibleInZRange(const QgsDoubleRange &range, QgsMapLayer *layer=nullptr) const
Returns true if the layer should be visible and rendered for the specified z range.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the object's property collection, used for data defined overrides.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the object's property collection, used for data defined overrides.
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().
virtual QString htmlSummary() const
Returns a HTML formatted summary of the properties.
static QgsPropertiesDefinition propertyDefinitions()
Returns the definitions for data defined properties available for use in elevation properties.
void changed()
Emitted when any of the elevation properties have changed.
void copyCommonProperties(const QgsMapLayerElevationProperties *other)
Copies common properties from another object.
@ RasterPerBandUpperElevation
Upper elevation for each raster band.
@ RasterPerBandLowerElevation
Lower elevation for each raster band.
void zOffsetChanged()
Emitted when the z offset changes.
double zScale() const
Returns the z scale, which is a scaling factor which should be applied to z values from the layer.
void setZOffset(double offset)
Sets the z offset, which is a fixed offset amount which will be added to z values from the layer.
virtual bool showByDefaultInElevationProfilePlots() const
Returns true if the layer should be visible by default in newly created elevation profile plots.
static QgsPropertiesDefinition sPropertyDefinitions
Property definitions.
virtual QgsDoubleRange calculateZRange(QgsMapLayer *layer) const
Attempts to calculate the overall elevation or z range for the specified layer, using the settings de...
virtual void setDefaultsFromLayer(QgsMapLayer *layer)
Sets default properties based on sensible choices for the given map layer.
void setZScale(double scale)
Sets the z scale, which is a scaling factor which will be applied to z values from the layer.
virtual bool hasElevation() const
Returns true if the layer has an elevation or z component.
double zOffset() const
Returns the z offset, which is a fixed offset amount which should be added to z values from the layer...
Base class for all map layer types.
Definition qgsmaplayer.h:76
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition for a property.
Definition qgsproperty.h:45
@ Double
Double value (including negative values)
Definition qgsproperty.h:55
@ DoublePositive
Positive double value (including 0)
Definition qgsproperty.h:56
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.
Definition qgis.h:5875
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:5958
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.