##// END OF EJS Templates
Minor refactoring...
Alexandre Leroux -
r424:09d21ab89520
parent child
Show More
@@ -1,76 +1,79
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "MainWindow.h"
22 #include "MainWindow.h"
23 #include <QProcessEnvironment>
23 #include <QProcessEnvironment>
24 #include <QThread>
24 #include <QThread>
25 #include <SqpApplication.h>
25 #include <SqpApplication.h>
26 #include <qglobal.h>
26 #include <qglobal.h>
27
27
28 #include <Plugin/PluginManager.h>
28 #include <Plugin/PluginManager.h>
29 #include <QDir>
29 #include <QDir>
30
30
31 #include <QLoggingCategory>
32
33 Q_LOGGING_CATEGORY(LOG_Main, "Main")
34
31 namespace {
35 namespace {
32
36
33 /// Name of the directory containing the plugins
37 /// Name of the directory containing the plugins
34
38
35 #if _WIN32 || _WIN64
39 #if _WIN32 || _WIN64
36 const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins");
40 const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins");
37 #endif
41 #endif
38
42
39 } // namespace
43 } // namespace
40
44
41 int main(int argc, char *argv[])
45 int main(int argc, char *argv[])
42 {
46 {
43 SqpApplication a{argc, argv};
47 SqpApplication a{argc, argv};
44 SqpApplication::setOrganizationName("LPP");
48 SqpApplication::setOrganizationName("LPP");
45 SqpApplication::setOrganizationDomain("lpp.fr");
49 SqpApplication::setOrganizationDomain("lpp.fr");
46 SqpApplication::setApplicationName("SciQLop");
50 SqpApplication::setApplicationName("SciQLop");
47 MainWindow w;
51 MainWindow w;
48 w.show();
52 w.show();
49
53
50 // Loads plugins
54 // Loads plugins
51 auto pluginDir = QDir{sqpApp->applicationDirPath()};
55 auto pluginDir = QDir{sqpApp->applicationDirPath()};
52 #if _WIN32 || _WIN64
56 #if _WIN32 || _WIN64
53 pluginDir.mkdir(PLUGIN_DIRECTORY_NAME);
57 pluginDir.mkdir(PLUGIN_DIRECTORY_NAME);
54 pluginDir.cd(PLUGIN_DIRECTORY_NAME);
58 pluginDir.cd(PLUGIN_DIRECTORY_NAME);
55 #endif
59 #endif
56
60
57
61
58 #if __unix || __APPLE
62 #if __unix || __APPLE
59 #if __x86_64__ || __ppc64__
63 #if __x86_64__ || __ppc64__
60 if (!pluginDir.cd("../lib64/SciQlop")) {
64 if (!pluginDir.cd("../lib64/SciQlop")) {
61 pluginDir.cd("../lib64/sciqlop");
65 pluginDir.cd("../lib64/sciqlop");
62 }
66 }
63 #else
67 #else
64 if (!pluginDir.cd("../lib/SciQlop")) {
68 if (!pluginDir.cd("../lib/SciQlop")) {
65 pluginDir.cd("../lib/sciqlop");
69 pluginDir.cd("../lib/sciqlop");
66 }
70 }
67 #endif
71 #endif
68 #endif
72 #endif
69 qCDebug(LOG_PluginManager())
73 qCDebug(LOG_Main()) << QObject::tr("Plugin directory: %1").arg(pluginDir.absolutePath());
70 << QObject::tr("Plugin directory: %1").arg(pluginDir.absolutePath());
71
74
72 PluginManager pluginManager{};
75 PluginManager pluginManager{};
73 pluginManager.loadPlugins(pluginDir);
76 pluginManager.loadPlugins(pluginDir);
74
77
75 return a.exec();
78 return a.exec();
76 }
79 }
@@ -1,269 +1,214
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SciQLop Software
2 -- This file is a part of the SciQLop Software
3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "MainWindow.h"
22 #include "MainWindow.h"
23 #include "ui_MainWindow.h"
23 #include "ui_MainWindow.h"
24
24
25 #include <DataSource/DataSourceController.h>
25 #include <DataSource/DataSourceController.h>
26 #include <DataSource/DataSourceWidget.h>
26 #include <DataSource/DataSourceWidget.h>
27 #include <SidePane/SqpSidePane.h>
27 #include <SidePane/SqpSidePane.h>
28 #include <SqpApplication.h>
28 #include <SqpApplication.h>
29 #include <Time/TimeController.h>
29 #include <Time/TimeController.h>
30 #include <TimeWidget/TimeWidget.h>
30 #include <TimeWidget/TimeWidget.h>
31 #include <Variable/Variable.h>
31 #include <Variable/Variable.h>
32 #include <Variable/VariableController.h>
32 #include <Variable/VariableController.h>
33 #include <Visualization/VisualizationController.h>
33 #include <Visualization/VisualizationController.h>
34
34
35 #include <QAction>
35 #include <QAction>
36 #include <QDate>
36 #include <QDate>
37 #include <QDateTime>
37 #include <QDateTime>
38 #include <QDir>
38 #include <QDir>
39 #include <QFileDialog>
39 #include <QFileDialog>
40 #include <QToolBar>
40 #include <QToolBar>
41 #include <QToolButton>
41 #include <QToolButton>
42 #include <memory.h>
42 #include <memory.h>
43
43
44 //#include <omp.h>
45 //#include <network/filedownloader.h>
46 //#include <qlopdatabase.h>
47 //#include <qlopsettings.h>
48 //#include <qlopgui.h>
49 //#include <spacedata.h>
50 //#include "qlopcore.h"
51 //#include "qlopcodecmanager.h"
52 //#include "cdfcodec.h"
53 //#include "amdatxtcodec.h"
54 //#include <qlopplotmanager.h>
55
56 #include "iostream"
44 #include "iostream"
57
45
58 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
46 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
59
47
60 namespace {
48 namespace {
61 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
49 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
62 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
50 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
63 const auto VIEWPLITTERINDEX = 2;
51 const auto VIEWPLITTERINDEX = 2;
64 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
52 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
65 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
53 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
66 }
54 }
67
55
68 class MainWindow::MainWindowPrivate {
56 class MainWindow::MainWindowPrivate {
69 public:
57 public:
70 QSize m_LastOpenLeftInspectorSize;
58 QSize m_LastOpenLeftInspectorSize;
71 QSize m_LastOpenRightInspectorSize;
59 QSize m_LastOpenRightInspectorSize;
72 };
60 };
73
61
74 MainWindow::MainWindow(QWidget *parent)
62 MainWindow::MainWindow(QWidget *parent)
75 : QMainWindow{parent},
63 : QMainWindow{parent},
76 m_Ui{new Ui::MainWindow},
64 m_Ui{new Ui::MainWindow},
77 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
65 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
78 {
66 {
79 m_Ui->setupUi(this);
67 m_Ui->setupUi(this);
80
68
81 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
69 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
82 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
70 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
83
71
84
72
85 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
73 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
86 auto openLeftInspectorAction = new QAction{QIcon{
74 auto openLeftInspectorAction = new QAction{QIcon{
87 ":/icones/previous.png",
75 ":/icones/previous.png",
88 },
76 },
89 tr("Show/hide the left inspector"), this};
77 tr("Show/hide the left inspector"), this};
90
78
91
79
92 auto spacerLeftTop = new QWidget{};
80 auto spacerLeftTop = new QWidget{};
93 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
81 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
94
82
95 auto spacerLeftBottom = new QWidget{};
83 auto spacerLeftBottom = new QWidget{};
96 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
84 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
97
85
98 leftSidePane->addWidget(spacerLeftTop);
86 leftSidePane->addWidget(spacerLeftTop);
99 leftSidePane->addAction(openLeftInspectorAction);
87 leftSidePane->addAction(openLeftInspectorAction);
100 leftSidePane->addWidget(spacerLeftBottom);
88 leftSidePane->addWidget(spacerLeftBottom);
101
89
102
90
103 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
91 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
104 auto openRightInspectorAction = new QAction{QIcon{
92 auto openRightInspectorAction = new QAction{QIcon{
105 ":/icones/next.png",
93 ":/icones/next.png",
106 },
94 },
107 tr("Show/hide the right inspector"), this};
95 tr("Show/hide the right inspector"), this};
108
96
109 auto spacerRightTop = new QWidget{};
97 auto spacerRightTop = new QWidget{};
110 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
98 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
111
99
112 auto spacerRightBottom = new QWidget{};
100 auto spacerRightBottom = new QWidget{};
113 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
101 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
114
102
115 rightSidePane->addWidget(spacerRightTop);
103 rightSidePane->addWidget(spacerRightTop);
116 rightSidePane->addAction(openRightInspectorAction);
104 rightSidePane->addAction(openRightInspectorAction);
117 rightSidePane->addWidget(spacerRightBottom);
105 rightSidePane->addWidget(spacerRightBottom);
118
106
119 openLeftInspectorAction->setCheckable(true);
107 openLeftInspectorAction->setCheckable(true);
120 openRightInspectorAction->setCheckable(true);
108 openRightInspectorAction->setCheckable(true);
121
109
122 auto openInspector = [this](bool checked, bool right, auto action) {
110 auto openInspector = [this](bool checked, bool right, auto action) {
123
111
124 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
112 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
125
113
126 auto &lastInspectorSize
114 auto &lastInspectorSize
127 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
115 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
128
116
129 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
117 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
130 : m_Ui->leftMainInspectorWidget->size();
118 : m_Ui->leftMainInspectorWidget->size();
131
119
132 // Update of the last opened geometry
120 // Update of the last opened geometry
133 if (checked) {
121 if (checked) {
134 lastInspectorSize = nextInspectorSize;
122 lastInspectorSize = nextInspectorSize;
135 }
123 }
136
124
137 auto startSize = lastInspectorSize;
125 auto startSize = lastInspectorSize;
138 auto endSize = startSize;
126 auto endSize = startSize;
139 endSize.setWidth(0);
127 endSize.setWidth(0);
140
128
141 auto splitterInspectorIndex
129 auto splitterInspectorIndex
142 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
130 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
143
131
144 auto currentSizes = m_Ui->splitter->sizes();
132 auto currentSizes = m_Ui->splitter->sizes();
145 if (checked) {
133 if (checked) {
146 // adjust sizes individually here, e.g.
134 // adjust sizes individually here, e.g.
147 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
135 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
148 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
136 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
149 m_Ui->splitter->setSizes(currentSizes);
137 m_Ui->splitter->setSizes(currentSizes);
150 }
138 }
151 else {
139 else {
152 // adjust sizes individually here, e.g.
140 // adjust sizes individually here, e.g.
153 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
141 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
154 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
142 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
155 m_Ui->splitter->setSizes(currentSizes);
143 m_Ui->splitter->setSizes(currentSizes);
156 }
144 }
157
145
158 };
146 };
159
147
160
148
161 connect(openLeftInspectorAction, &QAction::triggered,
149 connect(openLeftInspectorAction, &QAction::triggered,
162 [openInspector, openLeftInspectorAction](bool checked) {
150 [openInspector, openLeftInspectorAction](bool checked) {
163 openInspector(checked, false, openLeftInspectorAction);
151 openInspector(checked, false, openLeftInspectorAction);
164 });
152 });
165 connect(openRightInspectorAction, &QAction::triggered,
153 connect(openRightInspectorAction, &QAction::triggered,
166 [openInspector, openRightInspectorAction](bool checked) {
154 [openInspector, openRightInspectorAction](bool checked) {
167 openInspector(checked, true, openRightInspectorAction);
155 openInspector(checked, true, openRightInspectorAction);
168 });
156 });
169
157
170 this->menuBar()->addAction(tr("File"));
158 this->menuBar()->addAction(tr("File"));
171 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
159 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
172
160
173 auto timeWidget = new TimeWidget{};
161 auto timeWidget = new TimeWidget{};
174 mainToolBar->addWidget(timeWidget);
162 mainToolBar->addWidget(timeWidget);
175
163
176 // Controllers / controllers connections
164 // Controllers / controllers connections
177 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
165 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
178 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
166 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
179
167
180 // Widgets / controllers connections
168 // Widgets / controllers connections
181
169
182 // DataSource
170 // DataSource
183 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
171 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
184 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
172 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
185
173
186 // Time
174 // Time
187 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
175 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
188 SLOT(onTimeToUpdate(SqpDateTime)));
176 SLOT(onTimeToUpdate(SqpDateTime)));
189
177
190 // Visualization
178 // Visualization
191 connect(&sqpApp->visualizationController(),
179 connect(&sqpApp->visualizationController(),
192 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view,
180 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view,
193 SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>)));
181 SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>)));
194
182
195 connect(&sqpApp->visualizationController(),
183 connect(&sqpApp->visualizationController(),
196 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)), m_Ui->view,
184 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)), m_Ui->view,
197 SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)));
185 SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)));
198
186
199 // Widgets / widgets connections
187 // Widgets / widgets connections
200
188
201 // For the following connections, we use DirectConnection to allow each widget that can
189 // For the following connections, we use DirectConnection to allow each widget that can
202 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
190 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
203 // The order of connections is also important, since it determines the order in which each
191 // The order of connections is also important, since it determines the order in which each
204 // widget will attach its menu
192 // widget will attach its menu
205 connect(
193 connect(
206 m_Ui->variableInspectorWidget,
194 m_Ui->variableInspectorWidget,
207 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
195 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
208 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
196 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
209 Qt::DirectConnection);
197 Qt::DirectConnection);
210
211 /* QLopGUI::registerMenuBar(menuBar());
212 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
213 this->m_progressWidget = new QWidget();
214 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
215 this->m_progressWidget->setLayout(this->m_progressLayout);
216 this->m_progressWidget->setWindowModality(Qt::WindowModal);
217 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
218 for(int i=0;i<OMP_THREADS;i++)
219 {
220 this->m_progress.append(new QProgressBar(this->m_progressWidget));
221 this->m_progress.last()->setMinimum(0);
222 this->m_progress.last()->setMaximum(100);
223 this->m_progressLayout->addWidget(this->m_progress.last());
224 this->m_progressWidget->hide();
225 this->m_progressThreadIds[i] = -1;
226 }
227 this->m_progressWidget->setWindowTitle("Loading File");
228 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
229 << QLopCore::self()
230 << QLopPlotManager::self()
231 << QLopCodecManager::self()
232 << FileDownloader::self()
233 << QLopDataBase::self()
234 << SpaceData::self();
235
236 CDFCodec::registerToManager();
237 AMDATXTCodec::registerToManager();
238
239
240 for(int i=0;i<ServicesToLoad.count();i++)
241 {
242 qDebug()<<ServicesToLoad.at(i)->serviceName();
243 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
244 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
245 if(wdgt)
246 {
247 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
248 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
249 }
250 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
251 }*/
252 }
198 }
253
199
254 MainWindow::~MainWindow()
200 MainWindow::~MainWindow()
255 {
201 {
256 }
202 }
257
203
258
259 void MainWindow::changeEvent(QEvent *e)
204 void MainWindow::changeEvent(QEvent *e)
260 {
205 {
261 QMainWindow::changeEvent(e);
206 QMainWindow::changeEvent(e);
262 switch (e->type()) {
207 switch (e->type()) {
263 case QEvent::LanguageChange:
208 case QEvent::LanguageChange:
264 m_Ui->retranslateUi(this);
209 m_Ui->retranslateUi(this);
265 break;
210 break;
266 default:
211 default:
267 break;
212 break;
268 }
213 }
269 }
214 }
@@ -1,46 +1,43
1 #ifndef SCIQLOP_VARIABLECACHECONTROLLER_H
1 #ifndef SCIQLOP_VARIABLECACHECONTROLLER_H
2 #define SCIQLOP_VARIABLECACHECONTROLLER_H
2 #define SCIQLOP_VARIABLECACHECONTROLLER_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QObject>
5 #include <QObject>
6
6
7 #include <Data/SqpDateTime.h>
7 #include <Data/SqpDateTime.h>
8
8
9 #include <QLoggingCategory>
9 #include <QLoggingCategory>
10
10
11 #include <Common/spimpl.h>
11 #include <Common/spimpl.h>
12
12
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheController)
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheController)
14
14
15 class Variable;
15 class Variable;
16
16
17 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheController)
18
19
20 /// This class aims to store in the cache all of the dateTime already requested to the variable.
17 /// This class aims to store in the cache all of the dateTime already requested to the variable.
21 class VariableCacheController : public QObject {
18 class VariableCacheController : public QObject {
22 Q_OBJECT
19 Q_OBJECT
23 public:
20 public:
24 explicit VariableCacheController(QObject *parent = 0);
21 explicit VariableCacheController(QObject *parent = 0);
25
22
26
23
27 void addDateTime(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
24 void addDateTime(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
28
25
29 /// Clears cache concerning a variable
26 /// Clears cache concerning a variable
30 void clear(std::shared_ptr<Variable> variable) noexcept;
27 void clear(std::shared_ptr<Variable> variable) noexcept;
31
28
32 /// Return all of the SqpDataTime part of the dateTime whose are not in the cache
29 /// Return all of the SqpDataTime part of the dateTime whose are not in the cache
33 QVector<SqpDateTime> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
30 QVector<SqpDateTime> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
34 const SqpDateTime &dateTime);
31 const SqpDateTime &dateTime);
35
32
36
33
37 QVector<SqpDateTime> dateCacheList(std::shared_ptr<Variable> variable) const noexcept;
34 QVector<SqpDateTime> dateCacheList(std::shared_ptr<Variable> variable) const noexcept;
38
35
39 void displayCache(std::shared_ptr<Variable> variable) const;
36 void displayCache(std::shared_ptr<Variable> variable) const;
40
37
41 private:
38 private:
42 class VariableCacheControllerPrivate;
39 class VariableCacheControllerPrivate;
43 spimpl::unique_impl_ptr<VariableCacheControllerPrivate> impl;
40 spimpl::unique_impl_ptr<VariableCacheControllerPrivate> impl;
44 };
41 };
45
42
46 #endif // SCIQLOP_VARIABLECACHECONTROLLER_H
43 #endif // SCIQLOP_VARIABLECACHECONTROLLER_H
@@ -1,401 +1,401
1 #include "Visualization/VisualizationGraphWidget.h"
1 #include "Visualization/VisualizationGraphWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "Visualization/VisualizationGraphHelper.h"
3 #include "Visualization/VisualizationGraphHelper.h"
4 #include "ui_VisualizationGraphWidget.h"
4 #include "ui_VisualizationGraphWidget.h"
5
5
6 #include <Data/ArrayData.h>
6 #include <Data/ArrayData.h>
7 #include <Data/IDataSeries.h>
7 #include <Data/IDataSeries.h>
8 #include <SqpApplication.h>
8 #include <SqpApplication.h>
9 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10 #include <Variable/VariableController.h>
10 #include <Variable/VariableController.h>
11
11
12 #include <unordered_map>
12 #include <unordered_map>
13
13
14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
15
15
16 namespace {
16 namespace {
17
17
18 /// Key pressed to enable zoom on horizontal axis
18 /// Key pressed to enable zoom on horizontal axis
19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
20
20
21 /// Key pressed to enable zoom on vertical axis
21 /// Key pressed to enable zoom on vertical axis
22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
23
23
24 } // namespace
24 } // namespace
25
25
26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
27
27
28 explicit VisualizationGraphWidgetPrivate() : m_DoSynchronize{true}, m_IsCalibration{false} {}
28 explicit VisualizationGraphWidgetPrivate() : m_DoSynchronize{true}, m_IsCalibration{false} {}
29
29
30
30
31 // Return the operation when range changed
31 // Return the operation when range changed
32 VisualizationGraphWidgetZoomType getZoomType(const QCPRange &t1, const QCPRange &t2);
32 VisualizationGraphWidgetZoomType getZoomType(const QCPRange &t1, const QCPRange &t2);
33
33
34 // 1 variable -> n qcpplot
34 // 1 variable -> n qcpplot
35 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
35 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
36
36
37 bool m_DoSynchronize;
37 bool m_DoSynchronize;
38 bool m_IsCalibration;
38 bool m_IsCalibration;
39 };
39 };
40
40
41 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
41 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
42 : QWidget{parent},
42 : QWidget{parent},
43 ui{new Ui::VisualizationGraphWidget},
43 ui{new Ui::VisualizationGraphWidget},
44 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
44 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
45 {
45 {
46 ui->setupUi(this);
46 ui->setupUi(this);
47
47
48 ui->graphNameLabel->setText(name);
48 ui->graphNameLabel->setText(name);
49
49
50 // 'Close' options : widget is deleted when closed
50 // 'Close' options : widget is deleted when closed
51 setAttribute(Qt::WA_DeleteOnClose);
51 setAttribute(Qt::WA_DeleteOnClose);
52 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close);
52 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close);
53 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
53 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
54
54
55 // Set qcpplot properties :
55 // Set qcpplot properties :
56 // - Drag (on x-axis) and zoom are enabled
56 // - Drag (on x-axis) and zoom are enabled
57 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
57 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
58 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
58 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
59 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
59 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
60 connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress);
60 connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress);
61 connect(ui->widget, &QCustomPlot::mouseRelease, this,
61 connect(ui->widget, &QCustomPlot::mouseRelease, this,
62 &VisualizationGraphWidget::onMouseRelease);
62 &VisualizationGraphWidget::onMouseRelease);
63 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
63 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
64 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
64 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
65 &QCPAxis::rangeChanged),
65 &QCPAxis::rangeChanged),
66 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
66 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
67
67
68 // Activates menu when right clicking on the graph
68 // Activates menu when right clicking on the graph
69 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
69 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
70 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
70 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
71 &VisualizationGraphWidget::onGraphMenuRequested);
71 &VisualizationGraphWidget::onGraphMenuRequested);
72
72
73 connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
73 connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
74 &VariableController::onRequestDataLoading);
74 &VariableController::onRequestDataLoading);
75 }
75 }
76
76
77
77
78 VisualizationGraphWidget::~VisualizationGraphWidget()
78 VisualizationGraphWidget::~VisualizationGraphWidget()
79 {
79 {
80 delete ui;
80 delete ui;
81 }
81 }
82
82
83 void VisualizationGraphWidget::enableSynchronize(bool enable)
83 void VisualizationGraphWidget::enableSynchronize(bool enable)
84 {
84 {
85 impl->m_DoSynchronize = enable;
85 impl->m_DoSynchronize = enable;
86 }
86 }
87
87
88 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
88 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
89 {
89 {
90 // Uses delegate to create the qcpplot components according to the variable
90 // Uses delegate to create the qcpplot components according to the variable
91 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
91 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
92
92
93 for (auto createdPlottable : qAsConst(createdPlottables)) {
93 for (auto createdPlottable : qAsConst(createdPlottables)) {
94 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
94 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
95 }
95 }
96
96
97 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
97 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
98 }
98 }
99 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
99 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
100 {
100 {
101
101
102 // when adding a variable, we need to set its time range to the current graph range
102 // when adding a variable, we need to set its time range to the current graph range
103 auto grapheRange = ui->widget->xAxis->range();
103 auto grapheRange = ui->widget->xAxis->range();
104 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
104 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
105 variable->setDateTime(dateTime);
105 variable->setDateTime(dateTime);
106
106
107 auto variableDateTimeWithTolerance = dateTime;
107 auto variableDateTimeWithTolerance = dateTime;
108
108
109 // add 20% tolerance for each side
109 // add 20% tolerance for each side
110 auto tolerance = 0.2 * (dateTime.m_TEnd - dateTime.m_TStart);
110 auto tolerance = 0.2 * (dateTime.m_TEnd - dateTime.m_TStart);
111 variableDateTimeWithTolerance.m_TStart -= tolerance;
111 variableDateTimeWithTolerance.m_TStart -= tolerance;
112 variableDateTimeWithTolerance.m_TEnd += tolerance;
112 variableDateTimeWithTolerance.m_TEnd += tolerance;
113
113
114 // Uses delegate to create the qcpplot components according to the variable
114 // Uses delegate to create the qcpplot components according to the variable
115 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
115 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
116
116
117 for (auto createdPlottable : qAsConst(createdPlottables)) {
117 for (auto createdPlottable : qAsConst(createdPlottables)) {
118 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
118 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
119 }
119 }
120
120
121 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
121 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
122
122
123 // CHangement detected, we need to ask controller to request data loading
123 // CHangement detected, we need to ask controller to request data loading
124 emit requestDataLoading(variable, variableDateTimeWithTolerance);
124 emit requestDataLoading(variable, variableDateTimeWithTolerance);
125 }
125 }
126
126
127 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
127 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
128 {
128 {
129 // Each component associated to the variable :
129 // Each component associated to the variable :
130 // - is removed from qcpplot (which deletes it)
130 // - is removed from qcpplot (which deletes it)
131 // - is no longer referenced in the map
131 // - is no longer referenced in the map
132 auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
132 auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
133 for (auto it = componentsIt.first; it != componentsIt.second;) {
133 for (auto it = componentsIt.first; it != componentsIt.second;) {
134 ui->widget->removePlottable(it->second);
134 ui->widget->removePlottable(it->second);
135 it = impl->m_VariableToPlotMultiMap.erase(it);
135 it = impl->m_VariableToPlotMultiMap.erase(it);
136 }
136 }
137
137
138 // Updates graph
138 // Updates graph
139 ui->widget->replot();
139 ui->widget->replot();
140 }
140 }
141
141
142 void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable,
142 void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable,
143 const SqpDateTime &range)
143 const SqpDateTime &range)
144 {
144 {
145 // Note: in case of different axes that depends on variable, we could start with a code like
145 // Note: in case of different axes that depends on variable, we could start with a code like
146 // that:
146 // that:
147 // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
147 // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
148 // for (auto it = componentsIt.first; it != componentsIt.second;) {
148 // for (auto it = componentsIt.first; it != componentsIt.second;) {
149 // }
149 // }
150 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
150 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
151 ui->widget->replot();
151 ui->widget->replot();
152 }
152 }
153
153
154 SqpDateTime VisualizationGraphWidget::graphRange() const noexcept
154 SqpDateTime VisualizationGraphWidget::graphRange() const noexcept
155 {
155 {
156 auto grapheRange = ui->widget->xAxis->range();
156 auto grapheRange = ui->widget->xAxis->range();
157 return SqpDateTime{grapheRange.lower, grapheRange.upper};
157 return SqpDateTime{grapheRange.lower, grapheRange.upper};
158 }
158 }
159
159
160 void VisualizationGraphWidget::setGraphRange(const SqpDateTime &range)
160 void VisualizationGraphWidget::setGraphRange(const SqpDateTime &range)
161 {
161 {
162 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START");
162 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START");
163 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
163 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
164 ui->widget->replot();
164 ui->widget->replot();
165 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END");
165 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END");
166 }
166 }
167
167
168 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
168 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
169 {
169 {
170 if (visitor) {
170 if (visitor) {
171 visitor->visit(this);
171 visitor->visit(this);
172 }
172 }
173 else {
173 else {
174 qCCritical(LOG_VisualizationGraphWidget())
174 qCCritical(LOG_VisualizationGraphWidget())
175 << tr("Can't visit widget : the visitor is null");
175 << tr("Can't visit widget : the visitor is null");
176 }
176 }
177 }
177 }
178
178
179 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
179 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
180 {
180 {
181 /// @todo : for the moment, a graph can always accomodate a variable
181 /// @todo : for the moment, a graph can always accomodate a variable
182 Q_UNUSED(variable);
182 Q_UNUSED(variable);
183 return true;
183 return true;
184 }
184 }
185
185
186 bool VisualizationGraphWidget::contains(const Variable &variable) const
186 bool VisualizationGraphWidget::contains(const Variable &variable) const
187 {
187 {
188 // Finds the variable among the keys of the map
188 // Finds the variable among the keys of the map
189 auto variablePtr = &variable;
189 auto variablePtr = &variable;
190 auto findVariable
190 auto findVariable
191 = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); };
191 = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); };
192
192
193 auto end = impl->m_VariableToPlotMultiMap.cend();
193 auto end = impl->m_VariableToPlotMultiMap.cend();
194 auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable);
194 auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable);
195 return it != end;
195 return it != end;
196 }
196 }
197
197
198 QString VisualizationGraphWidget::name() const
198 QString VisualizationGraphWidget::name() const
199 {
199 {
200 return ui->graphNameLabel->text();
200 return ui->graphNameLabel->text();
201 }
201 }
202
202
203 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
203 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
204 {
204 {
205 QMenu graphMenu{};
205 QMenu graphMenu{};
206
206
207 // Iterates on variables (unique keys)
207 // Iterates on variables (unique keys)
208 for (auto it = impl->m_VariableToPlotMultiMap.cbegin(),
208 for (auto it = impl->m_VariableToPlotMultiMap.cbegin(),
209 end = impl->m_VariableToPlotMultiMap.cend();
209 end = impl->m_VariableToPlotMultiMap.cend();
210 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
210 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
211 // 'Remove variable' action
211 // 'Remove variable' action
212 graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()),
212 graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()),
213 [ this, var = it->first ]() { removeVariable(var); });
213 [ this, var = it->first ]() { removeVariable(var); });
214 }
214 }
215
215
216 if (!graphMenu.isEmpty()) {
216 if (!graphMenu.isEmpty()) {
217 graphMenu.exec(mapToGlobal(pos));
217 graphMenu.exec(mapToGlobal(pos));
218 }
218 }
219 }
219 }
220
220
221 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
221 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
222 {
222 {
223 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
223 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
224 << QThread::currentThread()->objectName();
224 << QThread::currentThread()->objectName();
225
225
226 auto dateTimeRange = SqpDateTime{t1.lower, t1.upper};
226 auto dateTimeRange = SqpDateTime{t1.lower, t1.upper};
227
227
228 auto zoomType = impl->getZoomType(t1, t2);
228 auto zoomType = impl->getZoomType(t1, t2);
229 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
229 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
230 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
230 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
231
231
232 auto variable = it->first;
232 auto variable = it->first;
233 auto currentDateTime = dateTimeRange;
233 auto currentDateTime = dateTimeRange;
234
234
235 auto toleranceFactor = 0.2;
235 auto toleranceFactor = 0.2;
236 auto tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
236 auto tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
237 auto variableDateTimeWithTolerance = currentDateTime;
237 auto variableDateTimeWithTolerance = currentDateTime;
238 variableDateTimeWithTolerance.m_TStart -= tolerance;
238 variableDateTimeWithTolerance.m_TStart -= tolerance;
239 variableDateTimeWithTolerance.m_TEnd += tolerance;
239 variableDateTimeWithTolerance.m_TEnd += tolerance;
240
240
241 qCDebug(LOG_VisualizationGraphWidget()) << "r" << currentDateTime;
241 qCDebug(LOG_VisualizationGraphWidget()) << "r" << currentDateTime;
242 qCDebug(LOG_VisualizationGraphWidget()) << "t" << variableDateTimeWithTolerance;
242 qCDebug(LOG_VisualizationGraphWidget()) << "t" << variableDateTimeWithTolerance;
243 qCDebug(LOG_VisualizationGraphWidget()) << "v" << variable->dateTime();
243 qCDebug(LOG_VisualizationGraphWidget()) << "v" << variable->dateTime();
244 // If new range with tol is upper than variable datetime parameters. we need to request new
244 // If new range with tol is upper than variable datetime parameters. we need to request new
245 // data
245 // data
246 if (!variable->contains(variableDateTimeWithTolerance)) {
246 if (!variable->contains(variableDateTimeWithTolerance)) {
247
247
248 auto variableDateTimeWithTolerance = currentDateTime;
248 auto variableDateTimeWithTolerance = currentDateTime;
249 if (!variable->isInside(currentDateTime)) {
249 if (!variable->isInside(currentDateTime)) {
250 auto variableDateTime = variable->dateTime();
250 auto variableDateTime = variable->dateTime();
251 if (variable->contains(variableDateTimeWithTolerance)) {
251 if (variable->contains(variableDateTimeWithTolerance)) {
252 qCDebug(LOG_VisualizationGraphWidget())
252 qCDebug(LOG_VisualizationGraphWidget())
253 << tr("TORM: Detection zoom in that need request:");
253 << tr("TORM: Detection zoom in that need request:");
254 // add 10% tolerance for each side
254 // add tolerance for each side
255 tolerance
255 tolerance
256 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
256 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
257 variableDateTimeWithTolerance.m_TStart -= tolerance;
257 variableDateTimeWithTolerance.m_TStart -= tolerance;
258 variableDateTimeWithTolerance.m_TEnd += tolerance;
258 variableDateTimeWithTolerance.m_TEnd += tolerance;
259 }
259 }
260 else if (variableDateTime.m_TStart < currentDateTime.m_TStart) {
260 else if (variableDateTime.m_TStart < currentDateTime.m_TStart) {
261 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:");
261 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:");
262
262
263 auto diffEndToKeepDelta = currentDateTime.m_TEnd - variableDateTime.m_TEnd;
263 auto diffEndToKeepDelta = currentDateTime.m_TEnd - variableDateTime.m_TEnd;
264 currentDateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
264 currentDateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
265 // Tolerance have to be added to the right
265 // Tolerance have to be added to the right
266 // add tolerance for right (end) side
266 // add tolerance for right (end) side
267 tolerance
267 tolerance
268 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
268 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
269 variableDateTimeWithTolerance.m_TEnd += tolerance;
269 variableDateTimeWithTolerance.m_TEnd += tolerance;
270 }
270 }
271 else if (variableDateTime.m_TEnd > currentDateTime.m_TEnd) {
271 else if (variableDateTime.m_TEnd > currentDateTime.m_TEnd) {
272 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: ");
272 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: ");
273 auto diffStartToKeepDelta
273 auto diffStartToKeepDelta
274 = variableDateTime.m_TStart - currentDateTime.m_TStart;
274 = variableDateTime.m_TStart - currentDateTime.m_TStart;
275 currentDateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
275 currentDateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
276 // Tolerance have to be added to the left
276 // Tolerance have to be added to the left
277 // add tolerance for left (start) side
277 // add tolerance for left (start) side
278 tolerance
278 tolerance
279 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
279 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
280 variableDateTimeWithTolerance.m_TStart -= tolerance;
280 variableDateTimeWithTolerance.m_TStart -= tolerance;
281 }
281 }
282 else {
282 else {
283 qCCritical(LOG_VisualizationGraphWidget())
283 qCCritical(LOG_VisualizationGraphWidget())
284 << tr("Detection anormal zoom detection: ");
284 << tr("Detection anormal zoom detection: ");
285 }
285 }
286 }
286 }
287 else {
287 else {
288 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: ");
288 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: ");
289 // add 10% tolerance for each side
289 // add tolerance for each side
290 tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
290 tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
291 variableDateTimeWithTolerance.m_TStart -= tolerance;
291 variableDateTimeWithTolerance.m_TStart -= tolerance;
292 variableDateTimeWithTolerance.m_TEnd += tolerance;
292 variableDateTimeWithTolerance.m_TEnd += tolerance;
293 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
293 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
294 }
294 }
295 if (!variable->contains(dateTimeRange)) {
295 if (!variable->contains(dateTimeRange)) {
296 qCDebug(LOG_VisualizationGraphWidget())
296 qCDebug(LOG_VisualizationGraphWidget())
297 << "TORM: Modif on variable datetime detected" << currentDateTime;
297 << "TORM: Modif on variable datetime detected" << currentDateTime;
298 variable->setDateTime(currentDateTime);
298 variable->setDateTime(currentDateTime);
299 }
299 }
300
300
301 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Request data detection: ");
301 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Request data detection: ");
302 // CHangement detected, we need to ask controller to request data loading
302 // CHangement detected, we need to ask controller to request data loading
303 emit requestDataLoading(variable, variableDateTimeWithTolerance);
303 emit requestDataLoading(variable, variableDateTimeWithTolerance);
304 }
304 }
305 else {
305 else {
306 qCInfo(LOG_VisualizationGraphWidget())
306 qCInfo(LOG_VisualizationGraphWidget())
307 << tr("TORM: Detection zoom in that doesn't need request: ");
307 << tr("TORM: Detection zoom in that doesn't need request: ");
308 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
308 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
309 }
309 }
310 }
310 }
311
311
312 if (impl->m_DoSynchronize && !impl->m_IsCalibration) {
312 if (impl->m_DoSynchronize && !impl->m_IsCalibration) {
313 auto oldDateTime = SqpDateTime{t2.lower, t2.upper};
313 auto oldDateTime = SqpDateTime{t2.lower, t2.upper};
314 qCDebug(LOG_VisualizationGraphWidget())
314 qCDebug(LOG_VisualizationGraphWidget())
315 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
315 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
316 << QThread::currentThread()->objectName();
316 << QThread::currentThread()->objectName();
317 emit synchronize(dateTimeRange, oldDateTime, zoomType);
317 emit synchronize(dateTimeRange, oldDateTime, zoomType);
318 }
318 }
319 }
319 }
320
320
321 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
321 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
322 {
322 {
323 auto zoomOrientations = QFlags<Qt::Orientation>{};
323 auto zoomOrientations = QFlags<Qt::Orientation>{};
324
324
325 // Lambda that enables a zoom orientation if the key modifier related to this orientation
325 // Lambda that enables a zoom orientation if the key modifier related to this orientation
326 // has
326 // has
327 // been pressed
327 // been pressed
328 auto enableOrientation
328 auto enableOrientation
329 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
329 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
330 auto orientationEnabled = event->modifiers().testFlag(modifier);
330 auto orientationEnabled = event->modifiers().testFlag(modifier);
331 zoomOrientations.setFlag(orientation, orientationEnabled);
331 zoomOrientations.setFlag(orientation, orientationEnabled);
332 };
332 };
333 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
333 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
334 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
334 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
335
335
336 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
336 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
337 }
337 }
338
338
339 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
339 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
340 {
340 {
341 impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier);
341 impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier);
342 }
342 }
343
343
344 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
344 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
345 {
345 {
346 impl->m_IsCalibration = false;
346 impl->m_IsCalibration = false;
347 }
347 }
348
348
349 void VisualizationGraphWidget::onDataCacheVariableUpdated()
349 void VisualizationGraphWidget::onDataCacheVariableUpdated()
350 {
350 {
351 // NOTE:
351 // NOTE:
352 // We don't want to call the method for each component of a variable unitarily, but for
352 // We don't want to call the method for each component of a variable unitarily, but for
353 // all
353 // all
354 // its components at once (eg its three components in the case of a vector).
354 // its components at once (eg its three components in the case of a vector).
355
355
356 // The unordered_multimap does not do this easily, so the question is whether to:
356 // The unordered_multimap does not do this easily, so the question is whether to:
357 // - use an ordered_multimap and the algos of std to group the values by key
357 // - use an ordered_multimap and the algos of std to group the values by key
358 // - use a map (unique keys) and store as values directly the list of components
358 // - use a map (unique keys) and store as values directly the list of components
359
359
360 auto grapheRange = ui->widget->xAxis->range();
360 auto grapheRange = ui->widget->xAxis->range();
361 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
361 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
362
362
363 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
363 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
364 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
364 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
365 auto variable = it->first;
365 auto variable = it->first;
366 qCDebug(LOG_VisualizationGraphWidget())
366 qCDebug(LOG_VisualizationGraphWidget())
367 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S"
367 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S"
368 << variable->dateTime();
368 << variable->dateTime();
369 qCDebug(LOG_VisualizationGraphWidget())
369 qCDebug(LOG_VisualizationGraphWidget())
370 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime;
370 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime;
371 if (dateTime.contains(variable->dateTime()) || dateTime.intersect(variable->dateTime())) {
371 if (dateTime.contains(variable->dateTime()) || dateTime.intersect(variable->dateTime())) {
372
372
373 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
373 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
374 variable->dataSeries(), variable->dateTime());
374 variable->dataSeries(), variable->dateTime());
375 }
375 }
376 }
376 }
377 }
377 }
378
378
379 VisualizationGraphWidgetZoomType
379 VisualizationGraphWidgetZoomType
380 VisualizationGraphWidget::VisualizationGraphWidgetPrivate::getZoomType(const QCPRange &t1,
380 VisualizationGraphWidget::VisualizationGraphWidgetPrivate::getZoomType(const QCPRange &t1,
381 const QCPRange &t2)
381 const QCPRange &t2)
382 {
382 {
383 // t1.lower <= t2.lower && t2.upper <= t1.upper
383 // t1.lower <= t2.lower && t2.upper <= t1.upper
384 auto zoomType = VisualizationGraphWidgetZoomType::Unknown;
384 auto zoomType = VisualizationGraphWidgetZoomType::Unknown;
385 if (t1.lower <= t2.lower && t2.upper <= t1.upper) {
385 if (t1.lower <= t2.lower && t2.upper <= t1.upper) {
386 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
386 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
387 }
387 }
388 else if (t1.lower > t2.lower && t1.upper > t2.upper) {
388 else if (t1.lower > t2.lower && t1.upper > t2.upper) {
389 zoomType = VisualizationGraphWidgetZoomType::PanRight;
389 zoomType = VisualizationGraphWidgetZoomType::PanRight;
390 }
390 }
391 else if (t1.lower < t2.lower && t1.upper < t2.upper) {
391 else if (t1.lower < t2.lower && t1.upper < t2.upper) {
392 zoomType = VisualizationGraphWidgetZoomType::PanLeft;
392 zoomType = VisualizationGraphWidgetZoomType::PanLeft;
393 }
393 }
394 else if (t1.lower > t2.lower && t2.upper > t1.upper) {
394 else if (t1.lower > t2.lower && t2.upper > t1.upper) {
395 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
395 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
396 }
396 }
397 else {
397 else {
398 qCCritical(LOG_VisualizationGraphWidget()) << "getZoomType: Unknown type detected";
398 qCCritical(LOG_VisualizationGraphWidget()) << "getZoomType: Unknown type detected";
399 }
399 }
400 return zoomType;
400 return zoomType;
401 }
401 }
@@ -1,148 +1,147
1 #include "AmdaProvider.h"
1 #include "AmdaProvider.h"
2 #include "AmdaDefs.h"
2 #include "AmdaDefs.h"
3 #include "AmdaResultParser.h"
3 #include "AmdaResultParser.h"
4
4
5 #include <Data/DataProviderParameters.h>
5 #include <Data/DataProviderParameters.h>
6 #include <Network/NetworkController.h>
6 #include <Network/NetworkController.h>
7 #include <SqpApplication.h>
7 #include <SqpApplication.h>
8 #include <Variable/Variable.h>
8 #include <Variable/Variable.h>
9
9
10 #include <QNetworkAccessManager>
10 #include <QNetworkAccessManager>
11 #include <QNetworkReply>
11 #include <QNetworkReply>
12 #include <QTemporaryFile>
12 #include <QTemporaryFile>
13 #include <QThread>
13 #include <QThread>
14
14
15 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
15 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
16
16
17 namespace {
17 namespace {
18
18
19 /// URL format for a request on AMDA server. The parameters are as follows:
19 /// URL format for a request on AMDA server. The parameters are as follows:
20 /// - %1: start date
20 /// - %1: start date
21 /// - %2: end date
21 /// - %2: end date
22 /// - %3: parameter id
22 /// - %3: parameter id
23 const auto AMDA_URL_FORMAT = QStringLiteral(
23 const auto AMDA_URL_FORMAT = QStringLiteral(
24 "http://amda.irap.omp.eu/php/rest/"
24 "http://amda.irap.omp.eu/php/rest/"
25 "getParameter.php?startTime=%1&stopTime=%2&parameterID=%3&sampling=60&outputFormat=ASCII&"
25 "getParameter.php?startTime=%1&stopTime=%2&parameterID=%3&sampling=60&outputFormat=ASCII&"
26 "timeFormat=ISO8601&gzip=0");
26 "timeFormat=ISO8601&gzip=0");
27
27
28 /// Dates format passed in the URL (e.g 2013-09-23T09:00)
28 /// Dates format passed in the URL (e.g 2013-09-23T09:00)
29 const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss");
29 const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss");
30
30
31 /// Formats a time to a date that can be passed in URL
31 /// Formats a time to a date that can be passed in URL
32 QString dateFormat(double sqpDateTime) noexcept
32 QString dateFormat(double sqpDateTime) noexcept
33 {
33 {
34 auto dateTime = QDateTime::fromMSecsSinceEpoch(sqpDateTime * 1000.);
34 auto dateTime = QDateTime::fromMSecsSinceEpoch(sqpDateTime * 1000.);
35 return dateTime.toString(AMDA_TIME_FORMAT);
35 return dateTime.toString(AMDA_TIME_FORMAT);
36 }
36 }
37
37
38 } // namespace
38 } // namespace
39
39
40 AmdaProvider::AmdaProvider()
40 AmdaProvider::AmdaProvider()
41 {
41 {
42 qCDebug(LOG_NetworkController()) << tr("AmdaProvider::AmdaProvider")
42 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread();
43 << QThread::currentThread();
44 if (auto app = sqpApp) {
43 if (auto app = sqpApp) {
45 auto &networkController = app->networkController();
44 auto &networkController = app->networkController();
46 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
45 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
47 std::function<void(QNetworkReply *, QUuid)>)),
46 std::function<void(QNetworkReply *, QUuid)>)),
48 &networkController,
47 &networkController,
49 SLOT(onProcessRequested(QNetworkRequest, QUuid,
48 SLOT(onProcessRequested(QNetworkRequest, QUuid,
50 std::function<void(QNetworkReply *, QUuid)>)));
49 std::function<void(QNetworkReply *, QUuid)>)));
51
50
52
51
53 connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this,
52 connect(&sqpApp->networkController(), SIGNAL(replyDownloadProgress(QUuid, double)), this,
54 SIGNAL(dataProvidedProgress(QUuid, double)));
53 SIGNAL(dataProvidedProgress(QUuid, double)));
55 }
54 }
56 }
55 }
57
56
58 void AmdaProvider::requestDataLoading(QUuid token, const DataProviderParameters &parameters)
57 void AmdaProvider::requestDataLoading(QUuid token, const DataProviderParameters &parameters)
59 {
58 {
60 // NOTE: Try to use multithread if possible
59 // NOTE: Try to use multithread if possible
61 const auto times = parameters.m_Times;
60 const auto times = parameters.m_Times;
62 const auto data = parameters.m_Data;
61 const auto data = parameters.m_Data;
63 for (const auto &dateTime : qAsConst(times)) {
62 for (const auto &dateTime : qAsConst(times)) {
64 retrieveData(token, dateTime, data);
63 retrieveData(token, dateTime, data);
65 }
64 }
66 }
65 }
67
66
68 void AmdaProvider::requestDataAborting(QUuid identifier)
67 void AmdaProvider::requestDataAborting(QUuid identifier)
69 {
68 {
70 if (auto app = sqpApp) {
69 if (auto app = sqpApp) {
71 auto &networkController = app->networkController();
70 auto &networkController = app->networkController();
72 networkController.onReplyCanceled(identifier);
71 networkController.onReplyCanceled(identifier);
73 }
72 }
74 }
73 }
75
74
76 void AmdaProvider::retrieveData(QUuid token, const SqpDateTime &dateTime, const QVariantHash &data)
75 void AmdaProvider::retrieveData(QUuid token, const SqpDateTime &dateTime, const QVariantHash &data)
77 {
76 {
78 // Retrieves product ID from data: if the value is invalid, no request is made
77 // Retrieves product ID from data: if the value is invalid, no request is made
79 auto productId = data.value(AMDA_XML_ID_KEY).toString();
78 auto productId = data.value(AMDA_XML_ID_KEY).toString();
80 if (productId.isNull()) {
79 if (productId.isNull()) {
81 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
80 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
82 return;
81 return;
83 }
82 }
84 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
83 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
85
84
86 // /////////// //
85 // /////////// //
87 // Creates URL //
86 // Creates URL //
88 // /////////// //
87 // /////////// //
89
88
90 auto startDate = dateFormat(dateTime.m_TStart);
89 auto startDate = dateFormat(dateTime.m_TStart);
91 auto endDate = dateFormat(dateTime.m_TEnd);
90 auto endDate = dateFormat(dateTime.m_TEnd);
92
91
93 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
92 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
94 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData url:") << url;
93 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData url:") << url;
95 auto tempFile = std::make_shared<QTemporaryFile>();
94 auto tempFile = std::make_shared<QTemporaryFile>();
96
95
97 // LAMBDA
96 // LAMBDA
98 auto httpDownloadFinished
97 auto httpDownloadFinished
99 = [this, dateTime, tempFile, token](QNetworkReply *reply, QUuid dataId) noexcept {
98 = [this, dateTime, tempFile, token](QNetworkReply *reply, QUuid dataId) noexcept {
100 Q_UNUSED(dataId);
99 Q_UNUSED(dataId);
101
100
102 // Don't do anything if the reply was abort
101 // Don't do anything if the reply was abort
103 if (reply->error() != QNetworkReply::OperationCanceledError) {
102 if (reply->error() != QNetworkReply::OperationCanceledError) {
104
103
105 if (tempFile) {
104 if (tempFile) {
106 auto replyReadAll = reply->readAll();
105 auto replyReadAll = reply->readAll();
107 if (!replyReadAll.isEmpty()) {
106 if (!replyReadAll.isEmpty()) {
108 tempFile->write(replyReadAll);
107 tempFile->write(replyReadAll);
109 }
108 }
110 tempFile->close();
109 tempFile->close();
111
110
112 // Parse results file
111 // Parse results file
113 if (auto dataSeries = AmdaResultParser::readTxt(tempFile->fileName())) {
112 if (auto dataSeries = AmdaResultParser::readTxt(tempFile->fileName())) {
114 emit dataProvided(token, dataSeries, dateTime);
113 emit dataProvided(token, dataSeries, dateTime);
115 }
114 }
116 else {
115 else {
117 /// @todo ALX : debug
116 /// @todo ALX : debug
118 }
117 }
119 }
118 }
120 }
119 }
121
120
122 };
121 };
123 auto httpFinishedLambda
122 auto httpFinishedLambda
124 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
123 = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
125
124
126 // Don't do anything if the reply was abort
125 // Don't do anything if the reply was abort
127 if (reply->error() != QNetworkReply::OperationCanceledError) {
126 if (reply->error() != QNetworkReply::OperationCanceledError) {
128 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
127 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
129
128
130
129
131 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData downloadFileUrl:")
130 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData downloadFileUrl:")
132 << downloadFileUrl;
131 << downloadFileUrl;
133 // Executes request for downloading file //
132 // Executes request for downloading file //
134
133
135 // Creates destination file
134 // Creates destination file
136 if (tempFile->open()) {
135 if (tempFile->open()) {
137 // Executes request
136 // Executes request
138 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
137 emit requestConstructed(QNetworkRequest{downloadFileUrl}, dataId,
139 httpDownloadFinished);
138 httpDownloadFinished);
140 }
139 }
141 }
140 }
142 };
141 };
143
142
144 // //////////////// //
143 // //////////////// //
145 // Executes request //
144 // Executes request //
146 // //////////////// //
145 // //////////////// //
147 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
146 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
148 }
147 }
General Comments 0
You need to be logged in to leave comments. Login now