Skip to content
Permalink
Browse files

update layers using project temporal range when the range has changed

  • Loading branch information
Samweli committed Apr 13, 2020
1 parent 01af33f commit 2f8a51b2ed00ac4092bde4fef5fcd03be208cdf1
Showing with 40 additions and 1 deletion.
  1. +37 −1 src/app/qgisapp.cpp
  2. +3 −0 src/app/qgisapp.h
@@ -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() );
@@ -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 );
@@ -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()
{
@@ -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 );

/**

0 comments on commit 2f8a51b

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