##// END OF EJS Templates
The cosinus provider can now handle data request
perrinel -
r215:14679d402ab7
parent child
Show More
@@ -1,16 +1,26
1 1 #ifndef SCIQLOP_COSINUSPROVIDER_H
2 2 #define SCIQLOP_COSINUSPROVIDER_H
3 3
4 4 #include <Data/IDataProvider.h>
5 5
6 #include <QLoggingCategory>
7
8 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
9
6 10 /**
7 11 * @brief The CosinusProvider class is an example of how a data provider can generate data
8 12 */
9 13 class CosinusProvider : public IDataProvider {
10 14 public:
11 15 /// @sa IDataProvider::retrieveData()
12 16 std::unique_ptr<IDataSeries>
13 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 26 #endif // SCIQLOP_COSINUSPROVIDER_H
@@ -1,32 +1,71
1 1 #include "CosinusProvider.h"
2 2
3 3 #include <Data/DataProviderParameters.h>
4 4 #include <Data/ScalarSeries.h>
5 5
6 6 #include <cmath>
7 7
8 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
9
8 10 std::unique_ptr<IDataSeries>
9 11 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
10 12 {
11 13 auto dateTime = parameters.m_Time;
12 14
13 15 // Gets the timerange from the parameters
14 16 auto start = dateTime.m_TStart;
15 17 auto end = dateTime.m_TEnd;
16 18
17 19 // We assure that timerange is valid
18 20 if (end < start) {
19 21 std::swap(start, end);
20 22 }
21 23
22 24 // Generates scalar series containing cosinus values (one value per second)
23 25 auto scalarSeries
24 26 = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
25 27
26 28 auto dataIndex = 0;
27 29 for (auto time = start; time < end; ++time, ++dataIndex) {
28 30 scalarSeries->setData(dataIndex, time, std::cos(time));
29 31 }
30 32
31 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) {
note

ok

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