diff --git a/core/include/DataSource/DataSourceController.h b/core/include/DataSource/DataSourceController.h index 6d3df61..13c2192 100644 --- a/core/include/DataSource/DataSourceController.h +++ b/core/include/DataSource/DataSourceController.h @@ -10,6 +10,7 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController) class DataSourceItem; +class IDataProvider; /** * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This @@ -42,6 +43,17 @@ public: void setDataSourceItem(const QUuid &dataSourceUid, std::unique_ptr dataSourceItem) noexcept; + /** + * Sets the data provider used to retrieve data from of a data source. The controller takes + * ownership of the provider. + * @param dataSourceUid the unique id with which the data source has been registered into the + * controller. If it is invalid, the method has no effect. + * @param dataProvider the provider of the data source + * @sa registerDataSource() + */ + void setDataProvider(const QUuid &dataSourceUid, + std::unique_ptr dataProvider) noexcept; + public slots: /// Manage init/end of the controller void initialize(); diff --git a/core/src/DataSource/DataSourceController.cpp b/core/src/DataSource/DataSourceController.cpp index c8066c1..aeed99e 100644 --- a/core/src/DataSource/DataSourceController.cpp +++ b/core/src/DataSource/DataSourceController.cpp @@ -1,6 +1,8 @@ #include #include +#include + #include #include @@ -16,6 +18,8 @@ public: QHash m_DataSources; /// Data sources structures std::map > m_DataSourceItems; + /// Data providers registered + std::map > m_DataProviders; }; DataSourceController::DataSourceController(QObject *parent) @@ -59,6 +63,19 @@ void DataSourceController::setDataSourceItem( } } +void DataSourceController::setDataProvider(const QUuid &dataSourceUid, + std::unique_ptr dataProvider) noexcept +{ + if (impl->m_DataSources.contains(dataSourceUid)) { + impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider))); + } + else { + qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data " + "source has been registered with the uid") + .arg(dataSourceUid.toString()); + } +} + void DataSourceController::initialize() { qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")