Variable.cpp
90 lines
| 2.3 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r163 | #include "Variable/Variable.h" | ||
Alexandre Leroux
|
r164 | #include <Data/IDataSeries.h> | ||
r226 | #include <Data/SqpDateTime.h> | |||
r364 | #include <QReadWriteLock> | |||
#include <QThread> | ||||
r226 | Q_LOGGING_CATEGORY(LOG_Variable, "Variable") | |||
Alexandre Leroux
|
r164 | |||
Alexandre Leroux
|
r163 | struct Variable::VariablePrivate { | ||
Alexandre Leroux
|
r406 | explicit VariablePrivate(const QString &name, const SqpDateTime &dateTime, | ||
const QVariantHash &metadata) | ||||
: m_Name{name}, m_DateTime{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr} | ||||
Alexandre Leroux
|
r163 | { | ||
} | ||||
QString m_Name; | ||||
r226 | ||||
SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache. | ||||
Alexandre Leroux
|
r406 | QVariantHash m_Metadata; | ||
Alexandre Leroux
|
r164 | std::unique_ptr<IDataSeries> m_DataSeries; | ||
Alexandre Leroux
|
r163 | }; | ||
Alexandre Leroux
|
r406 | Variable::Variable(const QString &name, const SqpDateTime &dateTime, const QVariantHash &metadata) | ||
: impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)} | ||||
Alexandre Leroux
|
r163 | { | ||
} | ||||
QString Variable::name() const noexcept | ||||
{ | ||||
return impl->m_Name; | ||||
} | ||||
r235 | SqpDateTime Variable::dateTime() const noexcept | |||
{ | ||||
return impl->m_DateTime; | ||||
} | ||||
r260 | void Variable::setDateTime(const SqpDateTime &dateTime) noexcept | |||
{ | ||||
impl->m_DateTime = dateTime; | ||||
} | ||||
Alexandre Leroux
|
r310 | void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | ||
Alexandre Leroux
|
r164 | { | ||
r367 | qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName(); | |||
Alexandre Leroux
|
r310 | if (!dataSeries) { | ||
/// @todo ALX : log | ||||
return; | ||||
Alexandre Leroux
|
r164 | } | ||
r235 | ||||
Alexandre Leroux
|
r310 | // Inits the data series of the variable | ||
if (!impl->m_DataSeries) { | ||||
impl->m_DataSeries = dataSeries->clone(); | ||||
} | ||||
else { | ||||
r364 | dataSeries->lockWrite(); | |||
impl->m_DataSeries->lockWrite(); | ||||
r235 | impl->m_DataSeries->merge(dataSeries.get()); | |||
r364 | impl->m_DataSeries->unlock(); | |||
dataSeries->unlock(); | ||||
r298 | emit updated(); | |||
r235 | } | |||
Alexandre Leroux
|
r164 | } | ||
Alexandre Leroux
|
r182 | |||
IDataSeries *Variable::dataSeries() const noexcept | ||||
{ | ||||
return impl->m_DataSeries.get(); | ||||
} | ||||
r226 | ||||
Alexandre Leroux
|
r406 | QVariantHash Variable::metadata() const noexcept | ||
{ | ||||
return impl->m_Metadata; | ||||
} | ||||
r318 | bool Variable::contains(const SqpDateTime &dateTime) const noexcept | |||
r226 | { | |||
r260 | return impl->m_DateTime.contains(dateTime); | |||
r226 | } | |||
r258 | ||||
r318 | bool Variable::intersect(const SqpDateTime &dateTime) const noexcept | |||
r258 | { | |||
return impl->m_DateTime.intersect(dateTime); | ||||
} | ||||
r318 | ||||
bool Variable::isInside(const SqpDateTime &dateTime) const noexcept | ||||
{ | ||||
return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd}); | ||||
} | ||||