##// END OF EJS Templates
Adds QVariantHash to store metadata in a variable
Alexandre Leroux -
r406:643df4da22dc
parent child
Show More
@@ -1,52 +1,55
1 1 #ifndef SCIQLOP_VARIABLE_H
2 2 #define SCIQLOP_VARIABLE_H
3 3
4 4 #include <Data/SqpDateTime.h>
5 5
6 6 #include <QLoggingCategory>
7 7 #include <QObject>
8 8
9 9 #include <Common/MetaTypes.h>
10 10 #include <Common/spimpl.h>
11 11
12 12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
13 13
14 14 class IDataSeries;
15 15 class QString;
16 16
17 17 /**
18 18 * @brief The Variable class represents a variable in SciQlop.
19 19 */
20 20 class Variable : public QObject {
21 21
22 22 Q_OBJECT
23 23
24 24 public:
25 explicit Variable(const QString &name, const SqpDateTime &dateTime);
25 explicit Variable(const QString &name, const SqpDateTime &dateTime,
26 const QVariantHash &metadata = {});
26 27
27 28 QString name() const noexcept;
28 29 SqpDateTime dateTime() const noexcept;
29 30 void setDateTime(const SqpDateTime &dateTime) noexcept;
30 31
31 32 /// @return the data of the variable, nullptr if there is no data
32 33 IDataSeries *dataSeries() const noexcept;
33 34
35 QVariantHash metadata() const noexcept;
36
34 37 bool contains(const SqpDateTime &dateTime) const noexcept;
35 38 bool intersect(const SqpDateTime &dateTime) const noexcept;
36 39 bool isInside(const SqpDateTime &dateTime) const noexcept;
37 40
38 41 public slots:
39 42 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
40 43
41 44 signals:
42 45 void updated();
43 46
44 47 private:
45 48 class VariablePrivate;
46 49 spimpl::unique_impl_ptr<VariablePrivate> impl;
47 50 };
48 51
49 52 // Required for using shared_ptr in signals/slots
50 53 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
51 54
52 55 #endif // SCIQLOP_VARIABLE_H
@@ -1,83 +1,90
1 1 #include "Variable/Variable.h"
2 2
3 3 #include <Data/IDataSeries.h>
4 4 #include <Data/SqpDateTime.h>
5 5
6 6 #include <QReadWriteLock>
7 7 #include <QThread>
8 8
9 9 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
10 10
11 11 struct Variable::VariablePrivate {
12 explicit VariablePrivate(const QString &name, const SqpDateTime &dateTime)
13 : m_Name{name}, m_DateTime{dateTime}, m_DataSeries{nullptr}
12 explicit VariablePrivate(const QString &name, const SqpDateTime &dateTime,
13 const QVariantHash &metadata)
14 : m_Name{name}, m_DateTime{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr}
14 15 {
15 16 }
16 17
17 18 QString m_Name;
18 19
19 20 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
21 QVariantHash m_Metadata;
20 22 std::unique_ptr<IDataSeries> m_DataSeries;
21 23 };
22 24
23 Variable::Variable(const QString &name, const SqpDateTime &dateTime)
24 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime)}
25 Variable::Variable(const QString &name, const SqpDateTime &dateTime, const QVariantHash &metadata)
26 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)}
25 27 {
26 28 }
27 29
28 30 QString Variable::name() const noexcept
29 31 {
30 32 return impl->m_Name;
31 33 }
32 34
33 35 SqpDateTime Variable::dateTime() const noexcept
34 36 {
35 37 return impl->m_DateTime;
36 38 }
37 39
38 40 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
39 41 {
40 42 impl->m_DateTime = dateTime;
41 43 }
42 44
43 45 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
44 46 {
45 47 qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName();
46 48 if (!dataSeries) {
47 49 /// @todo ALX : log
48 50 return;
49 51 }
50 52
51 53 // Inits the data series of the variable
52 54 if (!impl->m_DataSeries) {
53 55 impl->m_DataSeries = dataSeries->clone();
54 56 }
55 57 else {
56 58 dataSeries->lockWrite();
57 59 impl->m_DataSeries->lockWrite();
58 60 impl->m_DataSeries->merge(dataSeries.get());
59 61 impl->m_DataSeries->unlock();
60 62 dataSeries->unlock();
61 63 emit updated();
62 64 }
63 65 }
64 66
65 67 IDataSeries *Variable::dataSeries() const noexcept
66 68 {
67 69 return impl->m_DataSeries.get();
68 70 }
69 71
72 QVariantHash Variable::metadata() const noexcept
73 {
74 return impl->m_Metadata;
75 }
76
70 77 bool Variable::contains(const SqpDateTime &dateTime) const noexcept
71 78 {
72 79 return impl->m_DateTime.contains(dateTime);
73 80 }
74 81
75 82 bool Variable::intersect(const SqpDateTime &dateTime) const noexcept
76 83 {
77 84 return impl->m_DateTime.intersect(dateTime);
78 85 }
79 86
80 87 bool Variable::isInside(const SqpDateTime &dateTime) const noexcept
81 88 {
82 89 return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd});
83 90 }
General Comments 0
You need to be logged in to leave comments. Login now