@@ -4,6 +4,7 | |||
|
4 | 4 | #include <memory> |
|
5 | 5 | |
|
6 | 6 | #include <QObject> |
|
7 | #include <QUuid> | |
|
7 | 8 | |
|
8 | 9 | #include <Common/MetaTypes.h> |
|
9 | 10 | |
@@ -26,10 +27,11 class IDataProvider : public QObject { | |||
|
26 | 27 | public: |
|
27 | 28 | virtual ~IDataProvider() noexcept = default; |
|
28 | 29 | |
|
29 | virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0; | |
|
30 | virtual void requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) = 0; | |
|
30 | 31 | |
|
31 | 32 | signals: |
|
32 |
void dataProvided(std::shared_ptr<IDataSeries> dateSerie, |
|
|
33 | void dataProvided(QUuid token, std::shared_ptr<IDataSeries> dateSerie, | |
|
34 | const SqpDateTime &dateTime); | |
|
33 | 35 | }; |
|
34 | 36 | |
|
35 | 37 | // Required for using shared_ptr in signals/slots |
@@ -11,6 +11,7 | |||
|
11 | 11 | #include <QDateTime> |
|
12 | 12 | #include <QMutex> |
|
13 | 13 | #include <QThread> |
|
14 | #include <QUuid> | |
|
14 | 15 | #include <QtCore/QItemSelectionModel> |
|
15 | 16 | |
|
16 | 17 | #include <unordered_map> |
@@ -37,6 +38,7 struct VariableController::VariableControllerPrivate { | |||
|
37 | 38 | |
|
38 | 39 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
39 | 40 | m_VariableToProviderMap; |
|
41 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToToken; | |
|
40 | 42 | }; |
|
41 | 43 | |
|
42 | 44 | VariableController::VariableController(QObject *parent) |
@@ -118,16 +120,21 void VariableController::createVariable(const QString &name, | |||
|
118 | 120 | /// in sciqlop |
|
119 | 121 | auto dateTime = impl->m_TimeController->dateTime(); |
|
120 | 122 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { |
|
123 | auto token = QUuid::createUuid(); | |
|
121 | 124 | |
|
122 | 125 | // store the provider |
|
123 | 126 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
127 | impl->m_VariableToToken[newVariable] = token; | |
|
124 | 128 | |
|
125 | 129 | auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ]( |
|
126 | auto dataSeriesAcquired, auto dateTimeToPutInCache) | |
|
130 | QUuid token, auto dataSeriesAcquired, auto dateTimeToPutInCache) | |
|
127 | 131 | { |
|
128 | 132 | if (auto variable = varW.lock()) { |
|
129 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); | |
|
130 | variable->setDataSeries(dataSeriesAcquired); | |
|
133 | auto varToken = impl->m_VariableToToken.at(variable); | |
|
134 | if (varToken == token) { | |
|
135 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); | |
|
136 | variable->setDataSeries(dataSeriesAcquired); | |
|
137 | } | |
|
131 | 138 | } |
|
132 | 139 | }; |
|
133 | 140 | |
@@ -166,8 +173,9 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable | |||
|
166 | 173 | |
|
167 | 174 | if (!dateTimeListNotInCache.empty()) { |
|
168 | 175 | // Ask the provider for each data on the dateTimeListNotInCache |
|
176 | auto token = impl->m_VariableToToken.at(variable); | |
|
169 | 177 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( |
|
170 | std::move(dateTimeListNotInCache)); | |
|
178 | token, std::move(dateTimeListNotInCache)); | |
|
171 | 179 | } |
|
172 | 180 | else { |
|
173 | 181 | emit variable->updated(); |
@@ -14,7 +14,7 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider) | |||
|
14 | 14 | */ |
|
15 | 15 | class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider { |
|
16 | 16 | public: |
|
17 | void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override; | |
|
17 | void requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) override; | |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | private: |
@@ -38,13 +38,13 CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const | |||
|
38 | 38 | return scalarSeries; |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList) | |
|
41 | void CosinusProvider::requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) | |
|
42 | 42 | { |
|
43 | 43 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading" |
|
44 | 44 | << QThread::currentThread()->objectName(); |
|
45 | 45 | // NOTE: Try to use multithread if possible |
|
46 | 46 | for (const auto &dateTime : dateTimeList) { |
|
47 | 47 | auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime}); |
|
48 | emit dataProvided(scalarSeries, dateTime); | |
|
48 | emit dataProvided(token, scalarSeries, dateTime); | |
|
49 | 49 | } |
|
50 | 50 | } |
General Comments 0
You need to be logged in to leave comments.
Login now