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