Skip to content

Commit

Permalink
A horizontal mouse wheel scroll over the canvas "scrubs" the temporal
Browse files Browse the repository at this point in the history
range slider back or forward
  • Loading branch information
nyalldawson committed Feb 24, 2021
1 parent 5cbd3e9 commit ad56216
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
Expand Up @@ -29,7 +29,7 @@ A widget for controlling playback properties of a :py:class:`QgsTemporalControll
Constructor for QgsTemporalControllerWidget, with the specified ``parent`` widget.
%End

QgsTemporalController *temporalController();
QgsTemporalNavigationObject *temporalController();
%Docstring
Returns the temporal controller object used by this object in navigation.

Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -1226,6 +1226,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mTemporalControllerWidget->setToggleVisibilityAction( mActionTemporalController );

mMapCanvas->setTemporalController( mTemporalControllerWidget->temporalController() );
mTemporalControllerWidget->setMapCanvas( mMapCanvas );

QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsAppDirectoryItemGuiProvider() );
QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsProjectHomeItemGuiProvider() );
Expand Down
22 changes: 22 additions & 0 deletions src/app/qgstemporalcontrollerdockwidget.cpp
Expand Up @@ -51,6 +51,28 @@ QgsTemporalController *QgsTemporalControllerDockWidget::temporalController()
return mControllerWidget->temporalController();
}

void QgsTemporalControllerDockWidget::setMapCanvas( QgsMapCanvas *canvas )
{
if ( canvas && canvas->viewport() )
canvas->viewport()->installEventFilter( this );
}

bool QgsTemporalControllerDockWidget::eventFilter( QObject *object, QEvent *event )
{
if ( event->type() == QEvent::Wheel )
{
QWheelEvent *wheelEvent = dynamic_cast< QWheelEvent * >( event );
// handle horizontal wheel events by scrubbing timeline
if ( wheelEvent->angleDelta().x() != 0 )
{
const int step = -wheelEvent->angleDelta().x() / 120.0;
mControllerWidget->temporalController()->setCurrentFrameNumber( mControllerWidget->temporalController()->currentFrameNumber() + step );
return true;
}
}
return QgsDockWidget::eventFilter( object, event );
}

void QgsTemporalControllerDockWidget::exportAnimation()
{
QgsAnimationExportDialog *dlg = new QgsAnimationExportDialog( this, QgisApp::instance()->mapCanvas(), QgisApp::instance()->activeDecorations() );
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgstemporalcontrollerdockwidget.h
Expand Up @@ -23,6 +23,7 @@

class QgsTemporalControllerWidget;
class QgsTemporalController;
class QgsMapCanvas;

/**
* \ingroup app
Expand All @@ -47,6 +48,12 @@ class APP_EXPORT QgsTemporalControllerDockWidget : public QgsDockWidget
*/
QgsTemporalController *temporalController();

void setMapCanvas( QgsMapCanvas *canvas );

protected:

bool eventFilter( QObject *object, QEvent *event ) override;

private slots:

void exportAnimation();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgstemporalcontrollerwidget.cpp
Expand Up @@ -480,7 +480,7 @@ void QgsTemporalControllerWidget::updateRangeLabel( const QgsDateTimeRange &rang
}
}

QgsTemporalController *QgsTemporalControllerWidget::temporalController()
QgsTemporalNavigationObject *QgsTemporalControllerWidget::temporalController()
{
return mNavigationObject;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgstemporalcontrollerwidget.h
Expand Up @@ -51,7 +51,7 @@ class GUI_EXPORT QgsTemporalControllerWidget : public QgsPanelWidget, private Ui
*
* The dock widget retains ownership of the returned object.
*/
QgsTemporalController *temporalController();
QgsTemporalNavigationObject *temporalController();

#ifndef SIP_RUN

Expand Down

0 comments on commit ad56216

Please sign in to comment.