@@ -0,0 +1,9 | |||
|
1 | #ifndef DEBUG_H | |
|
2 | #define DEBUG_H | |
|
3 | ||
|
4 | #ifdef SCIQLOP_CRASH_ON_ERROR | |
|
5 | #define SCIQLOP_ERROR(x) assert(false) | |
|
6 | #else | |
|
7 | #define SCIQLOP_ERROR(x) | |
|
8 | #endif | |
|
9 | #endif |
@@ -50,6 +50,7 FILE (GLOB_RECURSE core_SRCS | |||
|
50 | 50 | ./include/Common/Numeric.h |
|
51 | 51 | ./include/Common/deprecate.h |
|
52 | 52 | ./include/Common/containers.h |
|
53 | ./include/Common/debug.h | |
|
53 | 54 | ./include/Plugin/IPlugin.h |
|
54 | 55 | ./include/Data/ArrayDataIterator.h |
|
55 | 56 | ./include/Data/VariableRequest.h |
@@ -46,7 +46,12 public: | |||
|
46 | 46 | = 0; |
|
47 | 47 | ) |
|
48 | 48 | |
|
49 | virtual QUuid getData(const DataProviderParameters ¶meters){return QUuid::createUuid();} | |
|
49 | // Synchronous call -> asyncGetData may be written for asynchronous get | |
|
50 | virtual IDataSeries* getData(const DataProviderParameters ¶meters) | |
|
51 | { | |
|
52 | Q_UNUSED(parameters); | |
|
53 | return nullptr; | |
|
54 | } | |
|
50 | 55 | |
|
51 | 56 | |
|
52 | 57 | DEPRECATE( |
@@ -56,7 +61,7 public: | |||
|
56 | 61 | virtual void requestDataAborting(QUuid acqIdentifier) = 0; |
|
57 | 62 | ) |
|
58 | 63 | |
|
59 | virtual void abort(QUuid requestID){} | |
|
64 | virtual void abort(QUuid requestID){Q_UNUSED(requestID);} | |
|
60 | 65 | |
|
61 | 66 | signals: |
|
62 | 67 | DEPRECATE( |
@@ -9,7 +9,9 | |||
|
9 | 9 | |
|
10 | 10 | #include <QLoggingCategory> |
|
11 | 11 | #include <QObject> |
|
12 | #include <QUuid> | |
|
12 | 13 | |
|
14 | #include <Common/deprecate.h> | |
|
13 | 15 | #include <Common/MetaTypes.h> |
|
14 | 16 | #include <Common/spimpl.h> |
|
15 | 17 | |
@@ -70,7 +72,10 public: | |||
|
70 | 72 | |
|
71 | 73 | QVector<DateTimeRange> provideNotInCacheRangeList(const DateTimeRange &range) const noexcept; |
|
72 | 74 | QVector<DateTimeRange> provideInCacheRangeList(const DateTimeRange &range) const noexcept; |
|
75 | DEPRECATE( | |
|
73 | 76 | void mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; |
|
77 | ) | |
|
78 | void mergeDataSeries(IDataSeries* dataSeries) noexcept; | |
|
74 | 79 | |
|
75 | 80 | static QVector<DateTimeRange> provideNotInCacheRangeList(const DateTimeRange &oldRange, |
|
76 | 81 | const DateTimeRange &nextRange); |
@@ -78,6 +83,7 public: | |||
|
78 | 83 | static QVector<DateTimeRange> provideInCacheRangeList(const DateTimeRange &oldRange, |
|
79 | 84 | const DateTimeRange &nextRange); |
|
80 | 85 | |
|
86 | QUuid ID(){return _uuid;} | |
|
81 | 87 | signals: |
|
82 | 88 | void updated(); |
|
83 | 89 | /// Signal emitted when when the data series of the variable is loaded for the first time |
@@ -86,6 +92,7 signals: | |||
|
86 | 92 | private: |
|
87 | 93 | class VariablePrivate; |
|
88 | 94 | spimpl::unique_impl_ptr<VariablePrivate> impl; |
|
95 | QUuid _uuid; | |
|
89 | 96 | }; |
|
90 | 97 | |
|
91 | 98 | // Required for using shared_ptr in signals/slots |
@@ -1,26 +1,36 | |||
|
1 | #include <Common/spimpl.h> | |
|
2 | 1 |
|
|
3 | 2 | #include <vector> |
|
4 | 3 | #include <QHash> |
|
4 | #include <QObject> | |
|
5 | #include <QMutexLocker> | |
|
6 | #include <QUuid> | |
|
7 | #include <QItemSelectionModel> | |
|
8 | #include <Common/spimpl.h> | |
|
5 | 9 | #include <Variable/Variable.h> |
|
6 | 10 | #include <Variable/VariableSynchronizationGroup.h> |
|
7 | 11 | #include <Variable/VariableModel.h> |
|
8 | 12 | #include <Data/IDataProvider.h> |
|
9 | 13 | #include "Data/DateTimeRange.h" |
|
10 | #include <QMutexLocker> | |
|
11 | #include <QUuid> | |
|
12 | #include <QItemSelectionModel> | |
|
13 | 14 | |
|
14 |
class VariableController2 |
|
|
15 | class VariableController2 | |
|
15 | class VariableController2: public QObject | |
|
16 | 16 | { |
|
17 | class VariableController2Private; | |
|
18 | Q_OBJECT | |
|
19 | ||
|
17 | 20 | spimpl::unique_impl_ptr<VariableController2Private> impl; |
|
18 | 21 | |
|
19 | 22 | public: |
|
20 | 23 | explicit VariableController2(); |
|
21 | 24 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, |
|
22 | 25 | std::shared_ptr<IDataProvider> provider, const DateTimeRange &range); |
|
23 | void changeRange(QUuid variable, DateTimeRange r); | |
|
24 | void asyncChangeRange(QUuid variable, DateTimeRange r); | |
|
26 | ||
|
27 | void deleteVariable(std::shared_ptr<Variable> variable); | |
|
28 | void changeRange(std::shared_ptr<Variable> variable, DateTimeRange r); | |
|
29 | void asyncChangeRange(std::shared_ptr<Variable> variable, DateTimeRange r); | |
|
30 | const std::set<std::shared_ptr<Variable> > &variables(); | |
|
31 | ||
|
32 | signals: | |
|
33 | void variableAdded(std::shared_ptr<Variable>); | |
|
34 | void variableDeleted(std::shared_ptr<Variable>); | |
|
25 | 35 | |
|
26 | 36 | }; |
@@ -6,6 +6,7 | |||
|
6 | 6 | #include <QMutex> |
|
7 | 7 | #include <QReadWriteLock> |
|
8 | 8 | #include <QThread> |
|
9 | #include <Common/debug.h> | |
|
9 | 10 | |
|
10 | 11 | Q_LOGGING_CATEGORY(LOG_Variable, "Variable") |
|
11 | 12 | |
@@ -106,12 +107,14 struct Variable::VariablePrivate { | |||
|
106 | 107 | }; |
|
107 | 108 | |
|
108 | 109 | Variable::Variable(const QString &name, const QVariantHash &metadata) |
|
109 | : impl{spimpl::make_unique_impl<VariablePrivate>(name, metadata)} | |
|
110 | : impl{spimpl::make_unique_impl<VariablePrivate>(name, metadata)}, | |
|
111 | _uuid{QUuid::createUuid()} | |
|
110 | 112 | { |
|
111 | 113 | } |
|
112 | 114 | |
|
113 | 115 | Variable::Variable(const Variable &other) |
|
114 | : impl{spimpl::make_unique_impl<VariablePrivate>(*other.impl)} | |
|
116 | : impl{spimpl::make_unique_impl<VariablePrivate>(*other.impl)}, | |
|
117 | _uuid{QUuid::createUuid()} //is a clone but must have a != uuid | |
|
115 | 118 | { |
|
116 | 119 | } |
|
117 | 120 | |
@@ -206,6 +209,34 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |||
|
206 | 209 | } |
|
207 | 210 | } |
|
208 | 211 | |
|
212 | void Variable::mergeDataSeries(IDataSeries *dataSeries) noexcept | |
|
213 | { | |
|
214 | if (dataSeries==nullptr) { | |
|
215 | SCIQLOP_ERROR("Given IDataSeries is nullptr"); | |
|
216 | return; | |
|
217 | } | |
|
218 | ||
|
219 | auto dataInit = false; | |
|
220 | // @TODO move to impl to Pimpl this is what it stands for... | |
|
221 | // Add or merge the data | |
|
222 | impl->lockWrite(); | |
|
223 | if (!impl->m_DataSeries) { | |
|
224 | //@TODO find a better way | |
|
225 | impl->m_DataSeries = dataSeries->clone(); | |
|
226 | dataInit = true; | |
|
227 | delete dataSeries; | |
|
228 | } | |
|
229 | else { | |
|
230 | impl->m_DataSeries->merge(dataSeries); | |
|
231 | } | |
|
232 | impl->purgeDataSeries(); | |
|
233 | impl->unlock(); | |
|
234 | ||
|
235 | if (dataInit) { | |
|
236 | emit dataInitialized(); | |
|
237 | } | |
|
238 | } | |
|
239 | ||
|
209 | 240 | |
|
210 | 241 | std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept |
|
211 | 242 | { |
@@ -1,17 +1,56 | |||
|
1 | 1 | #include "Variable/VariableController2.h" |
|
2 | #include <Common/containers.h> | |
|
3 | #include <Common/debug.h> | |
|
4 | #include <Data/DataProviderParameters.h> | |
|
2 | 5 | |
|
3 | ||
|
4 | class VariableController2Private | |
|
6 | class VariableController2::VariableController2Private | |
|
5 | 7 | { |
|
6 | ||
|
8 | std::set<std::shared_ptr<Variable>> _variables; | |
|
9 | QMap<QUuid,std::shared_ptr<IDataProvider>> _providers; | |
|
7 | 10 | public: |
|
8 | 11 | VariableController2Private(QObject* parent=Q_NULLPTR) |
|
9 |
{ |
|
|
12 | { | |
|
13 | Q_UNUSED(parent); | |
|
14 | } | |
|
15 | ||
|
10 | 16 | ~VariableController2Private() = default; |
|
17 | ||
|
11 | 18 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range) |
|
12 | 19 | { |
|
13 |
|
|
|
20 | auto newVar = std::make_shared<Variable>(name,metadata); | |
|
21 | this->_variables.insert(newVar); | |
|
22 | this->_providers[newVar->ID()] = provider; | |
|
23 | return newVar; | |
|
24 | } | |
|
25 | ||
|
26 | void deleteVariable(std::shared_ptr<Variable> variable) | |
|
27 | { | |
|
28 | if(this->_providers.contains(variable->ID())) | |
|
29 | this->_providers.remove(variable->ID()); | |
|
30 | if(SciQLop::containers::contains(this->_variables, variable)) | |
|
31 | this->_variables.erase(variable); | |
|
32 | } | |
|
33 | ||
|
34 | void changeRange(std::shared_ptr<Variable> variable, DateTimeRange r) | |
|
35 | { | |
|
36 | if(_providers.contains(variable->ID())) | |
|
37 | { | |
|
38 | auto provider = _providers[variable->ID()]; | |
|
39 | auto data = provider->getData(DataProviderParameters{{r},variable->metadata()}); | |
|
40 | variable->mergeDataSeries(data); | |
|
41 | } | |
|
42 | else | |
|
43 | { | |
|
44 | SCIQLOP_ERROR("No provider found for given variable"); | |
|
14 | 45 | } |
|
46 | } | |
|
47 | ||
|
48 | ||
|
49 | const std::set<std::shared_ptr<Variable>>& variables() | |
|
50 | { | |
|
51 | return _variables; | |
|
52 | } | |
|
53 | ||
|
15 | 54 | }; |
|
16 | 55 | |
|
17 | 56 | VariableController2::VariableController2() |
@@ -20,6 +59,25 VariableController2::VariableController2() | |||
|
20 | 59 | |
|
21 | 60 | std::shared_ptr<Variable> VariableController2::createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range) |
|
22 | 61 | { |
|
23 |
|
|
|
62 | auto var = impl->createVariable(name, metadata, provider, range); | |
|
63 | emit variableAdded(var); | |
|
64 | impl->changeRange(var,range); | |
|
65 | return var; | |
|
66 | } | |
|
67 | ||
|
68 | void VariableController2::deleteVariable(std::shared_ptr<Variable> variable) | |
|
69 | { | |
|
70 | impl->deleteVariable(variable); | |
|
71 | emit variableDeleted(variable); | |
|
72 | } | |
|
73 | ||
|
74 | void VariableController2::changeRange(std::shared_ptr<Variable> variable, DateTimeRange r) | |
|
75 | { | |
|
76 | impl->changeRange(variable, r); | |
|
77 | } | |
|
78 | ||
|
79 | const std::set<std::shared_ptr<Variable> > &VariableController2::variables() | |
|
80 | { | |
|
81 | return impl->variables(); | |
|
24 | 82 | } |
|
25 | 83 |
@@ -1,9 +1,51 | |||
|
1 | #include <cmath> | |
|
1 | 2 | #include <QtTest> |
|
2 | 3 | #include <QObject> |
|
4 | #include <Variable/VariableController2.h> | |
|
5 | #include <Data/DateTimeRange.h> | |
|
6 | #include <Data/IDataProvider.h> | |
|
7 | #include <Data/ScalarSeries.h> | |
|
8 | #include <Data/DataProviderParameters.h> | |
|
9 | #include <Common/containers.h> | |
|
3 | 10 | |
|
11 | class FakeProvider: public IDataProvider | |
|
12 | { | |
|
13 | public: | |
|
14 | FakeProvider() = default; | |
|
4 | 15 | |
|
5 | class TestVariableController2 : public QObject | |
|
16 | std::shared_ptr<IDataProvider> clone() const override{ return std::make_shared<FakeProvider>(); } | |
|
17 | ||
|
18 | IDataSeries* getData(const DataProviderParameters ¶meters) override | |
|
19 | { | |
|
20 | auto tstart = parameters.m_Times[0].m_TStart; | |
|
21 | auto tend = parameters.m_Times[0].m_TEnd; | |
|
22 | std::vector<double> x; | |
|
23 | std::vector<double> y; | |
|
24 | for(auto i = tstart;i<tend;i+=1.) //1 seconde data resolution | |
|
25 | { | |
|
26 | x.push_back(i); | |
|
27 | y.push_back(i); | |
|
28 | } | |
|
29 | auto serie = new ScalarSeries(std::move(x),std::move(y),Unit("Secondes",true),Unit("Volts",false)); | |
|
30 | return serie; | |
|
31 | } | |
|
32 | ||
|
33 | ||
|
34 | ||
|
35 | void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override | |
|
36 | { | |
|
37 | Q_UNUSED(acqIdentifier) | |
|
38 | Q_UNUSED(parameters) | |
|
39 | } | |
|
6 | 40 | |
|
41 | void requestDataAborting(QUuid acqIdentifier) override | |
|
42 | { | |
|
43 | Q_UNUSED(acqIdentifier) | |
|
44 | } | |
|
45 | ||
|
46 | }; | |
|
47 | ||
|
48 | class TestVariableController2 : public QObject | |
|
7 | 49 | { |
|
8 | 50 | Q_OBJECT |
|
9 | 51 | public: |
@@ -14,9 +56,45 private slots: | |||
|
14 | 56 | void initTestCase(){} |
|
15 | 57 | void cleanupTestCase(){} |
|
16 | 58 | |
|
17 |
void test |
|
|
59 | void testCreateVariable() | |
|
18 | 60 | { |
|
19 | QCOMPARE(1+1, 2); | |
|
61 | VariableController2 vc; | |
|
62 | bool callbackCalled = false; | |
|
63 | connect(&vc,&VariableController2::variableAdded, [&callbackCalled](std::shared_ptr<Variable>){callbackCalled=true;}); | |
|
64 | auto provider = std::make_shared<FakeProvider>(); | |
|
65 | QVERIFY(!callbackCalled); | |
|
66 | auto var1 = vc.createVariable("var1",{},provider,DateTimeRange()); | |
|
67 | QVERIFY(SciQLop::containers::contains(vc.variables(), var1)); | |
|
68 | QVERIFY(callbackCalled); | |
|
69 | } | |
|
70 | ||
|
71 | void testDeleteVariable() | |
|
72 | { | |
|
73 | VariableController2 vc; | |
|
74 | bool callbackCalled = false; | |
|
75 | connect(&vc,&VariableController2::variableDeleted, [&callbackCalled](std::shared_ptr<Variable>){callbackCalled=true;}); | |
|
76 | auto provider = std::make_shared<FakeProvider>(); | |
|
77 | auto var1 = vc.createVariable("var1",{},provider,DateTimeRange()); | |
|
78 | QVERIFY(SciQLop::containers::contains(vc.variables(), var1)); | |
|
79 | QVERIFY(!callbackCalled); | |
|
80 | vc.deleteVariable(var1); | |
|
81 | QVERIFY(!SciQLop::containers::contains(vc.variables(), var1)); | |
|
82 | QVERIFY(callbackCalled); | |
|
83 | } | |
|
84 | ||
|
85 | void testGetData() | |
|
86 | { | |
|
87 | VariableController2 vc; | |
|
88 | auto provider = std::make_shared<FakeProvider>(); | |
|
89 | auto range1 = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00), | |
|
90 | QDate(2018,8,7),QTime(16,00)); | |
|
91 | auto range2 = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(12,00), | |
|
92 | QDate(2018,8,7),QTime(18,00)); | |
|
93 | auto var1 = vc.createVariable("var1", {}, provider, range1); | |
|
94 | QCOMPARE(var1->nbPoints(), int(range1.delta())); | |
|
95 | vc.changeRange(var1, range2); | |
|
96 | QCOMPARE(var1->nbPoints(), int(range2.delta())); | |
|
97 | ||
|
20 | 98 | } |
|
21 | 99 | |
|
22 | 100 | private: |
General Comments 0
You need to be logged in to leave comments.
Login now