##// END OF EJS Templates
Handles merge of two data series
Alexandre Leroux -
r417:240544c83cc8
parent child
Show More
@@ -1,147 +1,167
1 #ifndef SCIQLOP_ARRAYDATA_H
1 #ifndef SCIQLOP_ARRAYDATA_H
2 #define SCIQLOP_ARRAYDATA_H
2 #define SCIQLOP_ARRAYDATA_H
3
3
4 #include <QReadLocker>
4 #include <QReadLocker>
5 #include <QReadWriteLock>
5 #include <QReadWriteLock>
6 #include <QVector>
6 #include <QVector>
7
7
8 #include <memory>
8 #include <memory>
9
9
10 /**
10 /**
11 * @brief The ArrayData class represents a dataset for a data series.
11 * @brief The ArrayData class represents a dataset for a data series.
12 *
12 *
13 * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim
13 * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim
14 * template-parameter.
14 * template-parameter.
15 *
15 *
16 * @tparam Dim the dimension of the ArrayData (one or two)
16 * @tparam Dim the dimension of the ArrayData (one or two)
17 * @sa IDataSeries
17 * @sa IDataSeries
18 */
18 */
19 template <int Dim>
19 template <int Dim>
20 class ArrayData {
20 class ArrayData {
21 public:
21 public:
22 /**
22 /**
23 * Ctor for a unidimensional ArrayData
23 * Ctor for a unidimensional ArrayData
24 * @param nbColumns the number of values the ArrayData will hold
24 * @param nbColumns the number of values the ArrayData will hold
25 */
25 */
26 template <int D = Dim, typename = std::enable_if_t<D == 1> >
26 template <int D = Dim, typename = std::enable_if_t<D == 1> >
27 explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}}
27 explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}}
28 {
28 {
29 QWriteLocker locker{&m_Lock};
29 QWriteLocker locker{&m_Lock};
30 m_Data[0].resize(nbColumns);
30 m_Data[0].resize(nbColumns);
31 }
31 }
32
32
33 /**
33 /**
34 * Ctor for a unidimensional ArrayData
34 * Ctor for a unidimensional ArrayData
35 * @param data the data the ArrayData will hold
35 * @param data the data the ArrayData will hold
36 */
36 */
37 template <int D = Dim, typename = std::enable_if_t<D == 1> >
37 template <int D = Dim, typename = std::enable_if_t<D == 1> >
38 explicit ArrayData(QVector<double> data) : m_Data{1, QVector<double>{}}
38 explicit ArrayData(QVector<double> data) : m_Data{1, QVector<double>{}}
39 {
39 {
40 QWriteLocker locker{&m_Lock};
40 QWriteLocker locker{&m_Lock};
41 m_Data[0] = std::move(data);
41 m_Data[0] = std::move(data);
42 }
42 }
43
43
44 /// Copy ctor
44 /// Copy ctor
45 explicit ArrayData(const ArrayData &other)
45 explicit ArrayData(const ArrayData &other)
46 {
46 {
47 QReadLocker otherLocker{&other.m_Lock};
47 QReadLocker otherLocker{&other.m_Lock};
48 QWriteLocker locker{&m_Lock};
48 QWriteLocker locker{&m_Lock};
49 m_Data = other.m_Data;
49 m_Data = other.m_Data;
50 }
50 }
51
51
52 /**
52 /**
53 * @return the data at a specified index
53 * @return the data at a specified index
54 * @remarks index must be a valid position
54 * @remarks index must be a valid position
55 * @remarks this method is only available for a unidimensional ArrayData
55 * @remarks this method is only available for a unidimensional ArrayData
56 */
56 */
57 template <int D = Dim, typename = std::enable_if_t<D == 1> >
57 template <int D = Dim, typename = std::enable_if_t<D == 1> >
58 double at(int index) const noexcept
58 double at(int index) const noexcept
59 {
59 {
60 QReadLocker locker{&m_Lock};
60 QReadLocker locker{&m_Lock};
61 return m_Data[0].at(index);
61 return m_Data[0].at(index);
62 }
62 }
63
63
64 /**
64 /**
65 * Sets a data at a specified index. The index has to be valid to be effective
65 * Sets a data at a specified index. The index has to be valid to be effective
66 * @param index the index to which the data will be set
66 * @param index the index to which the data will be set
67 * @param data the data to set
67 * @param data the data to set
68 * @remarks this method is only available for a unidimensional ArrayData
68 * @remarks this method is only available for a unidimensional ArrayData
69 */
69 */
70 template <int D = Dim, typename = std::enable_if_t<D == 1> >
70 template <int D = Dim, typename = std::enable_if_t<D == 1> >
71 void setData(int index, double data) noexcept
71 void setData(int index, double data) noexcept
72 {
72 {
73 QWriteLocker locker{&m_Lock};
73 QWriteLocker locker{&m_Lock};
74 if (index >= 0 && index < m_Data.at(0).size()) {
74 if (index >= 0 && index < m_Data.at(0).size()) {
75 m_Data[0].replace(index, data);
75 m_Data[0].replace(index, data);
76 }
76 }
77 }
77 }
78
78
79 /**
79 /**
80 * @return the data as a vector
80 * @return the data as a vector
81 * @remarks this method is only available for a unidimensional ArrayData
81 * @remarks this method is only available for a unidimensional ArrayData
82 */
82 */
83 template <int D = Dim, typename = std::enable_if_t<D == 1> >
83 template <int D = Dim, typename = std::enable_if_t<D == 1> >
84 QVector<double> data() const noexcept
84 QVector<double> data() const noexcept
85 {
85 {
86 QReadLocker locker{&m_Lock};
86 QReadLocker locker{&m_Lock};
87 return m_Data[0];
87 return m_Data[0];
88 }
88 }
89
89
90 /**
90 /**
91 * @return the data as a vector, as a const reference
91 * @return the data as a vector, as a const reference
92 * @remarks this method is only available for a unidimensional ArrayData
92 * @remarks this method is only available for a unidimensional ArrayData
93 */
93 */
94 template <int D = Dim, typename = std::enable_if_t<D == 1> >
94 template <int D = Dim, typename = std::enable_if_t<D == 1> >
95 const QVector<double> &cdata() const noexcept
95 const QVector<double> &cdata() const noexcept
96 {
96 {
97 QReadLocker locker{&m_Lock};
97 QReadLocker locker{&m_Lock};
98 return m_Data.at(0);
98 return m_Data.at(0);
99 }
99 }
100
100
101 // TODO Comment
101 /**
102 * Merges into the array data an other array data
103 * @param other the array data to merge with
104 * @param prepend if true, the other array data is inserted at the beginning, otherwise it is
105 * inserted at the end
106 * @remarks this method is only available for a unidimensional ArrayData
107 */
102 template <int D = Dim, typename = std::enable_if_t<D == 1> >
108 template <int D = Dim, typename = std::enable_if_t<D == 1> >
103 void merge(const ArrayData<1> &arrayData)
109 void add(const ArrayData<1> &other, bool prepend = false)
104 {
110 {
105 QWriteLocker locker{&m_Lock};
111 QWriteLocker locker{&m_Lock};
106 if (!m_Data.empty()) {
112 if (!m_Data.empty()) {
107 QReadLocker otherLocker{&arrayData.m_Lock};
113 QReadLocker otherLocker{&other.m_Lock};
108 m_Data[0] += arrayData.data();
114
115 if (prepend) {
116 const auto &otherData = other.data();
117 const auto otherDataSize = otherData.size();
118
119 auto &data = m_Data[0];
120 data.insert(data.begin(), otherDataSize, 0.);
121
122 for (auto i = 0; i < otherDataSize; ++i) {
123 data.replace(i, otherData.at(i));
124 }
125 }
126 else {
127 m_Data[0] += other.data();
128 }
109 }
129 }
110 }
130 }
111
131
112 template <int D = Dim, typename = std::enable_if_t<D == 1> >
132 template <int D = Dim, typename = std::enable_if_t<D == 1> >
113 int size() const
133 int size() const
114 {
134 {
115 QReadLocker locker{&m_Lock};
135 QReadLocker locker{&m_Lock};
116 return m_Data[0].size();
136 return m_Data[0].size();
117 }
137 }
118
138
119 template <int D = Dim, typename = std::enable_if_t<D == 1> >
139 template <int D = Dim, typename = std::enable_if_t<D == 1> >
120 std::shared_ptr<ArrayData<Dim> > sort(const std::vector<int> sortPermutation)
140 std::shared_ptr<ArrayData<Dim> > sort(const std::vector<int> sortPermutation)
121 {
141 {
122 QReadLocker locker{&m_Lock};
142 QReadLocker locker{&m_Lock};
123
143
124 const auto &data = m_Data.at(0);
144 const auto &data = m_Data.at(0);
125
145
126 // Inits result
146 // Inits result
127 auto sortedData = QVector<double>{};
147 auto sortedData = QVector<double>{};
128 sortedData.resize(data.size());
148 sortedData.resize(data.size());
129
149
130 std::transform(sortPermutation.cbegin(), sortPermutation.cend(), sortedData.begin(),
150 std::transform(sortPermutation.cbegin(), sortPermutation.cend(), sortedData.begin(),
131 [&data](int i) { return data[i]; });
151 [&data](int i) { return data[i]; });
132
152
133 return std::make_shared<ArrayData<Dim> >(std::move(sortedData));
153 return std::make_shared<ArrayData<Dim> >(std::move(sortedData));
134 }
154 }
135 void clear()
155 void clear()
136 {
156 {
137 QWriteLocker locker{&m_Lock};
157 QWriteLocker locker{&m_Lock};
138 m_Data.clear();
158 m_Data.clear();
139 }
159 }
140
160
141
161
142 private:
162 private:
143 QVector<QVector<double> > m_Data;
163 QVector<QVector<double> > m_Data;
144 mutable QReadWriteLock m_Lock;
164 mutable QReadWriteLock m_Lock;
145 };
165 };
146
166
147 #endif // SCIQLOP_ARRAYDATA_H
167 #endif // SCIQLOP_ARRAYDATA_H
@@ -1,134 +1,180
1 #ifndef SCIQLOP_DATASERIES_H
1 #ifndef SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
3
3
4 #include <Common/SortUtils.h>
4 #include <Common/SortUtils.h>
5
5
6 #include <Data/ArrayData.h>
6 #include <Data/ArrayData.h>
7 #include <Data/IDataSeries.h>
7 #include <Data/IDataSeries.h>
8
8
9 #include <QLoggingCategory>
9 #include <QLoggingCategory>
10
10
11 #include <QReadLocker>
11 #include <QReadLocker>
12 #include <QReadWriteLock>
12 #include <QReadWriteLock>
13 #include <memory>
13 #include <memory>
14
14
15 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSeries)
15 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSeries)
16 Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries")
16 Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries")
17
17
18
18
19 /**
19 /**
20 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
20 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
21 *
21 *
22 * It proposes to set a dimension for the values ​​data.
22 * It proposes to set a dimension for the values ​​data.
23 *
23 *
24 * A DataSeries is always sorted on its x-axis data.
24 * A DataSeries is always sorted on its x-axis data.
25 *
25 *
26 * @tparam Dim The dimension of the values data
26 * @tparam Dim The dimension of the values data
27 *
27 *
28 */
28 */
29 template <int Dim>
29 template <int Dim>
30 class DataSeries : public IDataSeries {
30 class DataSeries : public IDataSeries {
31 public:
31 public:
32 /// @sa IDataSeries::xAxisData()
32 /// @sa IDataSeries::xAxisData()
33 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
33 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
34 const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; }
34 const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; }
35
35
36 /// @sa IDataSeries::xAxisUnit()
36 /// @sa IDataSeries::xAxisUnit()
37 Unit xAxisUnit() const override { return m_XAxisUnit; }
37 Unit xAxisUnit() const override { return m_XAxisUnit; }
38
38
39 /// @return the values dataset
39 /// @return the values dataset
40 std::shared_ptr<ArrayData<Dim> > valuesData() { return m_ValuesData; }
40 std::shared_ptr<ArrayData<Dim> > valuesData() { return m_ValuesData; }
41 const std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
41 const std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
42
42
43 /// @sa IDataSeries::valuesUnit()
43 /// @sa IDataSeries::valuesUnit()
44 Unit valuesUnit() const override { return m_ValuesUnit; }
44 Unit valuesUnit() const override { return m_ValuesUnit; }
45
45
46 void clear()
46 void clear()
47 {
47 {
48 m_XAxisData->clear();
48 m_XAxisData->clear();
49 m_ValuesData->clear();
49 m_ValuesData->clear();
50 }
50 }
51
51
52 /// @sa IDataSeries::merge()
52 /// Merges into the data series an other data series
53 /// @remarks the data series to merge with is cleared after the operation
53 void merge(IDataSeries *dataSeries) override
54 void merge(IDataSeries *dataSeries) override
54 {
55 {
55 if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
56 dataSeries->lockWrite();
56 m_XAxisData->merge(*dimDataSeries->xAxisData());
57 lockWrite();
57 m_ValuesData->merge(*dimDataSeries->valuesData());
58
58 dimDataSeries->clear();
59 if (auto other = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
60 const auto &otherXAxisData = other->xAxisData()->cdata();
61 const auto &xAxisData = m_XAxisData->cdata();
62
63 // As data series are sorted, we can improve performances of merge, by call the sort
64 // method only if the two data series overlap.
65 if (!otherXAxisData.empty()) {
66 auto firstValue = otherXAxisData.front();
67 auto lastValue = otherXAxisData.back();
68
69 auto xAxisDataBegin = xAxisData.cbegin();
70 auto xAxisDataEnd = xAxisData.cend();
71
72 bool prepend;
73 bool sortNeeded;
74
75 if (std::lower_bound(xAxisDataBegin, xAxisDataEnd, firstValue) == xAxisDataEnd) {
76 // Other data series if after data series
77 prepend = false;
78 sortNeeded = false;
79 }
80 else if (std::upper_bound(xAxisDataBegin, xAxisDataEnd, lastValue)
81 == xAxisDataBegin) {
82 // Other data series if before data series
83 prepend = true;
84 sortNeeded = false;
85 }
86 else {
87 // The two data series overlap
88 prepend = false;
89 sortNeeded = true;
90 }
91
92 // Makes the merge
93 m_XAxisData->add(*other->xAxisData(), prepend);
94 m_ValuesData->add(*other->valuesData(), prepend);
95
96 if (sortNeeded) {
97 sort();
98 }
99 }
100
101 // Clears the other data series
102 other->clear();
59 }
103 }
60 else {
104 else {
61 qCWarning(LOG_DataSeries())
105 qCWarning(LOG_DataSeries())
62 << QObject::tr("Dection of a type of IDataSeries we cannot merge with !");
106 << QObject::tr("Detection of a type of IDataSeries we cannot merge with !");
63 }
107 }
108 unlock();
109 dataSeries->unlock();
64 }
110 }
65
111
66 virtual void lockRead() { m_Lock.lockForRead(); }
112 virtual void lockRead() { m_Lock.lockForRead(); }
67 virtual void lockWrite() { m_Lock.lockForWrite(); }
113 virtual void lockWrite() { m_Lock.lockForWrite(); }
68 virtual void unlock() { m_Lock.unlock(); }
114 virtual void unlock() { m_Lock.unlock(); }
69
115
70 protected:
116 protected:
71 /// Protected ctor (DataSeries is abstract). The vectors must have the same size, otherwise a
117 /// Protected ctor (DataSeries is abstract). The vectors must have the same size, otherwise a
72 /// DataSeries with no values will be created.
118 /// DataSeries with no values will be created.
73 /// @remarks data series is automatically sorted on its x-axis data
119 /// @remarks data series is automatically sorted on its x-axis data
74 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
120 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
75 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
121 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
76 : m_XAxisData{xAxisData},
122 : m_XAxisData{xAxisData},
77 m_XAxisUnit{xAxisUnit},
123 m_XAxisUnit{xAxisUnit},
78 m_ValuesData{valuesData},
124 m_ValuesData{valuesData},
79 m_ValuesUnit{valuesUnit}
125 m_ValuesUnit{valuesUnit}
80 {
126 {
81 if (m_XAxisData->size() != m_ValuesData->size()) {
127 if (m_XAxisData->size() != m_ValuesData->size()) {
82 clear();
128 clear();
83 }
129 }
84
130
85 // Sorts data if it's not the case
131 // Sorts data if it's not the case
86 const auto &xAxisCData = m_XAxisData->cdata();
132 const auto &xAxisCData = m_XAxisData->cdata();
87 if (!std::is_sorted(xAxisCData.cbegin(), xAxisCData.cend())) {
133 if (!std::is_sorted(xAxisCData.cbegin(), xAxisCData.cend())) {
88 sort();
134 sort();
89 }
135 }
90 }
136 }
91
137
92 /// Copy ctor
138 /// Copy ctor
93 explicit DataSeries(const DataSeries<Dim> &other)
139 explicit DataSeries(const DataSeries<Dim> &other)
94 : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)},
140 : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)},
95 m_XAxisUnit{other.m_XAxisUnit},
141 m_XAxisUnit{other.m_XAxisUnit},
96 m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)},
142 m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)},
97 m_ValuesUnit{other.m_ValuesUnit}
143 m_ValuesUnit{other.m_ValuesUnit}
98 {
144 {
99 // Since a series is ordered from its construction and is always ordered, it is not
145 // Since a series is ordered from its construction and is always ordered, it is not
100 // necessary to call the sort method here ('other' is sorted)
146 // necessary to call the sort method here ('other' is sorted)
101 }
147 }
102
148
103 /// Assignment operator
149 /// Assignment operator
104 template <int D>
150 template <int D>
105 DataSeries &operator=(DataSeries<D> other)
151 DataSeries &operator=(DataSeries<D> other)
106 {
152 {
107 std::swap(m_XAxisData, other.m_XAxisData);
153 std::swap(m_XAxisData, other.m_XAxisData);
108 std::swap(m_XAxisUnit, other.m_XAxisUnit);
154 std::swap(m_XAxisUnit, other.m_XAxisUnit);
109 std::swap(m_ValuesData, other.m_ValuesData);
155 std::swap(m_ValuesData, other.m_ValuesData);
110 std::swap(m_ValuesUnit, other.m_ValuesUnit);
156 std::swap(m_ValuesUnit, other.m_ValuesUnit);
111
157
112 return *this;
158 return *this;
113 }
159 }
114
160
115 private:
161 private:
116 /**
162 /**
117 * Sorts data series on its x-axis data
163 * Sorts data series on its x-axis data
118 */
164 */
119 void sort() noexcept
165 void sort() noexcept
120 {
166 {
121 auto permutation = SortUtils::sortPermutation(*m_XAxisData, std::less<double>());
167 auto permutation = SortUtils::sortPermutation(*m_XAxisData, std::less<double>());
122 m_XAxisData = m_XAxisData->sort(permutation);
168 m_XAxisData = m_XAxisData->sort(permutation);
123 m_ValuesData = m_ValuesData->sort(permutation);
169 m_ValuesData = m_ValuesData->sort(permutation);
124 }
170 }
125
171
126 std::shared_ptr<ArrayData<1> > m_XAxisData;
172 std::shared_ptr<ArrayData<1> > m_XAxisData;
127 Unit m_XAxisUnit;
173 Unit m_XAxisUnit;
128 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
174 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
129 Unit m_ValuesUnit;
175 Unit m_ValuesUnit;
130
176
131 QReadWriteLock m_Lock;
177 QReadWriteLock m_Lock;
132 };
178 };
133
179
134 #endif // SCIQLOP_DATASERIES_H
180 #endif // SCIQLOP_DATASERIES_H
@@ -1,90 +1,86
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 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_DateTime{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr}
15 {
15 {
16 }
16 }
17
17
18 QString m_Name;
18 QString m_Name;
19
19
20 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;
21 QVariantHash m_Metadata;
22 std::unique_ptr<IDataSeries> m_DataSeries;
22 std::unique_ptr<IDataSeries> m_DataSeries;
23 };
23 };
24
24
25 Variable::Variable(const QString &name, const SqpDateTime &dateTime, const QVariantHash &metadata)
25 Variable::Variable(const QString &name, const SqpDateTime &dateTime, const QVariantHash &metadata)
26 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)}
26 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)}
27 {
27 {
28 }
28 }
29
29
30 QString Variable::name() const noexcept
30 QString Variable::name() const noexcept
31 {
31 {
32 return impl->m_Name;
32 return impl->m_Name;
33 }
33 }
34
34
35 SqpDateTime Variable::dateTime() const noexcept
35 SqpDateTime Variable::dateTime() const noexcept
36 {
36 {
37 return impl->m_DateTime;
37 return impl->m_DateTime;
38 }
38 }
39
39
40 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
40 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
41 {
41 {
42 impl->m_DateTime = dateTime;
42 impl->m_DateTime = dateTime;
43 }
43 }
44
44
45 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
45 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
46 {
46 {
47 qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName();
47 qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName();
48 if (!dataSeries) {
48 if (!dataSeries) {
49 /// @todo ALX : log
49 /// @todo ALX : log
50 return;
50 return;
51 }
51 }
52
52
53 // Inits the data series of the variable
53 // Inits the data series of the variable
54 if (!impl->m_DataSeries) {
54 if (!impl->m_DataSeries) {
55 impl->m_DataSeries = dataSeries->clone();
55 impl->m_DataSeries = dataSeries->clone();
56 }
56 }
57 else {
57 else {
58 dataSeries->lockWrite();
59 impl->m_DataSeries->lockWrite();
60 impl->m_DataSeries->merge(dataSeries.get());
58 impl->m_DataSeries->merge(dataSeries.get());
61 impl->m_DataSeries->unlock();
62 dataSeries->unlock();
63 // emit updated();
59 // emit updated();
64 }
60 }
65 }
61 }
66
62
67 IDataSeries *Variable::dataSeries() const noexcept
63 IDataSeries *Variable::dataSeries() const noexcept
68 {
64 {
69 return impl->m_DataSeries.get();
65 return impl->m_DataSeries.get();
70 }
66 }
71
67
72 QVariantHash Variable::metadata() const noexcept
68 QVariantHash Variable::metadata() const noexcept
73 {
69 {
74 return impl->m_Metadata;
70 return impl->m_Metadata;
75 }
71 }
76
72
77 bool Variable::contains(const SqpDateTime &dateTime) const noexcept
73 bool Variable::contains(const SqpDateTime &dateTime) const noexcept
78 {
74 {
79 return impl->m_DateTime.contains(dateTime);
75 return impl->m_DateTime.contains(dateTime);
80 }
76 }
81
77
82 bool Variable::intersect(const SqpDateTime &dateTime) const noexcept
78 bool Variable::intersect(const SqpDateTime &dateTime) const noexcept
83 {
79 {
84 return impl->m_DateTime.intersect(dateTime);
80 return impl->m_DateTime.intersect(dateTime);
85 }
81 }
86
82
87 bool Variable::isInside(const SqpDateTime &dateTime) const noexcept
83 bool Variable::isInside(const SqpDateTime &dateTime) const noexcept
88 {
84 {
89 return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd});
85 return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd});
90 }
86 }
General Comments 0
You need to be logged in to leave comments. Login now