Skip to content
Permalink
Browse files

added temporal vcr widget

  • Loading branch information
Samweli authored and nyalldawson committed Mar 6, 2020
1 parent 76e7f76 commit 7700ef34b2841a10a244f207a9ba8e0bd7902b35
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg width="48" height="48" version="1.1" viewBox="0 0 12.7 12.7" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<metadata>
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<rect x="41.424" y="9.3896" width="6.3597" height="5.7683" ry=".2804" stroke-width=".014877"/>
<g transform="translate(-1.5964 -284.57)" stroke-width=".26458">
<path d="m53.422 300.58-0.01645-3.6732 0.03081-3.6733 4.2161 1.8148 4.1923 1.8458-4.1996 1.8584z" stroke-width=".01933"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 39.094 292.46)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 27.601 292.89)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 31.75 292.78)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(.048247 -.0013249 .0011336 .041078 62.033 281.6)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(.048247 -.0013249 .0011336 .041078 57.884 281.7)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
</g>
<path d="m10.431 2.68 0.04082 3.673-0.0064 3.6734-4.228-1.7868-4.2045-1.818 4.1871-1.8862z" stroke-width=".01933"/>
</svg>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg width="48" height="48" version="1.1" viewBox="0 0 12.7 12.7" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<metadata>
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<rect x="41.424" y="9.3896" width="6.3597" height="5.7683" ry=".2804" stroke-width=".014877"/>
<g transform="translate(-1.4633 -284.7)" stroke-width=".26458">
<path d="m4.5999 294.59-0.016452-3.6732 0.030812-3.6733 4.2161 1.8148 4.1923 1.8458-4.1996 1.8584z" stroke-width=".01933"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 39.094 292.46)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 27.601 292.89)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 31.75 292.78)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(.048247 -.0013249 .0011336 .041078 62.033 281.6)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(.048247 -.0013249 .0011336 .041078 57.884 281.7)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
</g>
</svg>
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg width="48" height="48" version="1.1" viewBox="0 0 12.7 12.7" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<metadata>
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<rect x="41.424" y="9.3896" width="6.3597" height="5.7683" ry=".2804" stroke-width=".014877"/>
<g transform="translate(-1.5964 -284.57)" stroke-width=".26458">
<path d="m53.422 300.58-0.01645-3.6732 0.03081-3.6733 4.2161 1.8148 4.1923 1.8458-4.1996 1.8584z" stroke-width=".01933"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 39.094 292.46)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 27.601 292.89)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 31.75 292.78)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(.048247 -.0013249 .0011336 .041078 62.033 281.6)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(.048247 -.0013249 .0011336 .041078 57.884 281.7)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
</g>
<path d="m38.102 9.0655 0.04082 3.673-0.0064 3.6734-4.228-1.7868-4.2045-1.818 4.1871-1.8862z" stroke-width=".01933"/>
<path d="m5.7198 10.121-0.037043-3.9058-0.0016855-3.9062 3.1691 1.8948 3.1515 1.9279-3.132 2.0109z" stroke-width=".017249"/>
<path d="m0.34067 10.197-0.037047-3.9058-0.0016778-3.9062 3.1691 1.8948 3.1515 1.9279-3.132 2.0109z" stroke-width=".017249"/>
</svg>
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg width="48" height="48" version="1.1" viewBox="0 0 12.7 12.7" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<metadata>
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<rect x="41.424" y="9.3896" width="6.3597" height="5.7683" ry=".2804" stroke-width=".014877"/>
<g transform="translate(-1.5964 -284.57)" stroke-width=".26458">
<path d="m53.422 300.58-0.01645-3.6732 0.03081-3.6733 4.2161 1.8148 4.1923 1.8458-4.1996 1.8584z" stroke-width=".01933"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 39.094 292.46)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 27.601 292.89)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 31.75 292.78)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(.048247 -.0013249 .0011336 .041078 62.033 281.6)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(.048247 -.0013249 .0011336 .041078 57.884 281.7)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
</g>
<path d="m38.102 9.0655 0.04082 3.673-0.0064 3.6734-4.228-1.7868-4.2045-1.818 4.1871-1.8862z" stroke-width=".01933"/>
<path d="m6.5921 2.3087 0.030566 3.9058-0.0047923 3.9062-3.1659-1.9001-3.1483-1.9332 3.1353-2.0057z" stroke-width=".017249"/>
<path d="m11.971 2.3087 0.03057 3.9058-0.0048 3.9062-3.1659-1.9001-3.1483-1.9332 3.1353-2.0057z" stroke-width=".017249"/>
</svg>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg width="48" height="48" version="1.1" viewBox="0 0 12.7 12.7" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<metadata>
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<rect x="3.3774" y="3.3367" width="6.3597" height="5.7683" ry=".2804" stroke-width=".014877"/>
<g transform="translate(0,-284.3)" stroke-width=".26458">
<path transform="matrix(.048262 -.00053303 .00045938 .041091 50.319 281.5)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 39.094 292.46)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 27.601 292.89)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(-.048247 .0013249 -.0011336 -.041078 31.75 292.78)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(.048247 -.0013249 .0011336 .041078 62.033 281.6)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
<path transform="matrix(.048247 -.0013249 .0011336 .041078 57.884 281.7)" d="m-3.7798 187.39 0.35453-57.823 0.91702-57.816 49.899 29.218 49.612 29.702-50.253 28.604z"/>
</g>
</svg>
@@ -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"
@@ -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() );
@@ -119,6 +119,7 @@ class QgsAdvancedDigitizingDockWidget;
class QgsGpsInformationWidget;
class QgsStatisticalSummaryDockWidget;
class QgsMapCanvasTracer;
class QgsTemporalVcrDockWidget;

class QgsDecorationItem;
class QgsMessageLogViewer;
@@ -383,6 +383,7 @@ SET(QGIS_CORE_SRCS
qgsstringutils.cpp
qgstablecell.cpp
qgstaskmanager.cpp
qgstemporalnavigationobject.cpp
qgstemporalproperty.cpp
qgstemporalrangeobject.cpp
qgstessellator.cpp
@@ -904,6 +905,7 @@ SET(QGIS_CORE_HDRS
qgsstringutils.h
qgstablecell.h
qgstaskmanager.h
qgstemporalnavigationobject.h
qgstemporalproperty.h
qgstemporalrangeobject.h
qgstessellator.h
@@ -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.
You can’t perform that action at this time.