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