Skip to content
Permalink
Browse files

Harmonize 3D map view widget with 2D ones to display the map theme dr…

…op-down menu (#34369)

fixes #33954

* Add tool button for 3d map theme for #33954
* Populate map theme options.
* Remove map theme from 3d config.
* Disable 3d map theme button if the terrain is a mesh.
  • Loading branch information
ismailsunni committed Mar 13, 2020
1 parent 613145c commit 9e5966cf8c079c49109254f5b8a3847e3f00c017
@@ -21,6 +21,7 @@
#include <QProgressBar>
#include <QToolBar>
#include <QUrl>
#include <QAction>

#include "qgisapp.h"
#include "qgs3dmapcanvas.h"
@@ -33,6 +34,7 @@
#include "qgsapplication.h"
#include "qgssettings.h"
#include "qgsgui.h"
#include "qgsmapthemecollection.h"

#include "qgs3danimationsettings.h"
#include "qgs3danimationwidget.h"
@@ -98,6 +100,19 @@ Qgs3DMapCanvasDockWidget::Qgs3DMapCanvasDockWidget( QWidget *parent )

toolBar->addSeparator();

// Map Theme Menu
mMapThemeMenu = new QMenu();
connect( mMapThemeMenu, &QMenu::aboutToShow, this, &Qgs3DMapCanvasDockWidget::mapThemeMenuAboutToShow );

mBtnMapThemes = new QToolButton();
mBtnMapThemes->setAutoRaise( true );
mBtnMapThemes->setToolTip( tr( "Set View Theme" ) );
mBtnMapThemes->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionShowAllLayers.svg" ) ) );
mBtnMapThemes->setPopupMode( QToolButton::InstantPopup );
mBtnMapThemes->setMenu( mMapThemeMenu );

toolBar->addWidget( mBtnMapThemes );

toolBar->addAction( QgsApplication::getThemeIcon( QStringLiteral( "mActionOptions.svg" ) ),
tr( "Configure…" ), this, &Qgs3DMapCanvasDockWidget::configure );

@@ -210,6 +225,9 @@ void Qgs3DMapCanvasDockWidget::setMapSettings( Qgs3DMapSettings *map )

mAnimationWidget->setCameraController( mCanvas->scene()->cameraController() );
mAnimationWidget->setMap( map );

// Disable button for switching the map theme if the terrain generator is a mesh
mBtnMapThemes->setDisabled( mCanvas->map()->terrainGenerator()->type() == QgsTerrainGenerator::Mesh );
}

void Qgs3DMapCanvasDockWidget::setMainCanvas( QgsMapCanvas *canvas )
@@ -266,6 +284,9 @@ void Qgs3DMapCanvasDockWidget::configure()
newCameraPose.setCenterPoint( p );
mCanvas->cameraController()->setCameraPose( newCameraPose );
}

// Disable map theme button if the terrain generator is a mesh
mBtnMapThemes->setDisabled( map->terrainGenerator()->type() == QgsTerrainGenerator::Mesh );
}

void Qgs3DMapCanvasDockWidget::onMainCanvasLayersChanged()
@@ -286,3 +307,40 @@ void Qgs3DMapCanvasDockWidget::onTotalPendingJobsCountChanged()
if ( count )
mLabelPendingJobs->setText( tr( "Loading %1 tiles" ).arg( count ) );
}

void Qgs3DMapCanvasDockWidget::mapThemeMenuAboutToShow()
{
qDeleteAll( mMapThemeMenuPresetActions );
mMapThemeMenuPresetActions.clear();

QString currentTheme = mCanvas->map()->terrainMapTheme();

QAction *actionFollowMain = new QAction( tr( "(none)" ), mMapThemeMenu );
actionFollowMain->setCheckable( true );
if ( currentTheme.isEmpty() || !QgsProject::instance()->mapThemeCollection()->hasMapTheme( currentTheme ) )
{
actionFollowMain->setChecked( true );
}
connect( actionFollowMain, &QAction::triggered, this, [ = ]
{
mCanvas->map()->setTerrainMapTheme( QString() );
} );
mMapThemeMenuPresetActions.append( actionFollowMain );

const auto constMapThemes = QgsProject::instance()->mapThemeCollection()->mapThemes();
for ( const QString &grpName : constMapThemes )
{
QAction *a = new QAction( grpName, mMapThemeMenu );
a->setCheckable( true );
if ( grpName == currentTheme )
{
a->setChecked( true );
}
connect( a, &QAction::triggered, this, [a, this]
{
mCanvas->map()->setTerrainMapTheme( a->text() );
} );
mMapThemeMenuPresetActions.append( a );
}
mMapThemeMenu->addActions( mMapThemeMenuPresetActions );
}
@@ -16,8 +16,10 @@
#ifndef QGS3DMAPCANVASDOCKWIDGET_H
#define QGS3DMAPCANVASDOCKWIDGET_H

#include "qmenu.h"
#include "qgsdockwidget.h"
#include "qgis_app.h"
#include "qtoolbutton.h"

#define SIP_NO_FILE

@@ -62,6 +64,7 @@ class APP_EXPORT Qgs3DMapCanvasDockWidget : public QgsDockWidget
void onMainCanvasLayersChanged();
void onMainCanvasColorChanged();
void onTotalPendingJobsCountChanged();
void mapThemeMenuAboutToShow();

private:
Qgs3DMapCanvas *mCanvas = nullptr;
@@ -71,6 +74,9 @@ class APP_EXPORT Qgs3DMapCanvasDockWidget : public QgsDockWidget
QLabel *mLabelPendingJobs = nullptr;
Qgs3DMapToolIdentify *mMapToolIdentify = nullptr;
Qgs3DMapToolMeasureLine *mMapToolMeasureLine = nullptr;
QMenu *mMapThemeMenu = nullptr;
QList<QAction *> mMapThemeMenuPresetActions;
QToolButton *mBtnMapThemes = nullptr;
};

#endif // QGS3DMAPCANVASDOCKWIDGET_H
@@ -107,14 +107,6 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas
widgetTerrainMaterial->setDiffuseVisible( false );
widgetTerrainMaterial->setMaterial( mMap->terrainShadingMaterial() );

// populate combo box with map themes
const QStringList mapThemeNames = QgsProject::instance()->mapThemeCollection()->mapThemes();
cboTerrainMapTheme->addItem( tr( "(none)" ) ); // item for no map theme
for ( QString themeName : mapThemeNames )
cboTerrainMapTheme->addItem( themeName );

cboTerrainMapTheme->setCurrentText( mMap->terrainMapTheme() );

widgetLights->setPointLights( mMap->pointLights() );

connect( cboTerrainType, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &Qgs3DMapConfigWidget::onTerrainTypeChanged );
@@ -233,8 +225,6 @@ void Qgs3DMapConfigWidget::apply()
mMap->setTerrainShadingEnabled( groupTerrainShading->isChecked() );
mMap->setTerrainShadingMaterial( widgetTerrainMaterial->material() );

mMap->setTerrainMapTheme( cboTerrainMapTheme->currentText() );

mMap->setPointLights( widgetLights->pointLights() );
}

@@ -249,8 +239,6 @@ void Qgs3DMapConfigWidget::onTerrainTypeChanged()
labelTerrainLayer->setVisible( genType == QgsTerrainGenerator::Dem || genType == QgsTerrainGenerator::Mesh );
cboTerrainLayer->setVisible( genType == QgsTerrainGenerator::Dem || genType == QgsTerrainGenerator::Mesh );
groupMeshTerrainShading->setVisible( genType == QgsTerrainGenerator::Mesh );
labelTerrainMapTheme->setVisible( !( genType == QgsTerrainGenerator::Mesh ) );
cboTerrainMapTheme->setVisible( !( genType == QgsTerrainGenerator::Mesh ) );

QgsMapLayer *oldTerrainLayer = cboTerrainLayer->currentLayer();
if ( cboTerrainType->currentData() == QgsTerrainGenerator::Dem )
@@ -37,7 +37,7 @@
<x>0</x>
<y>0</y>
<width>539</width>
<height>693</height>
<height>696</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
@@ -63,13 +63,37 @@
<item row="1" column="1" colspan="2">
<widget class="QgsMapLayerComboBox" name="cboTerrainLayer"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelTerrainLayer">
<property name="text">
<string>Elevation</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="cboTerrainType"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelTerrainResolution">
<property name="text">
<string>Tile resolution</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QgsDoubleSpinBox" name="spinTerrainScale">
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelTerrainType">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QgsSpinBox" name="spinTerrainResolution">
<property name="suffix">
@@ -80,17 +104,17 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelTerrainSkirtHeight">
<item row="2" column="0">
<widget class="QLabel" name="labelTerrainScale">
<property name="text">
<string>Skirt height</string>
<string>Vertical scale</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QComboBox" name="cboTerrainMapTheme">
<property name="editable">
<bool>false</bool>
<item row="4" column="0">
<widget class="QLabel" name="labelTerrainSkirtHeight">
<property name="text">
<string>Skirt height</string>
</property>
</widget>
</item>
@@ -110,44 +134,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelTerrainScale">
<property name="text">
<string>Vertical scale</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelTerrainType">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelTerrainLayer">
<property name="text">
<string>Elevation</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="labelTerrainMapTheme">
<property name="text">
<string>Map theme</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelTerrainResolution">
<property name="text">
<string>Tile resolution</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="cboTerrainType"/>
</item>
</layout>
</widget>
</item>
@@ -392,7 +378,6 @@
<tabstop>spinTerrainScale</tabstop>
<tabstop>spinTerrainResolution</tabstop>
<tabstop>spinTerrainSkirtHeight</tabstop>
<tabstop>cboTerrainMapTheme</tabstop>
<tabstop>groupTerrainShading</tabstop>
<tabstop>spinMapResolution</tabstop>
<tabstop>spinScreenError</tabstop>

0 comments on commit 9e5966c

Please sign in to comment.
You can’t perform that action at this time.