##// END OF EJS Templates
VariableController2 tests refactoring...
VariableController2 tests refactoring Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r2:c7f53bda4647
r3:7c9c9e90e0b8
Show More
VariableController2.cpp
83 lines | 2.5 KiB | text/x-c | CppLexer
/ src / Variable / VariableController2.cpp
#include "Variable/VariableController2.h"
#include <Common/containers.h>
#include <Common/debug.h>
#include <Data/DataProviderParameters.h>
class VariableController2::VariableController2Private
{
std::set<std::shared_ptr<Variable>> _variables;
QMap<QUuid,std::shared_ptr<IDataProvider>> _providers;
public:
VariableController2Private(QObject* parent=Q_NULLPTR)
{
Q_UNUSED(parent);
}
~VariableController2Private() = default;
std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range)
{
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;
}
};
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)
{
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();
}