@@ -8,6 +8,7 | |||||
8 | #include <Data/ArrayData.h> |
|
8 | #include <Data/ArrayData.h> | |
9 | #include <Data/DataSeriesMergeHelper.h> |
|
9 | #include <Data/DataSeriesMergeHelper.h> | |
10 | #include <Data/IDataSeries.h> |
|
10 | #include <Data/IDataSeries.h> | |
|
11 | #include <Data/OptionalAxis.h> | |||
11 |
|
12 | |||
12 | #include <QLoggingCategory> |
|
13 | #include <QLoggingCategory> | |
13 | #include <QReadLocker> |
|
14 | #include <QReadLocker> | |
@@ -156,7 +157,14 public: | |||||
156 |
|
157 | |||
157 | bool isEmpty() const noexcept { return m_XAxisData->size() == 0; } |
|
158 | bool isEmpty() const noexcept { return m_XAxisData->size() == 0; } | |
158 |
|
159 | |||
159 | /// Merges into the data series an other data series |
|
160 | /// Merges into the data series an other data series. | |
|
161 | /// | |||
|
162 | /// The two dataseries: | |||
|
163 | /// - must be of the same dimension | |||
|
164 | /// - must have the same y-axis (if defined) | |||
|
165 | /// | |||
|
166 | /// If the prerequisites are not valid, the method does nothing | |||
|
167 | /// | |||
160 | /// @remarks the data series to merge with is cleared after the operation |
|
168 | /// @remarks the data series to merge with is cleared after the operation | |
161 | void merge(IDataSeries *dataSeries) override |
|
169 | void merge(IDataSeries *dataSeries) override | |
162 | { |
|
170 | { | |
@@ -164,7 +172,13 public: | |||||
164 | lockWrite(); |
|
172 | lockWrite(); | |
165 |
|
173 | |||
166 | if (auto other = dynamic_cast<DataSeries<Dim> *>(dataSeries)) { |
|
174 | if (auto other = dynamic_cast<DataSeries<Dim> *>(dataSeries)) { | |
167 | DataSeriesMergeHelper::merge(*other, *this); |
|
175 | if (m_YAxis == other->m_YAxis) { | |
|
176 | DataSeriesMergeHelper::merge(*other, *this); | |||
|
177 | } | |||
|
178 | else { | |||
|
179 | qCWarning(LOG_DataSeries()) | |||
|
180 | << QObject::tr("Can't merge data series that have not the same y-axis"); | |||
|
181 | } | |||
168 | } |
|
182 | } | |
169 | else { |
|
183 | else { | |
170 | qCWarning(LOG_DataSeries()) |
|
184 | qCWarning(LOG_DataSeries()) | |
@@ -325,18 +339,31 public: | |||||
325 | virtual void unlock() { m_Lock.unlock(); } |
|
339 | virtual void unlock() { m_Lock.unlock(); } | |
326 |
|
340 | |||
327 | protected: |
|
341 | protected: | |
328 |
/// Protected ctor (DataSeries is abstract). |
|
342 | /// Protected ctor (DataSeries is abstract). | |
329 | /// DataSeries with no values will be created. |
|
343 | /// | |
|
344 | /// Data vectors must be consistent with each other, otherwise an exception will be thrown (@sa | |||
|
345 | /// class description for consistent rules) | |||
330 | /// @remarks data series is automatically sorted on its x-axis data |
|
346 | /// @remarks data series is automatically sorted on its x-axis data | |
|
347 | /// @throws std::invalid_argument if the data are inconsistent with each other | |||
331 | explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit, |
|
348 | explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit, | |
332 |
std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit |
|
349 | std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit, | |
|
350 | OptionalAxis yAxis = OptionalAxis{}) | |||
333 | : m_XAxisData{xAxisData}, |
|
351 | : m_XAxisData{xAxisData}, | |
334 | m_XAxisUnit{xAxisUnit}, |
|
352 | m_XAxisUnit{xAxisUnit}, | |
335 | m_ValuesData{valuesData}, |
|
353 | m_ValuesData{valuesData}, | |
336 | m_ValuesUnit{valuesUnit} |
|
354 | m_ValuesUnit{valuesUnit}, | |
|
355 | m_YAxis{std::move(yAxis)} | |||
337 | { |
|
356 | { | |
338 | if (m_XAxisData->size() != m_ValuesData->size()) { |
|
357 | if (m_XAxisData->size() != m_ValuesData->size()) { | |
339 | clear(); |
|
358 | throw std::invalid_argument{ | |
|
359 | "The number of values by component must be equal to the number of x-axis data"}; | |||
|
360 | } | |||
|
361 | ||||
|
362 | // Validates y-axis (if defined) | |||
|
363 | if (yAxis.isDefined() && (yAxis.size() != m_ValuesData->componentCount())) { | |||
|
364 | throw std::invalid_argument{ | |||
|
365 | "As the y-axis is defined, the number of value components must be equal to the " | |||
|
366 | "number of y-axis data"}; | |||
340 | } |
|
367 | } | |
341 |
|
368 | |||
342 | // Sorts data if it's not the case |
|
369 | // Sorts data if it's not the case | |
@@ -351,12 +378,16 protected: | |||||
351 | : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)}, |
|
378 | : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)}, | |
352 | m_XAxisUnit{other.m_XAxisUnit}, |
|
379 | m_XAxisUnit{other.m_XAxisUnit}, | |
353 | m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)}, |
|
380 | m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)}, | |
354 | m_ValuesUnit{other.m_ValuesUnit} |
|
381 | m_ValuesUnit{other.m_ValuesUnit}, | |
|
382 | m_YAxis{other.m_YAxis} | |||
355 | { |
|
383 | { | |
356 | // Since a series is ordered from its construction and is always ordered, it is not |
|
384 | // Since a series is ordered from its construction and is always ordered, it is not | |
357 | // necessary to call the sort method here ('other' is sorted) |
|
385 | // necessary to call the sort method here ('other' is sorted) | |
358 | } |
|
386 | } | |
359 |
|
387 | |||
|
388 | /// @return the y-axis associated to the data series | |||
|
389 | OptionalAxis yAxis() const { return m_YAxis; } | |||
|
390 | ||||
360 | /// Assignment operator |
|
391 | /// Assignment operator | |
361 | template <int D> |
|
392 | template <int D> | |
362 | DataSeries &operator=(DataSeries<D> other) |
|
393 | DataSeries &operator=(DataSeries<D> other) | |
@@ -365,6 +396,7 protected: | |||||
365 | std::swap(m_XAxisUnit, other.m_XAxisUnit); |
|
396 | std::swap(m_XAxisUnit, other.m_XAxisUnit); | |
366 | std::swap(m_ValuesData, other.m_ValuesData); |
|
397 | std::swap(m_ValuesData, other.m_ValuesData); | |
367 | std::swap(m_ValuesUnit, other.m_ValuesUnit); |
|
398 | std::swap(m_ValuesUnit, other.m_ValuesUnit); | |
|
399 | std::swap(m_YAxis, other.m_YAxis); | |||
368 |
|
400 | |||
369 | return *this; |
|
401 | return *this; | |
370 | } |
|
402 | } | |
@@ -380,11 +412,17 private: | |||||
380 | m_ValuesData = m_ValuesData->sort(permutation); |
|
412 | m_ValuesData = m_ValuesData->sort(permutation); | |
381 | } |
|
413 | } | |
382 |
|
414 | |||
|
415 | // x-axis | |||
383 | std::shared_ptr<ArrayData<1> > m_XAxisData; |
|
416 | std::shared_ptr<ArrayData<1> > m_XAxisData; | |
384 | Unit m_XAxisUnit; |
|
417 | Unit m_XAxisUnit; | |
|
418 | ||||
|
419 | // values | |||
385 | std::shared_ptr<ArrayData<Dim> > m_ValuesData; |
|
420 | std::shared_ptr<ArrayData<Dim> > m_ValuesData; | |
386 | Unit m_ValuesUnit; |
|
421 | Unit m_ValuesUnit; | |
387 |
|
422 | |||
|
423 | // y-axis (optional) | |||
|
424 | OptionalAxis m_YAxis; | |||
|
425 | ||||
388 | QReadWriteLock m_Lock; |
|
426 | QReadWriteLock m_Lock; | |
389 | }; |
|
427 | }; | |
390 |
|
428 |
General Comments 0
You need to be logged in to leave comments.
Login now