Skip to content

Commit ad56216

Browse files
committedFeb 24, 2021
A horizontal mouse wheel scroll over the canvas "scrubs" the temporal
range slider back or forward
1 parent 5cbd3e9 commit ad56216

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed
 

‎python/gui/auto_generated/qgstemporalcontrollerwidget.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ A widget for controlling playback properties of a :py:class:`QgsTemporalControll
2929
Constructor for QgsTemporalControllerWidget, with the specified ``parent`` widget.
3030
%End
3131

32-
QgsTemporalController *temporalController();
32+
QgsTemporalNavigationObject *temporalController();
3333
%Docstring
3434
Returns the temporal controller object used by this object in navigation.
3535

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
12261226
mTemporalControllerWidget->setToggleVisibilityAction( mActionTemporalController );
12271227

12281228
mMapCanvas->setTemporalController( mTemporalControllerWidget->temporalController() );
1229+
mTemporalControllerWidget->setMapCanvas( mMapCanvas );
12291230

12301231
QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsAppDirectoryItemGuiProvider() );
12311232
QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsProjectHomeItemGuiProvider() );

‎src/app/qgstemporalcontrollerdockwidget.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ QgsTemporalController *QgsTemporalControllerDockWidget::temporalController()
5151
return mControllerWidget->temporalController();
5252
}
5353

54+
void QgsTemporalControllerDockWidget::setMapCanvas( QgsMapCanvas *canvas )
55+
{
56+
if ( canvas && canvas->viewport() )
57+
canvas->viewport()->installEventFilter( this );
58+
}
59+
60+
bool QgsTemporalControllerDockWidget::eventFilter( QObject *object, QEvent *event )
61+
{
62+
if ( event->type() == QEvent::Wheel )
63+
{
64+
QWheelEvent *wheelEvent = dynamic_cast< QWheelEvent * >( event );
65+
// handle horizontal wheel events by scrubbing timeline
66+
if ( wheelEvent->angleDelta().x() != 0 )
67+
{
68+
const int step = -wheelEvent->angleDelta().x() / 120.0;
69+
mControllerWidget->temporalController()->setCurrentFrameNumber( mControllerWidget->temporalController()->currentFrameNumber() + step );
70+
return true;
71+
}
72+
}
73+
return QgsDockWidget::eventFilter( object, event );
74+
}
75+
5476
void QgsTemporalControllerDockWidget::exportAnimation()
5577
{
5678
QgsAnimationExportDialog *dlg = new QgsAnimationExportDialog( this, QgisApp::instance()->mapCanvas(), QgisApp::instance()->activeDecorations() );

‎src/app/qgstemporalcontrollerdockwidget.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
class QgsTemporalControllerWidget;
2525
class QgsTemporalController;
26+
class QgsMapCanvas;
2627

2728
/**
2829
* \ingroup app
@@ -47,6 +48,12 @@ class APP_EXPORT QgsTemporalControllerDockWidget : public QgsDockWidget
4748
*/
4849
QgsTemporalController *temporalController();
4950

51+
void setMapCanvas( QgsMapCanvas *canvas );
52+
53+
protected:
54+
55+
bool eventFilter( QObject *object, QEvent *event ) override;
56+
5057
private slots:
5158

5259
void exportAnimation();

‎src/gui/qgstemporalcontrollerwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ void QgsTemporalControllerWidget::updateRangeLabel( const QgsDateTimeRange &rang
480480
}
481481
}
482482

483-
QgsTemporalController *QgsTemporalControllerWidget::temporalController()
483+
QgsTemporalNavigationObject *QgsTemporalControllerWidget::temporalController()
484484
{
485485
return mNavigationObject;
486486
}

‎src/gui/qgstemporalcontrollerwidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class GUI_EXPORT QgsTemporalControllerWidget : public QgsPanelWidget, private Ui
5151
*
5252
* The dock widget retains ownership of the returned object.
5353
*/
54-
QgsTemporalController *temporalController();
54+
QgsTemporalNavigationObject *temporalController();
5555

5656
#ifndef SIP_RUN
5757

0 commit comments

Comments
 (0)
Please sign in to comment.