QGIS API Documentation  3.2.0-Bonn (bc43194)
qgs3dmapsettings.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgs3dmapsettings.h
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 #ifndef QGS3DMAPSETTINGS_H
17 #define QGS3DMAPSETTINGS_H
18 
19 #include "qgis_3d.h"
20 
21 #include <memory>
22 #include <QColor>
23 #include <QMatrix4x4>
24 
26 #include "qgsmaplayerref.h"
27 #include "qgsterraingenerator.h"
28 #include "qgsvector3d.h"
29 
30 class QgsMapLayer;
31 class QgsRasterLayer;
32 
34 
35 
37 class QgsProject;
38 
39 class QDomElement;
40 
41 
48 class _3D_EXPORT Qgs3DMapSettings : public QObject
49 {
50  Q_OBJECT
51  public:
52 
54  Qgs3DMapSettings() = default;
56  Qgs3DMapSettings( const Qgs3DMapSettings &other );
57  ~Qgs3DMapSettings() override;
58 
60  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
62  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
64  void resolveReferences( const QgsProject &project );
65 
77  void setOrigin( const QgsVector3D &origin ) { mOrigin = origin; }
79  QgsVector3D origin() const { return mOrigin; }
80 
82  QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords ) const;
84  QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords ) const;
85 
87  void setCrs( const QgsCoordinateReferenceSystem &crs );
89  QgsCoordinateReferenceSystem crs() const { return mCrs; }
90 
98  QgsCoordinateTransformContext transformContext() const;
99 
107  void setTransformContext( const QgsCoordinateTransformContext &context );
108 
116  const QgsPathResolver &pathResolver() const { return mPathResolver; }
117 
125  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
126 
128  void setBackgroundColor( const QColor &color );
130  QColor backgroundColor() const;
131 
133  void setSelectionColor( const QColor &color );
135  QColor selectionColor() const;
136 
137  //
138  // terrain related config
139  //
140 
145  void setTerrainVerticalScale( double zScale );
147  double terrainVerticalScale() const;
148 
150  void setLayers( const QList<QgsMapLayer *> &layers );
152  QList<QgsMapLayer *> layers() const;
153 
158  void setMapTileResolution( int res );
159 
164  int mapTileResolution() const;
165 
170  void setMaxTerrainScreenError( float error );
171 
179  float maxTerrainScreenError() const;
180 
185  void setMaxTerrainGroundError( float error );
186 
193  float maxTerrainGroundError() const;
194 
199  void setTerrainGenerator( QgsTerrainGenerator *gen SIP_TRANSFER );
201  QgsTerrainGenerator *terrainGenerator() const { return mTerrainGenerator.get(); }
202 
204  void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
206  QList<QgsAbstract3DRenderer *> renderers() const { return mRenderers; }
207 
214  void setSkybox( bool enabled, const QString &fileBase = QString(), const QString &fileExtension = QString() );
216  bool hasSkyboxEnabled() const { return mSkyboxEnabled; }
218  QString skyboxFileBase() const { return mSkyboxFileBase; }
220  QString skyboxFileExtension() const { return mSkyboxFileExtension; }
221 
223  void setShowTerrainBoundingBoxes( bool enabled );
225  bool showTerrainBoundingBoxes() const { return mShowTerrainBoundingBoxes; }
227  void setShowTerrainTilesInfo( bool enabled );
229  bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
231  void setShowLabels( bool enabled );
233  bool showLabels() const { return mShowLabels; }
234 
235  signals:
237  void backgroundColorChanged();
239  void selectionColorChanged();
241  void layersChanged();
243  void terrainGeneratorChanged();
245  void terrainVerticalScaleChanged();
247  void mapTileResolutionChanged();
249  void maxTerrainScreenErrorChanged();
251  void maxTerrainGroundErrorChanged();
253  void showTerrainBoundingBoxesChanged();
255  void showTerrainTilesInfoChanged();
257  void showLabelsChanged();
258 
259  private:
261  QgsVector3D mOrigin;
263  QColor mBackgroundColor = Qt::black;
264  QColor mSelectionColor;
265  double mTerrainVerticalScale = 1;
266  std::unique_ptr<QgsTerrainGenerator> mTerrainGenerator;
267  int mMapTileResolution = 512;
268  float mMaxTerrainScreenError = 3.f;
269  float mMaxTerrainGroundError = 1.f;
270  bool mShowTerrainBoundingBoxes = false;
271  bool mShowTerrainTileInfo = false;
272  bool mShowLabels = false;
273  QList<QgsMapLayerRef> mLayers;
274  QList<QgsAbstract3DRenderer *> mRenderers;
275  bool mSkyboxEnabled = false;
276  QString mSkyboxFileBase;
277  QString mSkyboxFileExtension;
278  QgsCoordinateTransformContext mTransformContext;
280  QgsPathResolver mPathResolver;
281 };
282 
283 
284 #endif // QGS3DMAPSETTINGS_H
The class is used as a container of context for various read/write operations on other objects...
3 Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double preci...
Definition: qgsvector3d.h:29
Base class for all map layer types.
Definition: qgsmaplayer.h:61
bool showTerrainBoundingBoxes() const
Returns whether to display bounding boxes of terrain tiles (for debugging)
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
Base class for all renderers that may to participate in 3D view.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QString skyboxFileBase() const
Returns base part of filenames of skybox (see setSkybox())
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
3 Definition of the world
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
bool hasSkyboxEnabled() const
Returns whether skybox is enabled.
bool showTerrainTilesInfo() const
Returns whether to display extra tile info on top of terrain tiles (for debugging) ...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Reads and writes project states.
Definition: qgsproject.h:85
Contains information about the context in which a coordinate transform is executed.
void setOrigin(const QgsVector3D &origin)
Sets coordinates in map CRS at which our 3D world has origin (0,0,0)
bool showLabels() const
Returns whether to display labels on terrain tiles.
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
3 Base class for generators of terrain.
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
This class represents a coordinate reference system (CRS).
QString skyboxFileExtension() const
Returns extension part of filenames of skybox (see setSkybox())
Resolves relative paths into absolute paths and vice versa.
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data...