Skip to content

Commit b250729

Browse files
authored
[3d] add show labels toggle, default to off (#5361)
1 parent 25d40f3 commit b250729

6 files changed

+30
-0
lines changed

src/3d/qgs3dmapsettings.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Qgs3DMapSettings::Qgs3DMapSettings()
3838
, mMaxTerrainGroundError( 1.f )
3939
, mShowTerrainBoundingBoxes( false )
4040
, mShowTerrainTileInfo( false )
41+
, mShowLabels( false )
4142
, mSkyboxEnabled( false )
4243
{
4344
}
@@ -87,6 +88,7 @@ void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteConte
8788
mMapTileResolution = elemTerrain.attribute( "texture-size", "512" ).toInt();
8889
mMaxTerrainScreenError = elemTerrain.attribute( "max-terrain-error", "3" ).toFloat();
8990
mMaxTerrainGroundError = elemTerrain.attribute( "max-ground-error", "1" ).toFloat();
91+
mShowLabels = elemTerrain.attribute( "show-labels", "0" ).toInt();
9092
QDomElement elemMapLayers = elemTerrain.firstChildElement( "layers" );
9193
QDomElement elemMapLayer = elemMapLayers.firstChildElement( "layer" );
9294
QList<QgsMapLayerRef> mapLayers;
@@ -168,6 +170,7 @@ QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteCon
168170
elemTerrain.setAttribute( "texture-size", mMapTileResolution );
169171
elemTerrain.setAttribute( "max-terrain-error", QString::number( mMaxTerrainScreenError ) );
170172
elemTerrain.setAttribute( "max-ground-error", QString::number( mMaxTerrainGroundError ) );
173+
elemTerrain.setAttribute( "show-labels", mShowLabels ? 1 : 0 );
171174
QDomElement elemMapLayers = doc.createElement( "layers" );
172175
Q_FOREACH ( const QgsMapLayerRef &layerRef, mLayers )
173176
{
@@ -376,3 +379,12 @@ void Qgs3DMapSettings::setShowTerrainTilesInfo( bool enabled )
376379
mShowTerrainTileInfo = enabled;
377380
emit showTerrainTilesInfoChanged();
378381
}
382+
383+
void Qgs3DMapSettings::setShowLabels( bool enabled )
384+
{
385+
if ( mShowLabels == enabled )
386+
return;
387+
388+
mShowLabels = enabled;
389+
emit showLabelsChanged();
390+
}

src/3d/qgs3dmapsettings.h

+7
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
176176
void setShowTerrainTilesInfo( bool enabled );
177177
//! Returns whether to display extra tile info on top of terrain tiles (for debugging)
178178
bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
179+
//! Sets whether to display labels on terrain tiles
180+
void setShowLabels( bool enabled );
181+
//! Returns whether to display labels on terrain tiles
182+
bool showLabels() const { return mShowLabels; }
179183

180184
signals:
181185
//! Emitted when the background color has changed
@@ -198,6 +202,8 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
198202
void showTerrainBoundingBoxesChanged();
199203
//! Emitted when the flag whether terrain's tile info is shown has changed
200204
void showTerrainTilesInfoChanged();
205+
//! Emitted when the flag whether labels are displayed on terrain tiles has changed
206+
void showLabelsChanged();
201207

202208
private:
203209
double mOriginX, mOriginY, mOriginZ; //!< Coordinates in map CRS at which our 3D world has origin (0,0,0)
@@ -211,6 +217,7 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
211217
float mMaxTerrainGroundError; //!< Maximum allowed horizontal map error in map units (determines how many zoom levels will be used)
212218
bool mShowTerrainBoundingBoxes; //!< Whether to show bounding boxes of entities - useful for debugging
213219
bool mShowTerrainTileInfo; //!< Whether to draw extra information about terrain tiles to the textures - useful for debugging
220+
bool mShowLabels; //!< Whether to display labels on terrain tiles
214221
QList<QgsMapLayerRef> mLayers; //!< Layers to be rendered
215222
QList<QgsAbstract3DRenderer *> mRenderers; //!< Extra stuff to render as 3D object
216223
bool mSkyboxEnabled; //!< Whether to render skybox

src/3d/terrain/qgsterrainentity_p.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ QgsTerrainEntity::QgsTerrainEntity( int maxLevel, const Qgs3DMapSettings &map, Q
6363

6464
connect( &map, &Qgs3DMapSettings::showTerrainBoundingBoxesChanged, this, &QgsTerrainEntity::onShowBoundingBoxesChanged );
6565
connect( &map, &Qgs3DMapSettings::showTerrainTilesInfoChanged, this, &QgsTerrainEntity::invalidateMapImages );
66+
connect( &map, &Qgs3DMapSettings::showLabelsChanged, this, &QgsTerrainEntity::invalidateMapImages );
6667
connect( &map, &Qgs3DMapSettings::layersChanged, this, &QgsTerrainEntity::onLayersChanged );
6768
connect( &map, &Qgs3DMapSettings::backgroundColorChanged, this, &QgsTerrainEntity::invalidateMapImages );
6869

src/3d/terrain/qgsterraintexturegenerator_p.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ QgsMapSettings QgsTerrainTextureGenerator::baseMapSettings()
131131
mapSettings.setOutputSize( QSize( mMap.mapTileResolution(), mMap.mapTileResolution() ) );
132132
mapSettings.setDestinationCrs( mMap.crs() );
133133
mapSettings.setBackgroundColor( mMap.backgroundColor() );
134+
mapSettings.setFlag( QgsMapSettings::DrawLabeling, mMap.showLabels() );
134135
return mapSettings;
135136
}
136137

src/app/3d/qgs3dmapconfigwidget.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas
5555
spinMapResolution->setValue( mMap->mapTileResolution() );
5656
spinScreenError->setValue( mMap->maxTerrainScreenError() );
5757
spinGroundError->setValue( mMap->maxTerrainGroundError() );
58+
chkShowLabels->setChecked( mMap->showLabels() );
5859
chkShowTileInfo->setChecked( mMap->showTerrainTilesInfo() );
5960
chkShowBoundingBoxes->setChecked( mMap->showTerrainBoundingBoxes() );
6061

@@ -93,6 +94,7 @@ void Qgs3DMapConfigWidget::apply()
9394
mMap->setMapTileResolution( spinMapResolution->value() );
9495
mMap->setMaxTerrainScreenError( spinScreenError->value() );
9596
mMap->setMaxTerrainGroundError( spinGroundError->value() );
97+
mMap->setShowLabels( chkShowLabels->isChecked() );
9698
mMap->setShowTerrainTilesInfo( chkShowTileInfo->isChecked() );
9799
mMap->setShowTerrainBoundingBoxes( chkShowBoundingBoxes->isChecked() );
98100
}

src/ui/3d/map3dconfigwidget.ui

+7
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@
142142
</item>
143143
</layout>
144144
</item>
145+
<item>
146+
<widget class="QCheckBox" name="chkShowLabels">
147+
<property name="text">
148+
<string>Show labels</string>
149+
</property>
150+
</widget>
151+
</item>
145152
<item>
146153
<widget class="QCheckBox" name="chkShowTileInfo">
147154
<property name="text">

0 commit comments

Comments
 (0)