##// END OF EJS Templates
Merge branch 'feature/TimeWidgetInUse' into develop
perrinel -
r194:435054a2a67e merge
parent child
Show More
@@ -0,0 +1,15
1 #ifndef SCIQLOP_SQPDATETIME_H
2 #define SCIQLOP_SQPDATETIME_H
3
4 /**
5 * @brief The SqpDateTime struct holds the information of time parameters
6 * @sa SqpDateTime
7 */
8 struct SqpDateTime {
9 /// Start time
10 double m_TStart;
11 /// End time
12 double m_TEnd;
13 };
14
15 #endif // SCIQLOP_SQPDATETIME_H
@@ -0,0 +1,37
1 #ifndef SCIQLOP_TIMECONTROLLER_H
2 #define SCIQLOP_TIMECONTROLLER_H
3
4 #include <Data/SqpDateTime.h>
5
6 #include <QLoggingCategory>
7 #include <QObject>
8
9 #include <Common/spimpl.h>
10
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_TimeController)
13
14 /**
15 * @brief The TimeController class aims to handle the Time parameters notification in SciQlop.
16 */
17 class TimeController : public QObject {
18 Q_OBJECT
19 public:
20 explicit TimeController(QObject *parent = 0);
21
22 SqpDateTime dateTime() const noexcept;
23
24 signals:
25 /// Signal emitted to notify that time parameters has beed updated
26 void timeUpdated(SqpDateTime time);
27
28 public slots:
29 /// Slot called when a new dateTime has been defined. Call timeUpdated signal
30 void onTimeToUpdate(SqpDateTime dateTime);
31
32 private:
33 class TimeControllerPrivate;
34 spimpl::unique_impl_ptr<TimeControllerPrivate> impl;
35 };
36
37 #endif // SCIQLOP_TIMECONTROLLER_H
@@ -0,0 +1,26
1 #include "Time/TimeController.h"
2
3 Q_LOGGING_CATEGORY(LOG_TimeController, "TimeController")
4
5 struct TimeController::TimeControllerPrivate {
6
7 SqpDateTime m_DateTime;
8 };
9
10 TimeController::TimeController(QObject *parent)
11 : QObject{parent}, impl{spimpl::make_unique_impl<TimeControllerPrivate>()}
12 {
13 qCDebug(LOG_TimeController()) << tr("TimeController construction");
14 }
15
16 SqpDateTime TimeController::dateTime() const noexcept
17 {
18 return impl->m_DateTime;
19 }
20
21 void TimeController::onTimeToUpdate(SqpDateTime dateTime)
22 {
23 impl->m_DateTime = dateTime;
24
25 emit timeUpdated(dateTime);
26 }
@@ -1,239 +1,248
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 <TimeWidget/TimeWidget.h>
30 #include <TimeWidget/TimeWidget.h>
30 #include <Variable/Variable.h>
31 #include <Variable/Variable.h>
31 #include <Visualization/VisualizationController.h>
32 #include <Visualization/VisualizationController.h>
32
33
33 #include <QAction>
34 #include <QAction>
34 #include <QDate>
35 #include <QDate>
35 #include <QDateTime>
36 #include <QDateTime>
36 #include <QDir>
37 #include <QDir>
37 #include <QFileDialog>
38 #include <QFileDialog>
38 #include <QToolBar>
39 #include <QToolBar>
39 #include <QToolButton>
40 #include <QToolButton>
40 #include <memory.h>
41 #include <memory.h>
41
42
42 //#include <omp.h>
43 //#include <omp.h>
43 //#include <network/filedownloader.h>
44 //#include <network/filedownloader.h>
44 //#include <qlopdatabase.h>
45 //#include <qlopdatabase.h>
45 //#include <qlopsettings.h>
46 //#include <qlopsettings.h>
46 //#include <qlopgui.h>
47 //#include <qlopgui.h>
47 //#include <spacedata.h>
48 //#include <spacedata.h>
48 //#include "qlopcore.h"
49 //#include "qlopcore.h"
49 //#include "qlopcodecmanager.h"
50 //#include "qlopcodecmanager.h"
50 //#include "cdfcodec.h"
51 //#include "cdfcodec.h"
51 //#include "amdatxtcodec.h"
52 //#include "amdatxtcodec.h"
52 //#include <qlopplotmanager.h>
53 //#include <qlopplotmanager.h>
53
54
54 #include "iostream"
55 #include "iostream"
55
56
56 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
57 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
57
58
58 namespace {
59 namespace {
59 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
60 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
60 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
61 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
61 const auto VIEWPLITTERINDEX = 2;
62 const auto VIEWPLITTERINDEX = 2;
62 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
63 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
63 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
64 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
64 }
65 }
65
66
66 class MainWindow::MainWindowPrivate {
67 class MainWindow::MainWindowPrivate {
67 public:
68 public:
68 QSize m_LastOpenLeftInspectorSize;
69 QSize m_LastOpenLeftInspectorSize;
69 QSize m_LastOpenRightInspectorSize;
70 QSize m_LastOpenRightInspectorSize;
70 };
71 };
71
72
72 MainWindow::MainWindow(QWidget *parent)
73 MainWindow::MainWindow(QWidget *parent)
73 : QMainWindow{parent},
74 : QMainWindow{parent},
74 m_Ui{new Ui::MainWindow},
75 m_Ui{new Ui::MainWindow},
75 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
76 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
76 {
77 {
77 m_Ui->setupUi(this);
78 m_Ui->setupUi(this);
78
79
79 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
80 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
80 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
81 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
81
82
82
83
83 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
84 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
84 auto openLeftInspectorAction = new QAction{QIcon{
85 auto openLeftInspectorAction = new QAction{QIcon{
85 ":/icones/previous.png",
86 ":/icones/previous.png",
86 },
87 },
87 tr("Show/hide the left inspector"), this};
88 tr("Show/hide the left inspector"), this};
88
89
89
90
90 auto spacerLeftTop = new QWidget{};
91 auto spacerLeftTop = new QWidget{};
91 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
92 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
92
93
93 auto spacerLeftBottom = new QWidget{};
94 auto spacerLeftBottom = new QWidget{};
94 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
95 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
95
96
96 leftSidePane->addWidget(spacerLeftTop);
97 leftSidePane->addWidget(spacerLeftTop);
97 leftSidePane->addAction(openLeftInspectorAction);
98 leftSidePane->addAction(openLeftInspectorAction);
98 leftSidePane->addWidget(spacerLeftBottom);
99 leftSidePane->addWidget(spacerLeftBottom);
99
100
100
101
101 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
102 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
102 auto openRightInspectorAction = new QAction{QIcon{
103 auto openRightInspectorAction = new QAction{QIcon{
103 ":/icones/next.png",
104 ":/icones/next.png",
104 },
105 },
105 tr("Show/hide the right inspector"), this};
106 tr("Show/hide the right inspector"), this};
106
107
107 auto spacerRightTop = new QWidget{};
108 auto spacerRightTop = new QWidget{};
108 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
109 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
109
110
110 auto spacerRightBottom = new QWidget{};
111 auto spacerRightBottom = new QWidget{};
111 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
112 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
112
113
113 rightSidePane->addWidget(spacerRightTop);
114 rightSidePane->addWidget(spacerRightTop);
114 rightSidePane->addAction(openRightInspectorAction);
115 rightSidePane->addAction(openRightInspectorAction);
115 rightSidePane->addWidget(spacerRightBottom);
116 rightSidePane->addWidget(spacerRightBottom);
116
117
117 openLeftInspectorAction->setCheckable(true);
118 openLeftInspectorAction->setCheckable(true);
118 openRightInspectorAction->setCheckable(true);
119 openRightInspectorAction->setCheckable(true);
119
120
120 auto openInspector = [this](bool checked, bool right, auto action) {
121 auto openInspector = [this](bool checked, bool right, auto action) {
121
122
122 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
123 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
123
124
124 auto &lastInspectorSize
125 auto &lastInspectorSize
125 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
126 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
126
127
127 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
128 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
128 : m_Ui->leftMainInspectorWidget->size();
129 : m_Ui->leftMainInspectorWidget->size();
129
130
130 // Update of the last opened geometry
131 // Update of the last opened geometry
131 if (checked) {
132 if (checked) {
132 lastInspectorSize = nextInspectorSize;
133 lastInspectorSize = nextInspectorSize;
133 }
134 }
134
135
135 auto startSize = lastInspectorSize;
136 auto startSize = lastInspectorSize;
136 auto endSize = startSize;
137 auto endSize = startSize;
137 endSize.setWidth(0);
138 endSize.setWidth(0);
138
139
139 auto splitterInspectorIndex
140 auto splitterInspectorIndex
140 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
141 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
141
142
142 auto currentSizes = m_Ui->splitter->sizes();
143 auto currentSizes = m_Ui->splitter->sizes();
143 if (checked) {
144 if (checked) {
144 // adjust sizes individually here, e.g.
145 // adjust sizes individually here, e.g.
145 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
146 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
146 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
147 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
147 m_Ui->splitter->setSizes(currentSizes);
148 m_Ui->splitter->setSizes(currentSizes);
148 }
149 }
149 else {
150 else {
150 // adjust sizes individually here, e.g.
151 // adjust sizes individually here, e.g.
151 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
152 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
152 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
153 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
153 m_Ui->splitter->setSizes(currentSizes);
154 m_Ui->splitter->setSizes(currentSizes);
154 }
155 }
155
156
156 };
157 };
157
158
158
159
159 connect(openLeftInspectorAction, &QAction::triggered,
160 connect(openLeftInspectorAction, &QAction::triggered,
160 [openInspector, openLeftInspectorAction](bool checked) {
161 [openInspector, openLeftInspectorAction](bool checked) {
161 openInspector(checked, false, openLeftInspectorAction);
162 openInspector(checked, false, openLeftInspectorAction);
162 });
163 });
163 connect(openRightInspectorAction, &QAction::triggered,
164 connect(openRightInspectorAction, &QAction::triggered,
164 [openInspector, openRightInspectorAction](bool checked) {
165 [openInspector, openRightInspectorAction](bool checked) {
165 openInspector(checked, true, openRightInspectorAction);
166 openInspector(checked, true, openRightInspectorAction);
166 });
167 });
167
168
168 this->menuBar()->addAction(tr("File"));
169 this->menuBar()->addAction(tr("File"));
169 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
170 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
170
171
171 mainToolBar->addWidget(new TimeWidget{});
172 auto timeWidget = new TimeWidget{};
173 mainToolBar->addWidget(timeWidget);
172
174
173 // Widgets / controllers connections
175 // Widgets / controllers connections
176
177 // DataSource
174 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
178 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
175 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
179 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
176
180
181 // Time
182 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
183 SLOT(onTimeToUpdate(SqpDateTime)));
184
185 // Variable
177 qRegisterMetaType<std::shared_ptr<Variable> >();
186 qRegisterMetaType<std::shared_ptr<Variable> >();
178 connect(&sqpApp->visualizationController(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
187 connect(&sqpApp->visualizationController(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
179 m_Ui->view, SLOT(displayVariable(std::shared_ptr<Variable>)));
188 m_Ui->view, SLOT(displayVariable(std::shared_ptr<Variable>)));
180
189
181 /* QLopGUI::registerMenuBar(menuBar());
190 /* QLopGUI::registerMenuBar(menuBar());
182 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
191 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
183 this->m_progressWidget = new QWidget();
192 this->m_progressWidget = new QWidget();
184 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
193 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
185 this->m_progressWidget->setLayout(this->m_progressLayout);
194 this->m_progressWidget->setLayout(this->m_progressLayout);
186 this->m_progressWidget->setWindowModality(Qt::WindowModal);
195 this->m_progressWidget->setWindowModality(Qt::WindowModal);
187 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
196 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
188 for(int i=0;i<OMP_THREADS;i++)
197 for(int i=0;i<OMP_THREADS;i++)
189 {
198 {
190 this->m_progress.append(new QProgressBar(this->m_progressWidget));
199 this->m_progress.append(new QProgressBar(this->m_progressWidget));
191 this->m_progress.last()->setMinimum(0);
200 this->m_progress.last()->setMinimum(0);
192 this->m_progress.last()->setMaximum(100);
201 this->m_progress.last()->setMaximum(100);
193 this->m_progressLayout->addWidget(this->m_progress.last());
202 this->m_progressLayout->addWidget(this->m_progress.last());
194 this->m_progressWidget->hide();
203 this->m_progressWidget->hide();
195 this->m_progressThreadIds[i] = -1;
204 this->m_progressThreadIds[i] = -1;
196 }
205 }
197 this->m_progressWidget->setWindowTitle("Loading File");
206 this->m_progressWidget->setWindowTitle("Loading File");
198 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
207 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
199 << QLopCore::self()
208 << QLopCore::self()
200 << QLopPlotManager::self()
209 << QLopPlotManager::self()
201 << QLopCodecManager::self()
210 << QLopCodecManager::self()
202 << FileDownloader::self()
211 << FileDownloader::self()
203 << QLopDataBase::self()
212 << QLopDataBase::self()
204 << SpaceData::self();
213 << SpaceData::self();
205
214
206 CDFCodec::registerToManager();
215 CDFCodec::registerToManager();
207 AMDATXTCodec::registerToManager();
216 AMDATXTCodec::registerToManager();
208
217
209
218
210 for(int i=0;i<ServicesToLoad.count();i++)
219 for(int i=0;i<ServicesToLoad.count();i++)
211 {
220 {
212 qDebug()<<ServicesToLoad.at(i)->serviceName();
221 qDebug()<<ServicesToLoad.at(i)->serviceName();
213 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
222 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
214 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
223 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
215 if(wdgt)
224 if(wdgt)
216 {
225 {
217 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
226 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
218 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
227 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
219 }
228 }
220 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
229 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
221 }*/
230 }*/
222 }
231 }
223
232
224 MainWindow::~MainWindow()
233 MainWindow::~MainWindow()
225 {
234 {
226 }
235 }
227
236
228
237
229 void MainWindow::changeEvent(QEvent *e)
238 void MainWindow::changeEvent(QEvent *e)
230 {
239 {
231 QMainWindow::changeEvent(e);
240 QMainWindow::changeEvent(e);
232 switch (e->type()) {
241 switch (e->type()) {
233 case QEvent::LanguageChange:
242 case QEvent::LanguageChange:
234 m_Ui->retranslateUi(this);
243 m_Ui->retranslateUi(this);
235 break;
244 break;
236 default:
245 default:
237 break;
246 break;
238 }
247 }
239 }
248 }
@@ -1,16 +1,15
1 #ifndef SCIQLOP_DATAPROVIDERPARAMETERS_H
1 #ifndef SCIQLOP_DATAPROVIDERPARAMETERS_H
2 #define SCIQLOP_DATAPROVIDERPARAMETERS_H
2 #define SCIQLOP_DATAPROVIDERPARAMETERS_H
3
3
4 #include "SqpDateTime.h"
5
4 /**
6 /**
5 * @brief The DataProviderParameters struct holds the information needed to retrieve data from a
7 * @brief The DataProviderParameters struct holds the information needed to retrieve data from a
6 * data provider
8 * data provider
7 * @sa IDataProvider
9 * @sa IDataProvider
8 */
10 */
9 struct DataProviderParameters {
11 struct DataProviderParameters {
10 /// Start time
12 SqpDateTime m_Time;
11 double m_TStart;
12 /// End time
13 double m_TEnd;
14 };
13 };
15
14
16 #endif // SCIQLOP_DATAPROVIDERPARAMETERS_H
15 #endif // SCIQLOP_DATAPROVIDERPARAMETERS_H
@@ -1,48 +1,51
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QObject>
5 #include <QObject>
6
6
7 #include <Common/spimpl.h>
7 #include <Common/spimpl.h>
8
8
9 class IDataProvider;
9 class IDataProvider;
10 class TimeController;
10 class Variable;
11 class Variable;
11 class VariableModel;
12 class VariableModel;
12
13
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
14 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
14
15
15 /**
16 /**
16 * @brief The VariableController class aims to handle the variables in SciQlop.
17 * @brief The VariableController class aims to handle the variables in SciQlop.
17 */
18 */
18 class VariableController : public QObject {
19 class VariableController : public QObject {
19 Q_OBJECT
20 Q_OBJECT
20 public:
21 public:
21 explicit VariableController(QObject *parent = 0);
22 explicit VariableController(QObject *parent = 0);
22 virtual ~VariableController();
23 virtual ~VariableController();
23
24
24 VariableModel *variableModel() noexcept;
25 VariableModel *variableModel() noexcept;
25
26
27 void setTimeController(TimeController *timeController) noexcept;
28
26 signals:
29 signals:
27 /// Signal emitted when a variable has been created
30 /// Signal emitted when a variable has been created
28 void variableCreated(std::shared_ptr<Variable> variable);
31 void variableCreated(std::shared_ptr<Variable> variable);
29
32
30 public slots:
33 public slots:
31 /**
34 /**
32 * Creates a new variable and adds it to the model
35 * Creates a new variable and adds it to the model
33 * @param name the name of the new variable
36 * @param name the name of the new variable
34 * @param provider the data provider for the new variable
37 * @param provider the data provider for the new variable
35 */
38 */
36 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
39 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
37
40
38 void initialize();
41 void initialize();
39 void finalize();
42 void finalize();
40
43
41 private:
44 private:
42 void waitForFinish();
45 void waitForFinish();
43
46
44 class VariableControllerPrivate;
47 class VariableControllerPrivate;
45 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
48 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
46 };
49 };
47
50
48 #endif // SCIQLOP_VARIABLECONTROLLER_H
51 #endif // SCIQLOP_VARIABLECONTROLLER_H
@@ -1,91 +1,110
1 #include <Variable/VariableController.h>
1 #include <Variable/VariableController.h>
2 #include <Variable/VariableModel.h>
2 #include <Variable/VariableModel.h>
3
3
4 #include <Data/DataProviderParameters.h>
4 #include <Data/DataProviderParameters.h>
5 #include <Data/IDataProvider.h>
5 #include <Data/IDataProvider.h>
6 #include <Data/IDataSeries.h>
6 #include <Data/IDataSeries.h>
7 #include <Time/TimeController.h>
7
8
8 #include <QDateTime>
9 #include <QDateTime>
9 #include <QMutex>
10 #include <QMutex>
10 #include <QThread>
11 #include <QThread>
11
12
12 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
13 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
13
14
14 namespace {
15 namespace {
15
16
16 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
17 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
17 /// will be deleted when the timerange is recovered from SciQlop
18 /// will be deleted when the timerange is recovered from SciQlop
18 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider) noexcept
19 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
20 const SqpDateTime &dateTime) noexcept
19 {
21 {
20 auto parameters = DataProviderParameters{
22 auto parameters = DataProviderParameters{dateTime};
21 // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above)
22 static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 00}}.toMSecsSinceEpoch()
23 / 1000.),
24 static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch())
25 / 1000.};
26
23
27 return provider.retrieveData(parameters);
24 return provider.retrieveData(parameters);
28 }
25 }
29
26
30 } // namespace
27 } // namespace
31
28
32 struct VariableController::VariableControllerPrivate {
29 struct VariableController::VariableControllerPrivate {
33 explicit VariableControllerPrivate(VariableController *parent)
30 explicit VariableControllerPrivate(VariableController *parent)
34 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
31 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
35 {
32 {
36 }
33 }
37
34
38 QMutex m_WorkingMutex;
35 QMutex m_WorkingMutex;
39 /// Variable model. The VariableController has the ownership
36 /// Variable model. The VariableController has the ownership
40 VariableModel *m_VariableModel;
37 VariableModel *m_VariableModel;
38
39 TimeController *m_TimeController;
41 };
40 };
42
41
43 VariableController::VariableController(QObject *parent)
42 VariableController::VariableController(QObject *parent)
44 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
43 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
45 {
44 {
46 qCDebug(LOG_VariableController()) << tr("VariableController construction")
45 qCDebug(LOG_VariableController()) << tr("VariableController construction")
47 << QThread::currentThread();
46 << QThread::currentThread();
48 }
47 }
49
48
50 VariableController::~VariableController()
49 VariableController::~VariableController()
51 {
50 {
52 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
51 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
53 << QThread::currentThread();
52 << QThread::currentThread();
54 this->waitForFinish();
53 this->waitForFinish();
55 }
54 }
56
55
57 VariableModel *VariableController::variableModel() noexcept
56 VariableModel *VariableController::variableModel() noexcept
58 {
57 {
59 return impl->m_VariableModel;
58 return impl->m_VariableModel;
60 }
59 }
61
60
61 void VariableController::setTimeController(TimeController *timeController) noexcept
62 {
63 impl->m_TimeController = timeController;
64 }
65
62 void VariableController::createVariable(const QString &name,
66 void VariableController::createVariable(const QString &name,
63 std::shared_ptr<IDataProvider> provider) noexcept
67 std::shared_ptr<IDataProvider> provider) noexcept
64 {
68 {
69 // TORM
70 // auto dateTime = SqpDateTime{
71 // // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above)
72 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 00}}.toMSecsSinceEpoch()
73 // / 1000.),
74 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch())
75 // / 1000.};
76
77 if (!impl->m_TimeController) {
78 qCCritical(LOG_VariableController())
79 << tr("Impossible to create variable: The time controller is null");
80 return;
81 }
82
83
65 /// @todo : for the moment :
84 /// @todo : for the moment :
66 /// - the provider is only used to retrieve data from the variable for its initialization, but
85 /// - the provider is only used to retrieve data from the variable for its initialization, but
67 /// it will be retained later
86 /// it will be retained later
68 /// - default data are generated for the variable, without taking into account the timerange set
87 /// - default data are generated for the variable, without taking into account the timerange set
69 /// in sciqlop
88 /// in sciqlop
70 if (auto newVariable
89 if (auto newVariable = impl->m_VariableModel->createVariable(
71 = impl->m_VariableModel->createVariable(name, generateDefaultDataSeries(*provider))) {
90 name, generateDefaultDataSeries(*provider, impl->m_TimeController->dateTime()))) {
72 emit variableCreated(newVariable);
91 emit variableCreated(newVariable);
73 }
92 }
74 }
93 }
75
94
76 void VariableController::initialize()
95 void VariableController::initialize()
77 {
96 {
78 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
97 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
79 impl->m_WorkingMutex.lock();
98 impl->m_WorkingMutex.lock();
80 qCDebug(LOG_VariableController()) << tr("VariableController init END");
99 qCDebug(LOG_VariableController()) << tr("VariableController init END");
81 }
100 }
82
101
83 void VariableController::finalize()
102 void VariableController::finalize()
84 {
103 {
85 impl->m_WorkingMutex.unlock();
104 impl->m_WorkingMutex.unlock();
86 }
105 }
87
106
88 void VariableController::waitForFinish()
107 void VariableController::waitForFinish()
89 {
108 {
90 QMutexLocker locker{&impl->m_WorkingMutex};
109 QMutexLocker locker{&impl->m_WorkingMutex};
91 }
110 }
@@ -1,48 +1,50
1 #ifndef SCIQLOP_SQPAPPLICATION_H
1 #ifndef SCIQLOP_SQPAPPLICATION_H
2 #define SCIQLOP_SQPAPPLICATION_H
2 #define SCIQLOP_SQPAPPLICATION_H
3
3
4 #include "SqpApplication.h"
4 #include "SqpApplication.h"
5
5
6 #include <QApplication>
6 #include <QApplication>
7 #include <QLoggingCategory>
7 #include <QLoggingCategory>
8
8
9 #include <Common/spimpl.h>
9 #include <Common/spimpl.h>
10
10
11 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
11 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
12
12
13 #if defined(sqpApp)
13 #if defined(sqpApp)
14 #undef sqpApp
14 #undef sqpApp
15 #endif
15 #endif
16 #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance()))
16 #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance()))
17
17
18 class DataSourceController;
18 class DataSourceController;
19 class TimeController;
19 class VariableController;
20 class VariableController;
20 class VisualizationController;
21 class VisualizationController;
21
22
22 /**
23 /**
23 * @brief The SqpApplication class aims to make the link between SciQlop
24 * @brief The SqpApplication class aims to make the link between SciQlop
24 * and its plugins. This is the intermediate class that SciQlop has to use
25 * and its plugins. This is the intermediate class that SciQlop has to use
25 * in the way to connect a data source. Please first use load method to initialize
26 * in the way to connect a data source. Please first use load method to initialize
26 * a plugin specified by its metadata name (JSON plugin source) then others specifics
27 * a plugin specified by its metadata name (JSON plugin source) then others specifics
27 * method will be able to access it.
28 * method will be able to access it.
28 * You can load a data source driver plugin then create a data source.
29 * You can load a data source driver plugin then create a data source.
29 */
30 */
30
31
31 class SqpApplication : public QApplication {
32 class SqpApplication : public QApplication {
32 Q_OBJECT
33 Q_OBJECT
33 public:
34 public:
34 explicit SqpApplication(int &argc, char **argv);
35 explicit SqpApplication(int &argc, char **argv);
35 virtual ~SqpApplication();
36 virtual ~SqpApplication();
36 void initialize();
37 void initialize();
37
38
38 /// Accessors for the differents sciqlop controllers
39 /// Accessors for the differents sciqlop controllers
39 DataSourceController &dataSourceController() noexcept;
40 DataSourceController &dataSourceController() noexcept;
41 TimeController &timeController() noexcept;
40 VariableController &variableController() noexcept;
42 VariableController &variableController() noexcept;
41 VisualizationController &visualizationController() noexcept;
43 VisualizationController &visualizationController() noexcept;
42
44
43 private:
45 private:
44 class SqpApplicationPrivate;
46 class SqpApplicationPrivate;
45 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
47 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
46 };
48 };
47
49
48 #endif // SCIQLOP_SQPAPPLICATION_H
50 #endif // SCIQLOP_SQPAPPLICATION_H
@@ -1,21 +1,32
1 #ifndef SCIQLOP_TIMEWIDGET_H
1 #ifndef SCIQLOP_TIMEWIDGET_H
2 #define SCIQLOP_TIMEWIDGET_H
2 #define SCIQLOP_TIMEWIDGET_H
3
3
4 #include <QWidget>
4 #include <QWidget>
5
5
6 #include <Data/SqpDateTime.h>
7
6 namespace Ui {
8 namespace Ui {
7 class TimeWidget;
9 class TimeWidget;
8 } // Ui
10 } // Ui
9
11
10 class TimeWidget : public QWidget {
12 class TimeWidget : public QWidget {
11 Q_OBJECT
13 Q_OBJECT
12
14
13 public:
15 public:
14 explicit TimeWidget(QWidget *parent = 0);
16 explicit TimeWidget(QWidget *parent = 0);
15 virtual ~TimeWidget();
17 virtual ~TimeWidget();
16
18
19 signals:
20 /// Signal emitted when the time parameters has beed updated
21 void timeUpdated(SqpDateTime time);
22
23 public slots:
24 /// slot called when time parameters update has ben requested
25 void onTimeUpdateRequested();
26
27
17 private:
28 private:
18 Ui::TimeWidget *ui;
29 Ui::TimeWidget *ui;
19 };
30 };
20
31
21 #endif // SCIQLOP_ SQPSIDEPANE_H
32 #endif // SCIQLOP_ SQPSIDEPANE_H
@@ -1,109 +1,120
1 #include "SqpApplication.h"
1 #include "SqpApplication.h"
2
2
3 #include <Data/IDataProvider.h>
3 #include <Data/IDataProvider.h>
4 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceController.h>
5 #include <QThread>
5 #include <QThread>
6 #include <Time/TimeController.h>
6 #include <Variable/Variable.h>
7 #include <Variable/Variable.h>
7 #include <Variable/VariableController.h>
8 #include <Variable/VariableController.h>
8 #include <Visualization/VisualizationController.h>
9 #include <Visualization/VisualizationController.h>
9
10
10 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
11 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
11
12
12 class SqpApplication::SqpApplicationPrivate {
13 class SqpApplication::SqpApplicationPrivate {
13 public:
14 public:
14 SqpApplicationPrivate()
15 SqpApplicationPrivate()
15 : m_DataSourceController{std::make_unique<DataSourceController>()},
16 : m_DataSourceController{std::make_unique<DataSourceController>()},
17 m_TimeController{std::make_unique<TimeController>()},
16 m_VariableController{std::make_unique<VariableController>()},
18 m_VariableController{std::make_unique<VariableController>()},
17 m_VisualizationController{std::make_unique<VisualizationController>()}
19 m_VisualizationController{std::make_unique<VisualizationController>()}
18 {
20 {
19 // /////////////////////////////// //
21 // /////////////////////////////// //
20 // Connections between controllers //
22 // Connections between controllers //
21 // /////////////////////////////// //
23 // /////////////////////////////// //
22
24
23 // VariableController <-> DataSourceController
25 // VariableController <-> DataSourceController
24 qRegisterMetaType<std::shared_ptr<IDataProvider> >();
26 qRegisterMetaType<std::shared_ptr<IDataProvider> >();
25 connect(m_DataSourceController.get(),
27 connect(m_DataSourceController.get(),
26 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
28 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
27 m_VariableController.get(),
29 m_VariableController.get(),
28 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
30 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
29
31
30 // VariableController <-> VisualizationController
32 // VariableController <-> VisualizationController
31 qRegisterMetaType<std::shared_ptr<Variable> >();
33 qRegisterMetaType<std::shared_ptr<Variable> >();
32 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
34 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
33 m_VisualizationController.get(),
35 m_VisualizationController.get(),
34 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
36 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
35
37
36 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
38 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
37 m_VariableController->moveToThread(&m_VariableControllerThread);
39 m_VariableController->moveToThread(&m_VariableControllerThread);
38 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
40 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
41
42 // Additionnal init
43 m_VariableController->setTimeController(m_TimeController.get());
39 }
44 }
40
45
41 virtual ~SqpApplicationPrivate()
46 virtual ~SqpApplicationPrivate()
42 {
47 {
43 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
48 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
44 m_DataSourceControllerThread.quit();
49 m_DataSourceControllerThread.quit();
45 m_DataSourceControllerThread.wait();
50 m_DataSourceControllerThread.wait();
46
51
47 m_VariableControllerThread.quit();
52 m_VariableControllerThread.quit();
48 m_VariableControllerThread.wait();
53 m_VariableControllerThread.wait();
49
54
50 m_VisualizationControllerThread.quit();
55 m_VisualizationControllerThread.quit();
51 m_VisualizationControllerThread.wait();
56 m_VisualizationControllerThread.wait();
52 }
57 }
53
58
54 std::unique_ptr<DataSourceController> m_DataSourceController;
59 std::unique_ptr<DataSourceController> m_DataSourceController;
55 std::unique_ptr<VariableController> m_VariableController;
60 std::unique_ptr<VariableController> m_VariableController;
61 std::unique_ptr<TimeController> m_TimeController;
56 std::unique_ptr<VisualizationController> m_VisualizationController;
62 std::unique_ptr<VisualizationController> m_VisualizationController;
57 QThread m_DataSourceControllerThread;
63 QThread m_DataSourceControllerThread;
58 QThread m_VariableControllerThread;
64 QThread m_VariableControllerThread;
59 QThread m_VisualizationControllerThread;
65 QThread m_VisualizationControllerThread;
60 };
66 };
61
67
62
68
63 SqpApplication::SqpApplication(int &argc, char **argv)
69 SqpApplication::SqpApplication(int &argc, char **argv)
64 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
70 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
65 {
71 {
66 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
72 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
67
73
68 connect(&impl->m_DataSourceControllerThread, &QThread::started,
74 connect(&impl->m_DataSourceControllerThread, &QThread::started,
69 impl->m_DataSourceController.get(), &DataSourceController::initialize);
75 impl->m_DataSourceController.get(), &DataSourceController::initialize);
70 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
76 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
71 impl->m_DataSourceController.get(), &DataSourceController::finalize);
77 impl->m_DataSourceController.get(), &DataSourceController::finalize);
72
78
73 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
79 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
74 &VariableController::initialize);
80 &VariableController::initialize);
75 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
81 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
76 &VariableController::finalize);
82 &VariableController::finalize);
77
83
78 connect(&impl->m_VisualizationControllerThread, &QThread::started,
84 connect(&impl->m_VisualizationControllerThread, &QThread::started,
79 impl->m_VisualizationController.get(), &VisualizationController::initialize);
85 impl->m_VisualizationController.get(), &VisualizationController::initialize);
80 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
86 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
81 impl->m_VisualizationController.get(), &VisualizationController::finalize);
87 impl->m_VisualizationController.get(), &VisualizationController::finalize);
82
88
83 impl->m_DataSourceControllerThread.start();
89 impl->m_DataSourceControllerThread.start();
84 impl->m_VariableControllerThread.start();
90 impl->m_VariableControllerThread.start();
85 impl->m_VisualizationControllerThread.start();
91 impl->m_VisualizationControllerThread.start();
86 }
92 }
87
93
88 SqpApplication::~SqpApplication()
94 SqpApplication::~SqpApplication()
89 {
95 {
90 }
96 }
91
97
92 void SqpApplication::initialize()
98 void SqpApplication::initialize()
93 {
99 {
94 }
100 }
95
101
96 DataSourceController &SqpApplication::dataSourceController() noexcept
102 DataSourceController &SqpApplication::dataSourceController() noexcept
97 {
103 {
98 return *impl->m_DataSourceController;
104 return *impl->m_DataSourceController;
99 }
105 }
100
106
107 TimeController &SqpApplication::timeController() noexcept
108 {
109 return *impl->m_TimeController;
110 }
111
101 VariableController &SqpApplication::variableController() noexcept
112 VariableController &SqpApplication::variableController() noexcept
102 {
113 {
103 return *impl->m_VariableController;
114 return *impl->m_VariableController;
104 }
115 }
105
116
106 VisualizationController &SqpApplication::visualizationController() noexcept
117 VisualizationController &SqpApplication::visualizationController() noexcept
107 {
118 {
108 return *impl->m_VisualizationController;
119 return *impl->m_VisualizationController;
109 }
120 }
@@ -1,12 +1,29
1 #include "TimeWidget/TimeWidget.h"
1 #include "TimeWidget/TimeWidget.h"
2 #include "ui_TimeWidget.h"
2 #include "ui_TimeWidget.h"
3
3
4
4 TimeWidget::TimeWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::TimeWidget}
5 TimeWidget::TimeWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::TimeWidget}
5 {
6 {
6 ui->setupUi(this);
7 ui->setupUi(this);
8
9 // Connection
10 connect(ui->startDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
11 &TimeWidget::onTimeUpdateRequested);
12
13 connect(ui->endDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
14 &TimeWidget::onTimeUpdateRequested);
7 }
15 }
8
16
9 TimeWidget::~TimeWidget()
17 TimeWidget::~TimeWidget()
10 {
18 {
11 delete ui;
19 delete ui;
12 }
20 }
21
22 void TimeWidget::onTimeUpdateRequested()
23 {
24 auto dateTime = SqpDateTime{
25 static_cast<double>(ui->startDateTimeEdit->dateTime().toMSecsSinceEpoch() / 1000.),
26 static_cast<double>(ui->endDateTimeEdit->dateTime().toMSecsSinceEpoch()) / 1000.};
27
28 emit timeUpdated(std::move(dateTime));
29 }
@@ -1,30 +1,32
1 #include "CosinusProvider.h"
1 #include "CosinusProvider.h"
2
2
3 #include <Data/DataProviderParameters.h>
3 #include <Data/DataProviderParameters.h>
4 #include <Data/ScalarSeries.h>
4 #include <Data/ScalarSeries.h>
5
5
6 #include <cmath>
6 #include <cmath>
7
7
8 std::unique_ptr<IDataSeries>
8 std::unique_ptr<IDataSeries>
9 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
9 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
10 {
10 {
11 auto dateTime = parameters.m_Time;
12
11 // Gets the timerange from the parameters
13 // Gets the timerange from the parameters
12 auto start = parameters.m_TStart;
14 auto start = dateTime.m_TStart;
13 auto end = parameters.m_TEnd;
15 auto end = dateTime.m_TEnd;
14
16
15 // We assure that timerange is valid
17 // We assure that timerange is valid
16 if (end < start) {
18 if (end < start) {
17 std::swap(start, end);
19 std::swap(start, end);
18 }
20 }
19
21
20 // Generates scalar series containing cosinus values (one value per second)
22 // Generates scalar series containing cosinus values (one value per second)
21 auto scalarSeries
23 auto scalarSeries
22 = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
24 = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
23
25
24 auto dataIndex = 0;
26 auto dataIndex = 0;
25 for (auto time = start; time < end; ++time, ++dataIndex) {
27 for (auto time = start; time < end; ++time, ++dataIndex) {
26 scalarSeries->setData(dataIndex, time, std::cos(time));
28 scalarSeries->setData(dataIndex, time, std::cos(time));
27 }
29 }
28
30
29 return scalarSeries;
31 return scalarSeries;
30 }
32 }
General Comments 0
You need to be logged in to leave comments. Login now