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