Skip to content

Commit

Permalink
added temporal vcr widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli authored and nyalldawson committed Mar 12, 2020
1 parent 76e7f76 commit 7700ef3
Show file tree
Hide file tree
Showing 14 changed files with 1,043 additions and 0 deletions.
23 changes: 23 additions & 0 deletions images/themes/default/temporal_navigation/back.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions images/themes/default/temporal_navigation/forward.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions images/themes/default/temporal_navigation/next.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions images/themes/default/temporal_navigation/previous.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions images/themes/default/temporal_navigation/stop.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -364,6 +364,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgslocaldefaultsettings.h"
#include "qgsbearingnumericformat.h"
#include "qgsprojectdisplaysettings.h"
#include "qgstemporalvcrdockwidget.h"

#include "qgsuserprofilemanager.h"
#include "qgsuserprofile.h"
Expand Down Expand Up @@ -1152,6 +1153,11 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mBrowserWidget->setObjectName( QStringLiteral( "Browser" ) );
mBrowserWidget->setMessageBar( mInfoBar );

mTemporalVcrWidget = new QgsTemporalVcrDockWidget( tr( "Temporal VCR" ), this );
mTemporalVcrWidget->setObjectName( QStringLiteral( "Temporal VCR" ) );
addDockWidget( Qt::BottomDockWidgetArea, mTemporalVcrWidget );
mTemporalVcrWidget->hide();

QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsAppDirectoryItemGuiProvider() );
QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsProjectHomeItemGuiProvider() );
QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsProjectItemGuiProvider() );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.h
Expand Up @@ -119,6 +119,7 @@ class QgsAdvancedDigitizingDockWidget;
class QgsGpsInformationWidget;
class QgsStatisticalSummaryDockWidget;
class QgsMapCanvasTracer;
class QgsTemporalVcrDockWidget;

class QgsDecorationItem;
class QgsMessageLogViewer;
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -383,6 +383,7 @@ SET(QGIS_CORE_SRCS
qgsstringutils.cpp
qgstablecell.cpp
qgstaskmanager.cpp
qgstemporalnavigationobject.cpp
qgstemporalproperty.cpp
qgstemporalrangeobject.cpp
qgstessellator.cpp
Expand Down Expand Up @@ -904,6 +905,7 @@ SET(QGIS_CORE_HDRS
qgsstringutils.h
qgstablecell.h
qgstaskmanager.h
qgstemporalnavigationobject.h
qgstemporalproperty.h
qgstemporalrangeobject.h
qgstessellator.h
Expand Down
187 changes: 187 additions & 0 deletions src/core/qgstemporalnavigationobject.cpp
@@ -0,0 +1,187 @@
/***************************************************************************
qgstemporalnavigationobject.cpp
---------------
begin : March 2020
copyright : (C) 2020 by Samweli Mwakisambwe
email : samweli at kartoza dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgstemporalnavigationobject.h"
#include "qgsproject.h"
#include "qgsprojecttimesettings.h"
#include "qgsmaplayer.h"
#include "qgsrasterlayer.h"

QgsTemporalNavigationObject::QgsTemporalNavigationObject()
{
}

QDateTime QgsTemporalNavigationObject::addToDateTime( QDateTime datetime, QString time, int value )
{
if ( time == QString( "Minutes" ) )
{
return datetime.addSecs( value * 60 );
}
if ( time == QString( "Hours" ) )
{
return datetime.addSecs( value * 3600 );
}
if ( time == QString( "Days" ) )
{
return datetime.addDays( value );
}
if ( time == QString( "Months" ) )
{
return datetime.addMonths( value );
}
if ( time == QString( "Years" ) )
{
return datetime.addYears( value );
}

return datetime;
}

void QgsTemporalNavigationObject::updateLayersTemporalRange( QDateTime datetime, QString time, int value )
{
const QMap<QString, QgsMapLayer *> &mapLayers = QgsProject::instance()->mapLayers();
QgsMapLayer *currentLayer = nullptr;

for ( QMap<QString, QgsMapLayer *>::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it )
{
currentLayer = it.value();
if ( !mPlayActive )
break;
if ( currentLayer->type() == QgsMapLayerType::RasterLayer &&
currentLayer->dataProvider() &&
currentLayer->dataProvider()->temporalCapabilities() )
{
QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( currentLayer );
if ( rasterLayer && rasterLayer->dataProvider() &&
rasterLayer->dataProvider()->temporalCapabilities() &&
rasterLayer->dataProvider()->temporalCapabilities()->isActive() )
{
QgsDateTimeRange range = rangeFromMode( rasterLayer, datetime, time, value );
if ( range.begin().isValid() && range.end().isValid() )
{
rasterLayer->dataProvider()->temporalCapabilities()->setTemporalRange( range );
rasterLayer->triggerRepaint();
}
}
}
}
}

QgsDateTimeRange QgsTemporalNavigationObject::rangeFromMode( QgsMapLayer *layer, QDateTime dateTime, QString time, int value )
{
QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( layer );
QList<QDateTime> availableTimes;

if ( rasterLayer &&
rasterLayer->dataProvider() &&
rasterLayer->dataProvider()->temporalCapabilities()
)
availableTimes = rasterLayer->dataProvider()->temporalCapabilities()->dateTimes();

if ( mode() == Mode::Snapshot )
{
if ( availableTimes.contains( dateTime ) )
return QgsDateTimeRange( dateTime, dateTime );
else
return QgsDateTimeRange();
}

if ( mode() == Mode::Composite )
{
QDateTime endDateTime = addToDateTime( dateTime, time, value );
return QgsDateTimeRange( dateTime, endDateTime );
}

if ( mode() == Mode::NearestPreviousProduct )
{
if ( availableTimes.contains( dateTime ) )
return QgsDateTimeRange( dateTime, dateTime );
else
{
QDateTime nearest = lessNearestDateTime( availableTimes, dateTime );
return QgsDateTimeRange( nearest, nearest );
}
}

return QgsDateTimeRange();
}

QDateTime QgsTemporalNavigationObject::lessNearestDateTime( QList<QDateTime> dateTimes, QDateTime dateTime )
{
int difference;
int lowest = 0;
bool found = false;
QDateTime result;

if ( dateTimes.empty() )
return dateTime;

for ( QDateTime currentDateTime : dateTimes )
{
difference = dateTime.msecsTo( currentDateTime );
if ( difference < 0 && difference < lowest )
{
result = currentDateTime;
found = true;
}
}

if ( !found )
result = dateTimes.at( 0 );

return result;
}

void QgsTemporalNavigationObject::setNavigationStatus( NavigationStatus status )
{
mStatus = status;
}

QgsTemporalNavigationObject::NavigationStatus QgsTemporalNavigationObject::navigationStatus() const
{
return mStatus;
}

void QgsTemporalNavigationObject::setMode( Mode mode )
{
mMode = mode;
}

QgsTemporalNavigationObject::Mode QgsTemporalNavigationObject::mode() const
{
return mMode;
}

QList<QDateTime> QgsTemporalNavigationObject::dateTimes() const
{
return mDateTimes;
}

void QgsTemporalNavigationObject::setDateTimes( QList<QDateTime> dateTimes )
{
mDateTimes = dateTimes;
}

void QgsTemporalNavigationObject::setIsPlaying( bool playing )
{
mPlayActive = playing;
}

bool QgsTemporalNavigationObject::isPlaying() const
{
return mPlayActive;
}

0 comments on commit 7700ef3

Please sign in to comment.