Skip to content

Commit 32ad0a7

Browse files
committed
Start of 3D map configuration widget
1 parent c8b5e63 commit 32ad0a7

16 files changed

+193
-5
lines changed

src/3d/map3d.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,28 @@ Map3D::Map3D()
8686
{
8787
}
8888

89+
Map3D::Map3D( const Map3D &other )
90+
: originX( other.originX )
91+
, originY( other.originY )
92+
, originZ( other.originZ )
93+
, crs( other.crs )
94+
, backgroundColor( other.backgroundColor )
95+
, zExaggeration( other.zExaggeration )
96+
, tileTextureSize( other.tileTextureSize )
97+
, maxTerrainError( other.maxTerrainError )
98+
, terrainGenerator( other.terrainGenerator ? other.terrainGenerator->clone() : nullptr )
99+
, polygonRenderers( other.polygonRenderers )
100+
, pointRenderers( other.pointRenderers )
101+
, lineRenderers( other.lineRenderers )
102+
, skybox( other.skybox )
103+
, skyboxFileBase( other.skyboxFileBase )
104+
, skyboxFileExtension( other.skyboxFileExtension )
105+
, showBoundingBoxes( other.showBoundingBoxes )
106+
, drawTerrainTileInfo( other.drawTerrainTileInfo )
107+
, mLayers( other.mLayers )
108+
{
109+
}
110+
89111
Map3D::~Map3D()
90112
{
91113
}

src/3d/map3d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class _3D_EXPORT Map3D
151151
{
152152
public:
153153
Map3D();
154+
Map3D( const Map3D &other );
154155
~Map3D();
155156

156157
void readXml( const QDomElement &elem, const QgsReadWriteContext &context );

src/3d/scene.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ Scene::Scene( const Map3D &map, Qt3DExtras::QForwardRenderer *defaultFrameGraph,
2828
{
2929
defaultFrameGraph->setClearColor( map.backgroundColor );
3030

31+
// TODO: strange - setting OnDemand render policy still keeps QGIS busy (Qt 5.9.0)
32+
// actually it is more busy than with the default "Always" policy although there are no changes in the scene.
33+
//renderSettings->setRenderPolicy( Qt3DRender::QRenderSettings::OnDemand );
34+
3135
#if QT_VERSION >= 0x050900
3236
// we want precise picking of terrain (also bounding volume picking does not seem to work - not sure why)
3337
renderSettings->pickingSettings()->setPickMethod( Qt3DRender::QPickingSettings::TrianglePicking );

src/3d/terrain/demterraingenerator.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ QgsRasterLayer *DemTerrainGenerator::layer() const
129129
return qobject_cast<QgsRasterLayer *>( mLayer.layer.data() );
130130
}
131131

132+
TerrainGenerator *DemTerrainGenerator::clone() const
133+
{
134+
DemTerrainGenerator *cloned = new DemTerrainGenerator;
135+
cloned->mLayer = mLayer;
136+
cloned->mResolution = mResolution;
137+
cloned->updateGenerator();
138+
return cloned;
139+
}
140+
132141
TerrainGenerator::Type DemTerrainGenerator::type() const
133142
{
134143
return TerrainGenerator::Dem;

src/3d/terrain/demterraingenerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class _3D_EXPORT DemTerrainGenerator : public TerrainGenerator
3030

3131
DemHeightMapGenerator *heightMapGenerator() { return mHeightMapGenerator.get(); }
3232

33+
virtual TerrainGenerator *clone() const override;
3334
Type type() const override;
3435
QgsRectangle extent() const override;
3536
float heightAt( double x, double y, const Map3D &map ) const override;

src/3d/terrain/flatterraingenerator.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ ChunkLoader *FlatTerrainGenerator::createChunkLoader( ChunkNode *node ) const
8686
return new FlatTerrainChunkLoader( mTerrain, tileGeometry, node );
8787
}
8888

89+
TerrainGenerator *FlatTerrainGenerator::clone() const
90+
{
91+
FlatTerrainGenerator *cloned = new FlatTerrainGenerator;
92+
cloned->mCrs = mCrs;
93+
cloned->mExtent = mExtent;
94+
cloned->updateTilingScheme();
95+
return cloned;
96+
}
97+
8998
TerrainGenerator::Type FlatTerrainGenerator::type() const
9099
{
91100
return TerrainGenerator::Flat;

src/3d/terrain/flatterraingenerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class _3D_EXPORT FlatTerrainGenerator : public TerrainGenerator
2121

2222
virtual ChunkLoader *createChunkLoader( ChunkNode *node ) const override;
2323

24+
virtual TerrainGenerator *clone() const override;
2425
Type type() const override;
2526
QgsRectangle extent() const override;
2627
virtual void rootChunkHeightRange( float &hMin, float &hMax ) const override;

src/3d/terrain/terraingenerator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class TerrainGenerator : public ChunkLoaderFactory
3535

3636
void setTerrain( Terrain *t ) { mTerrain = t; }
3737

38+
//! Makes a copy of the current instance
39+
virtual TerrainGenerator *clone() const = 0;
40+
3841
//! What texture generator implementation is this
3942
virtual Type type() const = 0;
4043

src/app/3d/qgs3dmapcanvas.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Qgs3DMapCanvas : public QWidget
2222
//! Configure map scene being displayed. Takes ownership.
2323
void setMap( Map3D *map );
2424

25+
const Map3D *map() const { return mMap; }
26+
2527
//! Resets camera position to the default: looking down at the origin of world coordinates
2628
void resetView();
2729

src/app/3d/qgs3dmapcanvasdockwidget.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#include "qgs3dmapcanvasdockwidget.h"
22

33
#include "qgs3dmapcanvas.h"
4+
#include "qgs3dmapconfigwidget.h"
5+
6+
#include "map3d.h"
47

58
#include <QBoxLayout>
9+
#include <QDialog>
10+
#include <QDialogButtonBox>
611
#include <QToolBar>
712

813
Qgs3DMapCanvasDockWidget::Qgs3DMapCanvasDockWidget( QWidget *parent )
@@ -12,6 +17,7 @@ Qgs3DMapCanvasDockWidget::Qgs3DMapCanvasDockWidget( QWidget *parent )
1217

1318
QToolBar *toolBar = new QToolBar( contentsWidget );
1419
toolBar->addAction( "Reset view", this, &Qgs3DMapCanvasDockWidget::resetView );
20+
toolBar->addAction( "Configure", this, &Qgs3DMapCanvasDockWidget::configure );
1521

1622
mCanvas = new Qgs3DMapCanvas( contentsWidget );
1723
mCanvas->setMinimumSize( QSize( 200, 200 ) );
@@ -34,3 +40,21 @@ void Qgs3DMapCanvasDockWidget::resetView()
3440
{
3541
mCanvas->resetView();
3642
}
43+
44+
void Qgs3DMapCanvasDockWidget::configure()
45+
{
46+
QDialog dlg;
47+
Qgs3DMapConfigWidget *w = new Qgs3DMapConfigWidget( mCanvas->map(), &dlg );
48+
QDialogButtonBox *buttons = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dlg );
49+
connect( buttons, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
50+
connect( buttons, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
51+
52+
QVBoxLayout *layout = new QVBoxLayout( &dlg );
53+
layout->addWidget( w, 1 );
54+
layout->addWidget( buttons );
55+
if ( !dlg.exec() )
56+
return;
57+
58+
// update map
59+
setMap( new Map3D( *w->map() ) );
60+
}

src/app/3d/qgs3dmapcanvasdockwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Qgs3DMapCanvasDockWidget : public QgsDockWidget
1919

2020
private slots:
2121
void resetView();
22+
void configure();
2223

2324
private:
2425
Qgs3DMapCanvas *mCanvas;

src/app/3d/qgs3dmapconfigwidget.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "qgs3dmapconfigwidget.h"
2+
3+
#include "map3d.h"
4+
#include "demterraingenerator.h"
5+
6+
#include "qgsrasterlayer.h"
7+
//#include "qgsproject.h"
8+
9+
Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( const Map3D *map, QWidget *parent )
10+
: QWidget( parent )
11+
, mMap( nullptr )
12+
{
13+
setupUi( this );
14+
15+
mMap = new Map3D( *map );
16+
17+
cboTerrainLayer->setAllowEmptyLayer( true );
18+
cboTerrainLayer->setFilters( QgsMapLayerProxyModel::RasterLayer );
19+
20+
TerrainGenerator *terrainGen = mMap->terrainGenerator.get();
21+
if ( terrainGen && terrainGen->type() == TerrainGenerator::Dem )
22+
{
23+
DemTerrainGenerator *demTerrainGen = static_cast<DemTerrainGenerator *>( terrainGen );
24+
spinTerrainResolution->setValue( demTerrainGen->resolution() );
25+
cboTerrainLayer->setLayer( demTerrainGen->layer() );
26+
}
27+
else
28+
{
29+
cboTerrainLayer->setLayer( nullptr );
30+
spinTerrainResolution->setEnabled( false );
31+
}
32+
33+
spinTerrainScale->setValue( mMap->zExaggeration );
34+
spinMapResolution->setValue( mMap->tileTextureSize );
35+
spinScreenError->setValue( mMap->maxTerrainError );
36+
chkShowTileInfo->setChecked( mMap->drawTerrainTileInfo );
37+
chkShowBoundingBoxes->setChecked( mMap->showBoundingBoxes );
38+
}
39+
40+
Qgs3DMapConfigWidget::~Qgs3DMapConfigWidget()
41+
{
42+
delete mMap;
43+
}
44+
45+
Map3D *Qgs3DMapConfigWidget::map()
46+
{
47+
// TODO: update terrain settings
48+
49+
mMap->zExaggeration = spinTerrainScale->value();
50+
mMap->tileTextureSize = spinMapResolution->value();
51+
mMap->maxTerrainError = spinScreenError->value();
52+
mMap->drawTerrainTileInfo = chkShowTileInfo->isChecked();
53+
mMap->showBoundingBoxes = chkShowBoundingBoxes->isChecked();
54+
55+
return mMap;
56+
}

src/app/3d/qgs3dmapconfigwidget.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef QGS3DMAPCONFIGWIDGET_H
2+
#define QGS3DMAPCONFIGWIDGET_H
3+
4+
#include <QWidget>
5+
6+
#include <ui_map3dconfigwidget.h>
7+
8+
class Map3D;
9+
10+
class Qgs3DMapConfigWidget : public QWidget, private Ui::Map3DConfigWidget
11+
{
12+
Q_OBJECT
13+
public:
14+
//! construct widget. does not take ownership of the passed map.
15+
explicit Qgs3DMapConfigWidget( const Map3D *map, QWidget *parent = nullptr );
16+
~Qgs3DMapConfigWidget();
17+
18+
Map3D *map();
19+
20+
signals:
21+
22+
public slots:
23+
24+
private:
25+
Map3D *mMap;
26+
};
27+
28+
#endif // QGS3DMAPCONFIGWIDGET_H

src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,14 @@ IF (WITH_3D)
369369
${QGIS_APP_SRCS}
370370
3d/qgs3dmapcanvas.cpp
371371
3d/qgs3dmapcanvasdockwidget.cpp
372+
3d/qgs3dmapconfigwidget.cpp
372373
)
373374

374375
SET (QGIS_APP_MOC_HDRS
375376
${QGIS_APP_MOC_HDRS}
376377
3d/qgs3dmapcanvas.h
377378
3d/qgs3dmapcanvasdockwidget.h
379+
3d/qgs3dmapconfigwidget.h
378380
)
379381
ENDIF (WITH_3D)
380382

src/ui/3d/map3dconfigwidget.ui

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ui version="4.0">
3-
<class>Form</class>
4-
<widget class="QWidget" name="Form">
3+
<class>Map3DConfigWidget</class>
4+
<widget class="QWidget" name="Map3DConfigWidget">
55
<property name="geometry">
66
<rect>
77
<x>0</x>
@@ -28,7 +28,7 @@
2828
</widget>
2929
</item>
3030
<item row="0" column="1" colspan="2">
31-
<widget class="QComboBox" name="cboTerrainLayer"/>
31+
<widget class="QgsMapLayerComboBox" name="cboTerrainLayer"/>
3232
</item>
3333
<item row="1" column="0">
3434
<widget class="QLabel" name="label_2">
@@ -56,6 +56,9 @@
5656
<property name="suffix">
5757
<string> px</string>
5858
</property>
59+
<property name="maximum">
60+
<number>4096</number>
61+
</property>
5962
</widget>
6063
</item>
6164
</layout>
@@ -75,6 +78,9 @@
7578
<property name="suffix">
7679
<string> px</string>
7780
</property>
81+
<property name="maximum">
82+
<number>4096</number>
83+
</property>
7884
</widget>
7985
</item>
8086
<item row="1" column="0">
@@ -85,7 +91,7 @@
8591
</widget>
8692
</item>
8793
<item row="1" column="1">
88-
<widget class="QDoubleSpinBox" name="spinScreenError">
94+
<widget class="QSpinBox" name="spinScreenError">
8995
<property name="suffix">
9096
<string> px</string>
9197
</property>
@@ -122,6 +128,13 @@
122128
</item>
123129
</layout>
124130
</widget>
131+
<customwidgets>
132+
<customwidget>
133+
<class>QgsMapLayerComboBox</class>
134+
<extends>QComboBox</extends>
135+
<header>qgsmaplayercombobox.h</header>
136+
</customwidget>
137+
</customwidgets>
125138
<resources/>
126139
<connections/>
127140
</ui>

src/ui/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@ FILE(GLOB LAYOUT_UIS "${CMAKE_CURRENT_SOURCE_DIR}/layout/*.ui")
88
FILE(GLOB AUTH_UIS "${CMAKE_CURRENT_SOURCE_DIR}/auth/*.ui")
99
FILE(GLOB RASTER_UIS "${CMAKE_CURRENT_SOURCE_DIR}/raster/*.ui")
1010
FILE(GLOB STYLEDOCK_UIS "${CMAKE_CURRENT_SOURCE_DIR}/styledock/*.ui")
11+
FILE(GLOB _3D_UIS "${CMAKE_CURRENT_SOURCE_DIR}/3d/*.ui")
1112

12-
QT5_WRAP_UI(QGIS_UIS_H ${QGIS_UIS} ${SYMBOLLAYER_UIS} ${EDITORWIDGET_UIS} ${PAINTEFFECT_UIS} ${COMPOSER_UIS} ${AUTH_UIS} ${RASTER_UIS} ${STYLEDOCK_UIS} ${LAYOUT_UIS})
13+
QT5_WRAP_UI(QGIS_UIS_H
14+
${QGIS_UIS}
15+
${SYMBOLLAYER_UIS}
16+
${EDITORWIDGET_UIS}
17+
${PAINTEFFECT_UIS}
18+
${COMPOSER_UIS}
19+
${AUTH_UIS}
20+
${RASTER_UIS}
21+
${STYLEDOCK_UIS}
22+
${LAYOUT_UIS}
23+
${_3D_UIS}
24+
)
1325

1426
ADD_CUSTOM_TARGET(ui ALL DEPENDS ${QGIS_UIS_H})

0 commit comments

Comments
 (0)