Variable.cpp
86 lines
| 2.1 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r151 | #include "Variable/Variable.h" | ||
Alexandre Leroux
|
r152 | #include <Data/IDataSeries.h> | ||
r471 | #include <Data/SqpRange.h> | |||
r210 | ||||
r336 | #include <QReadWriteLock> | |||
#include <QThread> | ||||
r210 | Q_LOGGING_CATEGORY(LOG_Variable, "Variable") | |||
Alexandre Leroux
|
r152 | |||
Alexandre Leroux
|
r151 | struct Variable::VariablePrivate { | ||
r471 | explicit VariablePrivate(const QString &name, const SqpRange &dateTime, | |||
Alexandre Leroux
|
r373 | const QVariantHash &metadata) | ||
: m_Name{name}, m_DateTime{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr} | ||||
Alexandre Leroux
|
r151 | { | ||
} | ||||
QString m_Name; | ||||
r210 | ||||
r471 | SqpRange m_DateTime; // The dateTime available in the view and loaded. not the cache. | |||
Alexandre Leroux
|
r373 | QVariantHash m_Metadata; | ||
Alexandre Leroux
|
r152 | std::unique_ptr<IDataSeries> m_DataSeries; | ||
Alexandre Leroux
|
r151 | }; | ||
r471 | Variable::Variable(const QString &name, const SqpRange &dateTime, const QVariantHash &metadata) | |||
Alexandre Leroux
|
r373 | : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)} | ||
Alexandre Leroux
|
r151 | { | ||
} | ||||
QString Variable::name() const noexcept | ||||
{ | ||||
return impl->m_Name; | ||||
} | ||||
r471 | SqpRange Variable::dateTime() const noexcept | |||
r219 | { | |||
return impl->m_DateTime; | ||||
} | ||||
r471 | void Variable::setDateTime(const SqpRange &dateTime) noexcept | |||
r241 | { | |||
impl->m_DateTime = dateTime; | ||||
} | ||||
Alexandre Leroux
|
r287 | void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | ||
Alexandre Leroux
|
r152 | { | ||
r339 | qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName(); | |||
Alexandre Leroux
|
r287 | if (!dataSeries) { | ||
/// @todo ALX : log | ||||
return; | ||||
Alexandre Leroux
|
r152 | } | ||
r219 | ||||
Alexandre Leroux
|
r287 | // Inits the data series of the variable | ||
if (!impl->m_DataSeries) { | ||||
impl->m_DataSeries = dataSeries->clone(); | ||||
} | ||||
else { | ||||
r219 | impl->m_DataSeries->merge(dataSeries.get()); | |||
r399 | // emit updated(); | |||
r219 | } | |||
Alexandre Leroux
|
r152 | } | ||
Alexandre Leroux
|
r169 | |||
IDataSeries *Variable::dataSeries() const noexcept | ||||
{ | ||||
return impl->m_DataSeries.get(); | ||||
} | ||||
r210 | ||||
Alexandre Leroux
|
r373 | QVariantHash Variable::metadata() const noexcept | ||
{ | ||||
return impl->m_Metadata; | ||||
} | ||||
r471 | bool Variable::contains(const SqpRange &dateTime) const noexcept | |||
r210 | { | |||
r241 | return impl->m_DateTime.contains(dateTime); | |||
r210 | } | |||
r240 | ||||
r471 | bool Variable::intersect(const SqpRange &dateTime) const noexcept | |||
r240 | { | |||
return impl->m_DateTime.intersect(dateTime); | ||||
} | ||||
r293 | ||||
r471 | bool Variable::isInside(const SqpRange &dateTime) const noexcept | |||
r293 | { | |||
r471 | return dateTime.contains(SqpRange{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd}); | |||
r293 | } | |||