QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsmeshlayerelevationproperties.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmeshlayerelevationproperties.cpp
3 ---------------
4 begin : February 2022
5 copyright : (C) 2022 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 "qgsmeshlayer.h"
20#include "qgslinesymbol.h"
21#include "qgsfillsymbol.h"
22#include "qgssymbollayerutils.h"
23#include "qgslinesymbollayer.h"
24#include "qgsfillsymbollayer.h"
25#include "qgsapplication.h"
27
30{
32 setDefaultProfileLineSymbol( color );
33 setDefaultProfileFillSymbol( color );
34}
35
37
39{
40 return true;
41}
42
43QDomElement QgsMeshLayerElevationProperties::writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context )
44{
45 QDomElement element = document.createElement( QStringLiteral( "elevation" ) );
46 element.setAttribute( QStringLiteral( "symbology" ), qgsEnumValueToKey( mSymbology ) );
47 if ( !std::isnan( mElevationLimit ) )
48 element.setAttribute( QStringLiteral( "elevationLimit" ), qgsDoubleToString( mElevationLimit ) );
49
50 writeCommonProperties( element, document, context );
51
52 QDomElement profileLineSymbolElement = document.createElement( QStringLiteral( "profileLineSymbol" ) );
53 profileLineSymbolElement.appendChild( QgsSymbolLayerUtils::saveSymbol( QString(), mProfileLineSymbol.get(), document, context ) );
54 element.appendChild( profileLineSymbolElement );
55
56 QDomElement profileFillSymbolElement = document.createElement( QStringLiteral( "profileFillSymbol" ) );
57 profileFillSymbolElement.appendChild( QgsSymbolLayerUtils::saveSymbol( QString(), mProfileFillSymbol.get(), document, context ) );
58 element.appendChild( profileFillSymbolElement );
59
60 parentElement.appendChild( element );
61 return element;
62}
63
64bool QgsMeshLayerElevationProperties::readXml( const QDomElement &element, const QgsReadWriteContext &context )
65{
66 const QDomElement elevationElement = element.firstChildElement( QStringLiteral( "elevation" ) ).toElement();
67 mSymbology = qgsEnumKeyToValue( elevationElement.attribute( QStringLiteral( "symbology" ) ), Qgis::ProfileSurfaceSymbology::Line );
68 if ( elevationElement.hasAttribute( QStringLiteral( "elevationLimit" ) ) )
69 mElevationLimit = elevationElement.attribute( QStringLiteral( "elevationLimit" ) ).toDouble();
70 else
71 mElevationLimit = std::numeric_limits< double >::quiet_NaN();
72
73 readCommonProperties( elevationElement, context );
74
75 const QColor defaultColor = QgsApplication::colorSchemeRegistry()->fetchRandomStyleColor();
76
77 const QDomElement profileLineSymbolElement = elevationElement.firstChildElement( QStringLiteral( "profileLineSymbol" ) ).firstChildElement( QStringLiteral( "symbol" ) );
78 mProfileLineSymbol.reset( QgsSymbolLayerUtils::loadSymbol< QgsLineSymbol >( profileLineSymbolElement, context ) );
79 if ( !mProfileLineSymbol )
80 setDefaultProfileLineSymbol( defaultColor );
81
82 const QDomElement profileFillSymbolElement = elevationElement.firstChildElement( QStringLiteral( "profileFillSymbol" ) ).firstChildElement( QStringLiteral( "symbol" ) );
83 mProfileFillSymbol.reset( QgsSymbolLayerUtils::loadSymbol< QgsFillSymbol >( profileFillSymbolElement, context ) );
84 if ( !mProfileFillSymbol )
85 setDefaultProfileFillSymbol( defaultColor );
86
87 return true;
88}
89
91{
92 QStringList properties;
93 properties << tr( "Scale: %1" ).arg( mZScale );
94 properties << tr( "Offset: %1" ).arg( mZOffset );
95 return QStringLiteral( "<li>%1</li>" ).arg( properties.join( QLatin1String( "</li><li>" ) ) );
96}
97
99{
100 std::unique_ptr< QgsMeshLayerElevationProperties > res = std::make_unique< QgsMeshLayerElevationProperties >( nullptr );
101 res->setProfileLineSymbol( mProfileLineSymbol->clone() );
102 res->setProfileFillSymbol( mProfileFillSymbol->clone() );
103 res->setProfileSymbology( mSymbology );
104 res->setElevationLimit( mElevationLimit );
105 res->copyCommonProperties( this );
106 return res.release();
107}
108
110{
111 // TODO -- test actual raster z range
112 return true;
113}
114
116{
117 // TODO -- determine actual z range from raster statistics
118 return QgsDoubleRange();
119}
120
125
127{
128 return mProfileLineSymbol.get();
129}
130
132{
133 mProfileLineSymbol.reset( symbol );
134 emit changed();
136}
137
139{
140 return mProfileFillSymbol.get();
141}
142
144{
145 mProfileFillSymbol.reset( symbol );
146 emit changed();
148}
149
151{
152 if ( mSymbology == symbology )
153 return;
154
155 mSymbology = symbology;
156 emit changed();
158}
159
161{
162 return mElevationLimit;
163}
164
166{
167 if ( qgsDoubleNear( mElevationLimit, limit ) )
168 return;
169
170 mElevationLimit = limit;
171 emit changed();
173}
174
175void QgsMeshLayerElevationProperties::setDefaultProfileLineSymbol( const QColor &color )
176{
177 std::unique_ptr< QgsSimpleLineSymbolLayer > profileLineLayer = std::make_unique< QgsSimpleLineSymbolLayer >( color, 0.6 );
178 mProfileLineSymbol = std::make_unique< QgsLineSymbol>( QgsSymbolLayerList( { profileLineLayer.release() } ) );
179}
180
181void QgsMeshLayerElevationProperties::setDefaultProfileFillSymbol( const QColor &color )
182{
183 std::unique_ptr< QgsSimpleFillSymbolLayer > profileFillLayer = std::make_unique< QgsSimpleFillSymbolLayer >( color );
184 profileFillLayer->setStrokeStyle( Qt::NoPen );
185 mProfileFillSymbol = std::make_unique< QgsFillSymbol>( QgsSymbolLayerList( { profileFillLayer.release() } ) );
186}
ProfileSurfaceSymbology
Surface symbology type for elevation profile plots.
Definition qgis.h:2823
@ Line
The elevation surface will be rendered using a line symbol.
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
QColor fetchRandomStyleColor() const
Returns a random color for use with a new symbol style (e.g.
QgsRange which stores a range of double values.
Definition qgsrange.h:203
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
A line symbol type, for rendering LineString and MultiLineString geometries.
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().
void changed()
Emitted when any of the elevation properties have changed.
void profileRenderingPropertyChanged()
Emitted when any of the elevation properties which relate solely to presentation of elevation results...
Base class for all map layer types.
Definition qgsmaplayer.h:74
Mesh layer specific subclass of QgsMapLayerElevationProperties.
QDomElement writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) override
Writes the properties to a DOM element, to be used later with readXml().
QgsLineSymbol * profileLineSymbol() const
Returns the line symbol used to render the mesh profile in elevation profile plots.
bool hasElevation() const override
Returns true if the layer has an elevation or z component.
QgsMeshLayerElevationProperties * clone() const override
Creates a clone of the properties.
bool isVisibleInZRange(const QgsDoubleRange &range) const override
Returns true if the layer should be visible and rendered for the specified z range.
void setElevationLimit(double limit)
Sets the elevation limit, which is used when profileSymbology() is Qgis::ProfileSurfaceSymbology::Fil...
QgsFillSymbol * profileFillSymbol() const
Returns the fill symbol used to render the mesh profile in elevation profile plots.
void setProfileSymbology(Qgis::ProfileSurfaceSymbology symbology)
Sets the symbology option used to render the mesh profile in elevation profile plots.
void setProfileFillSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to render the mesh profile in elevation profile plots.
void setProfileLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the mesh profile in elevation profile plots.
QgsMeshLayerElevationProperties(QObject *parent)
Constructor for QgsMeshLayerElevationProperties, with the specified parent object.
QString htmlSummary() const override
Returns a HTML formatted summary of the properties.
bool showByDefaultInElevationProfilePlots() const override
Returns true if the layer should be visible by default in newly created elevation profile plots.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the elevation properties from a DOM element previously written by writeXml().
double elevationLimit() const
Returns the elevation limit, which is used when profileSymbology() is Qgis::ProfileSurfaceSymbology::...
QgsDoubleRange calculateZRange(QgsMapLayer *layer) const override
Attempts to calculate the overall elevation or z range for the specified layer, using the settings de...
The class is used as a container of context for various read/write operations on other objects.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition qgis.h:4555
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:4271
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:4536
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:4332
QList< QgsSymbolLayer * > QgsSymbolLayerList
Definition qgssymbol.h:30