##// END OF EJS Templates
The cosinus provider can now handle data request
perrinel -
r215:14679d402ab7
parent child
Show More
@@ -3,6 +3,10
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 */
@@ -11,6 +15,12 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
@@ -5,6 +5,8
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 {
@@ -30,3 +32,40 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
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