From 951cc05bf33727acc41f91fba93573b6208c004e 2017-09-07 09:47:08 From: Alexandre Leroux Date: 2017-09-07 09:47:08 Subject: [PATCH] Generates and registers clone provider --- diff --git a/core/include/Data/IDataProvider.h b/core/include/Data/IDataProvider.h index 805348d..55dd069 100644 --- a/core/include/Data/IDataProvider.h +++ b/core/include/Data/IDataProvider.h @@ -32,6 +32,7 @@ class SCIQLOP_CORE_EXPORT IDataProvider : public QObject { Q_OBJECT public: virtual ~IDataProvider() noexcept = default; + virtual std::shared_ptr clone() const = 0; /** * @brief requestDataLoading provide datas for the data identified by acqIdentifier and diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 9569cf7..50b88cc 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -201,6 +201,15 @@ VariableController::cloneVariable(std::shared_ptr variable) noexcept // Generates clone identifier impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid(); + // Registers provider + auto variableProvider = impl->m_VariableToProviderMap.at(variable); + auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr; + + impl->m_VariableToProviderMap[duplicate] = duplicateProvider; + if (duplicateProvider) { + impl->registerProvider(duplicateProvider); + } + return duplicate; } else { diff --git a/core/tests/Variable/TestVariableController.cpp b/core/tests/Variable/TestVariableController.cpp index 1b278f1..ec1093e 100644 --- a/core/tests/Variable/TestVariableController.cpp +++ b/core/tests/Variable/TestVariableController.cpp @@ -12,6 +12,8 @@ namespace { /// Provider used for the tests class TestProvider : public IDataProvider { + std::shared_ptr clone() const { return std::make_shared(); } + void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override { // Does nothing diff --git a/plugins/amda/include/AmdaProvider.h b/plugins/amda/include/AmdaProvider.h index 292d9b8..16a25b9 100644 --- a/plugins/amda/include/AmdaProvider.h +++ b/plugins/amda/include/AmdaProvider.h @@ -18,6 +18,7 @@ class QNetworkReply; class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider { public: explicit AmdaProvider(); + std::shared_ptr clone() const override; void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override; diff --git a/plugins/amda/src/AmdaProvider.cpp b/plugins/amda/src/AmdaProvider.cpp index 8fe1f67..d17e6f9 100644 --- a/plugins/amda/src/AmdaProvider.cpp +++ b/plugins/amda/src/AmdaProvider.cpp @@ -68,6 +68,12 @@ AmdaProvider::AmdaProvider() } } +std::shared_ptr AmdaProvider::clone() const +{ + // No copy is made in the clone + return std::make_shared(); +} + void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) { // NOTE: Try to use multithread if possible diff --git a/plugins/mockplugin/include/CosinusProvider.h b/plugins/mockplugin/include/CosinusProvider.h index 05db4d1..1ef2c6e 100644 --- a/plugins/mockplugin/include/CosinusProvider.h +++ b/plugins/mockplugin/include/CosinusProvider.h @@ -16,6 +16,8 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider) */ class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider { public: + std::shared_ptr clone() const override; + /// @sa IDataProvider::requestDataLoading(). The current impl isn't thread safe. void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override; diff --git a/plugins/mockplugin/src/CosinusProvider.cpp b/plugins/mockplugin/src/CosinusProvider.cpp index 661a78f..6ba687f 100644 --- a/plugins/mockplugin/src/CosinusProvider.cpp +++ b/plugins/mockplugin/src/CosinusProvider.cpp @@ -11,6 +11,12 @@ Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") +std::shared_ptr CosinusProvider::clone() const +{ + // No copy is made in clone + return std::make_shared(); +} + std::shared_ptr CosinusProvider::retrieveData(QUuid acqIdentifier, const SqpRange &dataRangeRequested) {