From af1b645db780af0140cb5a043db71625c60889ea 2017-07-13 08:18:09 From: Alexandre Leroux Date: 2017-07-13 08:18:09 Subject: [PATCH] Updates variable creation to pass metadata When a variable is created from data source, the variable metadata are set with the data source metadata --- diff --git a/core/include/DataSource/DataSourceController.h b/core/include/DataSource/DataSourceController.h index 0fb897c..ce458d8 100644 --- a/core/include/DataSource/DataSourceController.h +++ b/core/include/DataSource/DataSourceController.h @@ -74,10 +74,12 @@ signals: /** * Signal emitted when a variable creation is asked for a product * @param variableName the name of the variable + * @param variableMetadata the metadata of the variable * @param variableProvider the provider that will be used to retrieve the data of the variable * (can be null) */ void variableCreationRequested(const QString &variableName, + const QVariantHash &variableMetadata, std::shared_ptr variableProvider); private: diff --git a/core/include/Variable/VariableController.h b/core/include/Variable/VariableController.h index dc7ef23..2776c18 100644 --- a/core/include/Variable/VariableController.h +++ b/core/include/Variable/VariableController.h @@ -60,9 +60,11 @@ public slots: /** * Creates a new variable and adds it to the model * @param name the name of the new variable + * @param metadata the metadata of the new variable * @param provider the data provider for the new variable */ - void createVariable(const QString &name, std::shared_ptr provider) noexcept; + void createVariable(const QString &name, const QVariantHash &metadata, + std::shared_ptr provider) noexcept; /// Update the temporal parameters of every selected variable to dateTime void onDateTimeOnSelection(const SqpDateTime &dateTime); diff --git a/core/include/Variable/VariableModel.h b/core/include/Variable/VariableModel.h index 554c292..8e8f317 100644 --- a/core/include/Variable/VariableModel.h +++ b/core/include/Variable/VariableModel.h @@ -29,10 +29,11 @@ public: * Creates a new variable in the model * @param name the name of the new variable * @param dateTime the dateTime of the new variable + * @param metadata the metadata associated to the new variable * @return the pointer to the new variable */ - std::shared_ptr createVariable(const QString &name, - const SqpDateTime &dateTime) noexcept; + std::shared_ptr createVariable(const QString &name, const SqpDateTime &dateTime, + const QVariantHash &metadata) noexcept; /** * Deletes a variable from the model, if it exists diff --git a/core/src/DataSource/DataSourceController.cpp b/core/src/DataSource/DataSourceController.cpp index 6107311..12243c1 100644 --- a/core/src/DataSource/DataSourceController.cpp +++ b/core/src/DataSource/DataSourceController.cpp @@ -94,7 +94,7 @@ void DataSourceController::loadProductItem(const QUuid &dataSourceUid, auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr; /// @todo retrieve timerange, and pass it to the signal - emit variableCreationRequested(productItem.name(), dataProvider); + emit variableCreationRequested(productItem.name(), productItem.data(), dataProvider); } else { qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product"); diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 8b698be..6242bc9 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -102,7 +102,7 @@ void VariableController::deleteVariables( } } -void VariableController::createVariable(const QString &name, +void VariableController::createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr provider) noexcept { @@ -119,7 +119,8 @@ void VariableController::createVariable(const QString &name, /// - default data are generated for the variable, without taking into account the timerange set /// in sciqlop auto dateTime = impl->m_TimeController->dateTime(); - if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { + + if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime, metadata)) { auto identifier = QUuid::createUuid(); // store the provider diff --git a/core/src/Variable/VariableModel.cpp b/core/src/Variable/VariableModel.cpp index 2b0ccc8..637c4cb 100644 --- a/core/src/Variable/VariableModel.cpp +++ b/core/src/Variable/VariableModel.cpp @@ -60,12 +60,13 @@ VariableModel::VariableModel(QObject *parent) } std::shared_ptr VariableModel::createVariable(const QString &name, - const SqpDateTime &dateTime) noexcept + const SqpDateTime &dateTime, + const QVariantHash &metadata) noexcept { auto insertIndex = rowCount(); beginInsertRows({}, insertIndex, insertIndex); - auto variable = std::make_shared(name, dateTime); + auto variable = std::make_shared(name, dateTime, metadata); impl->m_Variables.push_back(variable); connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated); diff --git a/gui/src/SqpApplication.cpp b/gui/src/SqpApplication.cpp index 0ec169f..04d8858 100644 --- a/gui/src/SqpApplication.cpp +++ b/gui/src/SqpApplication.cpp @@ -26,9 +26,11 @@ public: // VariableController <-> DataSourceController connect(m_DataSourceController.get(), - SIGNAL(variableCreationRequested(const QString &, std::shared_ptr)), + SIGNAL(variableCreationRequested(const QString &, const QVariantHash &, + std::shared_ptr)), m_VariableController.get(), - SLOT(createVariable(const QString &, std::shared_ptr))); + SLOT(createVariable(const QString &, const QVariantHash &, + std::shared_ptr))); // VariableController <-> VisualizationController connect(m_VariableController.get(),