QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 <mutex>
20 
21 
23 
25  : QObject( parent )
26 {
27 }
28 
30 {
31  return false;
32 }
33 
35 {
36 
37 }
38 
40 {
41  return QString();
42 }
43 
44 void QgsMapLayerElevationProperties::writeCommonProperties( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext & )
45 {
46  QDomElement elemDataDefinedProperties = doc.createElement( QStringLiteral( "data-defined-properties" ) );
47  mDataDefinedProperties.writeXml( elemDataDefinedProperties, propertyDefinitions() );
48  element.appendChild( elemDataDefinedProperties );
49 
50  element.setAttribute( QStringLiteral( "zoffset" ), qgsDoubleToString( mZOffset ) );
51  element.setAttribute( QStringLiteral( "zscale" ), qgsDoubleToString( mZScale ) );
52 }
53 
55 {
56  const QDomElement elemDataDefinedProperties = element.firstChildElement( QStringLiteral( "data-defined-properties" ) );
57  if ( !elemDataDefinedProperties.isNull() )
58  mDataDefinedProperties.readXml( elemDataDefinedProperties, propertyDefinitions() );
59 
60  mZOffset = element.attribute( QStringLiteral( "zoffset" ), QStringLiteral( "0" ) ).toDouble();
61  mZScale = element.attribute( QStringLiteral( "zscale" ), QStringLiteral( "1" ) ).toDouble();
62 }
63 
65 {
67  mZScale = other->zScale();
68  mZOffset = other->zOffset();
69 }
70 
72 {
73  return true;
74 }
75 
77 {
78  return QgsDoubleRange();
79 }
80 
82 {
83  return false;
84 }
85 
87 {
88  if ( qgsDoubleNear( offset, mZOffset ) )
89  return;
90 
91  mZOffset = offset;
92  emit changed();
93  emit zOffsetChanged();
95 }
96 
98 {
99  if ( qgsDoubleNear( scale, mZScale ) )
100  return;
101 
102  mZScale = scale;
103  emit changed();
104  emit zScaleChanged();
106 }
107 
109 {
110  if ( mDataDefinedProperties == collection )
111  return;
112 
113  mDataDefinedProperties = collection;
114  emit changed();
116 }
117 
119 {
120  static std::once_flag initialized;
121  std::call_once( initialized, [ = ]( )
122  {
123  initPropertyDefinitions();
124  } );
125  return sPropertyDefinitions;
126 }
127 
128 void QgsMapLayerElevationProperties::initPropertyDefinitions()
129 {
130  const QString origin = QStringLiteral( "elevation" );
131 
133  {
134  { QgsMapLayerElevationProperties::ZOffset, QgsPropertyDefinition( "ZOffset", QObject::tr( "Offset" ), QgsPropertyDefinition::Double, origin ) },
135  { QgsMapLayerElevationProperties::ExtrusionHeight, QgsPropertyDefinition( "ExtrusionHeight", QObject::tr( "Extrusion height" ), QgsPropertyDefinition::DoublePositive, origin ) },
136  };
137 }
QgsMapLayerElevationProperties::setZOffset
void setZOffset(double offset)
Sets the z offset, which is a fixed offset amount which will be added to z values from the layer.
Definition: qgsmaplayerelevationproperties.cpp:86
QgsMapLayerElevationProperties::ZOffset
@ ZOffset
Definition: qgsmaplayerelevationproperties.h:85
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsMapLayerElevationProperties
Base class for storage of map layer elevation properties.
Definition: qgsmaplayerelevationproperties.h:41
QgsMapLayerElevationProperties::zOffsetChanged
void zOffsetChanged()
Emitted when the z offset changes.
QgsMapLayerElevationProperties::propertyDefinitions
static QgsPropertiesDefinition propertyDefinitions()
Returns the definitions for data defined properties available for use in elevation properties.
Definition: qgsmaplayerelevationproperties.cpp:118
QgsAbstractPropertyCollection::readXml
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
Definition: qgspropertycollection.cpp:108
QgsMapLayerElevationProperties::ExtrusionHeight
@ ExtrusionHeight
Z offset.
Definition: qgsmaplayerelevationproperties.h:86
QgsMapLayerElevationProperties::zScaleChanged
void zScaleChanged()
Emitted when the z scale changes.
QgsPropertyDefinition::Double
@ Double
Double value (including negative values)
Definition: qgsproperty.h:57
QgsMapLayerElevationProperties::setDefaultsFromLayer
virtual void setDefaultsFromLayer(QgsMapLayer *layer)
Sets default properties based on sensible choices for the given map layer.
Definition: qgsmaplayerelevationproperties.cpp:34
QgsMapLayerElevationProperties::isVisibleInZRange
virtual bool isVisibleInZRange(const QgsDoubleRange &range) const
Returns true if the layer should be visible and rendered for the specified z range.
Definition: qgsmaplayerelevationproperties.cpp:71
qgsDoubleToString
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:2204
QgsMapLayerElevationProperties::readCommonProperties
void readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Reads common class properties from a DOM element previously written by writeXml().
Definition: qgsmaplayerelevationproperties.cpp:54
QgsMapLayerElevationProperties::calculateZRange
virtual QgsDoubleRange calculateZRange(QgsMapLayer *layer) const
Attempts to calculate the overall elevation or z range for the specified layer, using the settings de...
Definition: qgsmaplayerelevationproperties.cpp:76
QgsMapLayerElevationProperties::hasElevation
virtual bool hasElevation() const
Returns true if the layer has an elevation or z component.
Definition: qgsmaplayerelevationproperties.cpp:29
QgsMapLayerElevationProperties::htmlSummary
virtual QString htmlSummary() const
Returns a HTML formatted summary of the properties.
Definition: qgsmaplayerelevationproperties.cpp:39
QgsPropertiesDefinition
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition: qgspropertycollection.h:29
QgsMapLayerElevationProperties::zScale
double zScale() const
Returns the z scale, which is a scaling factor which should be applied to z values from the layer.
Definition: qgsmaplayerelevationproperties.h:203
QgsMapLayerElevationProperties::setDataDefinedProperties
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the object's property collection, used for data defined overrides.
Definition: qgsmaplayerelevationproperties.cpp:108
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:2265
QgsMapLayerElevationProperties::mDataDefinedProperties
QgsPropertyCollection mDataDefinedProperties
Property collection for data defined elevation settings.
Definition: qgsmaplayerelevationproperties.h:302
QgsMapLayerElevationProperties::mZOffset
double mZOffset
Z offset.
Definition: qgsmaplayerelevationproperties.h:299
QgsPropertyDefinition
Definition for a property.
Definition: qgsproperty.h:46
QgsMapLayerElevationProperties::copyCommonProperties
void copyCommonProperties(const QgsMapLayerElevationProperties *other)
Copies common properties from another object.
Definition: qgsmaplayerelevationproperties.cpp:64
QgsMapLayerElevationProperties::QgsMapLayerElevationProperties
QgsMapLayerElevationProperties(QObject *parent)
Constructor for QgsMapLayerElevationProperties, with the specified parent object.
Definition: qgsmaplayerelevationproperties.cpp:24
QgsMapLayerElevationProperties::profileGenerationPropertyChanged
void profileGenerationPropertyChanged()
Emitted when any of the elevation properties which relate solely to generation of elevation profiles ...
QgsMapLayerElevationProperties::sPropertyDefinitions
static QgsPropertiesDefinition sPropertyDefinitions
Property definitions.
Definition: qgsmaplayerelevationproperties.h:305
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsDoubleRange
QgsRange which stores a range of double values.
Definition: qgsrange.h:202
QgsMapLayerElevationProperties::mZScale
double mZScale
Z scale.
Definition: qgsmaplayerelevationproperties.h:297
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsMapLayerElevationProperties::showByDefaultInElevationProfilePlots
virtual bool showByDefaultInElevationProfilePlots() const
Returns true if the layer should be visible by default in newly created elevation profile plots.
Definition: qgsmaplayerelevationproperties.cpp:81
QgsMapLayerElevationProperties::changed
void changed()
Emitted when any of the elevation properties have changed.
QgsMapLayerElevationProperties::zOffset
double zOffset() const
Returns the z offset, which is a fixed offset amount which should be added to z values from the layer...
Definition: qgsmaplayerelevationproperties.h:180
QgsMapLayerElevationProperties::writeCommonProperties
void writeCommonProperties(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context)
Writes common class properties to a DOM element, to be used later with readXml().
Definition: qgsmaplayerelevationproperties.cpp:44
QgsMapLayerElevationProperties::dataDefinedProperties
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the object's property collection, used for data defined overrides.
Definition: qgsmaplayerelevationproperties.h:223
QgsMapLayerElevationProperties::setZScale
void setZScale(double scale)
Sets the z scale, which is a scaling factor which will be applied to z values from the layer.
Definition: qgsmaplayerelevationproperties.cpp:97
qgsmaplayerelevationproperties.h
QgsAbstractPropertyCollection::writeXml
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
Definition: qgspropertycollection.cpp:99
QgsPropertyDefinition::DoublePositive
@ DoublePositive
Positive double value (including 0)
Definition: qgsproperty.h:58