#include "Variable/VariableController2.h" #include #include #include class VariableController2::VariableController2Private { std::set> _variables; QMap> _providers; public: VariableController2Private(QObject* parent=Q_NULLPTR) { Q_UNUSED(parent); } ~VariableController2Private() = default; std::shared_ptr createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr provider, const DateTimeRange &range) { auto newVar = std::make_shared(name,metadata); this->_variables.insert(newVar); this->_providers[newVar->ID()] = provider; return newVar; } void deleteVariable(std::shared_ptr variable) { if(this->_providers.contains(variable->ID())) this->_providers.remove(variable->ID()); if(SciQLop::containers::contains(this->_variables, variable)) this->_variables.erase(variable); } void changeRange(std::shared_ptr variable, DateTimeRange r) { if(_providers.contains(variable->ID())) { auto provider = _providers[variable->ID()]; auto data = provider->getData(DataProviderParameters{{r},variable->metadata()}); variable->mergeDataSeries(data); } else { SCIQLOP_ERROR("No provider found for given variable"); } } const std::set>& variables() { return _variables; } }; VariableController2::VariableController2() :impl{spimpl::make_unique_impl()} {} std::shared_ptr VariableController2::createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr provider, const DateTimeRange &range) { auto var = impl->createVariable(name, metadata, provider, range); emit variableAdded(var); impl->changeRange(var,range); return var; } void VariableController2::deleteVariable(std::shared_ptr variable) { impl->deleteVariable(variable); emit variableDeleted(variable); } void VariableController2::changeRange(std::shared_ptr variable, DateTimeRange r) { impl->changeRange(variable, r); } const std::set > &VariableController2::variables() { return impl->variables(); }