Skip to content
Permalink
Browse files

Cleanup temporal controller dock widget code

  • Loading branch information
nyalldawson committed Mar 12, 2020
1 parent 66e8ef2 commit 5edaef84c5f2234568f8b93b30b68ce1a7d55514
@@ -24,27 +24,17 @@ The QgsTemporalControllerDockWidget class
%End
public:

QgsTemporalControllerDockWidget( const QString &name, QWidget *parent = 0 );
QgsTemporalControllerDockWidget( const QString &name, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsTemporalControllerDockWidget
Constructor for QgsTemporalControllerDockWidget, with the specified ``parent`` widget.
%End

~QgsTemporalControllerDockWidget();

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

enum TimeUnit
{
Seconds,
Minutes,
Hours,
Days,
Months,
Years
};
The dock widget retains ownership of the returned object.
%End

};

@@ -49,11 +49,6 @@ QgsTemporalControllerDockWidget::QgsTemporalControllerDockWidget( const QString
connect( mSettings, &QPushButton::clicked, this, &QgsTemporalControllerDockWidget::settings_clicked );
connect( mSetToProjectTimeButton, &QPushButton::clicked, this, &QgsTemporalControllerDockWidget::setDatesToProjectTime );

init();
}

void QgsTemporalControllerDockWidget::init()
{
QgsDateTimeRange range;

if ( QgsProject::instance()->timeSettings() )
@@ -71,28 +66,36 @@ void QgsTemporalControllerDockWidget::init()

mSetToProjectTimeButton->setToolTip( tr( "Set datetimes inputs to match project time" ) );

mTimeStepsComboBox->addItem( tr( "Seconds" ), QgsTemporalControllerDockWidget::Seconds );
mTimeStepsComboBox->addItem( tr( "Minutes" ), QgsTemporalControllerDockWidget::Minutes );
mTimeStepsComboBox->addItem( tr( "Hours" ), QgsTemporalControllerDockWidget::Hours );
mTimeStepsComboBox->addItem( tr( "Days" ), QgsTemporalControllerDockWidget::Days );
mTimeStepsComboBox->addItem( tr( "Months" ), QgsTemporalControllerDockWidget::Months );
mTimeStepsComboBox->addItem( tr( "Years" ), QgsTemporalControllerDockWidget::Years );
for ( QgsUnitTypes::TemporalUnit u :
{
QgsUnitTypes::TemporalMilliseconds,
QgsUnitTypes::TemporalSeconds,
QgsUnitTypes::TemporalMinutes,
QgsUnitTypes::TemporalHours,
QgsUnitTypes::TemporalDays,
QgsUnitTypes::TemporalWeeks,
QgsUnitTypes::TemporalMonths,
QgsUnitTypes::TemporalYears,
QgsUnitTypes::TemporalDecades,
QgsUnitTypes::TemporalCenturies
} )
{
mTimeStepsComboBox->addItem( QgsUnitTypes::toString( u ), u );
}

mTimeStepsComboBox->setCurrentIndex( mTimeStepsComboBox->findData(
QgsTemporalControllerDockWidget::Hours ) );
// TODO: might want to choose an appropriate default unit based on the range
mTimeStepsComboBox->setCurrentIndex( mTimeStepsComboBox->findData( QgsUnitTypes::TemporalHours ) );

mSpinBox->setMinimum( 0.0000001 );
mSpinBox->setSingleStep( 1 );
mSpinBox->setValue( 1 );
mSpinBox->setEnabled( true );

mForwardButton->setToolTip( tr( "Play" ) );
mBackButton->setToolTip( tr( "Reverse" ) );
mNextButton->setToolTip( tr( "Go to next frame" ) );
mPreviousButton->setToolTip( tr( "Go to previous frame" ) );
mStopButton->setToolTip( tr( "Pause" ) );

updateTemporalExtent();
updateFrameDuration();
}

@@ -107,8 +110,7 @@ void QgsTemporalControllerDockWidget::updateTemporalExtent()

void QgsTemporalControllerDockWidget::updateFrameDuration()
{
mNavigationObject->setFrameDuration( interval( mTimeStepsComboBox->currentData().toInt(),
mSpinBox->value() ) );
mNavigationObject->setFrameDuration( QgsInterval( mSpinBox->value(), static_cast< QgsUnitTypes::TemporalUnit>( mTimeStepsComboBox->currentData().toInt() ) ) );
mSlider->setRange( 0, mNavigationObject->totalFrameCount() - 1 );
}

@@ -133,60 +135,20 @@ QgsTemporalController *QgsTemporalControllerDockWidget::temporalController()

void QgsTemporalControllerDockWidget::settings_clicked()
{
QgsTemporalMapSettingsDialog dialog( this );
dialog.mapSettingsWidget()->setFrameRateValue( mNavigationObject->framesPerSeconds() );

QgsTemporalMapSettingsDialog *dialog = new QgsTemporalMapSettingsDialog( this );
dialog->setAttribute( Qt::WA_DeleteOnClose );

if ( dialog->mapSettingsWidget() )
dialog->mapSettingsWidget()->setFrameRateValue(
mNavigationObject->framesPerSeconds() );

dialog->setVisible( true );

connect( dialog->mapSettingsWidget(), &QgsTemporalMapSettingsWidget::frameRateChanged, this, [ this, dialog ]()
if ( dialog.exec() )
{
mNavigationObject->setFramesPerSeconds( dialog->mapSettingsWidget()->frameRateValue() );
} );
mNavigationObject->setFramesPerSeconds( dialog.mapSettingsWidget()->frameRateValue() );
}
}

void QgsTemporalControllerDockWidget::timeSlider_valueChanged( int value )
{
mNavigationObject->setCurrentFrameNumber( value );
}

QgsInterval QgsTemporalControllerDockWidget::interval( int time, double value )
{
QgsInterval interval;

if ( time == QgsTemporalControllerDockWidget::Seconds )
{
interval.setSeconds( value );
}
if ( time == QgsTemporalControllerDockWidget::Minutes )
{
interval.setMinutes( value );
}
if ( time == QgsTemporalControllerDockWidget::Hours )
{
interval.setHours( value );
}
if ( time == QgsTemporalControllerDockWidget::Days )
{
interval.setDays( value );
}
if ( time == QgsTemporalControllerDockWidget::Months )
{
interval.setMonths( value );
}
if ( time == QgsTemporalControllerDockWidget::Years )
{
interval.setYears( value );
}

return interval;
}


void QgsTemporalControllerDockWidget::setDatesToProjectTime()
{
QgsDateTimeRange range;
@@ -23,13 +23,13 @@
#include "qgsdockwidget.h"
#include "qgis_gui.h"
#include "qgsrange.h"
#include "qgsinterval.h"

class QgsMapLayer;
class QgsTemporalNavigationObject;
class QgsTemporalMapSettingsWidget;
class QgsTemporalMapSettingsDialog;
class QgsTemporalController;
class QgsInterval;

/**
* \ingroup gui
@@ -43,36 +43,19 @@ class GUI_EXPORT QgsTemporalControllerDockWidget : public QgsDockWidget, private
public:

/**
* Constructor for QgsTemporalControllerDockWidget
*
* Constructor for QgsTemporalControllerDockWidget, with the specified \a parent widget.
*/
QgsTemporalControllerDockWidget( const QString &name, QWidget *parent = nullptr );

~QgsTemporalControllerDockWidget() = default;
QgsTemporalControllerDockWidget( const QString &name, QWidget *parent SIP_TRANSFERTHIS = nullptr );

/**
* Returns the temporal controller object used by this object in navigation.
*
* The dock widget retains ownership of the returned object.
*/
QgsTemporalController *temporalController();

//! Stores the used time unit in the animation frame duration.
enum TimeUnit
{
Seconds = 0, //! For seconds
Minutes = 1, //! For minutes
Hours = 2, //! For hours
Days = 3, //! For days
Months = 4, //! For months
Years = 5 //! For years
};

private:

/**
* Initialize the widget with default state.
*/
void init();

/**
* Updates the controller widget navigation buttons enabled status.
*/
@@ -83,12 +66,6 @@ class GUI_EXPORT QgsTemporalControllerDockWidget : public QgsDockWidget, private
**/
void setDateInputsEnable( bool enabled );

/**
* Returns the time interval using the passed \a value and \a time
* to determine the interval duration.
*/
QgsInterval interval( int time, double value );

//! Handles all non gui navigation logic
QgsTemporalNavigationObject *mNavigationObject = nullptr;

0 comments on commit 5edaef8

Please sign in to comment.
You can’t perform that action at this time.