From ab6272d8de5a099afdf2b17dbb5deca11a4f4da1 2017-06-19 09:05:39 From: Alexandre Leroux Date: 2017-06-19 09:05:39 Subject: [PATCH] Updates VariableController::createVariable() method - Adds signal that will be emitted when the variable has been created - Changes method's signature from Variable* to void (the variable is passed in the signal) - Generates default data (on 48 hours) from the provider --- diff --git a/core/include/Variable/VariableController.h b/core/include/Variable/VariableController.h index d25da2b..f7fdba5 100644 --- a/core/include/Variable/VariableController.h +++ b/core/include/Variable/VariableController.h @@ -6,6 +6,7 @@ #include +class IDataProvider; class Variable; class VariableModel; @@ -20,16 +21,20 @@ public: explicit VariableController(QObject *parent = 0); virtual ~VariableController(); + VariableModel *variableModel() noexcept; + +signals: + /// Signal emitted when a variable has been created + void variableCreated(std::shared_ptr variable); + +public slots: /** - * Creates a new variable + * Creates a new variable and adds it to the model * @param name the name of the new variable - * @return the variable if it was created successfully, nullptr otherwise + * @param provider the data provider for the new variable */ - Variable *createVariable(const QString &name) noexcept; + void createVariable(const QString &name, std::shared_ptr provider) noexcept; - VariableModel *variableModel() noexcept; - -public slots: void initialize(); void finalize(); diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 8c05bd9..b7b0d44 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -1,11 +1,31 @@ #include #include +#include +#include +#include + +#include #include #include Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") +namespace { + +/// @todo Generates default dataseries, according to the provider passed in parameter. This method +/// will be deleted when the timerange is recovered from SciQlop +std::unique_ptr generateDefaultDataSeries(const IDataProvider &provider) noexcept +{ + auto parameters = DataProviderParameters{ + static_cast(QDateTime{QDate{2017, 01, 01}}.toSecsSinceEpoch()), + static_cast(QDateTime{QDate{2017, 01, 03}}.toSecsSinceEpoch())}; + + return provider.retrieveData(parameters); +} + +} // namespace + struct VariableController::VariableControllerPrivate { explicit VariableControllerPrivate(VariableController *parent) : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}} @@ -31,14 +51,23 @@ VariableController::~VariableController() this->waitForFinish(); } -Variable *VariableController::createVariable(const QString &name) noexcept +VariableModel *VariableController::variableModel() noexcept { - return impl->m_VariableModel->createVariable(name); + return impl->m_VariableModel; } -VariableModel *VariableController::variableModel() noexcept +void VariableController::createVariable(const QString &name, + std::shared_ptr provider) noexcept { - return impl->m_VariableModel; + /// @todo : for the moment : + /// - the provider is only used to retrieve data from the variable for its initialization, but + /// it will be retained later + /// - default data are generated for the variable, without taking into account the timerange set + /// in sciqlop + if (auto newVariable + = impl->m_VariableModel->createVariable(name, generateDefaultDataSeries(*provider))) { + emit variableCreated(newVariable); + } } void VariableController::initialize()