Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[3d] add show labels toggle, default to off (#5361)
  • Loading branch information
nirvn committed Oct 13, 2017
1 parent 25d40f3 commit b250729
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/3d/qgs3dmapsettings.cpp
Expand Up @@ -38,6 +38,7 @@ Qgs3DMapSettings::Qgs3DMapSettings()
, mMaxTerrainGroundError( 1.f )
, mShowTerrainBoundingBoxes( false )
, mShowTerrainTileInfo( false )
, mShowLabels( false )
, mSkyboxEnabled( false )
{
}
Expand Down Expand Up @@ -87,6 +88,7 @@ void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteConte
mMapTileResolution = elemTerrain.attribute( "texture-size", "512" ).toInt();
mMaxTerrainScreenError = elemTerrain.attribute( "max-terrain-error", "3" ).toFloat();
mMaxTerrainGroundError = elemTerrain.attribute( "max-ground-error", "1" ).toFloat();
mShowLabels = elemTerrain.attribute( "show-labels", "0" ).toInt();
QDomElement elemMapLayers = elemTerrain.firstChildElement( "layers" );
QDomElement elemMapLayer = elemMapLayers.firstChildElement( "layer" );
QList<QgsMapLayerRef> mapLayers;
Expand Down Expand Up @@ -168,6 +170,7 @@ QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteCon
elemTerrain.setAttribute( "texture-size", mMapTileResolution );
elemTerrain.setAttribute( "max-terrain-error", QString::number( mMaxTerrainScreenError ) );
elemTerrain.setAttribute( "max-ground-error", QString::number( mMaxTerrainGroundError ) );
elemTerrain.setAttribute( "show-labels", mShowLabels ? 1 : 0 );
QDomElement elemMapLayers = doc.createElement( "layers" );
Q_FOREACH ( const QgsMapLayerRef &layerRef, mLayers )
{
Expand Down Expand Up @@ -376,3 +379,12 @@ void Qgs3DMapSettings::setShowTerrainTilesInfo( bool enabled )
mShowTerrainTileInfo = enabled;
emit showTerrainTilesInfoChanged();
}

void Qgs3DMapSettings::setShowLabels( bool enabled )
{
if ( mShowLabels == enabled )
return;

mShowLabels = enabled;
emit showLabelsChanged();
}
7 changes: 7 additions & 0 deletions src/3d/qgs3dmapsettings.h
Expand Up @@ -176,6 +176,10 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
void setShowTerrainTilesInfo( bool enabled );
//! Returns whether to display extra tile info on top of terrain tiles (for debugging)
bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
//! Sets whether to display labels on terrain tiles
void setShowLabels( bool enabled );
//! Returns whether to display labels on terrain tiles
bool showLabels() const { return mShowLabels; }

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

private:
double mOriginX, mOriginY, mOriginZ; //!< Coordinates in map CRS at which our 3D world has origin (0,0,0)
Expand All @@ -211,6 +217,7 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
float mMaxTerrainGroundError; //!< Maximum allowed horizontal map error in map units (determines how many zoom levels will be used)
bool mShowTerrainBoundingBoxes; //!< Whether to show bounding boxes of entities - useful for debugging
bool mShowTerrainTileInfo; //!< Whether to draw extra information about terrain tiles to the textures - useful for debugging
bool mShowLabels; //!< Whether to display labels on terrain tiles
QList<QgsMapLayerRef> mLayers; //!< Layers to be rendered
QList<QgsAbstract3DRenderer *> mRenderers; //!< Extra stuff to render as 3D object
bool mSkyboxEnabled; //!< Whether to render skybox
Expand Down
1 change: 1 addition & 0 deletions src/3d/terrain/qgsterrainentity_p.cpp
Expand Up @@ -63,6 +63,7 @@ QgsTerrainEntity::QgsTerrainEntity( int maxLevel, const Qgs3DMapSettings &map, Q

connect( &map, &Qgs3DMapSettings::showTerrainBoundingBoxesChanged, this, &QgsTerrainEntity::onShowBoundingBoxesChanged );
connect( &map, &Qgs3DMapSettings::showTerrainTilesInfoChanged, this, &QgsTerrainEntity::invalidateMapImages );
connect( &map, &Qgs3DMapSettings::showLabelsChanged, this, &QgsTerrainEntity::invalidateMapImages );
connect( &map, &Qgs3DMapSettings::layersChanged, this, &QgsTerrainEntity::onLayersChanged );
connect( &map, &Qgs3DMapSettings::backgroundColorChanged, this, &QgsTerrainEntity::invalidateMapImages );

Expand Down
1 change: 1 addition & 0 deletions src/3d/terrain/qgsterraintexturegenerator_p.cpp
Expand Up @@ -131,6 +131,7 @@ QgsMapSettings QgsTerrainTextureGenerator::baseMapSettings()
mapSettings.setOutputSize( QSize( mMap.mapTileResolution(), mMap.mapTileResolution() ) );
mapSettings.setDestinationCrs( mMap.crs() );
mapSettings.setBackgroundColor( mMap.backgroundColor() );
mapSettings.setFlag( QgsMapSettings::DrawLabeling, mMap.showLabels() );
return mapSettings;
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/3d/qgs3dmapconfigwidget.cpp
Expand Up @@ -55,6 +55,7 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas
spinMapResolution->setValue( mMap->mapTileResolution() );
spinScreenError->setValue( mMap->maxTerrainScreenError() );
spinGroundError->setValue( mMap->maxTerrainGroundError() );
chkShowLabels->setChecked( mMap->showLabels() );
chkShowTileInfo->setChecked( mMap->showTerrainTilesInfo() );
chkShowBoundingBoxes->setChecked( mMap->showTerrainBoundingBoxes() );

Expand Down Expand Up @@ -93,6 +94,7 @@ void Qgs3DMapConfigWidget::apply()
mMap->setMapTileResolution( spinMapResolution->value() );
mMap->setMaxTerrainScreenError( spinScreenError->value() );
mMap->setMaxTerrainGroundError( spinGroundError->value() );
mMap->setShowLabels( chkShowLabels->isChecked() );
mMap->setShowTerrainTilesInfo( chkShowTileInfo->isChecked() );
mMap->setShowTerrainBoundingBoxes( chkShowBoundingBoxes->isChecked() );
}
Expand Down
7 changes: 7 additions & 0 deletions src/ui/3d/map3dconfigwidget.ui
Expand Up @@ -142,6 +142,13 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="chkShowLabels">
<property name="text">
<string>Show labels</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkShowTileInfo">
<property name="text">
Expand Down

0 comments on commit b250729

Please sign in to comment.