Skip to content

Commit

Permalink
[feature][quick] Add temporal handling to map {canvas,settings}
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn authored and nyalldawson committed Sep 25, 2022
1 parent f55b838 commit 1f4e564
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/quickgui/qgsquickmapcanvasmap.cpp
Expand Up @@ -19,6 +19,7 @@

#include "qgis.h"
#include "qgsexpressioncontextutils.h"
#include "qgsmaplayertemporalproperties.h"
#include "qgsmaprenderercache.h"
#include "qgsmaprendererparalleljob.h"
#include "qgsmessagelog.h"
Expand All @@ -43,6 +44,7 @@ QgsQuickMapCanvasMap::QgsQuickMapCanvasMap( QQuickItem *parent )

connect( mMapSettings.get(), &QgsQuickMapSettings::extentChanged, this, &QgsQuickMapCanvasMap::onExtentChanged );
connect( mMapSettings.get(), &QgsQuickMapSettings::layersChanged, this, &QgsQuickMapCanvasMap::onLayersChanged );
connect( mMapSettings.get(), &QgsQuickMapSettings::temporalStateChanged, this, &QgsQuickMapCanvasMap::onTemporalStateChanged );

connect( this, &QgsQuickMapCanvasMap::renderStarting, this, &QgsQuickMapCanvasMap::isRenderingChanged );
connect( this, &QgsQuickMapCanvasMap::mapCanvasRefreshed, this, &QgsQuickMapCanvasMap::isRenderingChanged );
Expand Down Expand Up @@ -276,6 +278,14 @@ void QgsQuickMapCanvasMap::onExtentChanged()
refresh();
}

void QgsQuickMapCanvasMap::onTemporalStateChanged()
{
clearTemporalCache();

// And trigger a new rendering job
refresh();
}

void QgsQuickMapCanvasMap::updateTransform()
{
QgsRectangle imageExtent = mImageMapSettings.visibleExtent();
Expand Down Expand Up @@ -479,3 +489,35 @@ void QgsQuickMapCanvasMap::clearCache()
if ( mCache )
mCache->clear();
}

void QgsQuickMapCanvasMap::clearTemporalCache()
{
if ( mCache )
{
bool invalidateLabels = false;
const QList<QgsMapLayer *> layerList = mMapSettings->mapSettings().layers();
for ( QgsMapLayer *layer : layerList )
{
if ( layer->temporalProperties() && layer->temporalProperties()->isActive() )
{
if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ) )
{
if ( vl->labelsEnabled() || vl->diagramsEnabled() )
invalidateLabels = true;
}

if ( layer->temporalProperties()->flags() & QgsTemporalProperty::FlagDontInvalidateCachedRendersWhenRangeChanges )
continue;

mCache->invalidateCacheForLayer( layer );
}
}

if ( invalidateLabels )
{
mCache->clearCacheImage( QStringLiteral( "_labels_" ) );
mCache->clearCacheImage( QStringLiteral( "_preview_labels_" ) );
}
}
}

2 changes: 2 additions & 0 deletions src/quickgui/qgsquickmapcanvasmap.h
Expand Up @@ -184,6 +184,7 @@ class QUICK_EXPORT QgsQuickMapCanvasMap : public QQuickItem
void onScreenChanged( QScreen *screen );
void onExtentChanged();
void onLayersChanged();
void onTemporalStateChanged();

private:

Expand All @@ -194,6 +195,7 @@ class QUICK_EXPORT QgsQuickMapCanvasMap : public QQuickItem
QgsMapSettings prepareMapSettings() const;
void updateTransform();
void zoomToFullExtent();
void clearTemporalCache();

std::unique_ptr<QgsQuickMapSettings> mMapSettings;
bool mPinching = false;
Expand Down
43 changes: 43 additions & 0 deletions src/quickgui/qgsquickmapsettings.cpp
Expand Up @@ -231,6 +231,13 @@ void QgsQuickMapSettings::onReadProject( const QDomDocument &doc )
int green = mProject->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorGreenPart" ), 255 );
int blue = mProject->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), 255 );
mMapSettings.setBackgroundColor( QColor( red, green, blue ) );

const bool isTemporal = mProject->readNumEntry( QStringLiteral( "TemporalControllerWidget" ), QStringLiteral( "/NavigationMode" ), 0 ) != 0;
const QString startString = QgsProject::instance()->readEntry( QStringLiteral( "TemporalControllerWidget" ), QStringLiteral( "/StartDateTime" ) );
const QString endString = QgsProject::instance()->readEntry( QStringLiteral( "TemporalControllerWidget" ), QStringLiteral( "/EndDateTime" ) );
mMapSettings.setIsTemporal( isTemporal );
mMapSettings.setTemporalRange( QgsDateTimeRange( QDateTime::fromString( startString, Qt::ISODateWithMs ),
QDateTime::fromString( endString, Qt::ISODateWithMs ) ) );
}

QDomNodeList nodes = doc.elementsByTagName( "mapcanvas" );
Expand Down Expand Up @@ -265,6 +272,7 @@ void QgsQuickMapSettings::onReadProject( const QDomDocument &doc )
emit outputSizeChanged();
emit outputDpiChanged();
emit layersChanged();
emit temporalStateChanged();
}

double QgsQuickMapSettings::rotation() const
Expand Down Expand Up @@ -302,3 +310,38 @@ void QgsQuickMapSettings::setDevicePixelRatio( const qreal &devicePixelRatio )
mDevicePixelRatio = devicePixelRatio;
emit devicePixelRatioChanged();
}

bool QgsQuickMapSettings::isTemporal() const
{
return mMapSettings.isTemporal();
}

void QgsQuickMapSettings::setIsTemporal( bool temporal )
{
mMapSettings.setIsTemporal( temporal );
emit temporalStateChanged();
}

QDateTime QgsQuickMapSettings::temporalBegin() const
{
return mMapSettings.temporalRange().begin();
}

void QgsQuickMapSettings::setTemporalBegin( const QDateTime &begin )
{
const QgsDateTimeRange range = mMapSettings.temporalRange();
mMapSettings.setTemporalRange( QgsDateTimeRange( begin, range.end() ) );
emit temporalStateChanged();
}

QDateTime QgsQuickMapSettings::temporalEnd() const
{
return mMapSettings.temporalRange().end();
}

void QgsQuickMapSettings::setTemporalEnd( const QDateTime &end )
{
const QgsDateTimeRange range = mMapSettings.temporalRange();
mMapSettings.setTemporalRange( QgsDateTimeRange( range.begin(), end ) );
emit temporalStateChanged();
}
41 changes: 41 additions & 0 deletions src/quickgui/qgsquickmapsettings.h
Expand Up @@ -122,6 +122,21 @@ class QUICK_EXPORT QgsQuickMapSettings : public QObject
*/
Q_PROPERTY( QList<QgsMapLayer *> layers READ layers WRITE setLayers NOTIFY layersChanged )

/**
* Returns TRUE if a temporal filtering is enabled
*/
Q_PROPERTY( bool isTemporal READ isTemporal WRITE setIsTemporal NOTIFY temporalStateChanged )

/**
* The temporal range's begin (i.e. lower) value
*/
Q_PROPERTY( QDateTime temporalBegin READ temporalBegin WRITE setTemporalBegin NOTIFY temporalStateChanged )

/**
* The temporal range's end (i.e. higher) value
*/
Q_PROPERTY( QDateTime temporalEnd READ temporalEnd WRITE setTemporalEnd NOTIFY temporalStateChanged )

public:
//! Create new map settings
explicit QgsQuickMapSettings( QObject *parent = nullptr );
Expand Down Expand Up @@ -257,6 +272,24 @@ class QUICK_EXPORT QgsQuickMapSettings : public QObject
*/
void setDevicePixelRatio( const qreal &devicePixelRatio );

//! \copydoc QgsQuickMapSettings::isTemporal
bool isTemporal() const;

//! \copydoc QgsQuickMapSettings::isTemporal
void setIsTemporal( bool temporal );

//! \copydoc QgsQuickMapSettings::temporalBegin
QDateTime temporalBegin() const;

//! \copydoc QgsQuickMapSettings::temporalBegin
void setTemporalBegin( const QDateTime &begin );

//! \copydoc QgsQuickMapSettings::temporalEnd
QDateTime temporalEnd() const;

//! \copydoc QgsQuickMapSettings::temporalEnd
void setTemporalEnd( const QDateTime &end );

signals:
//! \copydoc QgsQuickMapSettings::project
void projectChanged();
Expand Down Expand Up @@ -290,6 +323,14 @@ class QUICK_EXPORT QgsQuickMapSettings : public QObject
//! \copydoc QgsQuickMapSettings::layers
void layersChanged();

/**
* Emitted when the temporal state has changed.
* \see isTemporal()
* \see temporalBegin()
* \see temporalEnd()
*/
void temporalStateChanged();

//! \copydoc QgsQuickMapSettings::devicePixelRatio
void devicePixelRatioChanged();

Expand Down

0 comments on commit 1f4e564

Please sign in to comment.