@@ -10,7 +10,7 | |||
|
10 | 10 | */ |
|
11 | 11 | struct DataProviderParameters { |
|
12 | 12 | /// Times for which retrieve data |
|
13 |
|
|
|
13 | DateTimeRange m_Range; | |
|
14 | 14 | /// Extra data that can be used by the provider to retrieve data |
|
15 | 15 | QVariantHash m_Data; |
|
16 | 16 | }; |
@@ -34,14 +34,13 public: | |||
|
34 | 34 | const std::vector<std::shared_ptr<Variable>> variables(); |
|
35 | 35 | |
|
36 | 36 | bool isReady(const std::shared_ptr<Variable>& variable); |
|
37 | bool isReady(); | |
|
38 | ||
|
37 | 39 | |
|
38 | 40 | void synchronize(const std::shared_ptr<Variable>& var, const std::shared_ptr<Variable>& with); |
|
39 | 41 | |
|
40 | 42 | const std::vector<std::shared_ptr<Variable>> variables(const std::vector<QUuid>& ids); |
|
41 | 43 | |
|
42 | const std::shared_ptr<Variable>& operator[] (int index) const; | |
|
43 | std::shared_ptr<Variable> operator[] (int index); | |
|
44 | ||
|
45 | 44 | |
|
46 | 45 | signals: |
|
47 | 46 | void variableAdded(const std::shared_ptr<Variable>&); |
@@ -52,6 +52,8 public: | |||
|
52 | 52 | const QModelIndex &parent) const override; |
|
53 | 53 | virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, |
|
54 | 54 | const QModelIndex &parent) override; |
|
55 | const std::vector<std::shared_ptr<Variable>>& variables() const | |
|
56 | {return _variables;} | |
|
55 | 57 | |
|
56 | 58 | signals: |
|
57 | 59 | void createVariable(const QVariantHash &productData); |
@@ -276,6 +276,16 public: | |||
|
276 | 276 | return _transactions.active(*_maps.group(*variable)); |
|
277 | 277 | } |
|
278 | 278 | |
|
279 | bool hasPendingTransactions() | |
|
280 | { | |
|
281 | bool has = false; | |
|
282 | for(const auto& var:_maps.variables()) | |
|
283 | { | |
|
284 | has |= _transactions.active(*_maps.group(*var)); | |
|
285 | } | |
|
286 | return has; | |
|
287 | } | |
|
288 | ||
|
279 | 289 | void deleteVariable(const std::shared_ptr<Variable>& variable) |
|
280 | 290 | { |
|
281 | 291 | _maps.removeVariable(variable); |
@@ -326,6 +336,7 VariableController2::VariableController2() | |||
|
326 | 336 | std::shared_ptr<Variable> VariableController2::createVariable(const QString &name, const QVariantHash &metadata, const std::shared_ptr<IDataProvider>& provider, const DateTimeRange &range) |
|
327 | 337 | { |
|
328 | 338 | auto var = impl->createVariable(name, metadata, provider); |
|
339 | var->setRange(range); // even with no data this is it's range | |
|
329 | 340 | emit variableAdded(var); |
|
330 | 341 | if(!DateTimeRangeHelper::hasnan(range)) |
|
331 | 342 | impl->asyncChangeRange(var,range); |
@@ -362,7 +373,12 const std::vector<std::shared_ptr<Variable> > VariableController2::variables() | |||
|
362 | 373 | |
|
363 | 374 | bool VariableController2::isReady(const std::shared_ptr<Variable> &variable) |
|
364 | 375 | { |
|
365 | return impl->hasPendingTransactions(variable); | |
|
376 | return !impl->hasPendingTransactions(variable); | |
|
377 | } | |
|
378 | ||
|
379 | bool VariableController2::isReady() | |
|
380 | { | |
|
381 | return !impl->hasPendingTransactions(); | |
|
366 | 382 | } |
|
367 | 383 | |
|
368 | 384 | void VariableController2::synchronize(const std::shared_ptr<Variable> &var, const std::shared_ptr<Variable> &with) |
@@ -378,13 +394,3 const std::vector<std::shared_ptr<Variable>> VariableController2::variables(cons | |||
|
378 | 394 | } |
|
379 | 395 | return variables; |
|
380 | 396 | } |
|
381 | ||
|
382 | const std::shared_ptr<Variable> &VariableController2::operator[](int index) const | |
|
383 | { | |
|
384 | return impl->variable (index); | |
|
385 | } | |
|
386 | ||
|
387 | std::shared_ptr<Variable> VariableController2::operator[](int index) | |
|
388 | { | |
|
389 | return impl->variable (index); | |
|
390 | } |
@@ -29,8 +29,8 public: | |||
|
29 | 29 | IDataSeries* getData(const DataProviderParameters ¶meters) override |
|
30 | 30 | { |
|
31 | 31 | callCounter+=1; |
|
32 |
auto tstart = parameters.m_ |
|
|
33 |
auto tend = parameters.m_ |
|
|
32 | auto tstart = parameters.m_Range.m_TStart; | |
|
33 | auto tend = parameters.m_Range.m_TEnd; | |
|
34 | 34 | std::vector<double> x; |
|
35 | 35 | std::vector<double> y; |
|
36 | 36 | for(double i = ceil(tstart);i<=floor(tend);i+=1.) //1 seconde data resolution |
@@ -20,6 +20,7 | |||
|
20 | 20 | auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00),\ |
|
21 | 21 | QDate(2018,8,7),QTime(16,00));\ |
|
22 | 22 | auto name = vc.createVariable("name", {}, provider, range);\ |
|
23 | while(!vc.isReady(name))QCoreApplication::processEvents();\ | |
|
23 | 24 | |
|
24 | 25 | Q_DECLARE_METATYPE(DateTimeRangeTransformation); |
|
25 | 26 | |
@@ -56,6 +57,7 private slots: | |||
|
56 | 57 | bool callbackCalled = false; |
|
57 | 58 | connect(&vc,&VariableController2::variableDeleted, [&callbackCalled](std::shared_ptr<Variable>){callbackCalled=true;}); |
|
58 | 59 | auto var1 = vc.createVariable("var1", {}, provider, range); |
|
60 | while(!vc.isReady(var1))QCoreApplication::processEvents(); | |
|
59 | 61 | QVERIFY(SciQLop::containers::contains(vc.variables(), var1)); |
|
60 | 62 | QVERIFY(!callbackCalled); |
|
61 | 63 | vc.deleteVariable(var1); |
@@ -20,9 +20,11 | |||
|
20 | 20 | auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00),\ |
|
21 | 21 | QDate(2018,8,7),QTime(16,00));\ |
|
22 | 22 | auto name1 = vc.createVariable("name1", {}, provider, range);\ |
|
23 | while(!vc.isReady(name1))QCoreApplication::processEvents();\ | |
|
23 | 24 | auto name2 = vc.cloneVariable(name1);\ |
|
24 | 25 | auto name3 = vc.cloneVariable(name2);\ |
|
25 | 26 | vc.synchronize(name1,name2);\ |
|
27 | while(!vc.isReady(name1))QCoreApplication::processEvents();\ | |
|
26 | 28 | |
|
27 | 29 | |
|
28 | 30 | class TestVariableController2WithSync : public QObject |
General Comments 0
You need to be logged in to leave comments.
Login now