QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
qgs3dmapsettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgs3dmapsettings.cpp
3  --------------------------------------
4  Date : July 2017
5  Copyright : (C) 2017 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgs3dmapsettings.h"
17 
18 #include "qgs3dutils.h"
20 #include "qgsdemterraingenerator.h"
21 #include "qgsmeshterraingenerator.h"
24 #include "qgsmeshlayer3drenderer.h"
25 
26 #include <QDomDocument>
27 #include <QDomElement>
28 
29 #include "qgssymbollayerutils.h"
30 #include "qgsrasterlayer.h"
31 
33  : QObject( nullptr )
34  , mOrigin( other.mOrigin )
35  , mCrs( other.mCrs )
36  , mBackgroundColor( other.mBackgroundColor )
37  , mTerrainVerticalScale( other.mTerrainVerticalScale )
38  , mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
39  , mMapTileResolution( other.mMapTileResolution )
40  , mMaxTerrainScreenError( other.mMaxTerrainScreenError )
41  , mMaxTerrainGroundError( other.mMaxTerrainGroundError )
42  , mTerrainShadingEnabled( other.mTerrainShadingEnabled )
43  , mTerrainShadingMaterial( other.mTerrainShadingMaterial )
44  , mTerrainMapTheme( other.mTerrainMapTheme )
45  , mShowTerrainBoundingBoxes( other.mShowTerrainBoundingBoxes )
46  , mShowTerrainTileInfo( other.mShowTerrainTileInfo )
47  , mShowCameraViewCenter( other.mShowCameraViewCenter )
48  , mShowLabels( other.mShowLabels )
49  , mPointLights( other.mPointLights )
50  , mFieldOfView( other.mFieldOfView )
51  , mLayers( other.mLayers )
52  , mSkyboxEnabled( other.mSkyboxEnabled )
53  , mSkyboxFileBase( other.mSkyboxFileBase )
54  , mSkyboxFileExtension( other.mSkyboxFileExtension )
55  , mTransformContext( other.mTransformContext )
56  , mPathResolver( other.mPathResolver )
57  , mMapThemes( other.mMapThemes )
58 {
59  Q_FOREACH ( QgsAbstract3DRenderer *renderer, other.mRenderers )
60  {
61  mRenderers << renderer->clone();
62  }
63 }
64 
66 {
67  qDeleteAll( mRenderers );
68 }
69 
70 void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
71 {
72  QDomElement elemOrigin = elem.firstChildElement( QStringLiteral( "origin" ) );
73  mOrigin = QgsVector3D(
74  elemOrigin.attribute( QStringLiteral( "x" ) ).toDouble(),
75  elemOrigin.attribute( QStringLiteral( "y" ) ).toDouble(),
76  elemOrigin.attribute( QStringLiteral( "z" ) ).toDouble() );
77 
78  QDomElement elemCamera = elem.firstChildElement( QStringLiteral( "camera" ) );
79  if ( !elemCamera.isNull() )
80  {
81  mFieldOfView = elemCamera.attribute( QStringLiteral( "field-of-view" ), QStringLiteral( "45" ) ).toFloat();
82  }
83 
84  QDomElement elemColor = elem.firstChildElement( QStringLiteral( "color" ) );
85  if ( !elemColor.isNull() )
86  {
87  mBackgroundColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( QStringLiteral( "background" ) ) );
88  mSelectionColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( QStringLiteral( "selection" ) ) );
89  }
90 
91  QDomElement elemCrs = elem.firstChildElement( QStringLiteral( "crs" ) );
92  mCrs.readXml( elemCrs );
93 
94  QDomElement elemTerrain = elem.firstChildElement( QStringLiteral( "terrain" ) );
95  mTerrainVerticalScale = elemTerrain.attribute( QStringLiteral( "exaggeration" ), QStringLiteral( "1" ) ).toFloat();
96  mMapTileResolution = elemTerrain.attribute( QStringLiteral( "texture-size" ), QStringLiteral( "512" ) ).toInt();
97  mMaxTerrainScreenError = elemTerrain.attribute( QStringLiteral( "max-terrain-error" ), QStringLiteral( "3" ) ).toFloat();
98  mMaxTerrainGroundError = elemTerrain.attribute( QStringLiteral( "max-ground-error" ), QStringLiteral( "1" ) ).toFloat();
99  mTerrainShadingEnabled = elemTerrain.attribute( QStringLiteral( "shading-enabled" ), QStringLiteral( "0" ) ).toInt();
100  QDomElement elemTerrainShadingMaterial = elemTerrain.firstChildElement( QStringLiteral( "shading-material" ) );
101  if ( !elemTerrainShadingMaterial.isNull() )
102  mTerrainShadingMaterial.readXml( elemTerrainShadingMaterial );
103  mTerrainMapTheme = elemTerrain.attribute( QStringLiteral( "map-theme" ) );
104  mShowLabels = elemTerrain.attribute( QStringLiteral( "show-labels" ), QStringLiteral( "0" ) ).toInt();
105 
106  mPointLights.clear();
107  QDomElement elemPointLights = elem.firstChildElement( QStringLiteral( "point-lights" ) );
108  if ( !elemPointLights.isNull() )
109  {
110  QDomElement elemPointLight = elemPointLights.firstChildElement( QStringLiteral( "point-light" ) );
111  while ( !elemPointLight.isNull() )
112  {
113  QgsPointLightSettings pointLight;
114  pointLight.readXml( elemPointLight );
115  mPointLights << pointLight;
116  elemPointLight = elemPointLight.nextSiblingElement( QStringLiteral( "point-light" ) );
117  }
118  }
119  else
120  {
121  // QGIS <= 3.4 did not have light configuration
122  QgsPointLightSettings defaultLight;
123  defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
124  mPointLights << defaultLight;
125  }
126 
127  QDomElement elemMapLayers = elemTerrain.firstChildElement( QStringLiteral( "layers" ) );
128  QDomElement elemMapLayer = elemMapLayers.firstChildElement( QStringLiteral( "layer" ) );
129  QList<QgsMapLayerRef> mapLayers;
130  while ( !elemMapLayer.isNull() )
131  {
132  mapLayers << QgsMapLayerRef( elemMapLayer.attribute( QStringLiteral( "id" ) ) );
133  elemMapLayer = elemMapLayer.nextSiblingElement( QStringLiteral( "layer" ) );
134  }
135  mLayers = mapLayers; // needs to resolve refs afterwards
136 
137  QDomElement elemTerrainGenerator = elemTerrain.firstChildElement( QStringLiteral( "generator" ) );
138  QString terrainGenType = elemTerrainGenerator.attribute( QStringLiteral( "type" ) );
139  if ( terrainGenType == QLatin1String( "dem" ) )
140  {
141  QgsDemTerrainGenerator *demTerrainGenerator = new QgsDemTerrainGenerator;
142  demTerrainGenerator->setCrs( mCrs, mTransformContext );
143  mTerrainGenerator.reset( demTerrainGenerator );
144  }
145  else if ( terrainGenType == QLatin1String( "online" ) )
146  {
147  QgsOnlineTerrainGenerator *onlineTerrainGenerator = new QgsOnlineTerrainGenerator;
148  onlineTerrainGenerator->setCrs( mCrs, mTransformContext );
149  mTerrainGenerator.reset( onlineTerrainGenerator );
150  }
151  else if ( terrainGenType == QLatin1String( "mesh" ) )
152  {
153  QgsMeshTerrainGenerator *meshTerrainGenerator = new QgsMeshTerrainGenerator;
154  meshTerrainGenerator->setCrs( mCrs, mTransformContext );
155  mTerrainGenerator.reset( meshTerrainGenerator );
156  }
157  else // "flat"
158  {
160  flatGen->setCrs( mCrs );
161  mTerrainGenerator.reset( flatGen );
162  }
163  mTerrainGenerator->readXml( elemTerrainGenerator );
164 
165  qDeleteAll( mRenderers );
166  mRenderers.clear();
167 
168  QDomElement elemRenderers = elem.firstChildElement( QStringLiteral( "renderers" ) );
169  QDomElement elemRenderer = elemRenderers.firstChildElement( QStringLiteral( "renderer" ) );
170  while ( !elemRenderer.isNull() )
171  {
172  QgsAbstract3DRenderer *renderer = nullptr;
173  QString type = elemRenderer.attribute( QStringLiteral( "type" ) );
174  if ( type == QLatin1String( "vector" ) )
175  {
176  renderer = new QgsVectorLayer3DRenderer;
177  }
178  else if ( type == QLatin1String( "mesh" ) )
179  {
180  renderer = new QgsMeshLayer3DRenderer;
181  }
182 
183  if ( renderer )
184  {
185  renderer->readXml( elemRenderer, context );
186  mRenderers.append( renderer );
187  }
188  elemRenderer = elemRenderer.nextSiblingElement( QStringLiteral( "renderer" ) );
189  }
190 
191  QDomElement elemSkybox = elem.firstChildElement( QStringLiteral( "skybox" ) );
192  mSkyboxEnabled = elemSkybox.attribute( QStringLiteral( "enabled" ), QStringLiteral( "0" ) ).toInt();
193  mSkyboxFileBase = elemSkybox.attribute( QStringLiteral( "file-base" ) );
194  mSkyboxFileExtension = elemSkybox.attribute( QStringLiteral( "file-ext" ) );
195 
196  QDomElement elemDebug = elem.firstChildElement( QStringLiteral( "debug" ) );
197  mShowTerrainBoundingBoxes = elemDebug.attribute( QStringLiteral( "bounding-boxes" ), QStringLiteral( "0" ) ).toInt();
198  mShowTerrainTileInfo = elemDebug.attribute( QStringLiteral( "terrain-tile-info" ), QStringLiteral( "0" ) ).toInt();
199  mShowCameraViewCenter = elemDebug.attribute( QStringLiteral( "camera-view-center" ), QStringLiteral( "0" ) ).toInt();
200 }
201 
202 QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
203 {
204  QDomElement elem = doc.createElement( QStringLiteral( "qgis3d" ) );
205 
206  QDomElement elemOrigin = doc.createElement( QStringLiteral( "origin" ) );
207  elemOrigin.setAttribute( QStringLiteral( "x" ), QString::number( mOrigin.x() ) );
208  elemOrigin.setAttribute( QStringLiteral( "y" ), QString::number( mOrigin.y() ) );
209  elemOrigin.setAttribute( QStringLiteral( "z" ), QString::number( mOrigin.z() ) );
210  elem.appendChild( elemOrigin );
211 
212  QDomElement elemCamera = doc.createElement( QStringLiteral( "camera" ) );
213  elemCamera.setAttribute( QStringLiteral( "field-of-view" ), mFieldOfView );
214  elem.appendChild( elemCamera );
215 
216  QDomElement elemColor = doc.createElement( QStringLiteral( "color" ) );
217  elemColor.setAttribute( QStringLiteral( "background" ), QgsSymbolLayerUtils::encodeColor( mBackgroundColor ) );
218  elemColor.setAttribute( QStringLiteral( "selection" ), QgsSymbolLayerUtils::encodeColor( mSelectionColor ) );
219  elem.appendChild( elemColor );
220 
221  QDomElement elemCrs = doc.createElement( QStringLiteral( "crs" ) );
222  mCrs.writeXml( elemCrs, doc );
223  elem.appendChild( elemCrs );
224 
225  QDomElement elemTerrain = doc.createElement( QStringLiteral( "terrain" ) );
226  elemTerrain.setAttribute( QStringLiteral( "exaggeration" ), QString::number( mTerrainVerticalScale ) );
227  elemTerrain.setAttribute( QStringLiteral( "texture-size" ), mMapTileResolution );
228  elemTerrain.setAttribute( QStringLiteral( "max-terrain-error" ), QString::number( mMaxTerrainScreenError ) );
229  elemTerrain.setAttribute( QStringLiteral( "max-ground-error" ), QString::number( mMaxTerrainGroundError ) );
230  elemTerrain.setAttribute( QStringLiteral( "shading-enabled" ), mTerrainShadingEnabled ? 1 : 0 );
231  QDomElement elemTerrainShadingMaterial = doc.createElement( QStringLiteral( "shading-material" ) );
232  mTerrainShadingMaterial.writeXml( elemTerrainShadingMaterial );
233  elemTerrain.appendChild( elemTerrainShadingMaterial );
234  elemTerrain.setAttribute( QStringLiteral( "map-theme" ), mTerrainMapTheme );
235  elemTerrain.setAttribute( QStringLiteral( "show-labels" ), mShowLabels ? 1 : 0 );
236 
237  QDomElement elemPointLights = doc.createElement( QStringLiteral( "point-lights" ) );
238  for ( const QgsPointLightSettings &pointLight : qgis::as_const( mPointLights ) )
239  {
240  QDomElement elemPointLight = pointLight.writeXml( doc );
241  elemPointLights.appendChild( elemPointLight );
242  }
243  elem.appendChild( elemPointLights );
244 
245  QDomElement elemMapLayers = doc.createElement( QStringLiteral( "layers" ) );
246  Q_FOREACH ( const QgsMapLayerRef &layerRef, mLayers )
247  {
248  QDomElement elemMapLayer = doc.createElement( QStringLiteral( "layer" ) );
249  elemMapLayer.setAttribute( QStringLiteral( "id" ), layerRef.layerId );
250  elemMapLayers.appendChild( elemMapLayer );
251  }
252  elemTerrain.appendChild( elemMapLayers );
253  QDomElement elemTerrainGenerator = doc.createElement( QStringLiteral( "generator" ) );
254  elemTerrainGenerator.setAttribute( QStringLiteral( "type" ), QgsTerrainGenerator::typeToString( mTerrainGenerator->type() ) );
255  mTerrainGenerator->writeXml( elemTerrainGenerator );
256  elemTerrain.appendChild( elemTerrainGenerator );
257  elem.appendChild( elemTerrain );
258 
259  QDomElement elemRenderers = doc.createElement( QStringLiteral( "renderers" ) );
260  Q_FOREACH ( const QgsAbstract3DRenderer *renderer, mRenderers )
261  {
262  QDomElement elemRenderer = doc.createElement( QStringLiteral( "renderer" ) );
263  elemRenderer.setAttribute( QStringLiteral( "type" ), renderer->type() );
264  renderer->writeXml( elemRenderer, context );
265  elemRenderers.appendChild( elemRenderer );
266  }
267  elem.appendChild( elemRenderers );
268 
269  QDomElement elemSkybox = doc.createElement( QStringLiteral( "skybox" ) );
270  elemSkybox.setAttribute( QStringLiteral( "enabled" ), mSkyboxEnabled ? 1 : 0 );
271  // TODO: use context for relative paths, maybe explicitly list all files(?)
272  elemSkybox.setAttribute( QStringLiteral( "file-base" ), mSkyboxFileBase );
273  elemSkybox.setAttribute( QStringLiteral( "file-ext" ), mSkyboxFileExtension );
274  elem.appendChild( elemSkybox );
275 
276  QDomElement elemDebug = doc.createElement( QStringLiteral( "debug" ) );
277  elemDebug.setAttribute( QStringLiteral( "bounding-boxes" ), mShowTerrainBoundingBoxes ? 1 : 0 );
278  elemDebug.setAttribute( QStringLiteral( "terrain-tile-info" ), mShowTerrainTileInfo ? 1 : 0 );
279  elemDebug.setAttribute( QStringLiteral( "camera-view-center" ), mShowCameraViewCenter ? 1 : 0 );
280  elem.appendChild( elemDebug );
281 
282  return elem;
283 }
284 
286 {
287  for ( int i = 0; i < mLayers.count(); ++i )
288  {
289  QgsMapLayerRef &layerRef = mLayers[i];
290  layerRef.setLayer( project.mapLayer( layerRef.layerId ) );
291  }
292 
293  mTerrainGenerator->resolveReferences( project );
294 
295  for ( int i = 0; i < mRenderers.count(); ++i )
296  {
297  QgsAbstract3DRenderer *renderer = mRenderers[i];
298  renderer->resolveReferences( project );
299  }
300 }
301 
303 {
304  return Qgs3DUtils::mapToWorldCoordinates( mapCoords, mOrigin );
305 }
306 
308 {
309  return Qgs3DUtils::worldToMapCoordinates( worldCoords, mOrigin );
310 }
311 
313 {
314  mCrs = crs;
315 }
316 
318 {
319  return mTransformContext;
320 }
321 
323 {
324  mTransformContext = context;
325 }
326 
327 void Qgs3DMapSettings::setBackgroundColor( const QColor &color )
328 {
329  if ( color == mBackgroundColor )
330  return;
331 
332  mBackgroundColor = color;
333  emit backgroundColorChanged();
334 }
335 
337 {
338  return mBackgroundColor;
339 }
340 
341 void Qgs3DMapSettings::setSelectionColor( const QColor &color )
342 {
343  if ( color == mSelectionColor )
344  return;
345 
346  mSelectionColor = color;
347  emit selectionColorChanged();
348 }
349 
351 {
352  return mSelectionColor;
353 }
354 
356 {
357  if ( zScale == mTerrainVerticalScale )
358  return;
359 
360  mTerrainVerticalScale = zScale;
362 }
363 
365 {
366  return mTerrainVerticalScale;
367 }
368 
369 void Qgs3DMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
370 {
371  QList<QgsMapLayerRef> lst;
372  lst.reserve( layers.count() );
373  Q_FOREACH ( QgsMapLayer *layer, layers )
374  {
375  lst.append( layer );
376  }
377 
378  if ( mLayers == lst )
379  return;
380 
381  mLayers = lst;
382  emit layersChanged();
383 }
384 
385 QList<QgsMapLayer *> Qgs3DMapSettings::layers() const
386 {
387  QList<QgsMapLayer *> lst;
388  lst.reserve( mLayers.count() );
389  Q_FOREACH ( const QgsMapLayerRef &layerRef, mLayers )
390  {
391  if ( layerRef.layer )
392  lst.append( layerRef.layer );
393  }
394  return lst;
395 }
396 
398 {
399  if ( mMapTileResolution == res )
400  return;
401 
402  mMapTileResolution = res;
404 }
405 
407 {
408  return mMapTileResolution;
409 }
410 
412 {
413  if ( mMaxTerrainScreenError == error )
414  return;
415 
416  mMaxTerrainScreenError = error;
418 }
419 
421 {
422  return mMaxTerrainScreenError;
423 }
424 
426 {
427  if ( mMaxTerrainGroundError == error )
428  return;
429 
430  mMaxTerrainGroundError = error;
432 }
433 
435 {
436  return mMaxTerrainGroundError;
437 }
438 
440 {
441  mTerrainGenerator.reset( gen );
443 }
444 
446 {
447  if ( mTerrainShadingEnabled == enabled )
448  return;
449 
450  mTerrainShadingEnabled = enabled;
451  emit terrainShadingChanged();
452 }
453 
455 {
456  if ( mTerrainShadingMaterial == material )
457  return;
458 
459  mTerrainShadingMaterial = material;
460  emit terrainShadingChanged();
461 }
462 
463 void Qgs3DMapSettings::setTerrainMapTheme( const QString &theme )
464 {
465  if ( mTerrainMapTheme == theme )
466  return;
467 
468  mTerrainMapTheme = theme;
469  emit terrainMapThemeChanged();
470 }
471 
472 void Qgs3DMapSettings::setRenderers( const QList<QgsAbstract3DRenderer *> &renderers )
473 {
474  qDeleteAll( mRenderers );
475 
476  mRenderers = renderers;
477 
478  emit renderersChanged();
479 }
480 
482 {
483  if ( mShowTerrainBoundingBoxes == enabled )
484  return;
485 
486  mShowTerrainBoundingBoxes = enabled;
488 }
489 
491 {
492  if ( mShowTerrainTileInfo == enabled )
493  return;
494 
495  mShowTerrainTileInfo = enabled;
497 }
498 
500 {
501  if ( mShowCameraViewCenter == enabled )
502  return;
503 
504  mShowCameraViewCenter = enabled;
506 }
507 
509 {
510  if ( mShowLabels == enabled )
511  return;
512 
513  mShowLabels = enabled;
514  emit showLabelsChanged();
515 }
516 
517 void Qgs3DMapSettings::setPointLights( const QList<QgsPointLightSettings> &pointLights )
518 {
519  if ( mPointLights == pointLights )
520  return;
521 
522  mPointLights = pointLights;
523  emit pointLightsChanged();
524 }
525 
527 {
528  if ( mFieldOfView == fieldOfView )
529  return;
530 
531  mFieldOfView = fieldOfView;
532  emit fieldOfViewChanged();
533 }
534 
float maxTerrainScreenError() const
Returns maximum allowed screen error of terrain tiles in pixels.
void setFieldOfView(const float fieldOfView)
Sets the camera lens&#39; field of view.
QList< QgsMapLayer * > layers() const
Returns the list of map layers to be rendered as a texture of the terrain.
The class is used as a container of context for various read/write operations on other objects...
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
3 Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double preci...
Definition: qgsvector3d.h:31
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets coordinate reference system used in the 3D scene.
3 Terrain generator that creates a simple square flat area.
void renderersChanged()
Emitted when the list of map&#39;s extra renderers have been modified.
Base class for all map layer types.
Definition: qgsmaplayer.h:79
void maxTerrainGroundErrorChanged()
Emitted when the maximum terrain ground error has changed.
void setTerrainShadingMaterial(const QgsPhongMaterialSettings &material)
Sets terrain shading material.
void setShowCameraViewCenter(bool enabled)
Sets whether to show camera&#39;s view center as a sphere (for debugging)
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml()
void setTerrainGenerator(QgsTerrainGenerator *gen)
Sets terrain generator.
QColor selectionColor() const
Returns color used for selected features.
_LayerRef< QgsMapLayer > QgsMapLayerRef
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
Base class for all renderers that may to participate in 3D view.
void layersChanged()
Emitted when the list of map layers for terrain texture has changed.
void setShowTerrainTilesInfo(bool enabled)
Sets whether to display extra tile info on top of terrain tiles (for debugging)
void setPointLights(const QList< QgsPointLightSettings > &pointLights)
Sets list of point lights defined in the scene.
3D renderer that renders all mesh triangles of a mesh layer.
3 Implementation of terrain generator that uses online resources to download heightmaps.
void setTerrainShadingEnabled(bool enabled)
Sets whether terrain shading is enabled.
QList< QgsPointLightSettings > pointLights() const
Returns list of point lights defined in the scene.
QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords) const
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x...
void terrainVerticalScaleChanged()
Emitted when the vertical scale of the terrain has changed.
3 Basic shading material used for rendering based on the Phong shading model with three color compone...
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
3 Definition of the world
static QString encodeColor(const QColor &color)
3 Definition of a point light in a 3D map scene
void pointLightsChanged()
Emitted when the list of point lights changes.
float maxTerrainGroundError() const
Returns maximum ground error of terrain tiles in world units.
virtual void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const =0
Writes renderer&#39;s properties to given XML element.
double z() const
Returns Z coordinate.
Definition: qgsvector3d.h:53
static QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords, const QgsVector3D &origin)
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x...
Definition: qgs3dutils.cpp:438
QString layerId
Original layer ID.
void setRenderers(const QList< QgsAbstract3DRenderer *> &renderers)
Sets list of extra 3D renderers to use in the scene. Takes ownership of the objects.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
virtual QString type() const =0
Returns unique identifier of the renderer class (used to identify subclass)
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets CRS of the terrain.
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets CRS of the terrain.
QPointer< TYPE > layer
Weak pointer to map layer.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
void terrainMapThemeChanged()
Emitted when terrain&#39;s map theme has changed.
void fieldOfViewChanged()
Emitted when the camera lens field of view changes.
void readXml(const QDomElement &elem)
Reads settings from a DOM element.
void showCameraViewCenterChanged()
Emitted when the flag whether camera&#39;s view center is shown has changed.
int mapTileResolution() const
Returns resolution (in pixels) of the texture of a terrain tile.
void selectionColorChanged()
Emitted when the selection color has changed.
static QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords, const QgsVector3D &origin)
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x...
Definition: qgs3dutils.cpp:430
void terrainGeneratorChanged()
Emitted when the terrain generator has changed.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:91
QColor backgroundColor() const
Returns background color of the 3D map view.
void showTerrainBoundingBoxesChanged()
Emitted when the flag whether terrain&#39;s bounding boxes are shown has changed.
Contains information about the context in which a coordinate transform is executed.
static QString typeToString(Type type)
Converts terrain generator type enumeration into a string.
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
void setMaxTerrainGroundError(float error)
Returns maximum ground error of terrain tiles in world units.
void mapTileResolutionChanged()
Emitted when the map tile resoulution has changed.
void setTerrainVerticalScale(double zScale)
Sets vertical scale (exaggeration) of terrain (1 = true scale, > 1 = hills get more pronounced) ...
QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords) const
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x...
3D renderer that renders all features of a vector layer with the same 3D symbol.
void showTerrainTilesInfoChanged()
Emitted when the flag whether terrain&#39;s tile info is shown has changed.
double terrainVerticalScale() const
Returns vertical scale (exaggeration) of terrain.
void writeXml(QDomElement &elem) const
Writes settings to a DOM element.
void setMapTileResolution(int res)
Sets resolution (in pixels) of the texture of a terrain tile.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads renderer&#39;s properties from given XML element.
Qgs3DMapSettings()=default
Constructor for Qgs3DMapSettings.
void setPosition(const QgsVector3D &pos)
Sets position of the light (in 3D world coordinates)
void showLabelsChanged()
Emitted when the flag whether labels are displayed on terrain tiles has changed.
void maxTerrainScreenErrorChanged()
Emitted when the maximum terrain screen error has changed.
3 Base class for generators of terrain.
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
void setBackgroundColor(const QColor &color)
Sets background color of the 3D map view.
3 Implementation of terrain generator that uses a raster layer with DEM to build terrain.
This class represents a coordinate reference system (CRS).
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets CRS of the terrain.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
~Qgs3DMapSettings() override
void setShowLabels(bool enabled)
Sets whether to display labels on terrain tiles.
float fieldOfView() const
Returns the camera lens&#39; field of view.
virtual QgsAbstract3DRenderer * clone() const =0
Returns a cloned instance.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from a DOM element previously written by writeXml()
void backgroundColorChanged()
Emitted when the background color has changed.
void setLayers(const QList< QgsMapLayer *> &layers)
Sets the list of map layers to be rendered as a texture of the terrain.
void setMaxTerrainScreenError(float error)
Sets maximum allowed screen error of terrain tiles in pixels.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
void resolveReferences(const QgsProject &project)
Resolves references to other objects (map layers) after the call to readXml()
void setShowTerrainBoundingBoxes(bool enabled)
Sets whether to display bounding boxes of terrain tiles (for debugging)
void setSelectionColor(const QColor &color)
Sets color used for selected features.
void setTerrainMapTheme(const QString &theme)
Sets name of the map theme.
void terrainShadingChanged()
Emitted when terrain shading enabled flag or terrain shading material has changed.
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49
static QColor decodeColor(const QString &str)
void readXml(const QDomElement &elem)
Reads configuration from a DOM element previously written using writeXml()