Skip to content
Permalink
Browse files

Save the time step and frame rate settings into the project and restore

alongside projects
  • Loading branch information
nyalldawson committed Mar 12, 2020
1 parent ac3409e commit d66175ac9820649460bf845a5c0ebc5ad37fc94f
@@ -77,6 +77,64 @@ Reads the settings's state from a DOM ``element``.
Returns a DOM element representing the settings.

.. seealso:: :py:func:`readXml`
%End

QgsUnitTypes::TemporalUnit timeStepUnit() const;
%Docstring
Returns the project's time step (length of one animation frame) unit, which is used as the default value when
animating the project.

.. seealso:: :py:func:`setTimeStepUnit`

.. seealso:: :py:func:`timeStep`
%End

void setTimeStepUnit( QgsUnitTypes::TemporalUnit unit );
%Docstring
Sets the project's time step (length of one animation frame) ``unit``, which is used as the default value when
animating the project.

.. seealso:: :py:func:`timeStepUnit`

.. seealso:: :py:func:`setTimeStep`
%End

double timeStep() const;
%Docstring
Returns the project's time step (length of one animation frame), which is used as the default value when
animating the project.

Units are specified via timeStepUnit()

.. seealso:: :py:func:`setTimeStep`

.. seealso:: :py:func:`timeStepUnit`
%End

void setTimeStep( double step );
%Docstring
Sets the project's time ``step`` (length of one animation frame), which is used as the default value when
animating the project.

Units are specified via setTimeStepUnit()

.. seealso:: :py:func:`timeStep`

.. seealso:: :py:func:`setTimeStepUnit`
%End

void setFramesPerSecond( double rate );
%Docstring
Sets the project's default animation frame ``rate``, in frames per second.

.. seealso:: :py:func:`framesPerSecond`
%End

double framesPerSecond() const;
%Docstring
Returns the project's default animation frame rate, in frames per second.

.. seealso:: :py:func:`setFramesPerSecond`
%End

signals:
@@ -60,6 +60,10 @@ bool QgsProjectTimeSettings::readXml( const QDomElement &element, const QgsReadW

}

mTimeStepUnit = QgsUnitTypes::decodeTemporalUnit( element.attribute( QStringLiteral( "timeStepUnit" ), QgsUnitTypes::encodeUnit( QgsUnitTypes::TemporalHours ) ) );
mTimeStep = element.attribute( QStringLiteral( "timeStep" ), "1" ).toDouble();
mFrameRate = element.attribute( QStringLiteral( "frameRate" ), "1" ).toDouble();

return true;
}

@@ -85,5 +89,40 @@ QDomElement QgsProjectTimeSettings::writeXml( QDomDocument &document, const QgsR
element.appendChild( temporalElement );
}

element.setAttribute( QStringLiteral( "timeStepUnit" ), QgsUnitTypes::encodeUnit( mTimeStepUnit ) );
element.setAttribute( QStringLiteral( "timeStep" ), qgsDoubleToString( mTimeStep ) );
element.setAttribute( QStringLiteral( "frameRate" ), qgsDoubleToString( mFrameRate ) );

return element;
}

QgsUnitTypes::TemporalUnit QgsProjectTimeSettings::timeStepUnit() const
{
return mTimeStepUnit;
}

void QgsProjectTimeSettings::setTimeStepUnit( QgsUnitTypes::TemporalUnit unit )
{
mTimeStepUnit = unit;
}

double QgsProjectTimeSettings::timeStep() const
{
return mTimeStep;
}

void QgsProjectTimeSettings::setTimeStep( double timeStep )
{
mTimeStep = timeStep;
}

void QgsProjectTimeSettings::setFramesPerSecond( double rate )
{
mFrameRate = rate;
}

double QgsProjectTimeSettings::framesPerSecond() const
{
return mFrameRate;
}

@@ -19,6 +19,7 @@

#include "qgis_core.h"
#include "qgsrange.h"
#include "qgsunittypes.h"
#include <QObject>

class QDomElement;
@@ -86,6 +87,60 @@ class CORE_EXPORT QgsProjectTimeSettings : public QObject
*/
QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const;

/**
* Returns the project's time step (length of one animation frame) unit, which is used as the default value when
* animating the project.
*
* \see setTimeStepUnit()
* \see timeStep()
*/
QgsUnitTypes::TemporalUnit timeStepUnit() const;

/**
* Sets the project's time step (length of one animation frame) \a unit, which is used as the default value when
* animating the project.
*
* \see timeStepUnit()
* \see setTimeStep()
*/
void setTimeStepUnit( QgsUnitTypes::TemporalUnit unit );

/**
* Returns the project's time step (length of one animation frame), which is used as the default value when
* animating the project.
*
* Units are specified via timeStepUnit()
*
* \see setTimeStep()
* \see timeStepUnit()
*/
double timeStep() const;

/**
* Sets the project's time \a step (length of one animation frame), which is used as the default value when
* animating the project.
*
* Units are specified via setTimeStepUnit()
*
* \see timeStep()
* \see setTimeStepUnit()
*/
void setTimeStep( double step );

/**
* Sets the project's default animation frame \a rate, in frames per second.
*
* \see framesPerSecond()
*/
void setFramesPerSecond( double rate );

/**
* Returns the project's default animation frame rate, in frames per second.
*
* \see setFramesPerSecond()
*/
double framesPerSecond() const;

signals:

/**
@@ -99,6 +154,9 @@ class CORE_EXPORT QgsProjectTimeSettings : public QObject
private:

QgsDateTimeRange mRange;
QgsUnitTypes::TemporalUnit mTimeStepUnit = QgsUnitTypes::TemporalHours;
double mTimeStep = 1;
double mFrameRate = 1;
};


@@ -109,6 +109,8 @@ QgsTemporalControllerDockWidget::QgsTemporalControllerDockWidget( const QString
mFastForwardButton->setToolTip( tr( "Fast forward to end" ) );

updateFrameDuration();

connect( QgsProject::instance(), &QgsProject::readProject, this, &QgsTemporalControllerDockWidget::setWidgetStateFromProject );
}

void QgsTemporalControllerDockWidget::updateTemporalExtent()
@@ -122,10 +124,29 @@ void QgsTemporalControllerDockWidget::updateTemporalExtent()

void QgsTemporalControllerDockWidget::updateFrameDuration()
{
mNavigationObject->setFrameDuration( QgsInterval( mSpinBox->value(), static_cast< QgsUnitTypes::TemporalUnit>( mTimeStepsComboBox->currentData().toInt() ) ) );
if ( mBlockSettingUpdates )
return;

// save new settings into project
QgsProject::instance()->timeSettings()->setTimeStepUnit( static_cast< QgsUnitTypes::TemporalUnit>( mTimeStepsComboBox->currentData().toInt() ) );
QgsProject::instance()->timeSettings()->setTimeStep( mSpinBox->value() );

mNavigationObject->setFrameDuration( QgsInterval( QgsProject::instance()->timeSettings()->timeStep(),
QgsProject::instance()->timeSettings()->timeStepUnit() ) );
mSlider->setRange( 0, mNavigationObject->totalFrameCount() - 1 );
}

void QgsTemporalControllerDockWidget::setWidgetStateFromProject()
{
mBlockSettingUpdates++;
mTimeStepsComboBox->setCurrentIndex( mTimeStepsComboBox->findData( QgsProject::instance()->timeSettings()->timeStepUnit() ) );
mSpinBox->setValue( QgsProject::instance()->timeSettings()->timeStep() );
mBlockSettingUpdates--;
updateFrameDuration();

mNavigationObject->setFramesPerSecond( QgsProject::instance()->timeSettings()->framesPerSecond() );
}

void QgsTemporalControllerDockWidget::updateSlider( const QgsDateTimeRange &range )
{
whileBlocking( mSlider )->setValue( mNavigationObject->currentFrameNumber() );
@@ -148,11 +169,14 @@ QgsTemporalController *QgsTemporalControllerDockWidget::temporalController()
void QgsTemporalControllerDockWidget::settings_clicked()
{
QgsTemporalMapSettingsDialog dialog( this );
dialog.mapSettingsWidget()->setFrameRateValue( mNavigationObject->framesPerSeconds() );
dialog.mapSettingsWidget()->setFrameRateValue( mNavigationObject->framesPerSecond() );

if ( dialog.exec() )
{
mNavigationObject->setFramesPerSeconds( dialog.mapSettingsWidget()->frameRateValue() );
// save new settings into project
QgsProject::instance()->timeSettings()->setFramesPerSecond( dialog.mapSettingsWidget()->frameRateValue() );

mNavigationObject->setFramesPerSecond( QgsProject::instance()->timeSettings()->framesPerSecond() );
}
}

@@ -69,6 +69,8 @@ class GUI_EXPORT QgsTemporalControllerDockWidget : public QgsDockWidget, private
//! Handles all non gui navigation logic
QgsTemporalNavigationObject *mNavigationObject = nullptr;

int mBlockSettingUpdates = 0;

private slots:

/**
@@ -107,6 +109,9 @@ class GUI_EXPORT QgsTemporalControllerDockWidget : public QgsDockWidget, private
**/
void updateFrameDuration();

void setWidgetStateFromProject();


};

#endif // QGSTEMPORALCONTROLLERDOCKWIDGET_H

0 comments on commit d66175a

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