##// END OF EJS Templates
Add connection logical for the rescale operation
perrinel -
r437:9fabd78ca3ee
parent child
Show More
@@ -1,265 +1,269
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SciQLop Software
3 3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "MainWindow.h"
23 23 #include "ui_MainWindow.h"
24 24
25 25 #include <DataSource/DataSourceController.h>
26 26 #include <DataSource/DataSourceWidget.h>
27 27 #include <SidePane/SqpSidePane.h>
28 28 #include <SqpApplication.h>
29 29 #include <Time/TimeController.h>
30 30 #include <TimeWidget/TimeWidget.h>
31 31 #include <Variable/Variable.h>
32 32 #include <Variable/VariableController.h>
33 33 #include <Visualization/VisualizationController.h>
34 34
35 35 #include <QAction>
36 36 #include <QDate>
37 37 #include <QDateTime>
38 38 #include <QDir>
39 39 #include <QFileDialog>
40 40 #include <QToolBar>
41 41 #include <QToolButton>
42 42 #include <memory.h>
43 43
44 44 //#include <omp.h>
45 45 //#include <network/filedownloader.h>
46 46 //#include <qlopdatabase.h>
47 47 //#include <qlopsettings.h>
48 48 //#include <qlopgui.h>
49 49 //#include <spacedata.h>
50 50 //#include "qlopcore.h"
51 51 //#include "qlopcodecmanager.h"
52 52 //#include "cdfcodec.h"
53 53 //#include "amdatxtcodec.h"
54 54 //#include <qlopplotmanager.h>
55 55
56 56 #include "iostream"
57 57
58 58 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
59 59
60 60 namespace {
61 61 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
62 62 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
63 63 const auto VIEWPLITTERINDEX = 2;
64 64 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
65 65 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
66 66 }
67 67
68 68 class MainWindow::MainWindowPrivate {
69 69 public:
70 70 QSize m_LastOpenLeftInspectorSize;
71 71 QSize m_LastOpenRightInspectorSize;
72 72 };
73 73
74 74 MainWindow::MainWindow(QWidget *parent)
75 75 : QMainWindow{parent},
76 76 m_Ui{new Ui::MainWindow},
77 77 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
78 78 {
79 79 m_Ui->setupUi(this);
80 80
81 81 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
82 82 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
83 83
84 84
85 85 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
86 86 auto openLeftInspectorAction = new QAction{QIcon{
87 87 ":/icones/previous.png",
88 88 },
89 89 tr("Show/hide the left inspector"), this};
90 90
91 91
92 92 auto spacerLeftTop = new QWidget{};
93 93 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
94 94
95 95 auto spacerLeftBottom = new QWidget{};
96 96 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
97 97
98 98 leftSidePane->addWidget(spacerLeftTop);
99 99 leftSidePane->addAction(openLeftInspectorAction);
100 100 leftSidePane->addWidget(spacerLeftBottom);
101 101
102 102
103 103 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
104 104 auto openRightInspectorAction = new QAction{QIcon{
105 105 ":/icones/next.png",
106 106 },
107 107 tr("Show/hide the right inspector"), this};
108 108
109 109 auto spacerRightTop = new QWidget{};
110 110 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
111 111
112 112 auto spacerRightBottom = new QWidget{};
113 113 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
114 114
115 115 rightSidePane->addWidget(spacerRightTop);
116 116 rightSidePane->addAction(openRightInspectorAction);
117 117 rightSidePane->addWidget(spacerRightBottom);
118 118
119 119 openLeftInspectorAction->setCheckable(true);
120 120 openRightInspectorAction->setCheckable(true);
121 121
122 122 auto openInspector = [this](bool checked, bool right, auto action) {
123 123
124 124 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
125 125
126 126 auto &lastInspectorSize
127 127 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
128 128
129 129 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
130 130 : m_Ui->leftMainInspectorWidget->size();
131 131
132 132 // Update of the last opened geometry
133 133 if (checked) {
134 134 lastInspectorSize = nextInspectorSize;
135 135 }
136 136
137 137 auto startSize = lastInspectorSize;
138 138 auto endSize = startSize;
139 139 endSize.setWidth(0);
140 140
141 141 auto splitterInspectorIndex
142 142 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
143 143
144 144 auto currentSizes = m_Ui->splitter->sizes();
145 145 if (checked) {
146 146 // adjust sizes individually here, e.g.
147 147 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
148 148 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
149 149 m_Ui->splitter->setSizes(currentSizes);
150 150 }
151 151 else {
152 152 // adjust sizes individually here, e.g.
153 153 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
154 154 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
155 155 m_Ui->splitter->setSizes(currentSizes);
156 156 }
157 157
158 158 };
159 159
160 160
161 161 connect(openLeftInspectorAction, &QAction::triggered,
162 162 [openInspector, openLeftInspectorAction](bool checked) {
163 163 openInspector(checked, false, openLeftInspectorAction);
164 164 });
165 165 connect(openRightInspectorAction, &QAction::triggered,
166 166 [openInspector, openRightInspectorAction](bool checked) {
167 167 openInspector(checked, true, openRightInspectorAction);
168 168 });
169 169
170 170 this->menuBar()->addAction(tr("File"));
171 171 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
172 172
173 173 auto timeWidget = new TimeWidget{};
174 174 mainToolBar->addWidget(timeWidget);
175 175
176 176 // Controllers / controllers connections
177 177 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
178 178 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
179 179
180 180 // Widgets / controllers connections
181 181
182 182 // DataSource
183 183 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
184 184 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
185 185
186 186 // Time
187 187 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
188 188 SLOT(onTimeToUpdate(SqpDateTime)));
189 189
190 190 // Visualization
191 191 connect(&sqpApp->visualizationController(),
192 192 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view,
193 193 SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>)));
194 194
195 connect(&sqpApp->visualizationController(),
196 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)), m_Ui->view,
197 SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)));
198
195 199 // Widgets / widgets connections
196 200
197 201 // For the following connections, we use DirectConnection to allow each widget that can
198 202 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
199 203 // The order of connections is also important, since it determines the order in which each
200 204 // widget will attach its menu
201 205 connect(
202 206 m_Ui->variableInspectorWidget,
203 207 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
204 208 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
205 209 Qt::DirectConnection);
206 210
207 211 /* QLopGUI::registerMenuBar(menuBar());
208 212 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
209 213 this->m_progressWidget = new QWidget();
210 214 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
211 215 this->m_progressWidget->setLayout(this->m_progressLayout);
212 216 this->m_progressWidget->setWindowModality(Qt::WindowModal);
213 217 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
214 218 for(int i=0;i<OMP_THREADS;i++)
215 219 {
216 220 this->m_progress.append(new QProgressBar(this->m_progressWidget));
217 221 this->m_progress.last()->setMinimum(0);
218 222 this->m_progress.last()->setMaximum(100);
219 223 this->m_progressLayout->addWidget(this->m_progress.last());
220 224 this->m_progressWidget->hide();
221 225 this->m_progressThreadIds[i] = -1;
222 226 }
223 227 this->m_progressWidget->setWindowTitle("Loading File");
224 228 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
225 229 << QLopCore::self()
226 230 << QLopPlotManager::self()
227 231 << QLopCodecManager::self()
228 232 << FileDownloader::self()
229 233 << QLopDataBase::self()
230 234 << SpaceData::self();
231 235
232 236 CDFCodec::registerToManager();
233 237 AMDATXTCodec::registerToManager();
234 238
235 239
236 240 for(int i=0;i<ServicesToLoad.count();i++)
237 241 {
238 242 qDebug()<<ServicesToLoad.at(i)->serviceName();
239 243 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
240 244 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
241 245 if(wdgt)
242 246 {
243 247 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
244 248 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
245 249 }
246 250 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
247 251 }*/
248 252 }
249 253
250 254 MainWindow::~MainWindow()
251 255 {
252 256 }
253 257
254 258
255 259 void MainWindow::changeEvent(QEvent *e)
256 260 {
257 261 QMainWindow::changeEvent(e);
258 262 switch (e->type()) {
259 263 case QEvent::LanguageChange:
260 264 m_Ui->retranslateUi(this);
261 265 break;
262 266 default:
263 267 break;
264 268 }
265 269 }
@@ -1,92 +1,95
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 /**
54 54 * @brief abort the variable retrieve data progression
55 55 */
56 56 void abortProgress(std::shared_ptr<Variable> variable);
57 57
58 58 signals:
59 59 /// Signal emitted when a variable is about to be deleted from the controller
60 60 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
61 61
62 /// Signal emitted when a data acquisition is requested on a range for a variable
63 void rangeChanged(std::shared_ptr<Variable> variable, const SqpDateTime &range);
64
62 65 public slots:
63 66 /// Request the data loading of the variable whithin dateTime
64 67 void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
65 68 /**
66 69 * Creates a new variable and adds it to the model
67 70 * @param name the name of the new variable
68 71 * @param metadata the metadata of the new variable
69 72 * @param provider the data provider for the new variable
70 73 */
71 74 void createVariable(const QString &name, const QVariantHash &metadata,
72 75 std::shared_ptr<IDataProvider> provider) noexcept;
73 76
74 77 /// Update the temporal parameters of every selected variable to dateTime
75 78 void onDateTimeOnSelection(const SqpDateTime &dateTime);
76 79
77 80
78 81 void onVariableRetrieveDataInProgress(QUuid identifier, double progress);
79 82
80 83 void onAbortProgressRequested(std::shared_ptr<Variable> variable);
81 84
82 85 void initialize();
83 86 void finalize();
84 87
85 88 private:
86 89 void waitForFinish();
87 90
88 91 class VariableControllerPrivate;
89 92 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
90 93 };
91 94
92 95 #endif // SCIQLOP_VARIABLECONTROLLER_H
@@ -1,44 +1,49
1 1 #ifndef SCIQLOP_VISUALIZATIONCONTROLLER_H
2 2 #define SCIQLOP_VISUALIZATIONCONTROLLER_H
3 3
4 #include <Data/SqpDateTime.h>
5
4 6 #include <QLoggingCategory>
5 7 #include <QObject>
6 8 #include <QUuid>
7 9
8 10 #include <Common/spimpl.h>
9 11
10 12 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationController)
11 13
12 14 class DataSourceItem;
13 15 class Variable;
14 16
15 17 /**
16 18 * @brief The VisualizationController class aims to make the link between SciQlop and its plugins.
17 19 * This is the intermediate class that SciQlop has to use in the way to connect a data source.
18 20 * Please first use register method to initialize a plugin specified by its metadata name (JSON
19 21 * plugin source) then others specifics method will be able to access it. You can load a data source
20 22 * driver plugin then create a data source.
21 23 */
22 24 class VisualizationController : public QObject {
23 25 Q_OBJECT
24 26 public:
25 27 explicit VisualizationController(QObject *parent = 0);
26 28 virtual ~VisualizationController();
27 29
28 30 signals:
29 31 /// Signal emitted when a variable is about to be deleted from SciQlop
30 32 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
31 33
34 /// Signal emitted when a data acquisition is requested on a range for a variable
35 void rangeChanged(std::shared_ptr<Variable> variable, const SqpDateTime &range);
36
32 37 public slots:
33 38 /// Manage init/end of the controller
34 39 void initialize();
35 40 void finalize();
36 41
37 42 private:
38 43 void waitForFinish();
39 44
40 45 class VisualizationControllerPrivate;
41 46 spimpl::unique_impl_ptr<VisualizationControllerPrivate> impl;
42 47 };
43 48
44 49 #endif // SCIQLOP_VISUALIZATIONCONTROLLER_H
@@ -1,241 +1,242
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 <QUuid>
15 15 #include <QtCore/QItemSelectionModel>
16 16
17 17 #include <unordered_map>
18 18
19 19 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
20 20
21 21 struct VariableController::VariableControllerPrivate {
22 22 explicit VariableControllerPrivate(VariableController *parent)
23 23 : m_WorkingMutex{},
24 24 m_VariableModel{new VariableModel{parent}},
25 25 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
26 26 m_VariableCacheController{std::make_unique<VariableCacheController>()}
27 27 {
28 28 }
29 29
30 30 QMutex m_WorkingMutex;
31 31 /// Variable model. The VariableController has the ownership
32 32 VariableModel *m_VariableModel;
33 33 QItemSelectionModel *m_VariableSelectionModel;
34 34
35 35
36 36 TimeController *m_TimeController{nullptr};
37 37 std::unique_ptr<VariableCacheController> m_VariableCacheController;
38 38
39 39 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
40 40 m_VariableToProviderMap;
41 41 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
42 42 };
43 43
44 44 VariableController::VariableController(QObject *parent)
45 45 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
46 46 {
47 47 qCDebug(LOG_VariableController()) << tr("VariableController construction")
48 48 << QThread::currentThread();
49 49
50 50 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
51 51 &VariableController::onAbortProgressRequested);
52 52 }
53 53
54 54 VariableController::~VariableController()
55 55 {
56 56 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
57 57 << QThread::currentThread();
58 58 this->waitForFinish();
59 59 }
60 60
61 61 VariableModel *VariableController::variableModel() noexcept
62 62 {
63 63 return impl->m_VariableModel;
64 64 }
65 65
66 66 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
67 67 {
68 68 return impl->m_VariableSelectionModel;
69 69 }
70 70
71 71 void VariableController::setTimeController(TimeController *timeController) noexcept
72 72 {
73 73 impl->m_TimeController = timeController;
74 74 }
75 75
76 76 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
77 77 {
78 78 if (!variable) {
79 79 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
80 80 return;
81 81 }
82 82
83 83 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
84 84 // make some treatments before the deletion
85 85 emit variableAboutToBeDeleted(variable);
86 86
87 87 // Deletes identifier
88 88 impl->m_VariableToIdentifierMap.erase(variable);
89 89
90 90 // Deletes provider
91 91 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
92 92 qCDebug(LOG_VariableController())
93 93 << tr("Number of providers deleted for variable %1: %2")
94 94 .arg(variable->name(), QString::number(nbProvidersDeleted));
95 95
96 96 // Clears cache
97 97 impl->m_VariableCacheController->clear(variable);
98 98
99 99 // Deletes from model
100 100 impl->m_VariableModel->deleteVariable(variable);
101 101 }
102 102
103 103 void VariableController::deleteVariables(
104 104 const QVector<std::shared_ptr<Variable> > &variables) noexcept
105 105 {
106 106 for (auto variable : qAsConst(variables)) {
107 107 deleteVariable(variable);
108 108 }
109 109 }
110 110
111 111 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
112 112 {
113 113 }
114 114
115 115 void VariableController::createVariable(const QString &name, const QVariantHash &metadata,
116 116 std::shared_ptr<IDataProvider> provider) noexcept
117 117 {
118 118
119 119 if (!impl->m_TimeController) {
120 120 qCCritical(LOG_VariableController())
121 121 << tr("Impossible to create variable: The time controller is null");
122 122 return;
123 123 }
124 124
125 125 auto dateTime = impl->m_TimeController->dateTime();
126 126
127 127 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime, metadata)) {
128 128 auto identifier = QUuid::createUuid();
129 129
130 130 // store the provider
131 131 impl->m_VariableToProviderMap[newVariable] = provider;
132 132 impl->m_VariableToIdentifierMap[newVariable] = identifier;
133 133
134 134 auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ](
135 135 QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache)
136 136 {
137 137 if (auto variable = varW.lock()) {
138 138 auto varIdentifier = impl->m_VariableToIdentifierMap.at(variable);
139 139 if (varIdentifier == identifier) {
140 140 impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache);
141 141 variable->setDataSeries(dataSeriesAcquired);
142 142 emit variable->updated();
143 143 }
144 144 }
145 145 };
146 146
147 147 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
148 148 connect(provider.get(), &IDataProvider::dataProvidedProgress, this,
149 149 &VariableController::onVariableRetrieveDataInProgress);
150 150 this->onRequestDataLoading(newVariable, dateTime);
151 151 }
152 152 }
153 153
154 154 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
155 155 {
156 156 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
157 157 << QThread::currentThread()->objectName();
158 158 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
159 159
160 160 for (const auto &selectedRow : qAsConst(selectedRows)) {
161 161 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
162 162 selectedVariable->setDateTime(dateTime);
163 163 this->onRequestDataLoading(selectedVariable, dateTime);
164 emit rangeChanged(selectedVariable, dateTime);
164 165 }
165 166 }
166 167 }
167 168
168 169 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
169 170 {
170 171 auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
171 172
172 173 auto end = impl->m_VariableToIdentifierMap.cend();
173 174 auto it = std::find_if(impl->m_VariableToIdentifierMap.cbegin(), end, findReply);
174 175 if (it != end) {
175 176 impl->m_VariableModel->setDataProgress(it->first, progress);
176 177 }
177 178 }
178 179
179 180 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
180 181 {
181 182 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
182 183 << QThread::currentThread()->objectName();
183 184
184 185 auto it = impl->m_VariableToIdentifierMap.find(variable);
185 186 if (it != impl->m_VariableToIdentifierMap.cend()) {
186 187 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
187 188 }
188 189 else {
189 190 qCWarning(LOG_VariableController())
190 191 << tr("Aborting progression of inexistant variable detected !!!")
191 192 << QThread::currentThread()->objectName();
192 193 }
193 194 }
194 195
195 196
196 197 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
197 198 const SqpDateTime &dateTime)
198 199 {
199 200 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
200 201 << QThread::currentThread()->objectName();
201 202 // we want to load data of the variable for the dateTime.
202 203 // First we check if the cache contains some of them.
203 204 // For the other, we ask the provider to give them.
204 205 if (variable) {
205 206
206 207 auto dateTimeListNotInCache
207 208 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
208 209
209 210 if (!dateTimeListNotInCache.empty()) {
210 211 // Ask the provider for each data on the dateTimeListNotInCache
211 212 auto identifier = impl->m_VariableToIdentifierMap.at(variable);
212 213 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
213 214 identifier,
214 215 DataProviderParameters{std::move(dateTimeListNotInCache), variable->metadata()});
215 216 }
216 217 else {
217 218 emit variable->updated();
218 219 }
219 220 }
220 221 else {
221 222 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
222 223 }
223 224 }
224 225
225 226
226 227 void VariableController::initialize()
227 228 {
228 229 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
229 230 impl->m_WorkingMutex.lock();
230 231 qCDebug(LOG_VariableController()) << tr("VariableController init END");
231 232 }
232 233
233 234 void VariableController::finalize()
234 235 {
235 236 impl->m_WorkingMutex.unlock();
236 237 }
237 238
238 239 void VariableController::waitForFinish()
239 240 {
240 241 QMutexLocker locker{&impl->m_WorkingMutex};
241 242 }
@@ -1,65 +1,66
1 1 #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
2 2 #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 6 #include <QLoggingCategory>
7 7 #include <QWidget>
8 8
9 9 #include <memory>
10 10
11 11 #include <Common/spimpl.h>
12 12
13 13 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget)
14 14
15 15 class QCPRange;
16 16 class SqpDateTime;
17 17 class Variable;
18 18
19 19 namespace Ui {
20 20 class VisualizationGraphWidget;
21 21 } // namespace Ui
22 22
23 23 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
24 24 Q_OBJECT
25 25
26 26 public:
27 27 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
28 28 virtual ~VisualizationGraphWidget();
29 29
30 30 void addVariable(std::shared_ptr<Variable> variable);
31 31 void addVariableUsingGraph(std::shared_ptr<Variable> variable);
32 32 /// Removes a variable from the graph
33 33 void removeVariable(std::shared_ptr<Variable> variable) noexcept;
34 34
35 /// Rescale the X axe to range parameter
36 void setRange(std::shared_ptr<Variable> variable, const SqpDateTime &range);
37
35 38 // IVisualizationWidget interface
36 39 void accept(IVisualizationWidgetVisitor *visitor) override;
37 40 bool canDrop(const Variable &variable) const override;
38 41 bool contains(const Variable &variable) const override;
39 42 QString name() const override;
40 43
41 void updateDisplay(std::shared_ptr<Variable> variable);
42
43 44 signals:
44 45 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
45 46
46 47
47 48 private:
48 49 Ui::VisualizationGraphWidget *ui;
49 50
50 51 class VisualizationGraphWidgetPrivate;
51 52 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
52 53
53 54 private slots:
54 55 /// Slot called when right clicking on the graph (displays a menu)
55 56 void onGraphMenuRequested(const QPoint &pos) noexcept;
56 57
57 58 void onRangeChanged(const QCPRange &t1);
58 59
59 60 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
60 61 void onMouseWheel(QWheelEvent *event) noexcept;
61 62
62 63 void onDataCacheVariableUpdated();
63 64 };
64 65
65 66 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
@@ -1,48 +1,51
1 1 #ifndef SCIQLOP_VISUALIZATIONWIDGET_H
2 2 #define SCIQLOP_VISUALIZATIONWIDGET_H
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 #include <Data/SqpDateTime.h>
5 6
6 7 #include <QLoggingCategory>
7 8 #include <QWidget>
8 9
9 10 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
10 11
11 12 class QMenu;
12 13 class Variable;
13 14 class VisualizationTabWidget;
14 15
15 16 namespace Ui {
16 17 class VisualizationWidget;
17 18 } // namespace Ui
18 19
19 20 class VisualizationWidget : public QWidget, public IVisualizationWidget {
20 21 Q_OBJECT
21 22
22 23 public:
23 24 explicit VisualizationWidget(QWidget *parent = 0);
24 25 virtual ~VisualizationWidget();
25 26
26 27 // IVisualizationWidget interface
27 28 void accept(IVisualizationWidgetVisitor *visitor) override;
28 29 bool canDrop(const Variable &variable) const override;
29 30 bool contains(const Variable &variable) const override;
30 31 QString name() const override;
31 32
32 33 public slots:
33 34 /**
34 35 * Attaches to a menu the menu relative to the visualization of variables
35 36 * @param menu the parent menu of the generated menu
36 37 * @param variables the variables for which to generate the menu
37 38 */
38 39 void attachVariableMenu(QMenu *menu,
39 40 const QVector<std::shared_ptr<Variable> > &variables) noexcept;
40 41
41 42 /// Slot called when a variable is about to be deleted from SciQlop
42 43 void onVariableAboutToBeDeleted(std::shared_ptr<Variable> variable) noexcept;
43 44
45 void onRangeChanged(std::shared_ptr<Variable> variable, const SqpDateTime &range) noexcept;
46
44 47 private:
45 48 Ui::VisualizationWidget *ui;
46 49 };
47 50
48 51 #endif // VISUALIZATIONWIDGET_H
@@ -1,146 +1,151
1 1 #include "SqpApplication.h"
2 2
3 3 #include <Data/IDataProvider.h>
4 4 #include <DataSource/DataSourceController.h>
5 5 #include <Network/NetworkController.h>
6 6 #include <QThread>
7 7 #include <Time/TimeController.h>
8 8 #include <Variable/Variable.h>
9 9 #include <Variable/VariableController.h>
10 10 #include <Visualization/VisualizationController.h>
11 11
12 12 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
13 13
14 14 class SqpApplication::SqpApplicationPrivate {
15 15 public:
16 16 SqpApplicationPrivate()
17 17 : m_DataSourceController{std::make_unique<DataSourceController>()},
18 18 m_NetworkController{std::make_unique<NetworkController>()},
19 19 m_TimeController{std::make_unique<TimeController>()},
20 20 m_VariableController{std::make_unique<VariableController>()},
21 21 m_VisualizationController{std::make_unique<VisualizationController>()}
22 22 {
23 23 // /////////////////////////////// //
24 24 // Connections between controllers //
25 25 // /////////////////////////////// //
26 26
27 27 // VariableController <-> DataSourceController
28 28 connect(m_DataSourceController.get(),
29 29 SIGNAL(variableCreationRequested(const QString &, const QVariantHash &,
30 30 std::shared_ptr<IDataProvider>)),
31 31 m_VariableController.get(),
32 32 SLOT(createVariable(const QString &, const QVariantHash &,
33 33 std::shared_ptr<IDataProvider>)));
34 34
35 35 // VariableController <-> VisualizationController
36 36 connect(m_VariableController.get(),
37 37 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
38 38 m_VisualizationController.get(),
39 39 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
40 40
41 connect(m_VariableController.get(),
42 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)),
43 m_VisualizationController.get(),
44 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)));
45
41 46
42 47 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
43 48 m_DataSourceControllerThread.setObjectName("DataSourceControllerThread");
44 49 m_NetworkController->moveToThread(&m_NetworkControllerThread);
45 50 m_NetworkControllerThread.setObjectName("NetworkControllerThread");
46 51 m_VariableController->moveToThread(&m_VariableControllerThread);
47 52 m_VariableControllerThread.setObjectName("VariableControllerThread");
48 53 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
49 54 m_VisualizationControllerThread.setObjectName("VsualizationControllerThread");
50 55
51 56
52 57 // Additionnal init
53 58 m_VariableController->setTimeController(m_TimeController.get());
54 59 }
55 60
56 61 virtual ~SqpApplicationPrivate()
57 62 {
58 63 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
59 64 m_DataSourceControllerThread.quit();
60 65 m_DataSourceControllerThread.wait();
61 66
62 67 m_NetworkControllerThread.quit();
63 68 m_NetworkControllerThread.wait();
64 69
65 70 m_VariableControllerThread.quit();
66 71 m_VariableControllerThread.wait();
67 72
68 73 m_VisualizationControllerThread.quit();
69 74 m_VisualizationControllerThread.wait();
70 75 }
71 76
72 77 std::unique_ptr<DataSourceController> m_DataSourceController;
73 78 std::unique_ptr<VariableController> m_VariableController;
74 79 std::unique_ptr<TimeController> m_TimeController;
75 80 std::unique_ptr<NetworkController> m_NetworkController;
76 81 std::unique_ptr<VisualizationController> m_VisualizationController;
77 82 QThread m_DataSourceControllerThread;
78 83 QThread m_NetworkControllerThread;
79 84 QThread m_VariableControllerThread;
80 85 QThread m_VisualizationControllerThread;
81 86 };
82 87
83 88
84 89 SqpApplication::SqpApplication(int &argc, char **argv)
85 90 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
86 91 {
87 92 qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread();
88 93
89 94 connect(&impl->m_DataSourceControllerThread, &QThread::started,
90 95 impl->m_DataSourceController.get(), &DataSourceController::initialize);
91 96 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
92 97 impl->m_DataSourceController.get(), &DataSourceController::finalize);
93 98
94 99 connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(),
95 100 &NetworkController::initialize);
96 101 connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(),
97 102 &NetworkController::finalize);
98 103
99 104 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
100 105 &VariableController::initialize);
101 106 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
102 107 &VariableController::finalize);
103 108
104 109 connect(&impl->m_VisualizationControllerThread, &QThread::started,
105 110 impl->m_VisualizationController.get(), &VisualizationController::initialize);
106 111 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
107 112 impl->m_VisualizationController.get(), &VisualizationController::finalize);
108 113
109 114 impl->m_DataSourceControllerThread.start();
110 115 impl->m_NetworkControllerThread.start();
111 116 impl->m_VariableControllerThread.start();
112 117 impl->m_VisualizationControllerThread.start();
113 118 }
114 119
115 120 SqpApplication::~SqpApplication()
116 121 {
117 122 }
118 123
119 124 void SqpApplication::initialize()
120 125 {
121 126 }
122 127
123 128 DataSourceController &SqpApplication::dataSourceController() noexcept
124 129 {
125 130 return *impl->m_DataSourceController;
126 131 }
127 132
128 133 NetworkController &SqpApplication::networkController() noexcept
129 134 {
130 135 return *impl->m_NetworkController;
131 136 }
132 137
133 138 TimeController &SqpApplication::timeController() noexcept
134 139 {
135 140 return *impl->m_TimeController;
136 141 }
137 142
138 143 VariableController &SqpApplication::variableController() noexcept
139 144 {
140 145 return *impl->m_VariableController;
141 146 }
142 147
143 148 VisualizationController &SqpApplication::visualizationController() noexcept
144 149 {
145 150 return *impl->m_VisualizationController;
146 151 }
@@ -1,143 +1,152
1 1 #include "Visualization/VisualizationWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "Visualization/VisualizationGraphWidget.h"
4 4 #include "Visualization/VisualizationTabWidget.h"
5 5 #include "Visualization/VisualizationZoneWidget.h"
6 6 #include "Visualization/operations/GenerateVariableMenuOperation.h"
7 7 #include "Visualization/operations/RemoveVariableOperation.h"
8 #include "Visualization/operations/RescaleAxeOperation.h"
8 9 #include "Visualization/qcustomplot.h"
9 10
10 11 #include "ui_VisualizationWidget.h"
11 12
12 13 #include <QToolButton>
13 14
14 15 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
15 16
16 17 VisualizationWidget::VisualizationWidget(QWidget *parent)
17 18 : QWidget{parent}, ui{new Ui::VisualizationWidget}
18 19 {
19 20 ui->setupUi(this);
20 21
21 22 auto addTabViewButton = new QToolButton{ui->tabWidget};
22 23 addTabViewButton->setText(tr("Add View"));
23 24 addTabViewButton->setCursor(Qt::ArrowCursor);
24 25 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
25 26
26 27 auto enableMinimumCornerWidgetSize = [this](bool enable) {
27 28
28 29 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
29 30 auto width = enable ? tabViewCornerWidget->width() : 0;
30 31 auto height = enable ? tabViewCornerWidget->height() : 0;
31 32 tabViewCornerWidget->setMinimumHeight(height);
32 33 tabViewCornerWidget->setMinimumWidth(width);
33 34 ui->tabWidget->setMinimumHeight(height);
34 35 ui->tabWidget->setMinimumWidth(width);
35 36 };
36 37
37 38 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
38 39 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
39 40 ui->tabWidget};
40 41 auto index = ui->tabWidget->addTab(widget, widget->name());
41 42 if (ui->tabWidget->count() > 0) {
42 43 enableMinimumCornerWidgetSize(false);
43 44 }
44 45 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
45 46 };
46 47
47 48 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
48 49 if (ui->tabWidget->count() == 1) {
49 50 enableMinimumCornerWidgetSize(true);
50 51 }
51 52
52 53 // Removes widget from tab and closes it
53 54 auto widget = ui->tabWidget->widget(index);
54 55 ui->tabWidget->removeTab(index);
55 56 if (widget) {
56 57 widget->close();
57 58 }
58 59
59 60 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
60 61
61 62 };
62 63
63 64 ui->tabWidget->setTabsClosable(true);
64 65
65 66 connect(addTabViewButton, &QToolButton::clicked, addTabView);
66 67 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
67 68
68 69 // Adds default tab
69 70 addTabView();
70 71 }
71 72
72 73 VisualizationWidget::~VisualizationWidget()
73 74 {
74 75 delete ui;
75 76 }
76 77
77 78 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
78 79 {
79 80 if (visitor) {
80 81 visitor->visitEnter(this);
81 82
82 83 // Apply visitor for tab children
83 84 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
84 85 // Widgets different from tabs are not visited (no action)
85 86 if (auto visualizationTabWidget
86 87 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
87 88 visualizationTabWidget->accept(visitor);
88 89 }
89 90 }
90 91
91 92 visitor->visitLeave(this);
92 93 }
93 94 else {
94 95 qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null");
95 96 }
96 97 }
97 98
98 99 bool VisualizationWidget::canDrop(const Variable &variable) const
99 100 {
100 101 // The main widget can never accomodate a variable
101 102 Q_UNUSED(variable);
102 103 return false;
103 104 }
104 105
105 106 bool VisualizationWidget::contains(const Variable &variable) const
106 107 {
107 108 Q_UNUSED(variable);
108 109 return false;
109 110 }
110 111
111 112 QString VisualizationWidget::name() const
112 113 {
113 114 return QStringLiteral("MainView");
114 115 }
115 116
116 117 void VisualizationWidget::attachVariableMenu(
117 118 QMenu *menu, const QVector<std::shared_ptr<Variable> > &variables) noexcept
118 119 {
119 120 // Menu is generated only if there is a single variable
120 121 if (variables.size() == 1) {
121 122 if (auto variable = variables.first()) {
122 123 // Generates the actions that make it possible to visualize the variable
123 124 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
124 125 accept(&generateVariableMenuOperation);
125 126 }
126 127 else {
127 128 qCCritical(LOG_VisualizationWidget()) << tr(
128 129 "Can't generate the menu relative to the visualization: the variable is null");
129 130 }
130 131 }
131 132 else {
132 133 qCDebug(LOG_VisualizationWidget())
133 134 << tr("No generation of the menu related to the visualization: several variables are "
134 135 "selected");
135 136 }
136 137 }
137 138
138 139 void VisualizationWidget::onVariableAboutToBeDeleted(std::shared_ptr<Variable> variable) noexcept
139 140 {
140 141 // Calls the operation of removing all references to the variable in the visualization
141 142 auto removeVariableOperation = RemoveVariableOperation{variable};
142 143 accept(&removeVariableOperation);
143 144 }
145
146 void VisualizationWidget::onRangeChanged(std::shared_ptr<Variable> variable,
147 const SqpDateTime &range) noexcept
148 {
149 // Calls the operation of removing all references to the variable in the visualization
150 auto rescaleVariableOperation = RescaleAxeOperation{variable, range};
151 accept(&rescaleVariableOperation);
152 }
General Comments 0
You need to be logged in to leave comments. Login now