Navigation Menu

Skip to content

Commit

Permalink
update layers using project temporal range when the range has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli committed Apr 28, 2020
1 parent 01af33f commit 2f8a51b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -1189,7 +1189,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh

mMapCanvas->setTemporalController( mTemporalControllerWidget->temporalController() );


QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsAppDirectoryItemGuiProvider() );
QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsProjectHomeItemGuiProvider() );
QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsProjectItemGuiProvider() );
Expand Down Expand Up @@ -4080,6 +4079,8 @@ void QgisApp::setupConnections()
}
} );

connect( QgsProject::instance()->timeSettings(), &QgsProjectTimeSettings::temporalRangeChanged, this, &QgisApp::projectTemporalRangeChanged );

// connect legend signals
connect( this, &QgisApp::activeLayerChanged,
this, &QgisApp::activateDeactivateLayerRelatedActions );
Expand Down Expand Up @@ -11056,6 +11057,41 @@ void QgisApp::projectCrsChanged()
}
}

void QgisApp::projectTemporalRangeChanged()
{
QMap<QString, QgsMapLayer *> layers = QgsProject::instance()->mapLayers();
QgsMapLayer *currentLayer = nullptr;

for ( QMap<QString, QgsMapLayer *>::const_iterator it = layers.constBegin(); it != layers.constEnd(); ++it )
{
currentLayer = it.value();

if ( currentLayer->dataProvider() )
{
QgsDataSourceUri uri;
uri.setEncodedUri( currentLayer->dataProvider()->dataSourceUri() );

if ( uri.hasParam( QStringLiteral( "temporalSource" ) ) &&
uri.param( QStringLiteral( "temporalSource" ) ) == QStringLiteral( "project" ) )
{
QgsDateTimeRange range = QgsProject::instance()->timeSettings()->temporalRange();
if ( range.begin().isValid() && range.end().isValid() )
{
QString time = range.begin().toString( Qt::ISODateWithMs ) + "/" +
range.end().toString( Qt::ISODateWithMs );

uri.removeParam( QStringLiteral( "time" ) );
uri.setParam( QStringLiteral( "time" ), time );

currentLayer->dataProvider()->setDataSourceUri( uri.encodedUri() );
currentLayer->setDataSource( currentLayer->dataProvider()->dataSourceUri(), currentLayer->name(), currentLayer->providerType(), QgsDataProvider::ProviderOptions() );

}
}
}
}
}

// toggle overview status
void QgisApp::isInOverview()
{
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1788,6 +1788,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! handle project crs changes
void projectCrsChanged();

//! Updates the temporal range in layers that are using project temporal range.
void projectTemporalRangeChanged();

void onActiveLayerChanged( QgsMapLayer *layer );

/**
Expand Down

0 comments on commit 2f8a51b

Please sign in to comment.