VariableController2.cpp
83 lines
| 2.5 KiB
| text/x-c
|
CppLexer
r0 | #include "Variable/VariableController2.h" | |||
r2 | #include <Common/containers.h> | |||
#include <Common/debug.h> | ||||
#include <Data/DataProviderParameters.h> | ||||
r0 | ||||
r2 | class VariableController2::VariableController2Private | |||
r0 | { | |||
r2 | std::set<std::shared_ptr<Variable>> _variables; | |||
QMap<QUuid,std::shared_ptr<IDataProvider>> _providers; | ||||
r0 | public: | |||
VariableController2Private(QObject* parent=Q_NULLPTR) | ||||
r2 | { | |||
Q_UNUSED(parent); | ||||
} | ||||
r0 | ~VariableController2Private() = default; | |||
r2 | ||||
r0 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range) | |||
{ | ||||
r2 | auto newVar = std::make_shared<Variable>(name,metadata); | |||
this->_variables.insert(newVar); | ||||
this->_providers[newVar->ID()] = provider; | ||||
return newVar; | ||||
} | ||||
void deleteVariable(std::shared_ptr<Variable> 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> 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<std::shared_ptr<Variable>>& variables() | ||||
{ | ||||
return _variables; | ||||
r0 | } | |||
r2 | ||||
r0 | }; | |||
VariableController2::VariableController2() | ||||
:impl{spimpl::make_unique_impl<VariableController2Private>()} | ||||
{} | ||||
std::shared_ptr<Variable> VariableController2::createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range) | ||||
{ | ||||
r2 | auto var = impl->createVariable(name, metadata, provider, range); | |||
emit variableAdded(var); | ||||
impl->changeRange(var,range); | ||||
return var; | ||||
} | ||||
void VariableController2::deleteVariable(std::shared_ptr<Variable> variable) | ||||
{ | ||||
impl->deleteVariable(variable); | ||||
emit variableDeleted(variable); | ||||
} | ||||
void VariableController2::changeRange(std::shared_ptr<Variable> variable, DateTimeRange r) | ||||
{ | ||||
impl->changeRange(variable, r); | ||||
} | ||||
const std::set<std::shared_ptr<Variable> > &VariableController2::variables() | ||||
{ | ||||
return impl->variables(); | ||||
r0 | } | |||