@@ -1,82 +1,80 | |||||
1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H |
|
1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H | |
2 | #define SCIQLOP_VARIABLECONTROLLER_H |
|
2 | #define SCIQLOP_VARIABLECONTROLLER_H | |
3 |
|
3 | |||
4 | #include <Data/SqpDateTime.h> |
|
4 | #include <Data/SqpDateTime.h> | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <QObject> |
|
7 | #include <QObject> | |
8 |
|
8 | |||
9 | #include <Common/spimpl.h> |
|
9 | #include <Common/spimpl.h> | |
10 |
|
10 | |||
11 | class IDataProvider; |
|
11 | class IDataProvider; | |
12 | class QItemSelectionModel; |
|
12 | class QItemSelectionModel; | |
13 | class TimeController; |
|
13 | class TimeController; | |
14 | class Variable; |
|
14 | class Variable; | |
15 | class VariableModel; |
|
15 | class VariableModel; | |
16 |
|
16 | |||
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) |
|
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) | |
18 |
|
18 | |||
19 | /** |
|
19 | /** | |
20 | * @brief The VariableController class aims to handle the variables in SciQlop. |
|
20 | * @brief The VariableController class aims to handle the variables in SciQlop. | |
21 | */ |
|
21 | */ | |
22 | class VariableController : public QObject { |
|
22 | class VariableController : public QObject { | |
23 | Q_OBJECT |
|
23 | Q_OBJECT | |
24 | public: |
|
24 | public: | |
25 | explicit VariableController(QObject *parent = 0); |
|
25 | explicit VariableController(QObject *parent = 0); | |
26 | virtual ~VariableController(); |
|
26 | virtual ~VariableController(); | |
27 |
|
27 | |||
28 | VariableModel *variableModel() noexcept; |
|
28 | VariableModel *variableModel() noexcept; | |
29 | QItemSelectionModel *variableSelectionModel() noexcept; |
|
29 | QItemSelectionModel *variableSelectionModel() noexcept; | |
30 |
|
30 | |||
31 | void setTimeController(TimeController *timeController) noexcept; |
|
31 | void setTimeController(TimeController *timeController) noexcept; | |
32 |
|
32 | |||
33 | /** |
|
33 | /** | |
34 | * Deletes from the controller the variable passed in parameter. |
|
34 | * Deletes from the controller the variable passed in parameter. | |
35 | * |
|
35 | * | |
36 | * Delete a variable includes: |
|
36 | * Delete a variable includes: | |
37 | * - the deletion of the various references to the variable in SciQlop |
|
37 | * - the deletion of the various references to the variable in SciQlop | |
38 | * - the deletion of the model variable |
|
38 | * - the deletion of the model variable | |
39 | * - the deletion of the provider associated with the variable |
|
39 | * - the deletion of the provider associated with the variable | |
40 | * - removing the cache associated with the variable |
|
40 | * - removing the cache associated with the variable | |
41 | * |
|
41 | * | |
42 | * @param variable the variable to delete from the controller. |
|
42 | * @param variable the variable to delete from the controller. | |
43 | */ |
|
43 | */ | |
44 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; |
|
44 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; | |
45 |
|
45 | |||
46 | /** |
|
46 | /** | |
47 | * Deletes from the controller the variables passed in parameter. |
|
47 | * Deletes from the controller the variables passed in parameter. | |
48 | * @param variables the variables to delete from the controller. |
|
48 | * @param variables the variables to delete from the controller. | |
49 | * @sa deleteVariable() |
|
49 | * @sa deleteVariable() | |
50 | */ |
|
50 | */ | |
51 | void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept; |
|
51 | void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept; | |
52 |
|
52 | |||
53 | signals: |
|
53 | signals: | |
54 | /// Signal emitted when a variable is about to be deleted from the controller |
|
54 | /// Signal emitted when a variable is about to be deleted from the controller | |
55 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); |
|
55 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); | |
56 | /// Signal emitted when a variable has been created |
|
|||
57 | void variableCreated(std::shared_ptr<Variable> variable); |
|
|||
58 |
|
56 | |||
59 | public slots: |
|
57 | public slots: | |
60 | /// Request the data loading of the variable whithin dateTime |
|
58 | /// Request the data loading of the variable whithin dateTime | |
61 | void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); |
|
59 | void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); | |
62 | /** |
|
60 | /** | |
63 | * Creates a new variable and adds it to the model |
|
61 | * Creates a new variable and adds it to the model | |
64 | * @param name the name of the new variable |
|
62 | * @param name the name of the new variable | |
65 | * @param provider the data provider for the new variable |
|
63 | * @param provider the data provider for the new variable | |
66 | */ |
|
64 | */ | |
67 | void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept; |
|
65 | void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept; | |
68 |
|
66 | |||
69 | /// Update the temporal parameters of every selected variable to dateTime |
|
67 | /// Update the temporal parameters of every selected variable to dateTime | |
70 | void onDateTimeOnSelection(const SqpDateTime &dateTime); |
|
68 | void onDateTimeOnSelection(const SqpDateTime &dateTime); | |
71 |
|
69 | |||
72 | void initialize(); |
|
70 | void initialize(); | |
73 | void finalize(); |
|
71 | void finalize(); | |
74 |
|
72 | |||
75 | private: |
|
73 | private: | |
76 | void waitForFinish(); |
|
74 | void waitForFinish(); | |
77 |
|
75 | |||
78 | class VariableControllerPrivate; |
|
76 | class VariableControllerPrivate; | |
79 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; |
|
77 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; | |
80 | }; |
|
78 | }; | |
81 |
|
79 | |||
82 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
|
80 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
@@ -1,46 +1,44 | |||||
1 | #ifndef SCIQLOP_VISUALIZATIONCONTROLLER_H |
|
1 | #ifndef SCIQLOP_VISUALIZATIONCONTROLLER_H | |
2 | #define SCIQLOP_VISUALIZATIONCONTROLLER_H |
|
2 | #define SCIQLOP_VISUALIZATIONCONTROLLER_H | |
3 |
|
3 | |||
4 | #include <QLoggingCategory> |
|
4 | #include <QLoggingCategory> | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <QUuid> |
|
6 | #include <QUuid> | |
7 |
|
7 | |||
8 | #include <Common/spimpl.h> |
|
8 | #include <Common/spimpl.h> | |
9 |
|
9 | |||
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationController) |
|
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationController) | |
11 |
|
11 | |||
12 | class DataSourceItem; |
|
12 | class DataSourceItem; | |
13 | class Variable; |
|
13 | class Variable; | |
14 |
|
14 | |||
15 | /** |
|
15 | /** | |
16 | * @brief The VisualizationController class aims to make the link between SciQlop and its plugins. |
|
16 | * @brief The VisualizationController class aims to make the link between SciQlop and its plugins. | |
17 | * This is the intermediate class that SciQlop has to use in the way to connect a data source. |
|
17 | * This is the intermediate class that SciQlop has to use in the way to connect a data source. | |
18 | * Please first use register method to initialize a plugin specified by its metadata name (JSON |
|
18 | * Please first use register method to initialize a plugin specified by its metadata name (JSON | |
19 | * plugin source) then others specifics method will be able to access it. You can load a data source |
|
19 | * plugin source) then others specifics method will be able to access it. You can load a data source | |
20 | * driver plugin then create a data source. |
|
20 | * driver plugin then create a data source. | |
21 | */ |
|
21 | */ | |
22 | class VisualizationController : public QObject { |
|
22 | class VisualizationController : public QObject { | |
23 | Q_OBJECT |
|
23 | Q_OBJECT | |
24 | public: |
|
24 | public: | |
25 | explicit VisualizationController(QObject *parent = 0); |
|
25 | explicit VisualizationController(QObject *parent = 0); | |
26 | virtual ~VisualizationController(); |
|
26 | virtual ~VisualizationController(); | |
27 |
|
27 | |||
28 | signals: |
|
28 | signals: | |
29 | /// Signal emitted when a variable is about to be deleted from SciQlop |
|
29 | /// Signal emitted when a variable is about to be deleted from SciQlop | |
30 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); |
|
30 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); | |
31 | /// Signal emitted when a variable has been created in SciQlop |
|
|||
32 | void variableCreated(std::shared_ptr<Variable> variable); |
|
|||
33 |
|
31 | |||
34 | public slots: |
|
32 | public slots: | |
35 | /// Manage init/end of the controller |
|
33 | /// Manage init/end of the controller | |
36 | void initialize(); |
|
34 | void initialize(); | |
37 | void finalize(); |
|
35 | void finalize(); | |
38 |
|
36 | |||
39 | private: |
|
37 | private: | |
40 | void waitForFinish(); |
|
38 | void waitForFinish(); | |
41 |
|
39 | |||
42 | class VisualizationControllerPrivate; |
|
40 | class VisualizationControllerPrivate; | |
43 | spimpl::unique_impl_ptr<VisualizationControllerPrivate> impl; |
|
41 | spimpl::unique_impl_ptr<VisualizationControllerPrivate> impl; | |
44 | }; |
|
42 | }; | |
45 |
|
43 | |||
46 | #endif // SCIQLOP_VISUALIZATIONCONTROLLER_H |
|
44 | #endif // SCIQLOP_VISUALIZATIONCONTROLLER_H |
@@ -1,209 +1,206 | |||||
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 <QtCore/QItemSelectionModel> |
|
14 | #include <QtCore/QItemSelectionModel> | |
15 |
|
15 | |||
16 | #include <unordered_map> |
|
16 | #include <unordered_map> | |
17 |
|
17 | |||
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
19 |
|
19 | |||
20 | namespace { |
|
20 | namespace { | |
21 |
|
21 | |||
22 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method |
|
22 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method | |
23 | /// will be deleted when the timerange is recovered from SciQlop |
|
23 | /// will be deleted when the timerange is recovered from SciQlop | |
24 | std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, |
|
24 | std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, | |
25 | const SqpDateTime &dateTime) noexcept |
|
25 | const SqpDateTime &dateTime) noexcept | |
26 | { |
|
26 | { | |
27 | auto parameters = DataProviderParameters{dateTime}; |
|
27 | auto parameters = DataProviderParameters{dateTime}; | |
28 |
|
28 | |||
29 | return provider.retrieveData(parameters); |
|
29 | return provider.retrieveData(parameters); | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | } // namespace |
|
32 | } // namespace | |
33 |
|
33 | |||
34 | struct VariableController::VariableControllerPrivate { |
|
34 | struct VariableController::VariableControllerPrivate { | |
35 | explicit VariableControllerPrivate(VariableController *parent) |
|
35 | explicit VariableControllerPrivate(VariableController *parent) | |
36 | : m_WorkingMutex{}, |
|
36 | : m_WorkingMutex{}, | |
37 | m_VariableModel{new VariableModel{parent}}, |
|
37 | m_VariableModel{new VariableModel{parent}}, | |
38 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
38 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, | |
39 | m_VariableCacheController{std::make_unique<VariableCacheController>()} |
|
39 | m_VariableCacheController{std::make_unique<VariableCacheController>()} | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QMutex m_WorkingMutex; |
|
43 | QMutex m_WorkingMutex; | |
44 | /// Variable model. The VariableController has the ownership |
|
44 | /// Variable model. The VariableController has the ownership | |
45 | VariableModel *m_VariableModel; |
|
45 | VariableModel *m_VariableModel; | |
46 | QItemSelectionModel *m_VariableSelectionModel; |
|
46 | QItemSelectionModel *m_VariableSelectionModel; | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | TimeController *m_TimeController{nullptr}; |
|
49 | TimeController *m_TimeController{nullptr}; | |
50 | std::unique_ptr<VariableCacheController> m_VariableCacheController; |
|
50 | std::unique_ptr<VariableCacheController> m_VariableCacheController; | |
51 |
|
51 | |||
52 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
52 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
53 | m_VariableToProviderMap; |
|
53 | m_VariableToProviderMap; | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | VariableController::VariableController(QObject *parent) |
|
56 | VariableController::VariableController(QObject *parent) | |
57 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
57 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
58 | { |
|
58 | { | |
59 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
59 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
60 | << QThread::currentThread(); |
|
60 | << QThread::currentThread(); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | VariableController::~VariableController() |
|
63 | VariableController::~VariableController() | |
64 | { |
|
64 | { | |
65 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
65 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
66 | << QThread::currentThread(); |
|
66 | << QThread::currentThread(); | |
67 | this->waitForFinish(); |
|
67 | this->waitForFinish(); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | VariableModel *VariableController::variableModel() noexcept |
|
70 | VariableModel *VariableController::variableModel() noexcept | |
71 | { |
|
71 | { | |
72 | return impl->m_VariableModel; |
|
72 | return impl->m_VariableModel; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept |
|
75 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept | |
76 | { |
|
76 | { | |
77 | return impl->m_VariableSelectionModel; |
|
77 | return impl->m_VariableSelectionModel; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
80 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
81 | { |
|
81 | { | |
82 | impl->m_TimeController = timeController; |
|
82 | impl->m_TimeController = timeController; | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
85 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |
86 | { |
|
86 | { | |
87 | if (!variable) { |
|
87 | if (!variable) { | |
88 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; |
|
88 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; | |
89 | return; |
|
89 | return; | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can |
|
92 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can | |
93 | // make some treatments before the deletion |
|
93 | // make some treatments before the deletion | |
94 | emit variableAboutToBeDeleted(variable); |
|
94 | emit variableAboutToBeDeleted(variable); | |
95 |
|
95 | |||
96 | // Deletes provider |
|
96 | // Deletes provider | |
97 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); |
|
97 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); | |
98 | qCDebug(LOG_VariableController()) |
|
98 | qCDebug(LOG_VariableController()) | |
99 | << tr("Number of providers deleted for variable %1: %2") |
|
99 | << tr("Number of providers deleted for variable %1: %2") | |
100 | .arg(variable->name(), QString::number(nbProvidersDeleted)); |
|
100 | .arg(variable->name(), QString::number(nbProvidersDeleted)); | |
101 |
|
101 | |||
102 | // Clears cache |
|
102 | // Clears cache | |
103 | impl->m_VariableCacheController->clear(variable); |
|
103 | impl->m_VariableCacheController->clear(variable); | |
104 |
|
104 | |||
105 | // Deletes from model |
|
105 | // Deletes from model | |
106 | impl->m_VariableModel->deleteVariable(variable); |
|
106 | impl->m_VariableModel->deleteVariable(variable); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void VariableController::deleteVariables( |
|
109 | void VariableController::deleteVariables( | |
110 | const QVector<std::shared_ptr<Variable> > &variables) noexcept |
|
110 | const QVector<std::shared_ptr<Variable> > &variables) noexcept | |
111 | { |
|
111 | { | |
112 | for (auto variable : qAsConst(variables)) { |
|
112 | for (auto variable : qAsConst(variables)) { | |
113 | deleteVariable(variable); |
|
113 | deleteVariable(variable); | |
114 | } |
|
114 | } | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void VariableController::createVariable(const QString &name, |
|
117 | void VariableController::createVariable(const QString &name, | |
118 | std::shared_ptr<IDataProvider> provider) noexcept |
|
118 | std::shared_ptr<IDataProvider> provider) noexcept | |
119 | { |
|
119 | { | |
120 |
|
120 | |||
121 | if (!impl->m_TimeController) { |
|
121 | if (!impl->m_TimeController) { | |
122 | qCCritical(LOG_VariableController()) |
|
122 | qCCritical(LOG_VariableController()) | |
123 | << tr("Impossible to create variable: The time controller is null"); |
|
123 | << tr("Impossible to create variable: The time controller is null"); | |
124 | return; |
|
124 | return; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 |
|
127 | |||
128 | /// @todo : for the moment : |
|
128 | /// @todo : for the moment : | |
129 | /// - the provider is only used to retrieve data from the variable for its initialization, but |
|
129 | /// - the provider is only used to retrieve data from the variable for its initialization, but | |
130 | /// it will be retained later |
|
130 | /// it will be retained later | |
131 | /// - default data are generated for the variable, without taking into account the timerange set |
|
131 | /// - default data are generated for the variable, without taking into account the timerange set | |
132 | /// in sciqlop |
|
132 | /// in sciqlop | |
133 | auto dateTime = impl->m_TimeController->dateTime(); |
|
133 | auto dateTime = impl->m_TimeController->dateTime(); | |
134 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { |
|
134 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { | |
135 |
|
135 | |||
136 | // store the provider |
|
136 | // store the provider | |
137 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
137 | impl->m_VariableToProviderMap[newVariable] = provider; | |
138 |
|
138 | |||
139 | auto addDateTimeAcquired |
|
139 | auto addDateTimeAcquired | |
140 | = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) { |
|
140 | = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) { | |
141 |
|
141 | |||
142 | impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache); |
|
142 | impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache); | |
143 | newVariable->setDataSeries(dataSeriesAcquired); |
|
143 | newVariable->setDataSeries(dataSeriesAcquired); | |
144 |
|
144 | |||
145 | }; |
|
145 | }; | |
146 |
|
146 | |||
147 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); |
|
147 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); | |
148 | this->onRequestDataLoading(newVariable, dateTime); |
|
148 | this->onRequestDataLoading(newVariable, dateTime); | |
149 |
|
||||
150 | // notify the creation |
|
|||
151 | emit variableCreated(newVariable); |
|
|||
152 | } |
|
149 | } | |
153 | } |
|
150 | } | |
154 |
|
151 | |||
155 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) |
|
152 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) | |
156 | { |
|
153 | { | |
157 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
154 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); | |
158 |
|
155 | |||
159 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
156 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
160 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
157 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { | |
161 | selectedVariable->setDateTime(dateTime); |
|
158 | selectedVariable->setDateTime(dateTime); | |
162 | this->onRequestDataLoading(selectedVariable, dateTime); |
|
159 | this->onRequestDataLoading(selectedVariable, dateTime); | |
163 | } |
|
160 | } | |
164 | } |
|
161 | } | |
165 | } |
|
162 | } | |
166 |
|
163 | |||
167 |
|
164 | |||
168 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, |
|
165 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, | |
169 | const SqpDateTime &dateTime) |
|
166 | const SqpDateTime &dateTime) | |
170 | { |
|
167 | { | |
171 | // we want to load data of the variable for the dateTime. |
|
168 | // we want to load data of the variable for the dateTime. | |
172 | // First we check if the cache contains some of them. |
|
169 | // First we check if the cache contains some of them. | |
173 | // For the other, we ask the provider to give them. |
|
170 | // For the other, we ask the provider to give them. | |
174 | if (variable) { |
|
171 | if (variable) { | |
175 |
|
172 | |||
176 | auto dateTimeListNotInCache |
|
173 | auto dateTimeListNotInCache | |
177 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); |
|
174 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); | |
178 |
|
175 | |||
179 | if (!dateTimeListNotInCache.empty()) { |
|
176 | if (!dateTimeListNotInCache.empty()) { | |
180 | // Ask the provider for each data on the dateTimeListNotInCache |
|
177 | // Ask the provider for each data on the dateTimeListNotInCache | |
181 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( |
|
178 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( | |
182 | std::move(dateTimeListNotInCache)); |
|
179 | std::move(dateTimeListNotInCache)); | |
183 | } |
|
180 | } | |
184 | else { |
|
181 | else { | |
185 | emit variable->updated(); |
|
182 | emit variable->updated(); | |
186 | } |
|
183 | } | |
187 | } |
|
184 | } | |
188 | else { |
|
185 | else { | |
189 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
|
186 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); | |
190 | } |
|
187 | } | |
191 | } |
|
188 | } | |
192 |
|
189 | |||
193 |
|
190 | |||
194 | void VariableController::initialize() |
|
191 | void VariableController::initialize() | |
195 | { |
|
192 | { | |
196 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
193 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
197 | impl->m_WorkingMutex.lock(); |
|
194 | impl->m_WorkingMutex.lock(); | |
198 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
195 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
199 | } |
|
196 | } | |
200 |
|
197 | |||
201 | void VariableController::finalize() |
|
198 | void VariableController::finalize() | |
202 | { |
|
199 | { | |
203 | impl->m_WorkingMutex.unlock(); |
|
200 | impl->m_WorkingMutex.unlock(); | |
204 | } |
|
201 | } | |
205 |
|
202 | |||
206 | void VariableController::waitForFinish() |
|
203 | void VariableController::waitForFinish() | |
207 | { |
|
204 | { | |
208 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
205 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
209 | } |
|
206 | } |
@@ -1,122 +1,119 | |||||
1 | #include "SqpApplication.h" |
|
1 | #include "SqpApplication.h" | |
2 |
|
2 | |||
3 | #include <Data/IDataProvider.h> |
|
3 | #include <Data/IDataProvider.h> | |
4 | #include <DataSource/DataSourceController.h> |
|
4 | #include <DataSource/DataSourceController.h> | |
5 | #include <QThread> |
|
5 | #include <QThread> | |
6 | #include <Time/TimeController.h> |
|
6 | #include <Time/TimeController.h> | |
7 | #include <Variable/Variable.h> |
|
7 | #include <Variable/Variable.h> | |
8 | #include <Variable/VariableController.h> |
|
8 | #include <Variable/VariableController.h> | |
9 | #include <Visualization/VisualizationController.h> |
|
9 | #include <Visualization/VisualizationController.h> | |
10 |
|
10 | |||
11 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") |
|
11 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") | |
12 |
|
12 | |||
13 | class SqpApplication::SqpApplicationPrivate { |
|
13 | class SqpApplication::SqpApplicationPrivate { | |
14 | public: |
|
14 | public: | |
15 | SqpApplicationPrivate() |
|
15 | SqpApplicationPrivate() | |
16 | : m_DataSourceController{std::make_unique<DataSourceController>()}, |
|
16 | : m_DataSourceController{std::make_unique<DataSourceController>()}, | |
17 | m_TimeController{std::make_unique<TimeController>()}, |
|
17 | m_TimeController{std::make_unique<TimeController>()}, | |
18 | m_VariableController{std::make_unique<VariableController>()}, |
|
18 | m_VariableController{std::make_unique<VariableController>()}, | |
19 | m_VisualizationController{std::make_unique<VisualizationController>()} |
|
19 | m_VisualizationController{std::make_unique<VisualizationController>()} | |
20 | { |
|
20 | { | |
21 | // /////////////////////////////// // |
|
21 | // /////////////////////////////// // | |
22 | // Connections between controllers // |
|
22 | // Connections between controllers // | |
23 | // /////////////////////////////// // |
|
23 | // /////////////////////////////// // | |
24 |
|
24 | |||
25 | // VariableController <-> DataSourceController |
|
25 | // VariableController <-> DataSourceController | |
26 | connect(m_DataSourceController.get(), |
|
26 | connect(m_DataSourceController.get(), | |
27 | SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)), |
|
27 | SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)), | |
28 | m_VariableController.get(), |
|
28 | m_VariableController.get(), | |
29 | SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>))); |
|
29 | SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>))); | |
30 |
|
30 | |||
31 | // VariableController <-> VisualizationController |
|
31 | // VariableController <-> VisualizationController | |
32 | connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)), |
|
|||
33 | m_VisualizationController.get(), |
|
|||
34 | SIGNAL(variableCreated(std::shared_ptr<Variable>))); |
|
|||
35 | connect(m_VariableController.get(), |
|
32 | connect(m_VariableController.get(), | |
36 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), |
|
33 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), | |
37 | m_VisualizationController.get(), |
|
34 | m_VisualizationController.get(), | |
38 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); |
|
35 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); | |
39 |
|
36 | |||
40 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); |
|
37 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); | |
41 | m_VariableController->moveToThread(&m_VariableControllerThread); |
|
38 | m_VariableController->moveToThread(&m_VariableControllerThread); | |
42 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); |
|
39 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); | |
43 |
|
40 | |||
44 | // Additionnal init |
|
41 | // Additionnal init | |
45 | m_VariableController->setTimeController(m_TimeController.get()); |
|
42 | m_VariableController->setTimeController(m_TimeController.get()); | |
46 | } |
|
43 | } | |
47 |
|
44 | |||
48 | virtual ~SqpApplicationPrivate() |
|
45 | virtual ~SqpApplicationPrivate() | |
49 | { |
|
46 | { | |
50 | qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction"); |
|
47 | qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction"); | |
51 | m_DataSourceControllerThread.quit(); |
|
48 | m_DataSourceControllerThread.quit(); | |
52 | m_DataSourceControllerThread.wait(); |
|
49 | m_DataSourceControllerThread.wait(); | |
53 |
|
50 | |||
54 | m_VariableControllerThread.quit(); |
|
51 | m_VariableControllerThread.quit(); | |
55 | m_VariableControllerThread.wait(); |
|
52 | m_VariableControllerThread.wait(); | |
56 |
|
53 | |||
57 | m_VisualizationControllerThread.quit(); |
|
54 | m_VisualizationControllerThread.quit(); | |
58 | m_VisualizationControllerThread.wait(); |
|
55 | m_VisualizationControllerThread.wait(); | |
59 | } |
|
56 | } | |
60 |
|
57 | |||
61 | std::unique_ptr<DataSourceController> m_DataSourceController; |
|
58 | std::unique_ptr<DataSourceController> m_DataSourceController; | |
62 | std::unique_ptr<VariableController> m_VariableController; |
|
59 | std::unique_ptr<VariableController> m_VariableController; | |
63 | std::unique_ptr<TimeController> m_TimeController; |
|
60 | std::unique_ptr<TimeController> m_TimeController; | |
64 | std::unique_ptr<VisualizationController> m_VisualizationController; |
|
61 | std::unique_ptr<VisualizationController> m_VisualizationController; | |
65 | QThread m_DataSourceControllerThread; |
|
62 | QThread m_DataSourceControllerThread; | |
66 | QThread m_VariableControllerThread; |
|
63 | QThread m_VariableControllerThread; | |
67 | QThread m_VisualizationControllerThread; |
|
64 | QThread m_VisualizationControllerThread; | |
68 | }; |
|
65 | }; | |
69 |
|
66 | |||
70 |
|
67 | |||
71 | SqpApplication::SqpApplication(int &argc, char **argv) |
|
68 | SqpApplication::SqpApplication(int &argc, char **argv) | |
72 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} |
|
69 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} | |
73 | { |
|
70 | { | |
74 | qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction"); |
|
71 | qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction"); | |
75 |
|
72 | |||
76 | connect(&impl->m_DataSourceControllerThread, &QThread::started, |
|
73 | connect(&impl->m_DataSourceControllerThread, &QThread::started, | |
77 | impl->m_DataSourceController.get(), &DataSourceController::initialize); |
|
74 | impl->m_DataSourceController.get(), &DataSourceController::initialize); | |
78 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, |
|
75 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, | |
79 | impl->m_DataSourceController.get(), &DataSourceController::finalize); |
|
76 | impl->m_DataSourceController.get(), &DataSourceController::finalize); | |
80 |
|
77 | |||
81 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), |
|
78 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), | |
82 | &VariableController::initialize); |
|
79 | &VariableController::initialize); | |
83 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), |
|
80 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), | |
84 | &VariableController::finalize); |
|
81 | &VariableController::finalize); | |
85 |
|
82 | |||
86 | connect(&impl->m_VisualizationControllerThread, &QThread::started, |
|
83 | connect(&impl->m_VisualizationControllerThread, &QThread::started, | |
87 | impl->m_VisualizationController.get(), &VisualizationController::initialize); |
|
84 | impl->m_VisualizationController.get(), &VisualizationController::initialize); | |
88 | connect(&impl->m_VisualizationControllerThread, &QThread::finished, |
|
85 | connect(&impl->m_VisualizationControllerThread, &QThread::finished, | |
89 | impl->m_VisualizationController.get(), &VisualizationController::finalize); |
|
86 | impl->m_VisualizationController.get(), &VisualizationController::finalize); | |
90 |
|
87 | |||
91 | impl->m_DataSourceControllerThread.start(); |
|
88 | impl->m_DataSourceControllerThread.start(); | |
92 | impl->m_VariableControllerThread.start(); |
|
89 | impl->m_VariableControllerThread.start(); | |
93 | impl->m_VisualizationControllerThread.start(); |
|
90 | impl->m_VisualizationControllerThread.start(); | |
94 | } |
|
91 | } | |
95 |
|
92 | |||
96 | SqpApplication::~SqpApplication() |
|
93 | SqpApplication::~SqpApplication() | |
97 | { |
|
94 | { | |
98 | } |
|
95 | } | |
99 |
|
96 | |||
100 | void SqpApplication::initialize() |
|
97 | void SqpApplication::initialize() | |
101 | { |
|
98 | { | |
102 | } |
|
99 | } | |
103 |
|
100 | |||
104 | DataSourceController &SqpApplication::dataSourceController() noexcept |
|
101 | DataSourceController &SqpApplication::dataSourceController() noexcept | |
105 | { |
|
102 | { | |
106 | return *impl->m_DataSourceController; |
|
103 | return *impl->m_DataSourceController; | |
107 | } |
|
104 | } | |
108 |
|
105 | |||
109 | TimeController &SqpApplication::timeController() noexcept |
|
106 | TimeController &SqpApplication::timeController() noexcept | |
110 | { |
|
107 | { | |
111 | return *impl->m_TimeController; |
|
108 | return *impl->m_TimeController; | |
112 | } |
|
109 | } | |
113 |
|
110 | |||
114 | VariableController &SqpApplication::variableController() noexcept |
|
111 | VariableController &SqpApplication::variableController() noexcept | |
115 | { |
|
112 | { | |
116 | return *impl->m_VariableController; |
|
113 | return *impl->m_VariableController; | |
117 | } |
|
114 | } | |
118 |
|
115 | |||
119 | VisualizationController &SqpApplication::visualizationController() noexcept |
|
116 | VisualizationController &SqpApplication::visualizationController() noexcept | |
120 | { |
|
117 | { | |
121 | return *impl->m_VisualizationController; |
|
118 | return *impl->m_VisualizationController; | |
122 | } |
|
119 | } |
General Comments 0
You need to be logged in to leave comments.
Login now