##// END OF EJS Templates
add CacheRange for Variable and the provideNotInCacheRangeList method
perrinel -
r503:6d67365e6b04
parent child
Show More
@@ -1,57 +1,66
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 dateTime() const noexcept;
31 SqpRange range() const noexcept;
32 void setDateTime(const SqpRange &dateTime) noexcept;
32 void setRange(const SqpRange &range) noexcept;
33 SqpRange cacheRange() const noexcept;
34 void setCacheRange(const SqpRange &cacheRange) noexcept;
33
35
34 /// @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
35 IDataSeries *dataSeries() const noexcept;
37 IDataSeries *dataSeries() const noexcept;
36
38
37 QVariantHash metadata() const noexcept;
39 QVariantHash metadata() const noexcept;
38
40
39 bool contains(const SqpRange &dateTime) const noexcept;
41 bool contains(const SqpRange &range) const noexcept;
40 bool intersect(const SqpRange &dateTime) const noexcept;
42 bool intersect(const SqpRange &range) const noexcept;
41 bool isInside(const SqpRange &dateTime) const noexcept;
43 bool isInside(const SqpRange &range) const noexcept;
44
45 bool cacheContains(const SqpRange &range) const noexcept;
46 bool cacheIntersect(const SqpRange &range) const noexcept;
47 bool cacheIsInside(const SqpRange &range) const noexcept;
48
49 QVector<SqpRange> provideNotInCacheRangeList(const SqpRange &range);
50
42
51
43 public slots:
52 public slots:
44 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
53 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
45
54
46 signals:
55 signals:
47 void updated();
56 void updated();
48
57
49 private:
58 private:
50 class VariablePrivate;
59 class VariablePrivate;
51 spimpl::unique_impl_ptr<VariablePrivate> impl;
60 spimpl::unique_impl_ptr<VariablePrivate> impl;
52 };
61 };
53
62
54 // Required for using shared_ptr in signals/slots
63 // Required for using shared_ptr in signals/slots
55 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
64 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
56
65
57 #endif // SCIQLOP_VARIABLE_H
66 #endif // SCIQLOP_VARIABLE_H
@@ -1,86 +1,142
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_DateTime{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_DateTime; // The dateTime available in the view and loaded. not the cache.
20 SqpRange m_Range;
21 SqpRange m_CacheRange;
21 QVariantHash m_Metadata;
22 QVariantHash m_Metadata;
22 std::unique_ptr<IDataSeries> m_DataSeries;
23 std::unique_ptr<IDataSeries> m_DataSeries;
23 };
24 };
24
25
25 Variable::Variable(const QString &name, const SqpRange &dateTime, const QVariantHash &metadata)
26 Variable::Variable(const QString &name, const SqpRange &dateTime, const QVariantHash &metadata)
26 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)}
27 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)}
27 {
28 {
28 }
29 }
29
30
30 QString Variable::name() const noexcept
31 QString Variable::name() const noexcept
31 {
32 {
32 return impl->m_Name;
33 return impl->m_Name;
33 }
34 }
34
35
35 SqpRange Variable::dateTime() const noexcept
36 SqpRange Variable::range() const noexcept
36 {
37 {
37 return impl->m_DateTime;
38 return impl->m_Range;
38 }
39 }
39
40
40 void Variable::setDateTime(const SqpRange &dateTime) noexcept
41 void Variable::setRange(const SqpRange &range) noexcept
41 {
42 {
42 impl->m_DateTime = dateTime;
43 impl->m_Range = range;
44 }
45
46 SqpRange Variable::cacheRange() const noexcept
47 {
48 return impl->m_CacheRange;
49 }
50
51 void Variable::setCacheRange(const SqpRange &cacheRange) noexcept
52 {
53 impl->m_CacheRange = cacheRange;
43 }
54 }
44
55
45 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
56 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
46 {
57 {
47 qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName();
58 qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName();
48 if (!dataSeries) {
59 if (!dataSeries) {
49 /// @todo ALX : log
60 /// @todo ALX : log
50 return;
61 return;
51 }
62 }
52
63
53 // Inits the data series of the variable
64 // Inits the data series of the variable
54 if (!impl->m_DataSeries) {
65 if (!impl->m_DataSeries) {
55 impl->m_DataSeries = dataSeries->clone();
66 impl->m_DataSeries = dataSeries->clone();
56 }
67 }
57 else {
68 else {
58 impl->m_DataSeries->merge(dataSeries.get());
69 impl->m_DataSeries->merge(dataSeries.get());
59 // emit updated();
60 }
70 }
61 }
71 }
62
72
63 IDataSeries *Variable::dataSeries() const noexcept
73 IDataSeries *Variable::dataSeries() const noexcept
64 {
74 {
65 return impl->m_DataSeries.get();
75 return impl->m_DataSeries.get();
66 }
76 }
67
77
68 QVariantHash Variable::metadata() const noexcept
78 QVariantHash Variable::metadata() const noexcept
69 {
79 {
70 return impl->m_Metadata;
80 return impl->m_Metadata;
71 }
81 }
72
82
73 bool Variable::contains(const SqpRange &dateTime) const noexcept
83 bool Variable::contains(const SqpRange &range) const noexcept
74 {
84 {
75 return impl->m_DateTime.contains(dateTime);
85 return impl->m_Range.contains(range);
76 }
86 }
77
87
78 bool Variable::intersect(const SqpRange &dateTime) const noexcept
88 bool Variable::intersect(const SqpRange &range) const noexcept
79 {
89 {
80 return impl->m_DateTime.intersect(dateTime);
90 return impl->m_Range.intersect(range);
81 }
91 }
82
92
83 bool Variable::isInside(const SqpRange &dateTime) const noexcept
93 bool Variable::isInside(const SqpRange &range) const noexcept
84 {
94 {
85 return dateTime.contains(SqpRange{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd});
95 return range.contains(SqpRange{impl->m_Range.m_TStart, impl->m_Range.m_TEnd});
96 }
97
98 bool Variable::cacheContains(const SqpRange &range) const noexcept
99 {
100 return impl->m_CacheRange.contains(range);
101 }
102
103 bool Variable::cacheIntersect(const SqpRange &range) const noexcept
104 {
105 return impl->m_CacheRange.intersect(range);
106 }
107
108 bool Variable::cacheIsInside(const SqpRange &range) const noexcept
109 {
110 return range.contains(SqpRange{impl->m_CacheRange.m_TStart, impl->m_CacheRange.m_TEnd});
111 }
112
113
114 QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &range)
115 {
116 auto notInCache = QVector<SqpRange>{};
117
118 if (!this->cacheContains(range)) {
119 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
120 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
121 notInCache << range;
122 }
123 else if (range.m_TStart < impl->m_CacheRange.m_TStart
124 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
125 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart};
126 }
127 else if (range.m_TStart < impl->m_CacheRange.m_TStart
128 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
129 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}
130 << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TStart};
131 }
132 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
133 notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TStart};
134 }
135 else {
136 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
137 << QThread::currentThread();
138 }
139 }
140
141 return notInCache;
86 }
142 }
General Comments 1
Under Review
author

Auto status change to "Under Review"

You need to be logged in to leave comments. Login now