diff --git a/include/Data/DataProviderParameters.h b/include/Data/DataProviderParameters.h index 8b3d9e5..546d6ad 100644 --- a/include/Data/DataProviderParameters.h +++ b/include/Data/DataProviderParameters.h @@ -10,7 +10,7 @@ */ struct DataProviderParameters { /// Times for which retrieve data - QVector m_Times; + DateTimeRange m_Range; /// Extra data that can be used by the provider to retrieve data QVariantHash m_Data; }; diff --git a/include/Variable/VariableController2.h b/include/Variable/VariableController2.h index 6ea9a1b..8b768d8 100644 --- a/include/Variable/VariableController2.h +++ b/include/Variable/VariableController2.h @@ -34,14 +34,13 @@ public: const std::vector> variables(); bool isReady(const std::shared_ptr& variable); + bool isReady(); + void synchronize(const std::shared_ptr& var, const std::shared_ptr& with); const std::vector> variables(const std::vector& ids); - const std::shared_ptr& operator[] (int index) const; - std::shared_ptr operator[] (int index); - signals: void variableAdded(const std::shared_ptr&); diff --git a/include/Variable/VariableModel2.h b/include/Variable/VariableModel2.h index b176a55..705aa82 100644 --- a/include/Variable/VariableModel2.h +++ b/include/Variable/VariableModel2.h @@ -52,6 +52,8 @@ public: const QModelIndex &parent) const override; virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; + const std::vector>& variables() const + {return _variables;} signals: void createVariable(const QVariantHash &productData); diff --git a/src/Variable/VariableController2.cpp b/src/Variable/VariableController2.cpp index 6d4b3a3..008f078 100644 --- a/src/Variable/VariableController2.cpp +++ b/src/Variable/VariableController2.cpp @@ -276,6 +276,16 @@ public: return _transactions.active(*_maps.group(*variable)); } + bool hasPendingTransactions() + { + bool has = false; + for(const auto& var:_maps.variables()) + { + has |= _transactions.active(*_maps.group(*var)); + } + return has; + } + void deleteVariable(const std::shared_ptr& variable) { _maps.removeVariable(variable); @@ -326,6 +336,7 @@ VariableController2::VariableController2() std::shared_ptr VariableController2::createVariable(const QString &name, const QVariantHash &metadata, const std::shared_ptr& provider, const DateTimeRange &range) { auto var = impl->createVariable(name, metadata, provider); + var->setRange(range); // even with no data this is it's range emit variableAdded(var); if(!DateTimeRangeHelper::hasnan(range)) impl->asyncChangeRange(var,range); @@ -362,7 +373,12 @@ const std::vector > VariableController2::variables() bool VariableController2::isReady(const std::shared_ptr &variable) { - return impl->hasPendingTransactions(variable); + return !impl->hasPendingTransactions(variable); +} + +bool VariableController2::isReady() +{ + return !impl->hasPendingTransactions(); } void VariableController2::synchronize(const std::shared_ptr &var, const std::shared_ptr &with) @@ -378,13 +394,3 @@ const std::vector> VariableController2::variables(cons } return variables; } - -const std::shared_ptr &VariableController2::operator[](int index) const -{ - return impl->variable (index); -} - -std::shared_ptr VariableController2::operator[](int index) -{ - return impl->variable (index); -} diff --git a/tests/TestUtils/TestProviders.h b/tests/TestUtils/TestProviders.h index 8e6ad02..23253d8 100644 --- a/tests/TestUtils/TestProviders.h +++ b/tests/TestUtils/TestProviders.h @@ -29,8 +29,8 @@ public: IDataSeries* getData(const DataProviderParameters ¶meters) override { callCounter+=1; - auto tstart = parameters.m_Times[0].m_TStart; - auto tend = parameters.m_Times[0].m_TEnd; + auto tstart = parameters.m_Range.m_TStart; + auto tend = parameters.m_Range.m_TEnd; std::vector x; std::vector y; for(double i = ceil(tstart);i<=floor(tend);i+=1.) //1 seconde data resolution diff --git a/tests/Variable/TestVariableController2.cpp b/tests/Variable/TestVariableController2.cpp index d0ace81..a10a2d8 100644 --- a/tests/Variable/TestVariableController2.cpp +++ b/tests/Variable/TestVariableController2.cpp @@ -20,6 +20,7 @@ auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00),\ QDate(2018,8,7),QTime(16,00));\ auto name = vc.createVariable("name", {}, provider, range);\ + while(!vc.isReady(name))QCoreApplication::processEvents();\ Q_DECLARE_METATYPE(DateTimeRangeTransformation); @@ -56,6 +57,7 @@ private slots: bool callbackCalled = false; connect(&vc,&VariableController2::variableDeleted, [&callbackCalled](std::shared_ptr){callbackCalled=true;}); auto var1 = vc.createVariable("var1", {}, provider, range); + while(!vc.isReady(var1))QCoreApplication::processEvents(); QVERIFY(SciQLop::containers::contains(vc.variables(), var1)); QVERIFY(!callbackCalled); vc.deleteVariable(var1); diff --git a/tests/Variable/TestVariableController2WithSync.cpp b/tests/Variable/TestVariableController2WithSync.cpp index e4db0ad..0c84707 100644 --- a/tests/Variable/TestVariableController2WithSync.cpp +++ b/tests/Variable/TestVariableController2WithSync.cpp @@ -20,9 +20,11 @@ auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00),\ QDate(2018,8,7),QTime(16,00));\ auto name1 = vc.createVariable("name1", {}, provider, range);\ + while(!vc.isReady(name1))QCoreApplication::processEvents();\ auto name2 = vc.cloneVariable(name1);\ auto name3 = vc.cloneVariable(name2);\ vc.synchronize(name1,name2);\ + while(!vc.isReady(name1))QCoreApplication::processEvents();\ class TestVariableController2WithSync : public QObject