Skip to content

Commit

Permalink
[3d] Show a movement speed label temporarily after the movement
Browse files Browse the repository at this point in the history
speed is changed in 3d views via scroll wheel

Exposes to users what the scroll wheel is actually doing in this mode
  • Loading branch information
nyalldawson committed Jan 17, 2021
1 parent 4317c4c commit f16c256
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/3d/qgs3dmapcanvas.cpp
Expand Up @@ -116,6 +116,7 @@ void Qgs3DMapCanvas::setMap( Qgs3DMapSettings *map )
QCursor::setPos( mapToGlobal( point ) );
} );
connect( cameraController(), &QgsCameraController::cameraMovementSpeedChanged, mMap, &Qgs3DMapSettings::setCameraMovementSpeed );
connect( cameraController(), &QgsCameraController::cameraMovementSpeedChanged, this, &Qgs3DMapCanvas::cameraNavigationSpeedChanged );
connect( cameraController(), &QgsCameraController::navigationModeHotKeyPressed, this, &Qgs3DMapCanvas::onNavigationModeHotKeyPressed );

emit mapSettingsChanged();
Expand Down
8 changes: 8 additions & 0 deletions src/app/3d/qgs3dmapcanvas.h
Expand Up @@ -104,6 +104,14 @@ class Qgs3DMapCanvas : public QWidget
void fpsCountChanged( float fpsCount );
//! Emitted when the FPS counter is enabled or disabeld
void fpsCounterEnabledChanged( bool enabled );

/**
* Emitted when the camera navigation \a speed is changed.
*
* \since QGIS 3.18
*/
void cameraNavigationSpeedChanged( double speed );

private slots:
void updateTemporalRange( const QgsDateTimeRange &timeRange );
void onNavigationModeHotKeyPressed( QgsCameraController::NavigationMode mode );
Expand Down
20 changes: 20 additions & 0 deletions src/app/3d/qgs3dmapcanvasdockwidget.cpp
Expand Up @@ -178,6 +178,7 @@ Qgs3DMapCanvasDockWidget::Qgs3DMapCanvasDockWidget( QWidget *parent )
mProgressPendingJobs = new QProgressBar( this );
mProgressPendingJobs->setRange( 0, 0 );
mLabelFpsCounter = new QLabel( this );
mLabelNavigationSpeed = new QLabel( this );

mAnimationWidget = new Qgs3DAnimationWidget( this );
mAnimationWidget->setVisible( false );
Expand All @@ -189,8 +190,18 @@ Qgs3DMapCanvasDockWidget::Qgs3DMapCanvasDockWidget( QWidget *parent )
topLayout->addStretch( 1 );
topLayout->addWidget( mLabelPendingJobs );
topLayout->addWidget( mProgressPendingJobs );
topLayout->addWidget( mLabelNavigationSpeed );
mLabelNavigationSpeed->hide();
topLayout->addWidget( mLabelFpsCounter );

mLabelNavSpeedHideTimeout = new QTimer( this );
mLabelNavSpeedHideTimeout->setInterval( 1000 );
connect( mLabelNavSpeedHideTimeout, &QTimer::timeout, this, [ = ]
{
mLabelNavigationSpeed->hide();
mLabelNavSpeedHideTimeout->stop();
} );

QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins( 0, 0, 0, 0 );
layout->setSpacing( 0 );
Expand Down Expand Up @@ -283,6 +294,8 @@ void Qgs3DMapCanvasDockWidget::setMapSettings( Qgs3DMapSettings *map )
// Disable button for switching the map theme if the terrain generator is a mesh
mBtnMapThemes->setDisabled( mCanvas->map()->terrainGenerator()->type() == QgsTerrainGenerator::Mesh );
mLabelFpsCounter->setVisible( map->isFpsCounterEnabled() );

connect( mCanvas, &Qgs3DMapCanvas::cameraNavigationSpeedChanged, this, &Qgs3DMapCanvasDockWidget::cameraNavigationSpeedChanged );
}

void Qgs3DMapCanvasDockWidget::setMainCanvas( QgsMapCanvas *canvas )
Expand Down Expand Up @@ -412,6 +425,13 @@ void Qgs3DMapCanvasDockWidget::updateFpsCount( float fpsCount )
mLabelFpsCounter->setText( QStringLiteral( "%1 fps" ).arg( fpsCount, 10, 'f', 2, QLatin1Char( ' ' ) ) );
}

void Qgs3DMapCanvasDockWidget::cameraNavigationSpeedChanged( double speed )
{
mLabelNavigationSpeed->setText( QStringLiteral( "Speed: %1 ×" ).arg( QString::number( speed, 'f', 2 ) ) );
mLabelNavigationSpeed->show();
mLabelNavSpeedHideTimeout->start();
}

void Qgs3DMapCanvasDockWidget::mapThemeMenuAboutToShow()
{
qDeleteAll( mMapThemeMenuPresetActions );
Expand Down
3 changes: 3 additions & 0 deletions src/app/3d/qgs3dmapcanvasdockwidget.h
Expand Up @@ -67,6 +67,7 @@ class APP_EXPORT Qgs3DMapCanvasDockWidget : public QgsDockWidget
void onMainCanvasColorChanged();
void onTotalPendingJobsCountChanged();
void updateFpsCount( float fpsCount );
void cameraNavigationSpeedChanged( double speed );
void mapThemeMenuAboutToShow();
//! Renames the active map theme called \a theme to \a newTheme
void currentMapThemeRenamed( const QString &theme, const QString &newTheme );
Expand All @@ -78,6 +79,8 @@ class APP_EXPORT Qgs3DMapCanvasDockWidget : public QgsDockWidget
QProgressBar *mProgressPendingJobs = nullptr;
QLabel *mLabelPendingJobs = nullptr;
QLabel *mLabelFpsCounter = nullptr;
QLabel *mLabelNavigationSpeed = nullptr;
QTimer *mLabelNavSpeedHideTimeout = nullptr;
Qgs3DMapToolIdentify *mMapToolIdentify = nullptr;
Qgs3DMapToolMeasureLine *mMapToolMeasureLine = nullptr;
QMenu *mMapThemeMenu = nullptr;
Expand Down

0 comments on commit f16c256

Please sign in to comment.