##// END OF EJS Templates
The cosinus provider can now handle data request
perrinel -
r231:14679d402ab7
parent child
Show More
@@ -1,16 +1,26
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
3
3
4 #include <Data/IDataProvider.h>
4 #include <Data/IDataProvider.h>
5
5
6 #include <QLoggingCategory>
7
8 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
9
6 /**
10 /**
7 * @brief The CosinusProvider class is an example of how a data provider can generate data
11 * @brief The CosinusProvider class is an example of how a data provider can generate data
8 */
12 */
9 class CosinusProvider : public IDataProvider {
13 class CosinusProvider : public IDataProvider {
10 public:
14 public:
11 /// @sa IDataProvider::retrieveData()
15 /// @sa IDataProvider::retrieveData()
12 std::unique_ptr<IDataSeries>
16 std::unique_ptr<IDataSeries>
13 retrieveData(const DataProviderParameters &parameters) const override;
17 retrieveData(const DataProviderParameters &parameters) const override;
18
19 void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override;
20
21
22 private:
23 std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime);
14 };
24 };
15
25
16 #endif // SCIQLOP_COSINUSPROVIDER_H
26 #endif // SCIQLOP_COSINUSPROVIDER_H
@@ -1,32 +1,71
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 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
9
8 std::unique_ptr<IDataSeries>
10 std::unique_ptr<IDataSeries>
9 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
11 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
10 {
12 {
11 auto dateTime = parameters.m_Time;
13 auto dateTime = parameters.m_Time;
12
14
13 // Gets the timerange from the parameters
15 // Gets the timerange from the parameters
14 auto start = dateTime.m_TStart;
16 auto start = dateTime.m_TStart;
15 auto end = dateTime.m_TEnd;
17 auto end = dateTime.m_TEnd;
16
18
17 // We assure that timerange is valid
19 // We assure that timerange is valid
18 if (end < start) {
20 if (end < start) {
19 std::swap(start, end);
21 std::swap(start, end);
20 }
22 }
21
23
22 // Generates scalar series containing cosinus values (one value per second)
24 // Generates scalar series containing cosinus values (one value per second)
23 auto scalarSeries
25 auto scalarSeries
24 = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
26 = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
25
27
26 auto dataIndex = 0;
28 auto dataIndex = 0;
27 for (auto time = start; time < end; ++time, ++dataIndex) {
29 for (auto time = start; time < end; ++time, ++dataIndex) {
28 scalarSeries->setData(dataIndex, time, std::cos(time));
30 scalarSeries->setData(dataIndex, time, std::cos(time));
29 }
31 }
30
32
31 return scalarSeries;
33 return scalarSeries;
32 }
34 }
35
36 void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList)
37 {
38 // NOTE: Try to use multithread if possible
39 foreach (const auto &dateTime, dateTimeList) {
40
41 auto scalarSeries = this->retrieveDataSeries(dateTime);
42
43 emit dataProvided(scalarSeries, dateTime);
44 }
45 }
46
47
48 std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime)
49 {
50
51 // Gets the timerange from the parameters
52 auto start = dateTime.m_TStart;
53 auto end = dateTime.m_TEnd;
54
55 // We assure that timerange is valid
56 if (end < start) {
57 std::swap(start, end);
58 }
59
60 // Generates scalar series containing cosinus values (one value per second)
61 auto scalarSeries
62 = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
63
64 auto dataIndex = 0;
65 for (auto time = start; time < end; ++time, ++dataIndex) {
66 scalarSeries->setData(dataIndex, time, std::cos(time));
67 }
68
69
70 return scalarSeries;
71 }
General Comments 0
You need to be logged in to leave comments. Login now