mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-22 00:14:55 -05:00
Merge pull request #8509 from wonder-sk/terrain-map-themes
[FEATURE] Optionally use a map theme to render terrain textures
This commit is contained in:
commit
d4ef55dadb
@ -39,6 +39,7 @@ Qgs3DMapSettings::Qgs3DMapSettings( const Qgs3DMapSettings &other )
|
|||||||
, mMaxTerrainGroundError( other.mMaxTerrainGroundError )
|
, mMaxTerrainGroundError( other.mMaxTerrainGroundError )
|
||||||
, mTerrainShadingEnabled( other.mTerrainShadingEnabled )
|
, mTerrainShadingEnabled( other.mTerrainShadingEnabled )
|
||||||
, mTerrainShadingMaterial( other.mTerrainShadingMaterial )
|
, mTerrainShadingMaterial( other.mTerrainShadingMaterial )
|
||||||
|
, mTerrainMapTheme( other.mTerrainMapTheme )
|
||||||
, mShowTerrainBoundingBoxes( other.mShowTerrainBoundingBoxes )
|
, mShowTerrainBoundingBoxes( other.mShowTerrainBoundingBoxes )
|
||||||
, mShowTerrainTileInfo( other.mShowTerrainTileInfo )
|
, mShowTerrainTileInfo( other.mShowTerrainTileInfo )
|
||||||
, mShowCameraViewCenter( other.mShowCameraViewCenter )
|
, mShowCameraViewCenter( other.mShowCameraViewCenter )
|
||||||
@ -48,6 +49,9 @@ Qgs3DMapSettings::Qgs3DMapSettings( const Qgs3DMapSettings &other )
|
|||||||
, mSkyboxEnabled( other.mSkyboxEnabled )
|
, mSkyboxEnabled( other.mSkyboxEnabled )
|
||||||
, mSkyboxFileBase( other.mSkyboxFileBase )
|
, mSkyboxFileBase( other.mSkyboxFileBase )
|
||||||
, mSkyboxFileExtension( other.mSkyboxFileExtension )
|
, mSkyboxFileExtension( other.mSkyboxFileExtension )
|
||||||
|
, mTransformContext( other.mTransformContext )
|
||||||
|
, mPathResolver( other.mPathResolver )
|
||||||
|
, mMapThemes( other.mMapThemes )
|
||||||
{
|
{
|
||||||
Q_FOREACH ( QgsAbstract3DRenderer *renderer, other.mRenderers )
|
Q_FOREACH ( QgsAbstract3DRenderer *renderer, other.mRenderers )
|
||||||
{
|
{
|
||||||
@ -87,6 +91,7 @@ void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteConte
|
|||||||
QDomElement elemTerrainShadingMaterial = elemTerrain.firstChildElement( QStringLiteral( "shading-material" ) );
|
QDomElement elemTerrainShadingMaterial = elemTerrain.firstChildElement( QStringLiteral( "shading-material" ) );
|
||||||
if ( !elemTerrainShadingMaterial.isNull() )
|
if ( !elemTerrainShadingMaterial.isNull() )
|
||||||
mTerrainShadingMaterial.readXml( elemTerrainShadingMaterial );
|
mTerrainShadingMaterial.readXml( elemTerrainShadingMaterial );
|
||||||
|
mTerrainMapTheme = elemTerrain.attribute( QStringLiteral( "map-theme" ) );
|
||||||
mShowLabels = elemTerrain.attribute( QStringLiteral( "show-labels" ), QStringLiteral( "0" ) ).toInt();
|
mShowLabels = elemTerrain.attribute( QStringLiteral( "show-labels" ), QStringLiteral( "0" ) ).toInt();
|
||||||
|
|
||||||
mPointLights.clear();
|
mPointLights.clear();
|
||||||
@ -204,6 +209,7 @@ QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteCon
|
|||||||
QDomElement elemTerrainShadingMaterial = doc.createElement( QStringLiteral( "shading-material" ) );
|
QDomElement elemTerrainShadingMaterial = doc.createElement( QStringLiteral( "shading-material" ) );
|
||||||
mTerrainShadingMaterial.writeXml( elemTerrainShadingMaterial );
|
mTerrainShadingMaterial.writeXml( elemTerrainShadingMaterial );
|
||||||
elemTerrain.appendChild( elemTerrainShadingMaterial );
|
elemTerrain.appendChild( elemTerrainShadingMaterial );
|
||||||
|
elemTerrain.setAttribute( QStringLiteral( "map-theme" ), mTerrainMapTheme );
|
||||||
elemTerrain.setAttribute( QStringLiteral( "show-labels" ), mShowLabels ? 1 : 0 );
|
elemTerrain.setAttribute( QStringLiteral( "show-labels" ), mShowLabels ? 1 : 0 );
|
||||||
|
|
||||||
QDomElement elemPointLights = doc.createElement( QStringLiteral( "point-lights" ) );
|
QDomElement elemPointLights = doc.createElement( QStringLiteral( "point-lights" ) );
|
||||||
@ -432,6 +438,15 @@ void Qgs3DMapSettings::setTerrainShadingMaterial( const QgsPhongMaterialSettings
|
|||||||
emit terrainShadingChanged();
|
emit terrainShadingChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Qgs3DMapSettings::setTerrainMapTheme( const QString &theme )
|
||||||
|
{
|
||||||
|
if ( mTerrainMapTheme == theme )
|
||||||
|
return;
|
||||||
|
|
||||||
|
mTerrainMapTheme = theme;
|
||||||
|
emit terrainMapThemeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void Qgs3DMapSettings::setRenderers( const QList<QgsAbstract3DRenderer *> &renderers )
|
void Qgs3DMapSettings::setRenderers( const QList<QgsAbstract3DRenderer *> &renderers )
|
||||||
{
|
{
|
||||||
mRenderers = renderers;
|
mRenderers = renderers;
|
||||||
|
|||||||
@ -126,6 +126,21 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
|
|||||||
*/
|
*/
|
||||||
void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
|
void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns pointer to the collection of map themes. Normally this would be QgsProject::mapThemeCollection()
|
||||||
|
* of the currently used project. Without a valid map theme collection object it is not possible
|
||||||
|
* to resolve map themes from their names.
|
||||||
|
* \since QGIS 3.6
|
||||||
|
*/
|
||||||
|
QgsMapThemeCollection *mapThemeCollection() const { return mMapThemes; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets pointer to the collection of map themes.
|
||||||
|
* \see mapThemeCollection()
|
||||||
|
* \since QGIS 3.6
|
||||||
|
*/
|
||||||
|
void setMapThemeCollection( QgsMapThemeCollection *mapThemes ) { mMapThemes = mapThemes; }
|
||||||
|
|
||||||
//! Sets background color of the 3D map view
|
//! Sets background color of the 3D map view
|
||||||
void setBackgroundColor( const QColor &color );
|
void setBackgroundColor( const QColor &color );
|
||||||
//! Returns background color of the 3D map view
|
//! Returns background color of the 3D map view
|
||||||
@ -148,9 +163,16 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
|
|||||||
//! Returns vertical scale (exaggeration) of terrain
|
//! Returns vertical scale (exaggeration) of terrain
|
||||||
double terrainVerticalScale() const;
|
double terrainVerticalScale() const;
|
||||||
|
|
||||||
//! Sets the list of map layers to be rendered as a texture of the terrain
|
/**
|
||||||
|
* Sets the list of map layers to be rendered as a texture of the terrain
|
||||||
|
* \note If terrain map theme is set, it has a priority over the list of layers specified here.
|
||||||
|
*/
|
||||||
void setLayers( const QList<QgsMapLayer *> &layers );
|
void setLayers( const QList<QgsMapLayer *> &layers );
|
||||||
//! Returns the list of map layers to be rendered as a texture of the terrain
|
|
||||||
|
/**
|
||||||
|
* Returns the list of map layers to be rendered as a texture of the terrain
|
||||||
|
* \note If terrain map theme is set, it has a priority over the list of layers specified here.
|
||||||
|
*/
|
||||||
QList<QgsMapLayer *> layers() const;
|
QList<QgsMapLayer *> layers() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,6 +253,25 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
|
|||||||
*/
|
*/
|
||||||
QgsPhongMaterialSettings terrainShadingMaterial() const { return mTerrainShadingMaterial; }
|
QgsPhongMaterialSettings terrainShadingMaterial() const { return mTerrainShadingMaterial; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets name of the map theme.
|
||||||
|
* \see terrainMapTheme()
|
||||||
|
* \since QGIS 3.6
|
||||||
|
*/
|
||||||
|
void setTerrainMapTheme( const QString &theme );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns name of the map theme (from the active project) that will be used for terrain's texture.
|
||||||
|
* Empty map theme name means that the map theme is not overridden and the current map theme will be used.
|
||||||
|
* \note Support for map themes only works if mapThemeCollection() is a valid object (otherwise it is not possible to resolve map themes from names)
|
||||||
|
* \since QGIS 3.6
|
||||||
|
*/
|
||||||
|
QString terrainMapTheme() const { return mTerrainMapTheme; }
|
||||||
|
|
||||||
|
//
|
||||||
|
// misc configuration
|
||||||
|
//
|
||||||
|
|
||||||
//! Sets list of extra 3D renderers to use in the scene. Takes ownership of the objects.
|
//! Sets list of extra 3D renderers to use in the scene. Takes ownership of the objects.
|
||||||
void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
|
void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
|
||||||
//! Returns list of extra 3D renderers
|
//! Returns list of extra 3D renderers
|
||||||
@ -310,6 +351,12 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
|
|||||||
* \since QGIS 3.6
|
* \since QGIS 3.6
|
||||||
*/
|
*/
|
||||||
void terrainShadingChanged();
|
void terrainShadingChanged();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when terrain's map theme has changed
|
||||||
|
* \since QGIS 3.6
|
||||||
|
*/
|
||||||
|
void terrainMapThemeChanged();
|
||||||
//! Emitted when the flag whether terrain's bounding boxes are shown has changed
|
//! Emitted when the flag whether terrain's bounding boxes are shown has changed
|
||||||
void showTerrainBoundingBoxesChanged();
|
void showTerrainBoundingBoxesChanged();
|
||||||
//! Emitted when the flag whether terrain's tile info is shown has changed
|
//! Emitted when the flag whether terrain's tile info is shown has changed
|
||||||
@ -342,6 +389,7 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
|
|||||||
float mMaxTerrainGroundError = 1.f; //!< Maximum allowed horizontal map error in map units (determines how many zoom levels will be used)
|
float mMaxTerrainGroundError = 1.f; //!< Maximum allowed horizontal map error in map units (determines how many zoom levels will be used)
|
||||||
bool mTerrainShadingEnabled = false; //!< Whether terrain should be shaded taking lights into account
|
bool mTerrainShadingEnabled = false; //!< Whether terrain should be shaded taking lights into account
|
||||||
QgsPhongMaterialSettings mTerrainShadingMaterial; //!< Material to use for the terrain (if shading is enabled). Diffuse color is ignored.
|
QgsPhongMaterialSettings mTerrainShadingMaterial; //!< Material to use for the terrain (if shading is enabled). Diffuse color is ignored.
|
||||||
|
QString mTerrainMapTheme; //!< Name of map theme used for terrain's texture (empty means use the current map theme)
|
||||||
bool mShowTerrainBoundingBoxes = false; //!< Whether to show bounding boxes of entities - useful for debugging
|
bool mShowTerrainBoundingBoxes = false; //!< Whether to show bounding boxes of entities - useful for debugging
|
||||||
bool mShowTerrainTileInfo = false; //!< Whether to draw extra information about terrain tiles to the textures - useful for debugging
|
bool mShowTerrainTileInfo = false; //!< Whether to draw extra information about terrain tiles to the textures - useful for debugging
|
||||||
bool mShowCameraViewCenter = false; //!< Whether to show camera view center as a sphere - useful for debugging
|
bool mShowCameraViewCenter = false; //!< Whether to show camera view center as a sphere - useful for debugging
|
||||||
@ -355,6 +403,7 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
|
|||||||
//! Coordinate transform context
|
//! Coordinate transform context
|
||||||
QgsCoordinateTransformContext mTransformContext;
|
QgsCoordinateTransformContext mTransformContext;
|
||||||
QgsPathResolver mPathResolver;
|
QgsPathResolver mPathResolver;
|
||||||
|
QgsMapThemeCollection *mMapThemes = nullptr; //!< Pointer to map themes (e.g. from the current project) to resolve map theme content from the name
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -217,7 +217,13 @@ bool QgsLayoutItem3DMap::readPropertiesFromElement( const QDomElement &element,
|
|||||||
mSettings.reset( new Qgs3DMapSettings );
|
mSettings.reset( new Qgs3DMapSettings );
|
||||||
mSettings->readXml( elemSettings, context );
|
mSettings->readXml( elemSettings, context );
|
||||||
if ( mLayout->project() )
|
if ( mLayout->project() )
|
||||||
|
{
|
||||||
mSettings->resolveReferences( *mLayout->project() );
|
mSettings->resolveReferences( *mLayout->project() );
|
||||||
|
|
||||||
|
mSettings->setTransformContext( mLayout->project()->transformContext() );
|
||||||
|
mSettings->setPathResolver( mLayout->project()->pathResolver() );
|
||||||
|
mSettings->setMapThemeCollection( mLayout->project()->mapThemeCollection() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QDomElement elemCameraPose = element.firstChildElement( QStringLiteral( "camera-pose" ) );
|
QDomElement elemCameraPose = element.firstChildElement( QStringLiteral( "camera-pose" ) );
|
||||||
|
|||||||
@ -69,6 +69,7 @@ QgsTerrainEntity::QgsTerrainEntity( int maxLevel, const Qgs3DMapSettings &map, Q
|
|||||||
connect( &map, &Qgs3DMapSettings::showLabelsChanged, this, &QgsTerrainEntity::invalidateMapImages );
|
connect( &map, &Qgs3DMapSettings::showLabelsChanged, this, &QgsTerrainEntity::invalidateMapImages );
|
||||||
connect( &map, &Qgs3DMapSettings::layersChanged, this, &QgsTerrainEntity::onLayersChanged );
|
connect( &map, &Qgs3DMapSettings::layersChanged, this, &QgsTerrainEntity::onLayersChanged );
|
||||||
connect( &map, &Qgs3DMapSettings::backgroundColorChanged, this, &QgsTerrainEntity::invalidateMapImages );
|
connect( &map, &Qgs3DMapSettings::backgroundColorChanged, this, &QgsTerrainEntity::invalidateMapImages );
|
||||||
|
connect( &map, &Qgs3DMapSettings::terrainMapThemeChanged, this, &QgsTerrainEntity::invalidateMapImages );
|
||||||
|
|
||||||
connectToLayersRepaintRequest();
|
connectToLayersRepaintRequest();
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
#include <qgsmaprenderercustompainterjob.h>
|
#include <qgsmaprenderercustompainterjob.h>
|
||||||
#include <qgsmaprenderersequentialjob.h>
|
#include <qgsmaprenderersequentialjob.h>
|
||||||
#include <qgsmapsettings.h>
|
#include <qgsmapsettings.h>
|
||||||
|
#include <qgsmapthemecollection.h>
|
||||||
#include <qgsproject.h>
|
#include <qgsproject.h>
|
||||||
|
|
||||||
#include "qgs3dmapsettings.h"
|
#include "qgs3dmapsettings.h"
|
||||||
@ -127,13 +128,26 @@ void QgsTerrainTextureGenerator::onRenderingFinished()
|
|||||||
QgsMapSettings QgsTerrainTextureGenerator::baseMapSettings()
|
QgsMapSettings QgsTerrainTextureGenerator::baseMapSettings()
|
||||||
{
|
{
|
||||||
QgsMapSettings mapSettings;
|
QgsMapSettings mapSettings;
|
||||||
mapSettings.setLayers( mMap.layers() );
|
|
||||||
mapSettings.setOutputSize( QSize( mMap.mapTileResolution(), mMap.mapTileResolution() ) );
|
mapSettings.setOutputSize( QSize( mMap.mapTileResolution(), mMap.mapTileResolution() ) );
|
||||||
mapSettings.setDestinationCrs( mMap.crs() );
|
mapSettings.setDestinationCrs( mMap.crs() );
|
||||||
mapSettings.setBackgroundColor( mMap.backgroundColor() );
|
mapSettings.setBackgroundColor( mMap.backgroundColor() );
|
||||||
mapSettings.setFlag( QgsMapSettings::DrawLabeling, mMap.showLabels() );
|
mapSettings.setFlag( QgsMapSettings::DrawLabeling, mMap.showLabels() );
|
||||||
mapSettings.setTransformContext( mMap.transformContext() );
|
mapSettings.setTransformContext( mMap.transformContext() );
|
||||||
mapSettings.setPathResolver( mMap.pathResolver() );
|
mapSettings.setPathResolver( mMap.pathResolver() );
|
||||||
|
|
||||||
|
QgsMapThemeCollection *mapThemes = mMap.mapThemeCollection();
|
||||||
|
QString mapThemeName = mMap.terrainMapTheme();
|
||||||
|
if ( mapThemeName.isEmpty() || !mapThemes || !mapThemes->hasMapTheme( mapThemeName ) )
|
||||||
|
{
|
||||||
|
mapSettings.setLayers( mMap.layers() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mapSettings.setLayers( mapThemes->mapThemeVisibleLayers( mapThemeName ) );
|
||||||
|
mapSettings.setLayerStyleOverrides( mapThemes->mapThemeStyleOverrides( mapThemeName ) );
|
||||||
|
}
|
||||||
|
|
||||||
return mapSettings;
|
return mapSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,8 +21,9 @@
|
|||||||
#include "qgs3dutils.h"
|
#include "qgs3dutils.h"
|
||||||
|
|
||||||
#include "qgsmapcanvas.h"
|
#include "qgsmapcanvas.h"
|
||||||
|
#include "qgsmapthemecollection.h"
|
||||||
#include "qgsrasterlayer.h"
|
#include "qgsrasterlayer.h"
|
||||||
//#include "qgsproject.h"
|
#include "qgsproject.h"
|
||||||
|
|
||||||
Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas *mainCanvas, QWidget *parent )
|
Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas *mainCanvas, QWidget *parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
@ -73,6 +74,14 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas
|
|||||||
widgetTerrainMaterial->setDiffuseVisible( false );
|
widgetTerrainMaterial->setDiffuseVisible( false );
|
||||||
widgetTerrainMaterial->setMaterial( mMap->terrainShadingMaterial() );
|
widgetTerrainMaterial->setMaterial( mMap->terrainShadingMaterial() );
|
||||||
|
|
||||||
|
// populate combo box with map themes
|
||||||
|
const QStringList mapThemeNames = QgsProject::instance()->mapThemeCollection()->mapThemes();
|
||||||
|
cboTerrainMapTheme->addItem( QString() ); // empty item for no map theme
|
||||||
|
for ( QString themeName : mapThemeNames )
|
||||||
|
cboTerrainMapTheme->addItem( themeName );
|
||||||
|
|
||||||
|
cboTerrainMapTheme->setCurrentText( mMap->terrainMapTheme() );
|
||||||
|
|
||||||
widgetLights->setPointLights( mMap->pointLights() );
|
widgetLights->setPointLights( mMap->pointLights() );
|
||||||
|
|
||||||
connect( cboTerrainLayer, static_cast<void ( QComboBox::* )( int )>( &QgsMapLayerComboBox::currentIndexChanged ), this, &Qgs3DMapConfigWidget::onTerrainLayerChanged );
|
connect( cboTerrainLayer, static_cast<void ( QComboBox::* )( int )>( &QgsMapLayerComboBox::currentIndexChanged ), this, &Qgs3DMapConfigWidget::onTerrainLayerChanged );
|
||||||
@ -144,6 +153,8 @@ void Qgs3DMapConfigWidget::apply()
|
|||||||
mMap->setTerrainShadingEnabled( groupTerrainShading->isChecked() );
|
mMap->setTerrainShadingEnabled( groupTerrainShading->isChecked() );
|
||||||
mMap->setTerrainShadingMaterial( widgetTerrainMaterial->material() );
|
mMap->setTerrainShadingMaterial( widgetTerrainMaterial->material() );
|
||||||
|
|
||||||
|
mMap->setTerrainMapTheme( cboTerrainMapTheme->currentText() );
|
||||||
|
|
||||||
mMap->setPointLights( widgetLights->pointLights() );
|
mMap->setPointLights( widgetLights->pointLights() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11141,8 +11141,10 @@ void QgisApp::new3DMapCanvas()
|
|||||||
map->setSelectionColor( mMapCanvas->selectionColor() );
|
map->setSelectionColor( mMapCanvas->selectionColor() );
|
||||||
map->setBackgroundColor( mMapCanvas->canvasColor() );
|
map->setBackgroundColor( mMapCanvas->canvasColor() );
|
||||||
map->setLayers( mMapCanvas->layers() );
|
map->setLayers( mMapCanvas->layers() );
|
||||||
|
|
||||||
map->setTransformContext( QgsProject::instance()->transformContext() );
|
map->setTransformContext( QgsProject::instance()->transformContext() );
|
||||||
map->setPathResolver( QgsProject::instance()->pathResolver() );
|
map->setPathResolver( QgsProject::instance()->pathResolver() );
|
||||||
|
map->setMapThemeCollection( QgsProject::instance()->mapThemeCollection() );
|
||||||
connect( QgsProject::instance(), &QgsProject::transformContextChanged, map, [map]
|
connect( QgsProject::instance(), &QgsProject::transformContextChanged, map, [map]
|
||||||
{
|
{
|
||||||
map->setTransformContext( QgsProject::instance()->transformContext() );
|
map->setTransformContext( QgsProject::instance()->transformContext() );
|
||||||
@ -13562,6 +13564,14 @@ void QgisApp::readProject( const QDomDocument &doc )
|
|||||||
map->readXml( elem3D, readWriteContext );
|
map->readXml( elem3D, readWriteContext );
|
||||||
map->resolveReferences( *QgsProject::instance() );
|
map->resolveReferences( *QgsProject::instance() );
|
||||||
|
|
||||||
|
map->setTransformContext( QgsProject::instance()->transformContext() );
|
||||||
|
map->setPathResolver( QgsProject::instance()->pathResolver() );
|
||||||
|
map->setMapThemeCollection( QgsProject::instance()->mapThemeCollection() );
|
||||||
|
connect( QgsProject::instance(), &QgsProject::transformContextChanged, map, [map]
|
||||||
|
{
|
||||||
|
map->setTransformContext( QgsProject::instance()->transformContext() );
|
||||||
|
} );
|
||||||
|
|
||||||
// these things are not saved in project
|
// these things are not saved in project
|
||||||
map->setSelectionColor( mMapCanvas->selectionColor() );
|
map->setSelectionColor( mMapCanvas->selectionColor() );
|
||||||
map->setBackgroundColor( mMapCanvas->canvasColor() );
|
map->setBackgroundColor( mMapCanvas->canvasColor() );
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>691</width>
|
<width>691</width>
|
||||||
<height>1135</height>
|
<height>1122</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -15,7 +15,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QgsCollapsibleGroupBox" name="groupTerrain">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Terrain</string>
|
<string>Terrain</string>
|
||||||
</property>
|
</property>
|
||||||
@ -84,6 +84,20 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="label_9">
|
||||||
|
<property name="text">
|
||||||
|
<string>Map theme</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1" colspan="2">
|
||||||
|
<widget class="QComboBox" name="cboTerrainMapTheme">
|
||||||
|
<property name="editable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -275,12 +289,15 @@
|
|||||||
<tabstop>spinTerrainScale</tabstop>
|
<tabstop>spinTerrainScale</tabstop>
|
||||||
<tabstop>spinTerrainResolution</tabstop>
|
<tabstop>spinTerrainResolution</tabstop>
|
||||||
<tabstop>spinTerrainSkirtHeight</tabstop>
|
<tabstop>spinTerrainSkirtHeight</tabstop>
|
||||||
|
<tabstop>cboTerrainMapTheme</tabstop>
|
||||||
|
<tabstop>groupTerrainShading</tabstop>
|
||||||
<tabstop>spinMapResolution</tabstop>
|
<tabstop>spinMapResolution</tabstop>
|
||||||
<tabstop>spinScreenError</tabstop>
|
<tabstop>spinScreenError</tabstop>
|
||||||
<tabstop>spinGroundError</tabstop>
|
<tabstop>spinGroundError</tabstop>
|
||||||
<tabstop>chkShowLabels</tabstop>
|
<tabstop>chkShowLabels</tabstop>
|
||||||
<tabstop>chkShowTileInfo</tabstop>
|
<tabstop>chkShowTileInfo</tabstop>
|
||||||
<tabstop>chkShowBoundingBoxes</tabstop>
|
<tabstop>chkShowBoundingBoxes</tabstop>
|
||||||
|
<tabstop>chkShowCameraViewCenter</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|||||||
@ -16,8 +16,12 @@
|
|||||||
#include "qgstest.h"
|
#include "qgstest.h"
|
||||||
#include "qgsrenderchecker.h"
|
#include "qgsrenderchecker.h"
|
||||||
|
|
||||||
|
#include "qgsmaplayerstylemanager.h"
|
||||||
|
#include "qgsmapthemecollection.h"
|
||||||
#include "qgsproject.h"
|
#include "qgsproject.h"
|
||||||
#include "qgsrasterlayer.h"
|
#include "qgsrasterlayer.h"
|
||||||
|
#include "qgsrastershader.h"
|
||||||
|
#include "qgssinglebandpseudocolorrenderer.h"
|
||||||
#include "qgsvectorlayer.h"
|
#include "qgsvectorlayer.h"
|
||||||
|
|
||||||
#include "qgs3dmapscene.h"
|
#include "qgs3dmapscene.h"
|
||||||
@ -43,6 +47,7 @@ class TestQgs3DRendering : public QObject
|
|||||||
void testFlatTerrain();
|
void testFlatTerrain();
|
||||||
void testDemTerrain();
|
void testDemTerrain();
|
||||||
void testExtrudedPolygons();
|
void testExtrudedPolygons();
|
||||||
|
void testMapTheme();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool renderCheck( const QString &testName, QImage &image, int mismatchCount = 0 );
|
bool renderCheck( const QString &testName, QImage &image, int mismatchCount = 0 );
|
||||||
@ -88,6 +93,39 @@ void TestQgs3DRendering::initTestCase()
|
|||||||
mLayerBuildings->setRenderer3D( renderer3d );
|
mLayerBuildings->setRenderer3D( renderer3d );
|
||||||
|
|
||||||
mProject->setCrs( mLayerDtm->crs() );
|
mProject->setCrs( mLayerDtm->crs() );
|
||||||
|
|
||||||
|
//
|
||||||
|
// prepare styles for DTM layer
|
||||||
|
//
|
||||||
|
|
||||||
|
mLayerDtm->styleManager()->addStyleFromLayer( "grayscale" );
|
||||||
|
|
||||||
|
double vMin = 44, vMax = 198;
|
||||||
|
QColor cMin = Qt::red, cMax = Qt::yellow;
|
||||||
|
|
||||||
|
// change renderer for the new style
|
||||||
|
std::unique_ptr<QgsColorRampShader> colorRampShader( new QgsColorRampShader( vMin, vMax ) );
|
||||||
|
colorRampShader->setColorRampItemList( QList<QgsColorRampShader::ColorRampItem>()
|
||||||
|
<< QgsColorRampShader::ColorRampItem( vMin, cMin )
|
||||||
|
<< QgsColorRampShader::ColorRampItem( vMax, cMax ) );
|
||||||
|
std::unique_ptr<QgsRasterShader> shader( new QgsRasterShader( vMin, vMax ) );
|
||||||
|
shader->setRasterShaderFunction( colorRampShader.release() );
|
||||||
|
QgsSingleBandPseudoColorRenderer *r = new QgsSingleBandPseudoColorRenderer( mLayerDtm->renderer()->input(), 1, shader.release() );
|
||||||
|
mLayerDtm->setRenderer( r );
|
||||||
|
mLayerDtm->styleManager()->addStyleFromLayer( "my_style" );
|
||||||
|
|
||||||
|
mLayerDtm->styleManager()->setCurrentStyle( "grayscale" );
|
||||||
|
|
||||||
|
//
|
||||||
|
// add map theme
|
||||||
|
//
|
||||||
|
|
||||||
|
QgsMapThemeCollection::MapThemeLayerRecord layerRecord( mLayerDtm );
|
||||||
|
layerRecord.usingCurrentStyle = true;
|
||||||
|
layerRecord.currentStyle = "my_style";
|
||||||
|
QgsMapThemeCollection::MapThemeRecord record;
|
||||||
|
record.addLayerRecord( layerRecord );
|
||||||
|
mProject->mapThemeCollection()->insert( "theme_dtm", record );
|
||||||
}
|
}
|
||||||
|
|
||||||
//runs after all tests
|
//runs after all tests
|
||||||
@ -204,6 +242,40 @@ void TestQgs3DRendering::testExtrudedPolygons()
|
|||||||
QVERIFY( renderCheck( "polygon3d_extrusion", img, 40 ) );
|
QVERIFY( renderCheck( "polygon3d_extrusion", img, 40 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestQgs3DRendering::testMapTheme()
|
||||||
|
{
|
||||||
|
QgsRectangle fullExtent = mLayerDtm->extent();
|
||||||
|
|
||||||
|
Qgs3DMapSettings *map = new Qgs3DMapSettings;
|
||||||
|
map->setCrs( mProject->crs() );
|
||||||
|
map->setOrigin( QgsVector3D( fullExtent.center().x(), fullExtent.center().y(), 0 ) );
|
||||||
|
map->setLayers( QList<QgsMapLayer *>() << mLayerRgb );
|
||||||
|
|
||||||
|
// set theme - this should override what we set in setLayers()
|
||||||
|
map->setMapThemeCollection( mProject->mapThemeCollection() );
|
||||||
|
map->setTerrainMapTheme( "theme_dtm" );
|
||||||
|
|
||||||
|
QgsFlatTerrainGenerator *flatTerrain = new QgsFlatTerrainGenerator;
|
||||||
|
flatTerrain->setCrs( map->crs() );
|
||||||
|
flatTerrain->setExtent( fullExtent );
|
||||||
|
map->setTerrainGenerator( flatTerrain );
|
||||||
|
|
||||||
|
QgsOffscreen3DEngine engine;
|
||||||
|
Qgs3DMapScene *scene = new Qgs3DMapScene( *map, &engine );
|
||||||
|
engine.setRootEntity( scene );
|
||||||
|
|
||||||
|
// look from the top
|
||||||
|
scene->cameraController()->setLookingAtPoint( QgsVector3D( 0, 0, 0 ), 2500, 0, 0 );
|
||||||
|
|
||||||
|
// When running the test on Travis, it would initially return empty rendered image.
|
||||||
|
// Capturing the initial image and throwing it away fixes that. Hopefully we will
|
||||||
|
// find a better fix in the future.
|
||||||
|
Qgs3DUtils::captureSceneImage( engine, scene );
|
||||||
|
|
||||||
|
QImage img = Qgs3DUtils::captureSceneImage( engine, scene );
|
||||||
|
QVERIFY( renderCheck( "terrain_theme", img, 40 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TestQgs3DRendering::renderCheck( const QString &testName, QImage &image, int mismatchCount )
|
bool TestQgs3DRendering::renderCheck( const QString &testName, QImage &image, int mismatchCount )
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
tests/testdata/control_images/3d/expected_terrain_theme/expected_terrain_theme.png
vendored
Normal file
BIN
tests/testdata/control_images/3d/expected_terrain_theme/expected_terrain_theme.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
Loading…
x
Reference in New Issue
Block a user