@@ -1,121 +1,120 | |||||
1 | #include "DataSource/DataSourceController.h" |
|
1 | #include "DataSource/DataSourceController.h" | |
2 | #include "DataSource/DataSourceItem.h" |
|
2 | #include "DataSource/DataSourceItem.h" | |
3 |
|
3 | |||
4 | #include <Data/IDataProvider.h> |
|
4 | #include <Data/IDataProvider.h> | |
5 |
|
5 | |||
6 | #include <QMutex> |
|
6 | #include <QMutex> | |
7 | #include <QThread> |
|
7 | #include <QThread> | |
8 |
|
8 | |||
9 | #include <QDir> |
|
9 | #include <QDir> | |
10 | #include <QStandardPaths> |
|
10 | #include <QStandardPaths> | |
11 |
|
11 | |||
12 | Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController") |
|
12 | Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController") | |
13 |
|
13 | |||
14 | class DataSourceController::DataSourceControllerPrivate { |
|
14 | class DataSourceController::DataSourceControllerPrivate { | |
15 | public: |
|
15 | public: | |
16 | QMutex m_WorkingMutex; |
|
16 | QMutex m_WorkingMutex; | |
17 | /// Data sources registered |
|
17 | /// Data sources registered | |
18 | QHash<QUuid, QString> m_DataSources; |
|
18 | QHash<QUuid, QString> m_DataSources; | |
19 | /// Data sources structures |
|
19 | /// Data sources structures | |
20 | std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems; |
|
20 | std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems; | |
21 | /// Data providers registered |
|
21 | /// Data providers registered | |
22 | /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and |
|
22 | /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and | |
23 | /// continue to live without necessarily the data source controller |
|
23 | /// continue to live without necessarily the data source controller | |
24 | std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders; |
|
24 | std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders; | |
25 | }; |
|
25 | }; | |
26 |
|
26 | |||
27 | DataSourceController::DataSourceController(QObject *parent) |
|
27 | DataSourceController::DataSourceController(QObject *parent) | |
28 | : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()} |
|
28 | : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()} | |
29 | { |
|
29 | { | |
30 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction") |
|
30 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction") | |
31 | << QThread::currentThread(); |
|
31 | << QThread::currentThread(); | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | DataSourceController::~DataSourceController() |
|
34 | DataSourceController::~DataSourceController() | |
35 | { |
|
35 | { | |
36 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction") |
|
36 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction") | |
37 | << QThread::currentThread(); |
|
37 | << QThread::currentThread(); | |
38 | this->waitForFinish(); |
|
38 | this->waitForFinish(); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept |
|
41 | QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept | |
42 | { |
|
42 | { | |
43 | auto dataSourceUid = QUuid::createUuid(); |
|
43 | auto dataSourceUid = QUuid::createUuid(); | |
44 | impl->m_DataSources.insert(dataSourceUid, dataSourceName); |
|
44 | impl->m_DataSources.insert(dataSourceUid, dataSourceName); | |
45 |
|
45 | |||
46 | return dataSourceUid; |
|
46 | return dataSourceUid; | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | void DataSourceController::setDataSourceItem( |
|
49 | void DataSourceController::setDataSourceItem( | |
50 | const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept |
|
50 | const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept | |
51 | { |
|
51 | { | |
52 | if (!dataSourceItem) { |
|
52 | if (!dataSourceItem) { | |
53 | qCWarning(LOG_DataSourceController()) |
|
53 | qCWarning(LOG_DataSourceController()) | |
54 | << tr("Data source item can't be registered (null item)"); |
|
54 | << tr("Data source item can't be registered (null item)"); | |
55 | return; |
|
55 | return; | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | if (impl->m_DataSources.contains(dataSourceUid)) { |
|
58 | if (impl->m_DataSources.contains(dataSourceUid)) { | |
59 | // The data provider is implicitly converted to a shared_ptr |
|
59 | // The data provider is implicitly converted to a shared_ptr | |
60 | impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem))); |
|
60 | impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem))); | |
61 |
|
61 | |||
62 | // Retrieves the data source item to emit the signal with it |
|
62 | // Retrieves the data source item to emit the signal with it | |
63 | auto it = impl->m_DataSourceItems.find(dataSourceUid); |
|
63 | auto it = impl->m_DataSourceItems.find(dataSourceUid); | |
64 | if (it != impl->m_DataSourceItems.end()) { |
|
64 | if (it != impl->m_DataSourceItems.end()) { | |
65 | emit dataSourceItemSet(it->second.get()); |
|
65 | emit dataSourceItemSet(it->second.get()); | |
66 | } |
|
66 | } | |
67 | } |
|
67 | } | |
68 | else { |
|
68 | else { | |
69 | qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no " |
|
69 | qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no " | |
70 | "data source has been registered with the uid") |
|
70 | "data source has been registered with the uid") | |
71 | .arg(dataSourceUid.toString()); |
|
71 | .arg(dataSourceUid.toString()); | |
72 | } |
|
72 | } | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void DataSourceController::setDataProvider(const QUuid &dataSourceUid, |
|
75 | void DataSourceController::setDataProvider(const QUuid &dataSourceUid, | |
76 | std::unique_ptr<IDataProvider> dataProvider) noexcept |
|
76 | std::unique_ptr<IDataProvider> dataProvider) noexcept | |
77 | { |
|
77 | { | |
78 | if (impl->m_DataSources.contains(dataSourceUid)) { |
|
78 | if (impl->m_DataSources.contains(dataSourceUid)) { | |
79 | impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider))); |
|
79 | impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider))); | |
80 | } |
|
80 | } | |
81 | else { |
|
81 | else { | |
82 | qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data " |
|
82 | qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data " | |
83 | "source has been registered with the uid") |
|
83 | "source has been registered with the uid") | |
84 | .arg(dataSourceUid.toString()); |
|
84 | .arg(dataSourceUid.toString()); | |
85 | } |
|
85 | } | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void DataSourceController::loadProductItem(const QUuid &dataSourceUid, |
|
88 | void DataSourceController::loadProductItem(const QUuid &dataSourceUid, | |
89 | const DataSourceItem &productItem) noexcept |
|
89 | const DataSourceItem &productItem) noexcept | |
90 | { |
|
90 | { | |
91 | if (productItem.type() == DataSourceItemType::PRODUCT |
|
91 | if (productItem.type() == DataSourceItemType::PRODUCT | |
92 | || productItem.type() == DataSourceItemType::COMPONENT) { |
|
92 | || productItem.type() == DataSourceItemType::COMPONENT) { | |
93 | /// Retrieves the data provider of the data source (if any) |
|
93 | /// Retrieves the data provider of the data source (if any) | |
94 | auto it = impl->m_DataProviders.find(dataSourceUid); |
|
94 | auto it = impl->m_DataProviders.find(dataSourceUid); | |
95 | auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr; |
|
95 | auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr; | |
96 |
|
96 | |||
97 | /// @todo retrieve timerange, and pass it to the signal |
|
|||
98 | emit variableCreationRequested(productItem.name(), productItem.data(), dataProvider); |
|
97 | emit variableCreationRequested(productItem.name(), productItem.data(), dataProvider); | |
99 | } |
|
98 | } | |
100 | else { |
|
99 | else { | |
101 | qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product"); |
|
100 | qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product"); | |
102 | } |
|
101 | } | |
103 | } |
|
102 | } | |
104 |
|
103 | |||
105 | void DataSourceController::initialize() |
|
104 | void DataSourceController::initialize() | |
106 | { |
|
105 | { | |
107 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init") |
|
106 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init") | |
108 | << QThread::currentThread(); |
|
107 | << QThread::currentThread(); | |
109 | impl->m_WorkingMutex.lock(); |
|
108 | impl->m_WorkingMutex.lock(); | |
110 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END"); |
|
109 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END"); | |
111 | } |
|
110 | } | |
112 |
|
111 | |||
113 | void DataSourceController::finalize() |
|
112 | void DataSourceController::finalize() | |
114 | { |
|
113 | { | |
115 | impl->m_WorkingMutex.unlock(); |
|
114 | impl->m_WorkingMutex.unlock(); | |
116 | } |
|
115 | } | |
117 |
|
116 | |||
118 | void DataSourceController::waitForFinish() |
|
117 | void DataSourceController::waitForFinish() | |
119 | { |
|
118 | { | |
120 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
119 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
121 | } |
|
120 | } |
@@ -1,218 +1,212 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableCacheController.h> |
|
2 | #include <Variable/VariableCacheController.h> | |
3 | #include <Variable/VariableController.h> |
|
3 | #include <Variable/VariableController.h> | |
4 | #include <Variable/VariableModel.h> |
|
4 | #include <Variable/VariableModel.h> | |
5 |
|
5 | |||
6 | #include <Data/DataProviderParameters.h> |
|
6 | #include <Data/DataProviderParameters.h> | |
7 | #include <Data/IDataProvider.h> |
|
7 | #include <Data/IDataProvider.h> | |
8 | #include <Data/IDataSeries.h> |
|
8 | #include <Data/IDataSeries.h> | |
9 | #include <Time/TimeController.h> |
|
9 | #include <Time/TimeController.h> | |
10 |
|
10 | |||
11 | #include <QDateTime> |
|
11 | #include <QDateTime> | |
12 | #include <QMutex> |
|
12 | #include <QMutex> | |
13 | #include <QThread> |
|
13 | #include <QThread> | |
14 | #include <QUuid> |
|
14 | #include <QUuid> | |
15 | #include <QtCore/QItemSelectionModel> |
|
15 | #include <QtCore/QItemSelectionModel> | |
16 |
|
16 | |||
17 | #include <unordered_map> |
|
17 | #include <unordered_map> | |
18 |
|
18 | |||
19 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
19 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
20 |
|
20 | |||
21 | struct VariableController::VariableControllerPrivate { |
|
21 | struct VariableController::VariableControllerPrivate { | |
22 | explicit VariableControllerPrivate(VariableController *parent) |
|
22 | explicit VariableControllerPrivate(VariableController *parent) | |
23 | : m_WorkingMutex{}, |
|
23 | : m_WorkingMutex{}, | |
24 | m_VariableModel{new VariableModel{parent}}, |
|
24 | m_VariableModel{new VariableModel{parent}}, | |
25 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
25 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, | |
26 | m_VariableCacheController{std::make_unique<VariableCacheController>()} |
|
26 | m_VariableCacheController{std::make_unique<VariableCacheController>()} | |
27 | { |
|
27 | { | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | QMutex m_WorkingMutex; |
|
30 | QMutex m_WorkingMutex; | |
31 | /// Variable model. The VariableController has the ownership |
|
31 | /// Variable model. The VariableController has the ownership | |
32 | VariableModel *m_VariableModel; |
|
32 | VariableModel *m_VariableModel; | |
33 | QItemSelectionModel *m_VariableSelectionModel; |
|
33 | QItemSelectionModel *m_VariableSelectionModel; | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | TimeController *m_TimeController{nullptr}; |
|
36 | TimeController *m_TimeController{nullptr}; | |
37 | std::unique_ptr<VariableCacheController> m_VariableCacheController; |
|
37 | std::unique_ptr<VariableCacheController> m_VariableCacheController; | |
38 |
|
38 | |||
39 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
39 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
40 | m_VariableToProviderMap; |
|
40 | m_VariableToProviderMap; | |
41 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifier; |
|
41 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifier; | |
42 | }; |
|
42 | }; | |
43 |
|
43 | |||
44 | VariableController::VariableController(QObject *parent) |
|
44 | VariableController::VariableController(QObject *parent) | |
45 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
45 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
46 | { |
|
46 | { | |
47 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
47 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
48 | << QThread::currentThread(); |
|
48 | << QThread::currentThread(); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | VariableController::~VariableController() |
|
51 | VariableController::~VariableController() | |
52 | { |
|
52 | { | |
53 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
53 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
54 | << QThread::currentThread(); |
|
54 | << QThread::currentThread(); | |
55 | this->waitForFinish(); |
|
55 | this->waitForFinish(); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | VariableModel *VariableController::variableModel() noexcept |
|
58 | VariableModel *VariableController::variableModel() noexcept | |
59 | { |
|
59 | { | |
60 | return impl->m_VariableModel; |
|
60 | return impl->m_VariableModel; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept |
|
63 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept | |
64 | { |
|
64 | { | |
65 | return impl->m_VariableSelectionModel; |
|
65 | return impl->m_VariableSelectionModel; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
68 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
69 | { |
|
69 | { | |
70 | impl->m_TimeController = timeController; |
|
70 | impl->m_TimeController = timeController; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
73 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |
74 | { |
|
74 | { | |
75 | if (!variable) { |
|
75 | if (!variable) { | |
76 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; |
|
76 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; | |
77 | return; |
|
77 | return; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can |
|
80 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can | |
81 | // make some treatments before the deletion |
|
81 | // make some treatments before the deletion | |
82 | emit variableAboutToBeDeleted(variable); |
|
82 | emit variableAboutToBeDeleted(variable); | |
83 |
|
83 | |||
84 | // Deletes provider |
|
84 | // Deletes provider | |
85 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); |
|
85 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); | |
86 | qCDebug(LOG_VariableController()) |
|
86 | qCDebug(LOG_VariableController()) | |
87 | << tr("Number of providers deleted for variable %1: %2") |
|
87 | << tr("Number of providers deleted for variable %1: %2") | |
88 | .arg(variable->name(), QString::number(nbProvidersDeleted)); |
|
88 | .arg(variable->name(), QString::number(nbProvidersDeleted)); | |
89 |
|
89 | |||
90 | // Clears cache |
|
90 | // Clears cache | |
91 | impl->m_VariableCacheController->clear(variable); |
|
91 | impl->m_VariableCacheController->clear(variable); | |
92 |
|
92 | |||
93 | // Deletes from model |
|
93 | // Deletes from model | |
94 | impl->m_VariableModel->deleteVariable(variable); |
|
94 | impl->m_VariableModel->deleteVariable(variable); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void VariableController::deleteVariables( |
|
97 | void VariableController::deleteVariables( | |
98 | const QVector<std::shared_ptr<Variable> > &variables) noexcept |
|
98 | const QVector<std::shared_ptr<Variable> > &variables) noexcept | |
99 | { |
|
99 | { | |
100 | for (auto variable : qAsConst(variables)) { |
|
100 | for (auto variable : qAsConst(variables)) { | |
101 | deleteVariable(variable); |
|
101 | deleteVariable(variable); | |
102 | } |
|
102 | } | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void VariableController::createVariable(const QString &name, const QVariantHash &metadata, |
|
105 | void VariableController::createVariable(const QString &name, const QVariantHash &metadata, | |
106 | std::shared_ptr<IDataProvider> provider) noexcept |
|
106 | std::shared_ptr<IDataProvider> provider) noexcept | |
107 | { |
|
107 | { | |
108 |
|
108 | |||
109 | if (!impl->m_TimeController) { |
|
109 | if (!impl->m_TimeController) { | |
110 | qCCritical(LOG_VariableController()) |
|
110 | qCCritical(LOG_VariableController()) | |
111 | << tr("Impossible to create variable: The time controller is null"); |
|
111 | << tr("Impossible to create variable: The time controller is null"); | |
112 | return; |
|
112 | return; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 |
|
||||
116 | /// @todo : for the moment : |
|
|||
117 | /// - the provider is only used to retrieve data from the variable for its initialization, but |
|
|||
118 | /// it will be retained later |
|
|||
119 | /// - default data are generated for the variable, without taking into account the timerange set |
|
|||
120 | /// in sciqlop |
|
|||
121 | auto dateTime = impl->m_TimeController->dateTime(); |
|
115 | auto dateTime = impl->m_TimeController->dateTime(); | |
122 |
|
116 | |||
123 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime, metadata)) { |
|
117 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime, metadata)) { | |
124 | auto identifier = QUuid::createUuid(); |
|
118 | auto identifier = QUuid::createUuid(); | |
125 |
|
119 | |||
126 | // store the provider |
|
120 | // store the provider | |
127 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
121 | impl->m_VariableToProviderMap[newVariable] = provider; | |
128 | impl->m_VariableToIdentifier[newVariable] = identifier; |
|
122 | impl->m_VariableToIdentifier[newVariable] = identifier; | |
129 |
|
123 | |||
130 | auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ]( |
|
124 | auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ]( | |
131 | QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache) |
|
125 | QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache) | |
132 | { |
|
126 | { | |
133 | if (auto variable = varW.lock()) { |
|
127 | if (auto variable = varW.lock()) { | |
134 | auto varIdentifier = impl->m_VariableToIdentifier.at(variable); |
|
128 | auto varIdentifier = impl->m_VariableToIdentifier.at(variable); | |
135 | if (varIdentifier == identifier) { |
|
129 | if (varIdentifier == identifier) { | |
136 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); |
|
130 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); | |
137 | variable->setDataSeries(dataSeriesAcquired); |
|
131 | variable->setDataSeries(dataSeriesAcquired); | |
138 | } |
|
132 | } | |
139 | } |
|
133 | } | |
140 | }; |
|
134 | }; | |
141 |
|
135 | |||
142 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); |
|
136 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); | |
143 | this->onRequestDataLoading(newVariable, dateTime); |
|
137 | this->onRequestDataLoading(newVariable, dateTime); | |
144 | } |
|
138 | } | |
145 | } |
|
139 | } | |
146 |
|
140 | |||
147 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) |
|
141 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) | |
148 | { |
|
142 | { | |
149 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" |
|
143 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" | |
150 | << QThread::currentThread()->objectName(); |
|
144 | << QThread::currentThread()->objectName(); | |
151 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
145 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); | |
152 |
|
146 | |||
153 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
147 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
154 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
148 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { | |
155 | selectedVariable->setDateTime(dateTime); |
|
149 | selectedVariable->setDateTime(dateTime); | |
156 | this->onRequestDataLoading(selectedVariable, dateTime); |
|
150 | this->onRequestDataLoading(selectedVariable, dateTime); | |
157 | } |
|
151 | } | |
158 | } |
|
152 | } | |
159 | } |
|
153 | } | |
160 |
|
154 | |||
161 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) |
|
155 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) | |
162 | { |
|
156 | { | |
163 | auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; |
|
157 | auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; | |
164 |
|
158 | |||
165 | auto end = impl->m_VariableToIdentifier.cend(); |
|
159 | auto end = impl->m_VariableToIdentifier.cend(); | |
166 | auto it = std::find_if(impl->m_VariableToIdentifier.cbegin(), end, findReply); |
|
160 | auto it = std::find_if(impl->m_VariableToIdentifier.cbegin(), end, findReply); | |
167 | if (it != end) { |
|
161 | if (it != end) { | |
168 | impl->m_VariableModel->setDataProgress(it->first, progress); |
|
162 | impl->m_VariableModel->setDataProgress(it->first, progress); | |
169 | } |
|
163 | } | |
170 | } |
|
164 | } | |
171 |
|
165 | |||
172 |
|
166 | |||
173 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, |
|
167 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, | |
174 | const SqpDateTime &dateTime) |
|
168 | const SqpDateTime &dateTime) | |
175 | { |
|
169 | { | |
176 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" |
|
170 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" | |
177 | << QThread::currentThread()->objectName(); |
|
171 | << QThread::currentThread()->objectName(); | |
178 | // we want to load data of the variable for the dateTime. |
|
172 | // we want to load data of the variable for the dateTime. | |
179 | // First we check if the cache contains some of them. |
|
173 | // First we check if the cache contains some of them. | |
180 | // For the other, we ask the provider to give them. |
|
174 | // For the other, we ask the provider to give them. | |
181 | if (variable) { |
|
175 | if (variable) { | |
182 |
|
176 | |||
183 | auto dateTimeListNotInCache |
|
177 | auto dateTimeListNotInCache | |
184 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); |
|
178 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); | |
185 |
|
179 | |||
186 | if (!dateTimeListNotInCache.empty()) { |
|
180 | if (!dateTimeListNotInCache.empty()) { | |
187 | // Ask the provider for each data on the dateTimeListNotInCache |
|
181 | // Ask the provider for each data on the dateTimeListNotInCache | |
188 | auto identifier = impl->m_VariableToIdentifier.at(variable); |
|
182 | auto identifier = impl->m_VariableToIdentifier.at(variable); | |
189 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( |
|
183 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( | |
190 | identifier, |
|
184 | identifier, | |
191 | DataProviderParameters{std::move(dateTimeListNotInCache), variable->metadata()}); |
|
185 | DataProviderParameters{std::move(dateTimeListNotInCache), variable->metadata()}); | |
192 | } |
|
186 | } | |
193 | else { |
|
187 | else { | |
194 | emit variable->updated(); |
|
188 | emit variable->updated(); | |
195 | } |
|
189 | } | |
196 | } |
|
190 | } | |
197 | else { |
|
191 | else { | |
198 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
|
192 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); | |
199 | } |
|
193 | } | |
200 | } |
|
194 | } | |
201 |
|
195 | |||
202 |
|
196 | |||
203 | void VariableController::initialize() |
|
197 | void VariableController::initialize() | |
204 | { |
|
198 | { | |
205 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
199 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
206 | impl->m_WorkingMutex.lock(); |
|
200 | impl->m_WorkingMutex.lock(); | |
207 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
201 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
208 | } |
|
202 | } | |
209 |
|
203 | |||
210 | void VariableController::finalize() |
|
204 | void VariableController::finalize() | |
211 | { |
|
205 | { | |
212 | impl->m_WorkingMutex.unlock(); |
|
206 | impl->m_WorkingMutex.unlock(); | |
213 | } |
|
207 | } | |
214 |
|
208 | |||
215 | void VariableController::waitForFinish() |
|
209 | void VariableController::waitForFinish() | |
216 | { |
|
210 | { | |
217 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
211 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
218 | } |
|
212 | } |
General Comments 0
You need to be logged in to leave comments.
Login now