##// END OF EJS Templates
Replaces QString unit by a new struct...
Alexandre Leroux -
r177:4c64b786fec1
parent child
Show More
@@ -1,50 +1,50
1 #ifndef SCIQLOP_DATASERIES_H
1 #ifndef SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
3
3
4 #include <Data/ArrayData.h>
4 #include <Data/ArrayData.h>
5 #include <Data/IDataSeries.h>
5 #include <Data/IDataSeries.h>
6
6
7 #include <memory>
7 #include <memory>
8
8
9 /**
9 /**
10 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
10 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
11 *
11 *
12 * It proposes to set a dimension for the values ​​data
12 * It proposes to set a dimension for the values ​​data
13 *
13 *
14 * @tparam Dim The dimension of the values data
14 * @tparam Dim The dimension of the values data
15 *
15 *
16 */
16 */
17 template <int Dim>
17 template <int Dim>
18 class DataSeries : public IDataSeries {
18 class DataSeries : public IDataSeries {
19 public:
19 public:
20 /// @sa IDataSeries::xAxisData()
20 /// @sa IDataSeries::xAxisData()
21 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
21 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
22
22
23 /// @sa IDataSeries::xAxisUnit()
23 /// @sa IDataSeries::xAxisUnit()
24 QString xAxisUnit() const override { return m_XAxisUnit; }
24 Unit xAxisUnit() const override { return m_XAxisUnit; }
25
25
26 /// @return the values dataset
26 /// @return the values dataset
27 std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
27 std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
28
28
29 /// @sa IDataSeries::valuesUnit()
29 /// @sa IDataSeries::valuesUnit()
30 QString valuesUnit() const override { return m_ValuesUnit; }
30 Unit valuesUnit() const override { return m_ValuesUnit; }
31
31
32 protected:
32 protected:
33 /// Protected ctor (DataSeries is abstract)
33 /// Protected ctor (DataSeries is abstract)
34 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const QString &xAxisUnit,
34 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, Unit xAxisUnit,
35 std::shared_ptr<ArrayData<Dim> > valuesData, const QString &valuesUnit)
35 std::shared_ptr<ArrayData<Dim> > valuesData, Unit valuesUnit)
36 : m_XAxisData{xAxisData},
36 : m_XAxisData{xAxisData},
37 m_XAxisUnit{xAxisUnit},
37 m_XAxisUnit{std::move(xAxisUnit)},
38 m_ValuesData{valuesData},
38 m_ValuesData{valuesData},
39 m_ValuesUnit{valuesUnit}
39 m_ValuesUnit{std::move(valuesUnit)}
40 {
40 {
41 }
41 }
42
42
43 private:
43 private:
44 std::shared_ptr<ArrayData<1> > m_XAxisData;
44 std::shared_ptr<ArrayData<1> > m_XAxisData;
45 QString m_XAxisUnit;
45 Unit m_XAxisUnit;
46 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
46 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
47 QString m_ValuesUnit;
47 Unit m_ValuesUnit;
48 };
48 };
49
49
50 #endif // SCIQLOP_DATASERIES_H
50 #endif // SCIQLOP_DATASERIES_H
@@ -1,37 +1,47
1 #ifndef SCIQLOP_IDATASERIES_H
1 #ifndef SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
3
3
4 #include <QString>
4 #include <QString>
5
5
6 #include <memory>
6 #include <memory>
7
7
8 template <int Dim>
8 template <int Dim>
9 class ArrayData;
9 class ArrayData;
10
10
11 struct Unit {
12 explicit Unit(const QString &name = {}, bool timeUnit = false)
13 : m_Name{name}, m_TimeUnit{timeUnit}
14 {
15 }
16
17 QString m_Name; ///< Unit name
18 bool m_TimeUnit; ///< The unit is a unit of time
19 };
20
11 /**
21 /**
12 * @brief The IDataSeries aims to declare a data series.
22 * @brief The IDataSeries aims to declare a data series.
13 *
23 *
14 * A data series is an entity that contains at least :
24 * A data series is an entity that contains at least :
15 * - one dataset representing the x-axis
25 * - one dataset representing the x-axis
16 * - one dataset representing the values
26 * - one dataset representing the values
17 *
27 *
18 * Each dataset is represented by an ArrayData, and is associated with a unit.
28 * Each dataset is represented by an ArrayData, and is associated with a unit.
19 *
29 *
20 * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the
30 * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the
21 * IDataSeries. The x-axis dataset is always unidimensional.
31 * IDataSeries. The x-axis dataset is always unidimensional.
22 *
32 *
23 * @sa ArrayData
33 * @sa ArrayData
24 */
34 */
25 class IDataSeries {
35 class IDataSeries {
26 public:
36 public:
27 virtual ~IDataSeries() noexcept = default;
37 virtual ~IDataSeries() noexcept = default;
28
38
29 /// Returns the x-axis dataset
39 /// Returns the x-axis dataset
30 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
40 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
31
41
32 virtual QString xAxisUnit() const = 0;
42 virtual Unit xAxisUnit() const = 0;
33
43
34 virtual QString valuesUnit() const = 0;
44 virtual Unit valuesUnit() const = 0;
35 };
45 };
36
46
37 #endif // SCIQLOP_IDATASERIES_H
47 #endif // SCIQLOP_IDATASERIES_H
@@ -1,28 +1,28
1 #ifndef SCIQLOP_SCALARSERIES_H
1 #ifndef SCIQLOP_SCALARSERIES_H
2 #define SCIQLOP_SCALARSERIES_H
2 #define SCIQLOP_SCALARSERIES_H
3
3
4 #include <Data/DataSeries.h>
4 #include <Data/DataSeries.h>
5
5
6 /**
6 /**
7 * @brief The ScalarSeries class is the implementation for a data series representing a scalar.
7 * @brief The ScalarSeries class is the implementation for a data series representing a scalar.
8 */
8 */
9 class ScalarSeries : public DataSeries<1> {
9 class ScalarSeries : public DataSeries<1> {
10 public:
10 public:
11 /**
11 /**
12 * Ctor
12 * Ctor
13 * @param size the number of data the series will hold
13 * @param size the number of data the series will hold
14 * @param xAxisUnit x-axis unit
14 * @param xAxisUnit x-axis unit
15 * @param valuesUnit values unit
15 * @param valuesUnit values unit
16 */
16 */
17 explicit ScalarSeries(int size, const QString &xAxisUnit, const QString &valuesUnit);
17 explicit ScalarSeries(int size, Unit xAxisUnit, Unit valuesUnit);
18
18
19 /**
19 /**
20 * Sets data for a specific index. The index has to be valid to be effective
20 * Sets data for a specific index. The index has to be valid to be effective
21 * @param index the index to which the data will be set
21 * @param index the index to which the data will be set
22 * @param x the x-axis data
22 * @param x the x-axis data
23 * @param value the value data
23 * @param value the value data
24 */
24 */
25 void setData(int index, double x, double value) noexcept;
25 void setData(int index, double x, double value) noexcept;
26 };
26 };
27
27
28 #endif // SCIQLOP_SCALARSERIES_H
28 #endif // SCIQLOP_SCALARSERIES_H
@@ -1,13 +1,13
1 #include <Data/ScalarSeries.h>
1 #include <Data/ScalarSeries.h>
2
2
3 ScalarSeries::ScalarSeries(int size, const QString &xAxisUnit, const QString &valuesUnit)
3 ScalarSeries::ScalarSeries(int size, Unit xAxisUnit, Unit valuesUnit)
4 : DataSeries{std::make_shared<ArrayData<1> >(size), xAxisUnit,
4 : DataSeries{std::make_shared<ArrayData<1> >(size), std::move(xAxisUnit),
5 std::make_shared<ArrayData<1> >(size), valuesUnit}
5 std::make_shared<ArrayData<1> >(size), std::move(valuesUnit)}
6 {
6 {
7 }
7 }
8
8
9 void ScalarSeries::setData(int index, double x, double value) noexcept
9 void ScalarSeries::setData(int index, double x, double value) noexcept
10 {
10 {
11 xAxisData()->setData(index, x);
11 xAxisData()->setData(index, x);
12 valuesData()->setData(index, value);
12 valuesData()->setData(index, value);
13 }
13 }
@@ -1,30 +1,30
1 #include "CosinusProvider.h"
1 #include "CosinusProvider.h"
2
2
3 #include <Data/DataProviderParameters.h>
3 #include <Data/DataProviderParameters.h>
4 #include <Data/ScalarSeries.h>
4 #include <Data/ScalarSeries.h>
5
5
6 #include <cmath>
6 #include <cmath>
7
7
8 std::unique_ptr<IDataSeries>
8 std::unique_ptr<IDataSeries>
9 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
9 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
10 {
10 {
11 // Gets the timerange from the parameters
11 // Gets the timerange from the parameters
12 auto start = parameters.m_TStart;
12 auto start = parameters.m_TStart;
13 auto end = parameters.m_TEnd;
13 auto end = parameters.m_TEnd;
14
14
15 // We assure that timerange is valid
15 // We assure that timerange is valid
16 if (end < start) {
16 if (end < start) {
17 std::swap(start, end);
17 std::swap(start, end);
18 }
18 }
19
19
20 // Generates scalar series containing cosinus values (one value per second)
20 // Generates scalar series containing cosinus values (one value per second)
21 auto scalarSeries
21 auto scalarSeries
22 = std::make_unique<ScalarSeries>(end - start, QStringLiteral("t"), QStringLiteral(""));
22 = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
23
23
24 auto dataIndex = 0;
24 auto dataIndex = 0;
25 for (auto time = start; time < end; ++time, ++dataIndex) {
25 for (auto time = start; time < end; ++time, ++dataIndex) {
26 scalarSeries->setData(dataIndex, time, std::cos(time));
26 scalarSeries->setData(dataIndex, time, std::cos(time));
27 }
27 }
28
28
29 return scalarSeries;
29 return scalarSeries;
30 }
30 }
General Comments 0
You need to be logged in to leave comments. Login now