##// END OF EJS Templates
Update Variable impl for v5
perrinel -
r494:798c6712baad
parent child
Show More
@@ -1,66 +1,65
1 #ifndef SCIQLOP_VARIABLE_H
1 #ifndef SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Data/SqpRange.h>
6 #include <Data/SqpRange.h>
7
7
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9 #include <QObject>
9 #include <QObject>
10
10
11 #include <Common/MetaTypes.h>
11 #include <Common/MetaTypes.h>
12 #include <Common/spimpl.h>
12 #include <Common/spimpl.h>
13
13
14 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
14 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
15
15
16 class IDataSeries;
16 class IDataSeries;
17 class QString;
17 class QString;
18
18
19 /**
19 /**
20 * @brief The Variable class represents a variable in SciQlop.
20 * @brief The Variable class represents a variable in SciQlop.
21 */
21 */
22 class SCIQLOP_CORE_EXPORT Variable : public QObject {
22 class SCIQLOP_CORE_EXPORT Variable : public QObject {
23
23
24 Q_OBJECT
24 Q_OBJECT
25
25
26 public:
26 public:
27 explicit Variable(const QString &name, const SqpRange &dateTime,
27 explicit Variable(const QString &name, const SqpRange &dateTime,
28 const QVariantHash &metadata = {});
28 const QVariantHash &metadata = {});
29
29
30 QString name() const noexcept;
30 QString name() const noexcept;
31 SqpRange range() const noexcept;
31 SqpRange range() const noexcept;
32 void setRange(const SqpRange &range) noexcept;
32 void setRange(const SqpRange &range) noexcept;
33 SqpRange cacheRange() const noexcept;
33 SqpRange cacheRange() const noexcept;
34 void setCacheRange(const SqpRange &cacheRange) noexcept;
34 void setCacheRange(const SqpRange &cacheRange) noexcept;
35
35
36 /// @return the data of the variable, nullptr if there is no data
36 /// @return the data of the variable, nullptr if there is no data
37 IDataSeries *dataSeries() const noexcept;
37 IDataSeries *dataSeries() const noexcept;
38
38
39 QVariantHash metadata() const noexcept;
39 QVariantHash metadata() const noexcept;
40
40
41 bool contains(const SqpRange &range) const noexcept;
41 bool contains(const SqpRange &range) const noexcept;
42 bool intersect(const SqpRange &range) const noexcept;
42 bool intersect(const SqpRange &range) const noexcept;
43 bool isInside(const SqpRange &range) const noexcept;
43 bool isInside(const SqpRange &range) const noexcept;
44
44
45 bool cacheContains(const SqpRange &range) const noexcept;
45 bool cacheContains(const SqpRange &range) const noexcept;
46 bool cacheIntersect(const SqpRange &range) const noexcept;
46 bool cacheIntersect(const SqpRange &range) const noexcept;
47 bool cacheIsInside(const SqpRange &range) const noexcept;
47 bool cacheIsInside(const SqpRange &range) const noexcept;
48
48
49 QVector<SqpRange> provideNotInCacheRangeList(const SqpRange &range);
49 QVector<SqpRange> provideNotInCacheRangeList(const SqpRange &range);
50
51
52 public slots:
53 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
50 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
51 void mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
54
52
55 signals:
53 signals:
56 void updated();
54 void updated();
57
55
58 private:
56 private:
59 class VariablePrivate;
57 class VariablePrivate;
60 spimpl::unique_impl_ptr<VariablePrivate> impl;
58 spimpl::unique_impl_ptr<VariablePrivate> impl;
61 };
59 };
62
60
63 // Required for using shared_ptr in signals/slots
61 // Required for using shared_ptr in signals/slots
64 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
62 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
63 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_VECTOR_REGISTRY, QVector<std::shared_ptr<Variable> >)
65
64
66 #endif // SCIQLOP_VARIABLE_H
65 #endif // SCIQLOP_VARIABLE_H
@@ -1,142 +1,169
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/SqpRange.h>
4 #include <Data/SqpRange.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 SqpRange &dateTime,
12 explicit VariablePrivate(const QString &name, const SqpRange &dateTime,
13 const QVariantHash &metadata)
13 const QVariantHash &metadata)
14 : m_Name{name}, m_Range{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr}
14 : m_Name{name}, m_Range{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr}
15 {
15 {
16 }
16 }
17
17
18 QString m_Name;
18 QString m_Name;
19
19
20 SqpRange m_Range;
20 SqpRange m_Range;
21 SqpRange m_CacheRange;
21 SqpRange m_CacheRange;
22 QVariantHash m_Metadata;
22 QVariantHash m_Metadata;
23 std::unique_ptr<IDataSeries> m_DataSeries;
23 std::unique_ptr<IDataSeries> m_DataSeries;
24 };
24 };
25
25
26 Variable::Variable(const QString &name, const SqpRange &dateTime, const QVariantHash &metadata)
26 Variable::Variable(const QString &name, const SqpRange &dateTime, const QVariantHash &metadata)
27 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)}
27 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)}
28 {
28 {
29 }
29 }
30
30
31 QString Variable::name() const noexcept
31 QString Variable::name() const noexcept
32 {
32 {
33 return impl->m_Name;
33 return impl->m_Name;
34 }
34 }
35
35
36 SqpRange Variable::range() const noexcept
36 SqpRange Variable::range() const noexcept
37 {
37 {
38 return impl->m_Range;
38 return impl->m_Range;
39 }
39 }
40
40
41 void Variable::setRange(const SqpRange &range) noexcept
41 void Variable::setRange(const SqpRange &range) noexcept
42 {
42 {
43 impl->m_Range = range;
43 impl->m_Range = range;
44 }
44 }
45
45
46 SqpRange Variable::cacheRange() const noexcept
46 SqpRange Variable::cacheRange() const noexcept
47 {
47 {
48 return impl->m_CacheRange;
48 return impl->m_CacheRange;
49 }
49 }
50
50
51 void Variable::setCacheRange(const SqpRange &cacheRange) noexcept
51 void Variable::setCacheRange(const SqpRange &cacheRange) noexcept
52 {
52 {
53 impl->m_CacheRange = cacheRange;
53 impl->m_CacheRange = cacheRange;
54 }
54 }
55
55
56 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
56 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
57 {
57 {
58 qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName();
58 qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName();
59 if (!dataSeries) {
59 if (!dataSeries) {
60 /// @todo ALX : log
60 /// @todo ALX : log
61 return;
61 return;
62 }
62 }
63
63
64 impl->m_DataSeries = dataSeries->clone();
65
66 // // Inits the data series of the variable
67 // if (!impl->m_DataSeries) {
68 // impl->m_DataSeries = dataSeries->clone();
69 // }
70 // else {
71 // impl->m_DataSeries->merge(dataSeries.get());
72 // }
73 }
74
75 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
76 {
77 qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName();
78 if (!dataSeries) {
79 /// @todo ALX : log
80 return;
81 }
82
83 // Add or merge the data
64 // Inits the data series of the variable
84 // Inits the data series of the variable
65 if (!impl->m_DataSeries) {
85 if (!impl->m_DataSeries) {
66 impl->m_DataSeries = dataSeries->clone();
86 impl->m_DataSeries = dataSeries->clone();
67 }
87 }
68 else {
88 else {
69 impl->m_DataSeries->merge(dataSeries.get());
89 impl->m_DataSeries->merge(dataSeries.get());
70 }
90 }
91
92 // sub the data
93 auto subData = this->dataSeries()->subData(this->cacheRange());
94 qCCritical(LOG_Variable()) << "TORM: Variable::mergeDataSeries sub" << subData->range();
95 this->setDataSeries(subData);
96 qCCritical(LOG_Variable()) << "TORM: Variable::mergeDataSeries set"
97 << this->dataSeries()->range();
71 }
98 }
72
99
73 IDataSeries *Variable::dataSeries() const noexcept
100 IDataSeries *Variable::dataSeries() const noexcept
74 {
101 {
75 return impl->m_DataSeries.get();
102 return impl->m_DataSeries.get();
76 }
103 }
77
104
78 QVariantHash Variable::metadata() const noexcept
105 QVariantHash Variable::metadata() const noexcept
79 {
106 {
80 return impl->m_Metadata;
107 return impl->m_Metadata;
81 }
108 }
82
109
83 bool Variable::contains(const SqpRange &range) const noexcept
110 bool Variable::contains(const SqpRange &range) const noexcept
84 {
111 {
85 return impl->m_Range.contains(range);
112 return impl->m_Range.contains(range);
86 }
113 }
87
114
88 bool Variable::intersect(const SqpRange &range) const noexcept
115 bool Variable::intersect(const SqpRange &range) const noexcept
89 {
116 {
90 return impl->m_Range.intersect(range);
117 return impl->m_Range.intersect(range);
91 }
118 }
92
119
93 bool Variable::isInside(const SqpRange &range) const noexcept
120 bool Variable::isInside(const SqpRange &range) const noexcept
94 {
121 {
95 return range.contains(SqpRange{impl->m_Range.m_TStart, impl->m_Range.m_TEnd});
122 return range.contains(SqpRange{impl->m_Range.m_TStart, impl->m_Range.m_TEnd});
96 }
123 }
97
124
98 bool Variable::cacheContains(const SqpRange &range) const noexcept
125 bool Variable::cacheContains(const SqpRange &range) const noexcept
99 {
126 {
100 return impl->m_CacheRange.contains(range);
127 return impl->m_CacheRange.contains(range);
101 }
128 }
102
129
103 bool Variable::cacheIntersect(const SqpRange &range) const noexcept
130 bool Variable::cacheIntersect(const SqpRange &range) const noexcept
104 {
131 {
105 return impl->m_CacheRange.intersect(range);
132 return impl->m_CacheRange.intersect(range);
106 }
133 }
107
134
108 bool Variable::cacheIsInside(const SqpRange &range) const noexcept
135 bool Variable::cacheIsInside(const SqpRange &range) const noexcept
109 {
136 {
110 return range.contains(SqpRange{impl->m_CacheRange.m_TStart, impl->m_CacheRange.m_TEnd});
137 return range.contains(SqpRange{impl->m_CacheRange.m_TStart, impl->m_CacheRange.m_TEnd});
111 }
138 }
112
139
113
140
114 QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &range)
141 QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &range)
115 {
142 {
116 auto notInCache = QVector<SqpRange>{};
143 auto notInCache = QVector<SqpRange>{};
117
144
118 if (!this->cacheContains(range)) {
145 if (!this->cacheContains(range)) {
119 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
146 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
120 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
147 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
121 notInCache << range;
148 notInCache << range;
122 }
149 }
123 else if (range.m_TStart < impl->m_CacheRange.m_TStart
150 else if (range.m_TStart < impl->m_CacheRange.m_TStart
124 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
151 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
125 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart};
152 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart};
126 }
153 }
127 else if (range.m_TStart < impl->m_CacheRange.m_TStart
154 else if (range.m_TStart < impl->m_CacheRange.m_TStart
128 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
155 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
129 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}
156 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}
130 << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TStart};
157 << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
131 }
158 }
132 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
159 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
133 notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TStart};
160 notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
134 }
161 }
135 else {
162 else {
136 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
163 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
137 << QThread::currentThread();
164 << QThread::currentThread();
138 }
165 }
139 }
166 }
140
167
141 return notInCache;
168 return notInCache;
142 }
169 }
General Comments 0
You need to be logged in to leave comments. Login now