@@ -1,248 +1,254 | |||||
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 <Visualization/VisualizationController.h> |
|
32 | #include <Visualization/VisualizationController.h> | |
33 |
|
33 | |||
34 | #include <QAction> |
|
34 | #include <QAction> | |
35 | #include <QDate> |
|
35 | #include <QDate> | |
36 | #include <QDateTime> |
|
36 | #include <QDateTime> | |
37 | #include <QDir> |
|
37 | #include <QDir> | |
38 | #include <QFileDialog> |
|
38 | #include <QFileDialog> | |
39 | #include <QToolBar> |
|
39 | #include <QToolBar> | |
40 | #include <QToolButton> |
|
40 | #include <QToolButton> | |
41 | #include <memory.h> |
|
41 | #include <memory.h> | |
42 |
|
42 | |||
43 | //#include <omp.h> |
|
43 | //#include <omp.h> | |
44 | //#include <network/filedownloader.h> |
|
44 | //#include <network/filedownloader.h> | |
45 | //#include <qlopdatabase.h> |
|
45 | //#include <qlopdatabase.h> | |
46 | //#include <qlopsettings.h> |
|
46 | //#include <qlopsettings.h> | |
47 | //#include <qlopgui.h> |
|
47 | //#include <qlopgui.h> | |
48 | //#include <spacedata.h> |
|
48 | //#include <spacedata.h> | |
49 | //#include "qlopcore.h" |
|
49 | //#include "qlopcore.h" | |
50 | //#include "qlopcodecmanager.h" |
|
50 | //#include "qlopcodecmanager.h" | |
51 | //#include "cdfcodec.h" |
|
51 | //#include "cdfcodec.h" | |
52 | //#include "amdatxtcodec.h" |
|
52 | //#include "amdatxtcodec.h" | |
53 | //#include <qlopplotmanager.h> |
|
53 | //#include <qlopplotmanager.h> | |
54 |
|
54 | |||
55 | #include "iostream" |
|
55 | #include "iostream" | |
56 |
|
56 | |||
57 | Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") |
|
57 | Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") | |
58 |
|
58 | |||
59 | namespace { |
|
59 | namespace { | |
60 | const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; |
|
60 | const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; | |
61 | const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; |
|
61 | const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; | |
62 | const auto VIEWPLITTERINDEX = 2; |
|
62 | const auto VIEWPLITTERINDEX = 2; | |
63 | const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; |
|
63 | const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; | |
64 | const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; |
|
64 | const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | class MainWindow::MainWindowPrivate { |
|
67 | class MainWindow::MainWindowPrivate { | |
68 | public: |
|
68 | public: | |
69 | QSize m_LastOpenLeftInspectorSize; |
|
69 | QSize m_LastOpenLeftInspectorSize; | |
70 | QSize m_LastOpenRightInspectorSize; |
|
70 | QSize m_LastOpenRightInspectorSize; | |
71 | }; |
|
71 | }; | |
72 |
|
72 | |||
73 | MainWindow::MainWindow(QWidget *parent) |
|
73 | MainWindow::MainWindow(QWidget *parent) | |
74 | : QMainWindow{parent}, |
|
74 | : QMainWindow{parent}, | |
75 | m_Ui{new Ui::MainWindow}, |
|
75 | m_Ui{new Ui::MainWindow}, | |
76 | impl{spimpl::make_unique_impl<MainWindowPrivate>()} |
|
76 | impl{spimpl::make_unique_impl<MainWindowPrivate>()} | |
77 | { |
|
77 | { | |
78 | m_Ui->setupUi(this); |
|
78 | m_Ui->setupUi(this); | |
79 |
|
79 | |||
80 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
80 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); | |
81 | m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
81 | m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); | |
82 |
|
82 | |||
83 |
|
83 | |||
84 | auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); |
|
84 | auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); | |
85 | auto openLeftInspectorAction = new QAction{QIcon{ |
|
85 | auto openLeftInspectorAction = new QAction{QIcon{ | |
86 | ":/icones/previous.png", |
|
86 | ":/icones/previous.png", | |
87 | }, |
|
87 | }, | |
88 | tr("Show/hide the left inspector"), this}; |
|
88 | tr("Show/hide the left inspector"), this}; | |
89 |
|
89 | |||
90 |
|
90 | |||
91 | auto spacerLeftTop = new QWidget{}; |
|
91 | auto spacerLeftTop = new QWidget{}; | |
92 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
92 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
93 |
|
93 | |||
94 | auto spacerLeftBottom = new QWidget{}; |
|
94 | auto spacerLeftBottom = new QWidget{}; | |
95 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
95 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
96 |
|
96 | |||
97 | leftSidePane->addWidget(spacerLeftTop); |
|
97 | leftSidePane->addWidget(spacerLeftTop); | |
98 | leftSidePane->addAction(openLeftInspectorAction); |
|
98 | leftSidePane->addAction(openLeftInspectorAction); | |
99 | leftSidePane->addWidget(spacerLeftBottom); |
|
99 | leftSidePane->addWidget(spacerLeftBottom); | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); |
|
102 | auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); | |
103 | auto openRightInspectorAction = new QAction{QIcon{ |
|
103 | auto openRightInspectorAction = new QAction{QIcon{ | |
104 | ":/icones/next.png", |
|
104 | ":/icones/next.png", | |
105 | }, |
|
105 | }, | |
106 | tr("Show/hide the right inspector"), this}; |
|
106 | tr("Show/hide the right inspector"), this}; | |
107 |
|
107 | |||
108 | auto spacerRightTop = new QWidget{}; |
|
108 | auto spacerRightTop = new QWidget{}; | |
109 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
109 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
110 |
|
110 | |||
111 | auto spacerRightBottom = new QWidget{}; |
|
111 | auto spacerRightBottom = new QWidget{}; | |
112 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
112 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
113 |
|
113 | |||
114 | rightSidePane->addWidget(spacerRightTop); |
|
114 | rightSidePane->addWidget(spacerRightTop); | |
115 | rightSidePane->addAction(openRightInspectorAction); |
|
115 | rightSidePane->addAction(openRightInspectorAction); | |
116 | rightSidePane->addWidget(spacerRightBottom); |
|
116 | rightSidePane->addWidget(spacerRightBottom); | |
117 |
|
117 | |||
118 | openLeftInspectorAction->setCheckable(true); |
|
118 | openLeftInspectorAction->setCheckable(true); | |
119 | openRightInspectorAction->setCheckable(true); |
|
119 | openRightInspectorAction->setCheckable(true); | |
120 |
|
120 | |||
121 | auto openInspector = [this](bool checked, bool right, auto action) { |
|
121 | auto openInspector = [this](bool checked, bool right, auto action) { | |
122 |
|
122 | |||
123 | 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"}); | |
124 |
|
124 | |||
125 | auto &lastInspectorSize |
|
125 | auto &lastInspectorSize | |
126 | = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize; |
|
126 | = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize; | |
127 |
|
127 | |||
128 | auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size() |
|
128 | auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size() | |
129 | : m_Ui->leftMainInspectorWidget->size(); |
|
129 | : m_Ui->leftMainInspectorWidget->size(); | |
130 |
|
130 | |||
131 | // Update of the last opened geometry |
|
131 | // Update of the last opened geometry | |
132 | if (checked) { |
|
132 | if (checked) { | |
133 | lastInspectorSize = nextInspectorSize; |
|
133 | lastInspectorSize = nextInspectorSize; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | auto startSize = lastInspectorSize; |
|
136 | auto startSize = lastInspectorSize; | |
137 | auto endSize = startSize; |
|
137 | auto endSize = startSize; | |
138 | endSize.setWidth(0); |
|
138 | endSize.setWidth(0); | |
139 |
|
139 | |||
140 | auto splitterInspectorIndex |
|
140 | auto splitterInspectorIndex | |
141 | = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX; |
|
141 | = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX; | |
142 |
|
142 | |||
143 | auto currentSizes = m_Ui->splitter->sizes(); |
|
143 | auto currentSizes = m_Ui->splitter->sizes(); | |
144 | if (checked) { |
|
144 | if (checked) { | |
145 | // adjust sizes individually here, e.g. |
|
145 | // adjust sizes individually here, e.g. | |
146 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); |
|
146 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); | |
147 | currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); |
|
147 | currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); | |
148 | m_Ui->splitter->setSizes(currentSizes); |
|
148 | m_Ui->splitter->setSizes(currentSizes); | |
149 | } |
|
149 | } | |
150 | else { |
|
150 | else { | |
151 | // adjust sizes individually here, e.g. |
|
151 | // adjust sizes individually here, e.g. | |
152 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); |
|
152 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); | |
153 | currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); |
|
153 | currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); | |
154 | m_Ui->splitter->setSizes(currentSizes); |
|
154 | m_Ui->splitter->setSizes(currentSizes); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | }; |
|
157 | }; | |
158 |
|
158 | |||
159 |
|
159 | |||
160 | connect(openLeftInspectorAction, &QAction::triggered, |
|
160 | connect(openLeftInspectorAction, &QAction::triggered, | |
161 | [openInspector, openLeftInspectorAction](bool checked) { |
|
161 | [openInspector, openLeftInspectorAction](bool checked) { | |
162 | openInspector(checked, false, openLeftInspectorAction); |
|
162 | openInspector(checked, false, openLeftInspectorAction); | |
163 | }); |
|
163 | }); | |
164 | connect(openRightInspectorAction, &QAction::triggered, |
|
164 | connect(openRightInspectorAction, &QAction::triggered, | |
165 | [openInspector, openRightInspectorAction](bool checked) { |
|
165 | [openInspector, openRightInspectorAction](bool checked) { | |
166 | openInspector(checked, true, openRightInspectorAction); |
|
166 | openInspector(checked, true, openRightInspectorAction); | |
167 | }); |
|
167 | }); | |
168 |
|
168 | |||
169 | this->menuBar()->addAction(tr("File")); |
|
169 | this->menuBar()->addAction(tr("File")); | |
170 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); |
|
170 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); | |
171 |
|
171 | |||
172 | auto timeWidget = new TimeWidget{}; |
|
172 | auto timeWidget = new TimeWidget{}; | |
173 | mainToolBar->addWidget(timeWidget); |
|
173 | mainToolBar->addWidget(timeWidget); | |
174 |
|
174 | |||
175 | // Widgets / controllers connections |
|
175 | // Widgets / controllers connections | |
176 |
|
176 | |||
177 | // DataSource |
|
177 | // DataSource | |
178 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), |
|
178 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), | |
179 | m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); |
|
179 | m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); | |
180 |
|
180 | |||
181 | // Time |
|
181 | // Time | |
182 | connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(), |
|
182 | connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(), | |
183 | SLOT(onTimeToUpdate(SqpDateTime))); |
|
183 | SLOT(onTimeToUpdate(SqpDateTime))); | |
184 |
|
184 | |||
185 | // Variable |
|
185 | // Widgets / widgets connections | |
186 | qRegisterMetaType<std::shared_ptr<Variable> >(); |
|
186 | qRegisterMetaType<std::shared_ptr<Variable> >(); | |
187 | connect(&sqpApp->visualizationController(), SIGNAL(variableCreated(std::shared_ptr<Variable>)), |
|
187 | ||
188 | m_Ui->view, SLOT(displayVariable(std::shared_ptr<Variable>))); |
|
188 | // For the following connections, we use DirectConnection to allow each widget that can | |
|
189 | // potentially attach a menu to the variable's menu to do so before this menu is displayed. | |||
|
190 | // The order of connections is also important, since it determines the order in which each | |||
|
191 | // widget will attach its menu | |||
|
192 | connect(m_Ui->variableInspectorWidget, | |||
|
193 | SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, std::shared_ptr<Variable>)), m_Ui->view, | |||
|
194 | SLOT(attachVariableMenu(QMenu *, std::shared_ptr<Variable>)), Qt::DirectConnection); | |||
189 |
|
195 | |||
190 | /* QLopGUI::registerMenuBar(menuBar()); |
|
196 | /* QLopGUI::registerMenuBar(menuBar()); | |
191 | this->setWindowIcon(QIcon(":/sciqlopLOGO.svg")); |
|
197 | this->setWindowIcon(QIcon(":/sciqlopLOGO.svg")); | |
192 | this->m_progressWidget = new QWidget(); |
|
198 | this->m_progressWidget = new QWidget(); | |
193 | this->m_progressLayout = new QVBoxLayout(this->m_progressWidget); |
|
199 | this->m_progressLayout = new QVBoxLayout(this->m_progressWidget); | |
194 | this->m_progressWidget->setLayout(this->m_progressLayout); |
|
200 | this->m_progressWidget->setLayout(this->m_progressLayout); | |
195 | this->m_progressWidget->setWindowModality(Qt::WindowModal); |
|
201 | this->m_progressWidget->setWindowModality(Qt::WindowModal); | |
196 | m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); |
|
202 | m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); | |
197 | for(int i=0;i<OMP_THREADS;i++) |
|
203 | for(int i=0;i<OMP_THREADS;i++) | |
198 | { |
|
204 | { | |
199 | this->m_progress.append(new QProgressBar(this->m_progressWidget)); |
|
205 | this->m_progress.append(new QProgressBar(this->m_progressWidget)); | |
200 | this->m_progress.last()->setMinimum(0); |
|
206 | this->m_progress.last()->setMinimum(0); | |
201 | this->m_progress.last()->setMaximum(100); |
|
207 | this->m_progress.last()->setMaximum(100); | |
202 | this->m_progressLayout->addWidget(this->m_progress.last()); |
|
208 | this->m_progressLayout->addWidget(this->m_progress.last()); | |
203 | this->m_progressWidget->hide(); |
|
209 | this->m_progressWidget->hide(); | |
204 | this->m_progressThreadIds[i] = -1; |
|
210 | this->m_progressThreadIds[i] = -1; | |
205 | } |
|
211 | } | |
206 | this->m_progressWidget->setWindowTitle("Loading File"); |
|
212 | this->m_progressWidget->setWindowTitle("Loading File"); | |
207 | const QList<QLopService*>ServicesToLoad=QList<QLopService*>() |
|
213 | const QList<QLopService*>ServicesToLoad=QList<QLopService*>() | |
208 | << QLopCore::self() |
|
214 | << QLopCore::self() | |
209 | << QLopPlotManager::self() |
|
215 | << QLopPlotManager::self() | |
210 | << QLopCodecManager::self() |
|
216 | << QLopCodecManager::self() | |
211 | << FileDownloader::self() |
|
217 | << FileDownloader::self() | |
212 | << QLopDataBase::self() |
|
218 | << QLopDataBase::self() | |
213 | << SpaceData::self(); |
|
219 | << SpaceData::self(); | |
214 |
|
220 | |||
215 | CDFCodec::registerToManager(); |
|
221 | CDFCodec::registerToManager(); | |
216 | AMDATXTCodec::registerToManager(); |
|
222 | AMDATXTCodec::registerToManager(); | |
217 |
|
223 | |||
218 |
|
224 | |||
219 | for(int i=0;i<ServicesToLoad.count();i++) |
|
225 | for(int i=0;i<ServicesToLoad.count();i++) | |
220 | { |
|
226 | { | |
221 | qDebug()<<ServicesToLoad.at(i)->serviceName(); |
|
227 | qDebug()<<ServicesToLoad.at(i)->serviceName(); | |
222 | ServicesToLoad.at(i)->initialize(); //must be called before getGUI |
|
228 | ServicesToLoad.at(i)->initialize(); //must be called before getGUI | |
223 | QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI(); |
|
229 | QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI(); | |
224 | if(wdgt) |
|
230 | if(wdgt) | |
225 | { |
|
231 | { | |
226 | wdgt->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
232 | wdgt->setAllowedAreas(Qt::AllDockWidgetAreas); | |
227 | this->addDockWidget(Qt::TopDockWidgetArea,wdgt); |
|
233 | this->addDockWidget(Qt::TopDockWidgetArea,wdgt); | |
228 | } |
|
234 | } | |
229 | PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i)); |
|
235 | PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i)); | |
230 | }*/ |
|
236 | }*/ | |
231 | } |
|
237 | } | |
232 |
|
238 | |||
233 | MainWindow::~MainWindow() |
|
239 | MainWindow::~MainWindow() | |
234 | { |
|
240 | { | |
235 | } |
|
241 | } | |
236 |
|
242 | |||
237 |
|
243 | |||
238 | void MainWindow::changeEvent(QEvent *e) |
|
244 | void MainWindow::changeEvent(QEvent *e) | |
239 | { |
|
245 | { | |
240 | QMainWindow::changeEvent(e); |
|
246 | QMainWindow::changeEvent(e); | |
241 | switch (e->type()) { |
|
247 | switch (e->type()) { | |
242 | case QEvent::LanguageChange: |
|
248 | case QEvent::LanguageChange: | |
243 | m_Ui->retranslateUi(this); |
|
249 | m_Ui->retranslateUi(this); | |
244 | break; |
|
250 | break; | |
245 | default: |
|
251 | default: | |
246 | break; |
|
252 | break; | |
247 | } |
|
253 | } | |
248 | } |
|
254 | } |
@@ -1,59 +1,59 | |||||
1 | # |
|
1 | # | |
2 | # Generate the source package of SciqLop. |
|
2 | # Generate the source package of SciqLop. | |
3 | # |
|
3 | # | |
4 |
|
4 | |||
5 | install(DIRECTORY |
|
5 | install(DIRECTORY | |
6 | ${EXECUTABLE_OUTPUT_PATH} |
|
6 | ${EXECUTABLE_OUTPUT_PATH} | |
7 | DESTINATION "." |
|
7 | DESTINATION "." | |
8 | USE_SOURCE_PERMISSIONS |
|
8 | USE_SOURCE_PERMISSIONS | |
9 | COMPONENT CORE |
|
9 | COMPONENT CORE | |
10 | PATTERN "*.a" EXCLUDE |
|
10 | PATTERN "*.a" EXCLUDE | |
11 | ) |
|
11 | ) | |
12 |
|
12 | |||
13 | set(EXECUTABLEDOTEXTENSION) |
|
13 | set(EXECUTABLEDOTEXTENSION) | |
14 | if(WIN32) |
|
14 | if(WIN32) | |
15 | set(EXECUTABLEDOTEXTENSION ".exe") |
|
15 | set(EXECUTABLEDOTEXTENSION ".exe") | |
16 | endif(WIN32) |
|
16 | endif(WIN32) | |
17 | set (SCIQLOP_EXE_LOCATION ${EXECUTABLE_OUTPUT_PATH}/${EXECUTABLE_NAME}${EXECUTABLEDOTEXTENSION}) |
|
17 | set (SCIQLOP_EXE_LOCATION ${EXECUTABLE_OUTPUT_PATH}/${EXECUTABLE_NAME}${EXECUTABLEDOTEXTENSION}) | |
18 |
|
18 | |||
19 | if(WIN32) |
|
19 | if(WIN32) | |
20 | include ("cmake/sciqlop_package_qt.cmake") |
|
20 | include ("cmake/sciqlop_package_qt.cmake") | |
21 | endif(WIN32) |
|
21 | endif(WIN32) | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | SET (CPACK_PACKAGE_VENDOR "CNRS") |
|
24 | SET (CPACK_PACKAGE_VENDOR "CNRS") | |
25 | SET (CPACK_PACKAGE_VERSION_MAJOR "${SCIQLOP_VERSION_MAJOR}") |
|
25 | SET (CPACK_PACKAGE_VERSION_MAJOR "${SCIQLOP_VERSION_MAJOR}") | |
26 | SET (CPACK_PACKAGE_VERSION_MINOR "${SCIQLOP_VERSION_MINOR}") |
|
26 | SET (CPACK_PACKAGE_VERSION_MINOR "${SCIQLOP_VERSION_MINOR}") | |
27 | SET (CPACK_PACKAGE_VERSION_PATCH "${SCIQLOP_VERSION_PATCH}${SCIQLOP_VERSION_SUFFIX}") |
|
27 | SET (CPACK_PACKAGE_VERSION_PATCH "${SCIQLOP_VERSION_PATCH}${SCIQLOP_VERSION_SUFFIX}") | |
28 | SET (CPACK_PACKAGE_VERSION "${SCIQLOP_VERSION}") |
|
28 | SET (CPACK_PACKAGE_VERSION "${SCIQLOP_VERSION}") | |
29 |
SET (CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/ |
|
29 | SET (CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/COPYING) | |
30 | SET (CPACK_PACKAGE_CONTACT "nicolas.aunai@lpp.polytechnique.fr") |
|
30 | SET (CPACK_PACKAGE_CONTACT "nicolas.aunai@lpp.polytechnique.fr") | |
31 | SET(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.md) |
|
31 | SET(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.md) | |
32 | # SET(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_SOURCE_DIR}/WARN.txt) |
|
32 | # SET(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_SOURCE_DIR}/WARN.txt) | |
33 |
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/ |
|
33 | SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING) | |
34 | # SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_NAME}-${PROJECT_VERSION}) |
|
34 | # SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_NAME}-${PROJECT_VERSION}) | |
35 | SET(FULLBUILD ON) |
|
35 | SET(FULLBUILD ON) | |
36 |
|
36 | |||
37 | SET(CPACK_PACKAGE_NAME ${PROJECT_NAME}) |
|
37 | SET(CPACK_PACKAGE_NAME ${PROJECT_NAME}) | |
38 | SET(CPACK_GENERATOR "NSIS") |
|
38 | SET(CPACK_GENERATOR "NSIS") | |
39 | SET(CPACK_MONOLITHIC_INSTALL 1) |
|
39 | SET(CPACK_MONOLITHIC_INSTALL 1) | |
40 | #SET(CPACK_COMPONENTS_ALL sciqlop qt) |
|
40 | #SET(CPACK_COMPONENTS_ALL sciqlop qt) | |
41 | SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Setup") |
|
41 | SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Setup") | |
42 | SET(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_NAME}) |
|
42 | SET(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_NAME}) | |
43 |
|
43 | |||
44 | set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) |
|
44 | set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) | |
45 |
|
45 | |||
46 | if (WIN32) |
|
46 | if (WIN32) | |
47 | SET(CPACK_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) |
|
47 | SET(CPACK_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) | |
48 | SET(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON) |
|
48 | SET(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON) | |
49 | SET(CPACK_NSIS_COMPONENT_INSTALL ON) |
|
49 | SET(CPACK_NSIS_COMPONENT_INSTALL ON) | |
50 | SET(CPACK_SYSTEM_NAME "MinGW32") |
|
50 | SET(CPACK_SYSTEM_NAME "MinGW32") | |
51 | SET(CPACK_PACKAGING_INSTALL_PREFIX "") |
|
51 | SET(CPACK_PACKAGING_INSTALL_PREFIX "") | |
52 | #SET(CPACK_GENERATOR "NSIS") |
|
52 | #SET(CPACK_GENERATOR "NSIS") | |
53 | SET(CPACK_NSIS_DISPLAY_NAME ${PROJECT_NAME}) |
|
53 | SET(CPACK_NSIS_DISPLAY_NAME ${PROJECT_NAME}) | |
54 | SET(CPACK_NSIS_MUI_FINISHPAGE_RUN ${SCIQLOP_EXECUTABLE_NAME}) |
|
54 | SET(CPACK_NSIS_MUI_FINISHPAGE_RUN ${SCIQLOP_EXECUTABLE_NAME}) | |
55 | SET(CPACK_NSIS_MUI_ICON ${SCIQLOP_EXECUTABLE_ICON_LOCATION}) |
|
55 | SET(CPACK_NSIS_MUI_ICON ${SCIQLOP_EXECUTABLE_ICON_LOCATION}) | |
56 | SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\${SCIQLOP_EXECUTABLE_NAME}.exe") |
|
56 | SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\${SCIQLOP_EXECUTABLE_NAME}.exe") | |
57 | endif (WIN32) |
|
57 | endif (WIN32) | |
58 |
|
58 | |||
59 | INCLUDE(CPack) |
|
59 | INCLUDE(CPack) |
@@ -1,59 +1,70 | |||||
1 | #ifndef SCIQLOP_DATASERIES_H |
|
1 | #ifndef SCIQLOP_DATASERIES_H | |
2 | #define SCIQLOP_DATASERIES_H |
|
2 | #define SCIQLOP_DATASERIES_H | |
3 |
|
3 | |||
4 | #include <Data/ArrayData.h> |
|
4 | #include <Data/ArrayData.h> | |
5 | #include <Data/IDataSeries.h> |
|
5 | #include <Data/IDataSeries.h> | |
6 |
|
6 | |||
|
7 | #include <QLoggingCategory> | |||
|
8 | ||||
7 | #include <memory> |
|
9 | #include <memory> | |
8 |
|
10 | |||
|
11 | ||||
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_DataSeries) | |||
|
13 | Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries") | |||
|
14 | ||||
|
15 | ||||
9 | /** |
|
16 | /** | |
10 | * @brief The DataSeries class is the base (abstract) implementation of IDataSeries. |
|
17 | * @brief The DataSeries class is the base (abstract) implementation of IDataSeries. | |
11 | * |
|
18 | * | |
12 | * It proposes to set a dimension for the values ββdata |
|
19 | * It proposes to set a dimension for the values ββdata | |
13 | * |
|
20 | * | |
14 | * @tparam Dim The dimension of the values data |
|
21 | * @tparam Dim The dimension of the values data | |
15 | * |
|
22 | * | |
16 | */ |
|
23 | */ | |
17 | template <int Dim> |
|
24 | template <int Dim> | |
18 | class DataSeries : public IDataSeries { |
|
25 | class DataSeries : public IDataSeries { | |
19 | public: |
|
26 | public: | |
20 | /// @sa IDataSeries::xAxisData() |
|
27 | /// @sa IDataSeries::xAxisData() | |
21 | std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; } |
|
28 | std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; } | |
22 |
|
29 | |||
23 | /// @sa IDataSeries::xAxisUnit() |
|
30 | /// @sa IDataSeries::xAxisUnit() | |
24 | Unit xAxisUnit() const override { return m_XAxisUnit; } |
|
31 | Unit xAxisUnit() const override { return m_XAxisUnit; } | |
25 |
|
32 | |||
26 | /// @return the values dataset |
|
33 | /// @return the values dataset | |
27 | std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; } |
|
34 | std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; } | |
28 |
|
35 | |||
29 | /// @sa IDataSeries::valuesUnit() |
|
36 | /// @sa IDataSeries::valuesUnit() | |
30 | Unit valuesUnit() const override { return m_ValuesUnit; } |
|
37 | Unit valuesUnit() const override { return m_ValuesUnit; } | |
31 |
|
38 | |||
32 | /// @sa IDataSeries::merge() |
|
39 | /// @sa IDataSeries::merge() | |
33 | void merge(IDataSeries *dataSeries) override |
|
40 | void merge(IDataSeries *dataSeries) override | |
34 | { |
|
41 | { | |
35 | if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) { |
|
42 | if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) { | |
36 | m_XAxisData->merge(dimDataSeries->xAxisData().get()); |
|
43 | m_XAxisData->merge(dimDataSeries->xAxisData().get()); | |
37 | m_ValuesData->merge(dimDataSeries->valuesData().get()); |
|
44 | m_ValuesData->merge(dimDataSeries->valuesData().get()); | |
38 | } |
|
45 | } | |
|
46 | else { | |||
|
47 | qCWarning(LOG_DataSeries()) | |||
|
48 | << QObject::tr("Dection of a type of IDataSeries we cannot merge with !"); | |||
|
49 | } | |||
39 | } |
|
50 | } | |
40 |
|
51 | |||
41 | protected: |
|
52 | protected: | |
42 | /// Protected ctor (DataSeries is abstract) |
|
53 | /// Protected ctor (DataSeries is abstract) | |
43 | explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit, |
|
54 | explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit, | |
44 | std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit) |
|
55 | std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit) | |
45 | : m_XAxisData{xAxisData}, |
|
56 | : m_XAxisData{xAxisData}, | |
46 | m_XAxisUnit{xAxisUnit}, |
|
57 | m_XAxisUnit{xAxisUnit}, | |
47 | m_ValuesData{valuesData}, |
|
58 | m_ValuesData{valuesData}, | |
48 | m_ValuesUnit{valuesUnit} |
|
59 | m_ValuesUnit{valuesUnit} | |
49 | { |
|
60 | { | |
50 | } |
|
61 | } | |
51 |
|
62 | |||
52 | private: |
|
63 | private: | |
53 | std::shared_ptr<ArrayData<1> > m_XAxisData; |
|
64 | std::shared_ptr<ArrayData<1> > m_XAxisData; | |
54 | Unit m_XAxisUnit; |
|
65 | Unit m_XAxisUnit; | |
55 | std::shared_ptr<ArrayData<Dim> > m_ValuesData; |
|
66 | std::shared_ptr<ArrayData<Dim> > m_ValuesData; | |
56 | Unit m_ValuesUnit; |
|
67 | Unit m_ValuesUnit; | |
57 | }; |
|
68 | }; | |
58 |
|
69 | |||
59 | #endif // SCIQLOP_DATASERIES_H |
|
70 | #endif // SCIQLOP_DATASERIES_H |
@@ -1,39 +1,39 | |||||
1 | #ifndef SCIQLOP_IDATAPROVIDER_H |
|
1 | #ifndef SCIQLOP_IDATAPROVIDER_H | |
2 | #define SCIQLOP_IDATAPROVIDER_H |
|
2 | #define SCIQLOP_IDATAPROVIDER_H | |
3 |
|
3 | |||
4 | #include <memory> |
|
4 | #include <memory> | |
5 |
|
5 | |||
6 | #include <QObject> |
|
6 | #include <QObject> | |
7 |
|
7 | |||
8 | #include <Data/SqpDateTime.h> |
|
8 | #include <Data/SqpDateTime.h> | |
9 |
|
9 | |||
10 | class DataProviderParameters; |
|
10 | class DataProviderParameters; | |
11 | class IDataSeries; |
|
11 | class IDataSeries; | |
12 |
|
12 | |||
13 | /** |
|
13 | /** | |
14 | * @brief The IDataProvider interface aims to declare a data provider. |
|
14 | * @brief The IDataProvider interface aims to declare a data provider. | |
15 | * |
|
15 | * | |
16 | * A data provider is an entity that generates data and returns it according to various parameters |
|
16 | * A data provider is an entity that generates data and returns it according to various parameters | |
17 | * (time interval, product to retrieve the data, etc.) |
|
17 | * (time interval, product to retrieve the data, etc.) | |
18 | * |
|
18 | * | |
19 | * @sa IDataSeries |
|
19 | * @sa IDataSeries | |
20 | */ |
|
20 | */ | |
21 | class IDataProvider : public QObject { |
|
21 | class IDataProvider : public QObject { | |
22 |
|
22 | |||
23 | Q_OBJECT |
|
23 | Q_OBJECT | |
24 | public: |
|
24 | public: | |
25 | virtual ~IDataProvider() noexcept = default; |
|
25 | virtual ~IDataProvider() noexcept = default; | |
26 |
|
26 | |||
27 | virtual std::unique_ptr<IDataSeries> |
|
27 | virtual std::unique_ptr<IDataSeries> | |
28 | retrieveData(const DataProviderParameters ¶meters) const = 0; |
|
28 | retrieveData(const DataProviderParameters ¶meters) const = 0; | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0; |
|
31 | virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0; | |
32 |
|
32 | |||
33 | signals: |
|
33 | signals: | |
34 | void dataProvided(std::shared_ptr<IDataSeries> dateSerie, SqpDateTime dateTime); |
|
34 | void dataProvided(std::shared_ptr<IDataSeries> dateSerie, const SqpDateTime &dateTime); | |
35 | }; |
|
35 | }; | |
36 | // Required for using shared_ptr in signals/slots |
|
36 | // Required for using shared_ptr in signals/slots | |
37 | Q_DECLARE_METATYPE(std::shared_ptr<IDataProvider>) |
|
37 | Q_DECLARE_METATYPE(std::shared_ptr<IDataProvider>) | |
38 |
|
38 | |||
39 | #endif // SCIQLOP_IDATAPROVIDER_H |
|
39 | #endif // SCIQLOP_IDATAPROVIDER_H |
@@ -1,54 +1,54 | |||||
1 | #ifndef SCIQLOP_VARIABLE_H |
|
1 | #ifndef SCIQLOP_VARIABLE_H | |
2 | #define SCIQLOP_VARIABLE_H |
|
2 | #define SCIQLOP_VARIABLE_H | |
3 |
|
3 | |||
4 | #include <Data/SqpDateTime.h> |
|
4 | #include <Data/SqpDateTime.h> | |
5 |
|
5 | |||
6 |
|
6 | |||
7 | #include <QLoggingCategory> |
|
7 | #include <QLoggingCategory> | |
8 | #include <QObject> |
|
8 | #include <QObject> | |
9 |
|
9 | |||
10 | #include <Common/spimpl.h> |
|
10 | #include <Common/spimpl.h> | |
11 |
|
11 | |||
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_Variable) |
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_Variable) | |
13 |
|
13 | |||
14 | class IDataSeries; |
|
14 | class IDataSeries; | |
15 | class QString; |
|
15 | class QString; | |
16 |
|
16 | |||
17 | /** |
|
17 | /** | |
18 | * @brief The Variable class represents a variable in SciQlop. |
|
18 | * @brief The Variable class represents a variable in SciQlop. | |
19 | */ |
|
19 | */ | |
20 | class Variable : public QObject { |
|
20 | class Variable : public QObject { | |
21 |
|
21 | |||
22 | Q_OBJECT |
|
22 | Q_OBJECT | |
23 |
|
23 | |||
24 | public: |
|
24 | public: | |
25 | explicit Variable(const QString &name, const QString &unit, const QString &mission, |
|
25 | explicit Variable(const QString &name, const QString &unit, const QString &mission, | |
26 | const SqpDateTime &dateTime); |
|
26 | const SqpDateTime &dateTime); | |
27 |
|
27 | |||
28 | QString name() const noexcept; |
|
28 | QString name() const noexcept; | |
29 | QString mission() const noexcept; |
|
29 | QString mission() const noexcept; | |
30 | QString unit() const noexcept; |
|
30 | QString unit() const noexcept; | |
31 | SqpDateTime dateTime() const noexcept; |
|
31 | SqpDateTime dateTime() const noexcept; | |
32 |
|
32 | |||
33 | /// @return the data of the variable, nullptr if there is no data |
|
33 | /// @return the data of the variable, nullptr if there is no data | |
34 | IDataSeries *dataSeries() const noexcept; |
|
34 | IDataSeries *dataSeries() const noexcept; | |
35 |
|
35 | |||
36 | bool contains(SqpDateTime dateTime); |
|
36 | bool contains(const SqpDateTime &dateTime); | |
37 | void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept; |
|
37 | void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept; | |
38 |
|
38 | |||
39 | public slots: |
|
39 | public slots: | |
40 | void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; |
|
40 | void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; | |
41 |
|
41 | |||
42 | signals: |
|
42 | signals: | |
43 | void dataCacheUpdated(); |
|
43 | void dataCacheUpdated(); | |
44 |
|
44 | |||
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | class VariablePrivate; |
|
47 | class VariablePrivate; | |
48 | spimpl::unique_impl_ptr<VariablePrivate> impl; |
|
48 | spimpl::unique_impl_ptr<VariablePrivate> impl; | |
49 | }; |
|
49 | }; | |
50 |
|
50 | |||
51 | // Required for using shared_ptr in signals/slots |
|
51 | // Required for using shared_ptr in signals/slots | |
52 | Q_DECLARE_METATYPE(std::shared_ptr<Variable>) |
|
52 | Q_DECLARE_METATYPE(std::shared_ptr<Variable>) | |
53 |
|
53 | |||
54 | #endif // SCIQLOP_VARIABLE_H |
|
54 | #endif // SCIQLOP_VARIABLE_H |
@@ -1,33 +1,33 | |||||
1 | #ifndef SCIQLOP_VARIABLECACHECONTROLLER_H |
|
1 | #ifndef SCIQLOP_VARIABLECACHECONTROLLER_H | |
2 | #define SCIQLOP_VARIABLECACHECONTROLLER_H |
|
2 | #define SCIQLOP_VARIABLECACHECONTROLLER_H | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 |
|
5 | |||
6 | #include <Data/SqpDateTime.h> |
|
6 | #include <Data/SqpDateTime.h> | |
7 |
|
7 | |||
8 | #include <Common/spimpl.h> |
|
8 | #include <Common/spimpl.h> | |
9 |
|
9 | |||
10 | class Variable; |
|
10 | class Variable; | |
11 |
|
11 | |||
12 |
/// This class aims to store in the ca |
|
12 | /// This class aims to store in the cache all of the dateTime already requested to the variable. | |
13 | class VariableCacheController : public QObject { |
|
13 | class VariableCacheController : public QObject { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | explicit VariableCacheController(QObject *parent = 0); |
|
16 | explicit VariableCacheController(QObject *parent = 0); | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | void addDateTime(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); |
|
19 | void addDateTime(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); | |
20 |
|
20 | |||
21 | /// Return all of the SqpDataTime part of the dateTime whose are not in the cache |
|
21 | /// Return all of the SqpDataTime part of the dateTime whose are not in the cache | |
22 | QVector<SqpDateTime> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, |
|
22 | QVector<SqpDateTime> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, | |
23 | const SqpDateTime &dateTime); |
|
23 | const SqpDateTime &dateTime); | |
24 |
|
24 | |||
25 |
|
25 | |||
26 | QVector<SqpDateTime> dateCacheList(std::shared_ptr<Variable> variable) const noexcept; |
|
26 | QVector<SqpDateTime> dateCacheList(std::shared_ptr<Variable> variable) const noexcept; | |
27 |
|
27 | |||
28 | private: |
|
28 | private: | |
29 | class VariableCacheControllerPrivate; |
|
29 | class VariableCacheControllerPrivate; | |
30 | spimpl::unique_impl_ptr<VariableCacheControllerPrivate> impl; |
|
30 | spimpl::unique_impl_ptr<VariableCacheControllerPrivate> impl; | |
31 | }; |
|
31 | }; | |
32 |
|
32 | |||
33 | #endif // SCIQLOP_VARIABLECACHECONTROLLER_H |
|
33 | #endif // SCIQLOP_VARIABLECACHECONTROLLER_H |
@@ -1,49 +1,51 | |||||
1 | #ifndef SCIQLOP_VARIABLEMODEL_H |
|
1 | #ifndef SCIQLOP_VARIABLEMODEL_H | |
2 | #define SCIQLOP_VARIABLEMODEL_H |
|
2 | #define SCIQLOP_VARIABLEMODEL_H | |
3 |
|
3 | |||
4 |
|
4 | |||
5 | #include <Data/SqpDateTime.h> |
|
5 | #include <Data/SqpDateTime.h> | |
6 |
|
6 | |||
7 | #include <QAbstractTableModel> |
|
7 | #include <QAbstractTableModel> | |
8 | #include <QLoggingCategory> |
|
8 | #include <QLoggingCategory> | |
9 |
|
9 | |||
10 | #include <Common/spimpl.h> |
|
10 | #include <Common/spimpl.h> | |
11 |
|
11 | |||
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) |
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) | |
13 |
|
13 | |||
14 | class IDataSeries; |
|
14 | class IDataSeries; | |
15 | class Variable; |
|
15 | class Variable; | |
16 |
|
16 | |||
17 | /** |
|
17 | /** | |
18 | * @brief The VariableModel class aims to hold the variables that have been created in SciQlop |
|
18 | * @brief The VariableModel class aims to hold the variables that have been created in SciQlop | |
19 | */ |
|
19 | */ | |
20 | class VariableModel : public QAbstractTableModel { |
|
20 | class VariableModel : public QAbstractTableModel { | |
21 | public: |
|
21 | public: | |
22 | explicit VariableModel(QObject *parent = nullptr); |
|
22 | explicit VariableModel(QObject *parent = nullptr); | |
23 |
|
23 | |||
24 | /** |
|
24 | /** | |
25 | * Creates a new variable in the model |
|
25 | * Creates a new variable in the model | |
26 | * @param name the name of the new variable |
|
26 | * @param name the name of the new variable | |
27 | * @param dateTime the dateTime of the new variable |
|
27 | * @param dateTime the dateTime of the new variable | |
28 | * @param defaultDataSeries the default data of the new variable |
|
28 | * @param defaultDataSeries the default data of the new variable | |
29 | * @return the pointer to the new variable |
|
29 | * @return the pointer to the new variable | |
30 | */ |
|
30 | */ | |
31 | std::shared_ptr<Variable> |
|
31 | std::shared_ptr<Variable> | |
32 | createVariable(const QString &name, const SqpDateTime &dateTime, |
|
32 | createVariable(const QString &name, const SqpDateTime &dateTime, | |
33 | std::unique_ptr<IDataSeries> defaultDataSeries) noexcept; |
|
33 | std::unique_ptr<IDataSeries> defaultDataSeries) noexcept; | |
34 |
|
34 | |||
|
35 | std::shared_ptr<Variable> variable(int index) const; | |||
|
36 | ||||
35 | // /////////////////////////// // |
|
37 | // /////////////////////////// // | |
36 | // QAbstractTableModel methods // |
|
38 | // QAbstractTableModel methods // | |
37 | // /////////////////////////// // |
|
39 | // /////////////////////////// // | |
38 | virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override; |
|
40 | virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override; | |
39 | virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override; |
|
41 | virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override; | |
40 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
|
42 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | |
41 | virtual QVariant headerData(int section, Qt::Orientation orientation, |
|
43 | virtual QVariant headerData(int section, Qt::Orientation orientation, | |
42 | int role = Qt::DisplayRole) const override; |
|
44 | int role = Qt::DisplayRole) const override; | |
43 |
|
45 | |||
44 | private: |
|
46 | private: | |
45 | class VariableModelPrivate; |
|
47 | class VariableModelPrivate; | |
46 | spimpl::unique_impl_ptr<VariableModelPrivate> impl; |
|
48 | spimpl::unique_impl_ptr<VariableModelPrivate> impl; | |
47 | }; |
|
49 | }; | |
48 |
|
50 | |||
49 | #endif // SCIQLOP_VARIABLEMODEL_H |
|
51 | #endif // SCIQLOP_VARIABLEMODEL_H |
@@ -1,89 +1,89 | |||||
1 | #include "Variable/Variable.h" |
|
1 | #include "Variable/Variable.h" | |
2 |
|
2 | |||
3 | #include <Data/IDataSeries.h> |
|
3 | #include <Data/IDataSeries.h> | |
4 | #include <Data/SqpDateTime.h> |
|
4 | #include <Data/SqpDateTime.h> | |
5 |
|
5 | |||
6 | Q_LOGGING_CATEGORY(LOG_Variable, "Variable") |
|
6 | Q_LOGGING_CATEGORY(LOG_Variable, "Variable") | |
7 |
|
7 | |||
8 | struct Variable::VariablePrivate { |
|
8 | struct Variable::VariablePrivate { | |
9 | explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission, |
|
9 | explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission, | |
10 | const SqpDateTime &dateTime) |
|
10 | const SqpDateTime &dateTime) | |
11 | : m_Name{name}, |
|
11 | : m_Name{name}, | |
12 | m_Unit{unit}, |
|
12 | m_Unit{unit}, | |
13 | m_Mission{mission}, |
|
13 | m_Mission{mission}, | |
14 | m_DateTime{dateTime}, |
|
14 | m_DateTime{dateTime}, | |
15 | m_DataSeries{nullptr} |
|
15 | m_DataSeries{nullptr} | |
16 | { |
|
16 | { | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 | QString m_Name; |
|
19 | QString m_Name; | |
20 | QString m_Unit; |
|
20 | QString m_Unit; | |
21 | QString m_Mission; |
|
21 | QString m_Mission; | |
22 |
|
22 | |||
23 | SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache. |
|
23 | SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache. | |
24 | std::unique_ptr<IDataSeries> m_DataSeries; |
|
24 | std::unique_ptr<IDataSeries> m_DataSeries; | |
25 | }; |
|
25 | }; | |
26 |
|
26 | |||
27 | Variable::Variable(const QString &name, const QString &unit, const QString &mission, |
|
27 | Variable::Variable(const QString &name, const QString &unit, const QString &mission, | |
28 | const SqpDateTime &dateTime) |
|
28 | const SqpDateTime &dateTime) | |
29 | : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)} |
|
29 | : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)} | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | QString Variable::name() const noexcept |
|
33 | QString Variable::name() const noexcept | |
34 | { |
|
34 | { | |
35 | return impl->m_Name; |
|
35 | return impl->m_Name; | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | QString Variable::mission() const noexcept |
|
38 | QString Variable::mission() const noexcept | |
39 | { |
|
39 | { | |
40 | return impl->m_Mission; |
|
40 | return impl->m_Mission; | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QString Variable::unit() const noexcept |
|
43 | QString Variable::unit() const noexcept | |
44 | { |
|
44 | { | |
45 | return impl->m_Unit; |
|
45 | return impl->m_Unit; | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | SqpDateTime Variable::dateTime() const noexcept |
|
48 | SqpDateTime Variable::dateTime() const noexcept | |
49 | { |
|
49 | { | |
50 | return impl->m_DateTime; |
|
50 | return impl->m_DateTime; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | void Variable::setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept |
|
53 | void Variable::setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept | |
54 | { |
|
54 | { | |
55 | if (!impl->m_DataSeries) { |
|
55 | if (!impl->m_DataSeries) { | |
56 | impl->m_DataSeries = std::move(dataSeries); |
|
56 | impl->m_DataSeries = std::move(dataSeries); | |
57 | } |
|
57 | } | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept |
|
60 | void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |
61 | { |
|
61 | { | |
62 | if (impl->m_DataSeries) { |
|
62 | if (impl->m_DataSeries) { | |
63 | impl->m_DataSeries->merge(dataSeries.get()); |
|
63 | impl->m_DataSeries->merge(dataSeries.get()); | |
64 |
|
64 | |||
65 | emit dataCacheUpdated(); |
|
65 | emit dataCacheUpdated(); | |
66 | } |
|
66 | } | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | IDataSeries *Variable::dataSeries() const noexcept |
|
69 | IDataSeries *Variable::dataSeries() const noexcept | |
70 | { |
|
70 | { | |
71 | return impl->m_DataSeries.get(); |
|
71 | return impl->m_DataSeries.get(); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | bool Variable::contains(SqpDateTime dateTime) |
|
74 | bool Variable::contains(const SqpDateTime &dateTime) | |
75 | { |
|
75 | { | |
76 | if (!impl->m_DateTime.contains(dateTime)) { |
|
76 | if (!impl->m_DateTime.contains(dateTime)) { | |
77 | // The current variable dateTime isn't enough to display the dateTime requested. |
|
77 | // The current variable dateTime isn't enough to display the dateTime requested. | |
78 | // We have to update it to the new dateTime requested. |
|
78 | // We have to update it to the new dateTime requested. | |
79 | // the correspondant new data to display will be given by the cache if possible and the |
|
79 | // the correspondant new data to display will be given by the cache if possible and the | |
80 | // provider if necessary. |
|
80 | // provider if necessary. | |
81 | qCInfo(LOG_Variable()) << "NEW DATE NEEDED"; |
|
81 | qCInfo(LOG_Variable()) << "NEW DATE NEEDED"; | |
82 |
|
82 | |||
83 | impl->m_DateTime = dateTime; |
|
83 | impl->m_DateTime = dateTime; | |
84 |
|
84 | |||
85 | return false; |
|
85 | return false; | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | return true; |
|
88 | return true; | |
89 | } |
|
89 | } |
@@ -1,173 +1,170 | |||||
1 | #include "Variable/VariableCacheController.h" |
|
1 | #include "Variable/VariableCacheController.h" | |
2 |
|
2 | |||
3 | #include "Variable/Variable.h" |
|
3 | #include "Variable/Variable.h" | |
4 | #include <unordered_map> |
|
4 | #include <unordered_map> | |
5 |
|
5 | |||
6 | struct VariableCacheController::VariableCacheControllerPrivate { |
|
6 | struct VariableCacheController::VariableCacheControllerPrivate { | |
7 |
|
7 | |||
8 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> > |
|
8 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> > | |
9 | m_VariableToSqpDateTimeListMap; |
|
9 | m_VariableToSqpDateTimeListMap; | |
10 |
|
10 | |||
11 | void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
11 | void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
12 | QVector<SqpDateTime> ¬InCache, int cacheIndex, |
|
12 | QVector<SqpDateTime> ¬InCache, int cacheIndex, | |
13 | double currentTStart); |
|
13 | double currentTStart); | |
14 |
|
14 | |||
15 | void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
15 | void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
16 | QVector<SqpDateTime> ¬InCache, int cacheIndex, |
|
16 | QVector<SqpDateTime> ¬InCache, int cacheIndex, | |
17 | double currentTStart); |
|
17 | double currentTStart); | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
20 | void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
21 | int cacheIndex); |
|
21 | int cacheIndex); | |
22 | }; |
|
22 | }; | |
23 |
|
23 | |||
24 |
|
24 | |||
25 | VariableCacheController::VariableCacheController(QObject *parent) |
|
25 | VariableCacheController::VariableCacheController(QObject *parent) | |
26 |
: QObject |
|
26 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()} | |
27 | { |
|
27 | { | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable, |
|
30 | void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable, | |
31 | const SqpDateTime &dateTime) |
|
31 | const SqpDateTime &dateTime) | |
32 | { |
|
32 | { | |
33 | if (variable) { |
|
33 | if (variable) { | |
34 | auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable); |
|
34 | auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable); | |
35 | if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) { |
|
35 | if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) { | |
36 | impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime); |
|
36 | impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime); | |
37 | } |
|
37 | } | |
38 | else { |
|
38 | else { | |
39 |
|
39 | |||
40 | // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure |
|
40 | // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure | |
41 | // that the list is ordered : l(0) < l(1). We assume also a < b |
|
41 | // that the list is ordered : l(0) < l(1). We assume also a < b | |
42 | // (with a & b of type SqpDateTime) means ts(b) > te(a) |
|
42 | // (with a & b of type SqpDateTime) means ts(b) > te(a) | |
43 |
|
43 | |||
44 | // The algorithm will try the merge of two interval: |
|
44 | // The algorithm will try the merge of two interval: | |
45 | // - dateTime will be compare with the first interval of the list: |
|
45 | // - dateTime will be compare with the first interval of the list: | |
46 | // A: if it is inferior, it will be inserted and it's finished. |
|
46 | // A: if it is inferior, it will be inserted and it's finished. | |
47 | // B: if it is in intersection, it will be merge then the merged one |
|
47 | // B: if it is in intersection, it will be merge then the merged one | |
48 | // will be compared to the next interval. The old one is remove from the list |
|
48 | // will be compared to the next interval. The old one is remove from the list | |
49 | // C: if it is superior, we do the same with the next interval of the list |
|
49 | // C: if it is superior, we do the same with the next interval of the list | |
50 |
|
50 | |||
51 | int cacheIndex = 0; |
|
|||
52 | impl->addDateTimeRecurse(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), |
|
51 | impl->addDateTimeRecurse(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), | |
53 |
|
|
52 | 0); | |
54 | } |
|
53 | } | |
55 | } |
|
54 | } | |
56 | } |
|
55 | } | |
57 |
|
56 | |||
58 | QVector<SqpDateTime> |
|
57 | QVector<SqpDateTime> | |
59 | VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, |
|
58 | VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, | |
60 | const SqpDateTime &dateTime) |
|
59 | const SqpDateTime &dateTime) | |
61 | { |
|
60 | { | |
62 | auto notInCache = QVector<SqpDateTime>{}; |
|
61 | auto notInCache = QVector<SqpDateTime>{}; | |
63 |
|
62 | |||
64 | // This algorithm is recursif. The idea is to localise the start time then the end time in the |
|
63 | // This algorithm is recursif. The idea is to localise the start time then the end time in the | |
65 | // list of date time request associated to the variable |
|
64 | // list of date time request associated to the variable | |
66 | // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b |
|
65 | // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b | |
67 | // (with a & b of type SqpDateTime) means ts(b) > te(a) |
|
66 | // (with a & b of type SqpDateTime) means ts(b) > te(a) | |
68 |
|
67 | |||
69 | impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), |
|
68 | impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), | |
70 | notInCache, 0, dateTime.m_TStart); |
|
69 | notInCache, 0, dateTime.m_TStart); | |
71 |
|
70 | |||
72 | return notInCache; |
|
71 | return notInCache; | |
73 | } |
|
72 | } | |
74 |
|
73 | |||
75 | QVector<SqpDateTime> |
|
74 | QVector<SqpDateTime> | |
76 | VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept |
|
75 | VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept | |
77 | { |
|
76 | { | |
78 | return impl->m_VariableToSqpDateTimeListMap.at(variable); |
|
77 | return impl->m_VariableToSqpDateTimeListMap.at(variable); | |
79 | } |
|
78 | } | |
80 |
|
79 | |||
81 | void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse( |
|
80 | void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse( | |
82 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex) |
|
81 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex) | |
83 | { |
|
82 | { | |
84 | const auto dateTimeListSize = dateTimeList.count(); |
|
83 | const auto dateTimeListSize = dateTimeList.count(); | |
85 | if (cacheIndex >= dateTimeListSize) { |
|
84 | if (cacheIndex >= dateTimeListSize) { | |
86 | dateTimeList.push_back(dateTime); |
|
85 | dateTimeList.push_back(dateTime); | |
87 | // there is no anymore interval to compore, we can just push_back it |
|
86 | // there is no anymore interval to compore, we can just push_back it | |
88 | return; |
|
87 | return; | |
89 | } |
|
88 | } | |
90 |
|
89 | |||
91 | auto currentDateTime = dateTimeList[cacheIndex]; |
|
90 | auto currentDateTime = dateTimeList[cacheIndex]; | |
92 |
|
91 | |||
93 | if (dateTime.m_TEnd < currentDateTime.m_TStart) { |
|
92 | if (dateTime.m_TEnd < currentDateTime.m_TStart) { | |
94 | // The compared one is < to current one compared, we can insert it |
|
93 | // The compared one is < to current one compared, we can insert it | |
95 | dateTimeList.insert(cacheIndex, dateTime); |
|
94 | dateTimeList.insert(cacheIndex, dateTime); | |
96 | } |
|
95 | } | |
97 |
|
||||
98 | else if (dateTime.m_TStart > currentDateTime.m_TEnd) { |
|
96 | else if (dateTime.m_TStart > currentDateTime.m_TEnd) { | |
99 | // The compared one is > to current one compared we can comparet if to the next one |
|
97 | // The compared one is > to current one compared we can comparet if to the next one | |
100 | addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex); |
|
98 | addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex); | |
101 | } |
|
99 | } | |
102 | else { |
|
100 | else { | |
103 | // Merge cases: we need to merge the two interval, remove the old one from the list then |
|
101 | // Merge cases: we need to merge the two interval, remove the old one from the list then | |
104 | // rerun the algo from this index with the merged interval |
|
102 | // rerun the algo from this index with the merged interval | |
105 | auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart); |
|
103 | auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart); | |
106 | auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd); |
|
104 | auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd); | |
107 | auto mergeDateTime = SqpDateTime{mTStart, mTEnd}; |
|
105 | auto mergeDateTime = SqpDateTime{mTStart, mTEnd}; | |
108 |
|
106 | |||
109 | dateTimeList.remove(cacheIndex); |
|
107 | dateTimeList.remove(cacheIndex); | |
110 | addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex); |
|
108 | addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex); | |
111 | } |
|
109 | } | |
112 | } |
|
110 | } | |
113 |
|
111 | |||
114 |
|
112 | |||
115 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd( |
|
113 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd( | |
116 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
114 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
117 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) |
|
115 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) | |
118 | { |
|
116 | { | |
119 | const auto dateTimeListSize = dateTimeList.count(); |
|
117 | const auto dateTimeListSize = dateTimeList.count(); | |
120 | if (cacheIndex >= dateTimeListSize) { |
|
118 | if (cacheIndex >= dateTimeListSize) { | |
121 | if (currentTStart < dateTime.m_TEnd) { |
|
119 | if (currentTStart < dateTime.m_TEnd) { | |
122 |
|
120 | |||
123 | // te localised after all other interval: The last interval is [currentTsart, te] |
|
121 | // te localised after all other interval: The last interval is [currentTsart, te] | |
124 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
122 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
125 | } |
|
123 | } | |
126 | return; |
|
124 | return; | |
127 | } |
|
125 | } | |
128 |
|
126 | |||
129 | auto currentDateTimeJ = dateTimeList[cacheIndex]; |
|
127 | auto currentDateTimeJ = dateTimeList[cacheIndex]; | |
130 | if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) { |
|
128 | if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) { | |
131 | // te localised between to interval: The last interval is [currentTsart, te] |
|
129 | // te localised between to interval: The last interval is [currentTsart, te] | |
132 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
130 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
133 | } |
|
131 | } | |
134 | else { |
|
132 | else { | |
135 | notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart}); |
|
133 | notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart}); | |
136 | if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) { |
|
134 | if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) { | |
137 | // te not localised before the current interval: we need to look at the next interval |
|
135 | // te not localised before the current interval: we need to look at the next interval | |
138 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex, |
|
136 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex, | |
139 | currentDateTimeJ.m_TEnd); |
|
137 | currentDateTimeJ.m_TEnd); | |
140 | } |
|
138 | } | |
141 | } |
|
139 | } | |
142 | } |
|
140 | } | |
143 |
|
141 | |||
144 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart( |
|
142 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart( | |
145 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
143 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
146 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) |
|
144 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) | |
147 | { |
|
145 | { | |
148 | const auto dateTimeListSize = dateTimeList.count(); |
|
146 | const auto dateTimeListSize = dateTimeList.count(); | |
149 | if (cacheIndex >= dateTimeListSize) { |
|
147 | if (cacheIndex >= dateTimeListSize) { | |
150 | // ts localised after all other interval: The last interval is [ts, te] |
|
148 | // ts localised after all other interval: The last interval is [ts, te] | |
151 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
149 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
152 | return; |
|
150 | return; | |
153 | } |
|
151 | } | |
154 |
|
152 | |||
155 | auto currentDateTimeI = dateTimeList[cacheIndex]; |
|
153 | auto currentDateTimeI = dateTimeList[cacheIndex]; | |
156 | auto cacheIndexJ = cacheIndex; |
|
|||
157 | if (currentTStart < currentDateTimeI.m_TStart) { |
|
154 | if (currentTStart < currentDateTimeI.m_TStart) { | |
158 |
|
155 | |||
159 | // ts localised between to interval: let's localized te |
|
156 | // ts localised between to interval: let's localized te | |
160 |
addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex |
|
157 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart); | |
161 | } |
|
158 | } | |
162 | else if (dateTime.m_TStart < currentDateTimeI.m_TEnd) { |
|
159 | else if (dateTime.m_TStart < currentDateTimeI.m_TEnd) { | |
163 | // ts not localised before the current interval: we need to look at the next interval |
|
160 | // ts not localised before the current interval: we need to look at the next interval | |
164 | // We can assume now current tstart is the last interval tend, because data between them are |
|
161 | // We can assume now current tstart is the last interval tend, because data between them are | |
165 | // in the cache |
|
162 | // in the cache | |
166 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, |
|
163 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, | |
167 | currentDateTimeI.m_TEnd); |
|
164 | currentDateTimeI.m_TEnd); | |
168 | } |
|
165 | } | |
169 | else { |
|
166 | else { | |
170 | // ts not localised before the current interval: we need to look at the next interval |
|
167 | // ts not localised before the current interval: we need to look at the next interval | |
171 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart); |
|
168 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart); | |
172 | } |
|
169 | } | |
173 | } |
|
170 | } |
@@ -1,164 +1,164 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableCacheController.h> |
|
2 | #include <Variable/VariableCacheController.h> | |
3 | #include <Variable/VariableController.h> |
|
3 | #include <Variable/VariableController.h> | |
4 | #include <Variable/VariableModel.h> |
|
4 | #include <Variable/VariableModel.h> | |
5 |
|
5 | |||
6 | #include <Data/DataProviderParameters.h> |
|
6 | #include <Data/DataProviderParameters.h> | |
7 | #include <Data/IDataProvider.h> |
|
7 | #include <Data/IDataProvider.h> | |
8 | #include <Data/IDataSeries.h> |
|
8 | #include <Data/IDataSeries.h> | |
9 | #include <Time/TimeController.h> |
|
9 | #include <Time/TimeController.h> | |
10 |
|
10 | |||
11 | #include <QDateTime> |
|
11 | #include <QDateTime> | |
12 | #include <QElapsedTimer> |
|
12 | #include <QElapsedTimer> | |
13 | #include <QMutex> |
|
13 | #include <QMutex> | |
14 | #include <QThread> |
|
14 | #include <QThread> | |
15 |
|
15 | |||
16 | #include <unordered_map> |
|
16 | #include <unordered_map> | |
17 |
|
17 | |||
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
19 |
|
19 | |||
20 | namespace { |
|
20 | namespace { | |
21 |
|
21 | |||
22 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method |
|
22 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method | |
23 | /// will be deleted when the timerange is recovered from SciQlop |
|
23 | /// will be deleted when the timerange is recovered from SciQlop | |
24 | std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, |
|
24 | std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, | |
25 | const SqpDateTime &dateTime) noexcept |
|
25 | const SqpDateTime &dateTime) noexcept | |
26 | { |
|
26 | { | |
27 | auto parameters = DataProviderParameters{dateTime}; |
|
27 | auto parameters = DataProviderParameters{dateTime}; | |
28 |
|
28 | |||
29 | return provider.retrieveData(parameters); |
|
29 | return provider.retrieveData(parameters); | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | } // namespace |
|
32 | } // namespace | |
33 |
|
33 | |||
34 | struct VariableController::VariableControllerPrivate { |
|
34 | struct VariableController::VariableControllerPrivate { | |
35 | explicit VariableControllerPrivate(VariableController *parent) |
|
35 | explicit VariableControllerPrivate(VariableController *parent) | |
36 | : m_WorkingMutex{}, |
|
36 | : m_WorkingMutex{}, | |
37 | m_VariableModel{new VariableModel{parent}}, |
|
37 | m_VariableModel{new VariableModel{parent}}, | |
38 | m_VariableCacheController{std::make_unique<VariableCacheController>()} |
|
38 | m_VariableCacheController{std::make_unique<VariableCacheController>()} | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QMutex m_WorkingMutex; |
|
42 | QMutex m_WorkingMutex; | |
43 | /// Variable model. The VariableController has the ownership |
|
43 | /// Variable model. The VariableController has the ownership | |
44 | VariableModel *m_VariableModel; |
|
44 | VariableModel *m_VariableModel; | |
45 |
|
45 | |||
46 |
|
46 | |||
47 | TimeController *m_TimeController{nullptr}; |
|
47 | TimeController *m_TimeController{nullptr}; | |
48 | std::unique_ptr<VariableCacheController> m_VariableCacheController; |
|
48 | std::unique_ptr<VariableCacheController> m_VariableCacheController; | |
49 |
|
49 | |||
50 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
50 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
51 | m_VariableToProviderMap; |
|
51 | m_VariableToProviderMap; | |
52 | }; |
|
52 | }; | |
53 |
|
53 | |||
54 | VariableController::VariableController(QObject *parent) |
|
54 | VariableController::VariableController(QObject *parent) | |
55 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
55 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
56 | { |
|
56 | { | |
57 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
57 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
58 | << QThread::currentThread(); |
|
58 | << QThread::currentThread(); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | VariableController::~VariableController() |
|
61 | VariableController::~VariableController() | |
62 | { |
|
62 | { | |
63 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
63 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
64 | << QThread::currentThread(); |
|
64 | << QThread::currentThread(); | |
65 | this->waitForFinish(); |
|
65 | this->waitForFinish(); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | VariableModel *VariableController::variableModel() noexcept |
|
68 | VariableModel *VariableController::variableModel() noexcept | |
69 | { |
|
69 | { | |
70 | return impl->m_VariableModel; |
|
70 | return impl->m_VariableModel; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
73 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
74 | { |
|
74 | { | |
75 | impl->m_TimeController = timeController; |
|
75 | impl->m_TimeController = timeController; | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void VariableController::createVariable(const QString &name, |
|
78 | void VariableController::createVariable(const QString &name, | |
79 | std::shared_ptr<IDataProvider> provider) noexcept |
|
79 | std::shared_ptr<IDataProvider> provider) noexcept | |
80 | { |
|
80 | { | |
81 |
|
81 | |||
82 | if (!impl->m_TimeController) { |
|
82 | if (!impl->m_TimeController) { | |
83 | qCCritical(LOG_VariableController()) |
|
83 | qCCritical(LOG_VariableController()) | |
84 | << tr("Impossible to create variable: The time controller is null"); |
|
84 | << tr("Impossible to create variable: The time controller is null"); | |
85 | return; |
|
85 | return; | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 |
|
88 | |||
89 | /// @todo : for the moment : |
|
89 | /// @todo : for the moment : | |
90 | /// - the provider is only used to retrieve data from the variable for its initialization, but |
|
90 | /// - the provider is only used to retrieve data from the variable for its initialization, but | |
91 | /// it will be retained later |
|
91 | /// it will be retained later | |
92 | /// - default data are generated for the variable, without taking into account the timerange set |
|
92 | /// - default data are generated for the variable, without taking into account the timerange set | |
93 | /// in sciqlop |
|
93 | /// in sciqlop | |
94 | auto dateTime = impl->m_TimeController->dateTime(); |
|
94 | auto dateTime = impl->m_TimeController->dateTime(); | |
95 | if (auto newVariable = impl->m_VariableModel->createVariable( |
|
95 | if (auto newVariable = impl->m_VariableModel->createVariable( | |
96 | name, dateTime, generateDefaultDataSeries(*provider, dateTime))) { |
|
96 | name, dateTime, generateDefaultDataSeries(*provider, dateTime))) { | |
97 |
|
97 | |||
98 | // store the provider |
|
98 | // store the provider | |
99 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
99 | impl->m_VariableToProviderMap[newVariable] = provider; | |
100 | qRegisterMetaType<std::shared_ptr<IDataSeries> >(); |
|
100 | qRegisterMetaType<std::shared_ptr<IDataSeries> >(); | |
101 | qRegisterMetaType<SqpDateTime>(); |
|
101 | qRegisterMetaType<SqpDateTime>(); | |
102 | connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(), |
|
102 | connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(), | |
103 | &Variable::onAddDataSeries); |
|
103 | &Variable::onAddDataSeries); | |
104 |
|
104 | |||
105 |
|
105 | |||
106 | // store in cache |
|
106 | // store in cache | |
107 | impl->m_VariableCacheController->addDateTime(newVariable, dateTime); |
|
107 | impl->m_VariableCacheController->addDateTime(newVariable, dateTime); | |
108 |
|
108 | |||
109 | // notify the creation |
|
109 | // notify the creation | |
110 | emit variableCreated(newVariable); |
|
110 | emit variableCreated(newVariable); | |
111 | } |
|
111 | } | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 |
|
114 | |||
115 | void VariableController::requestDataLoading(std::shared_ptr<Variable> variable, |
|
115 | void VariableController::requestDataLoading(std::shared_ptr<Variable> variable, | |
116 | const SqpDateTime &dateTime) |
|
116 | const SqpDateTime &dateTime) | |
117 | { |
|
117 | { | |
118 | // we want to load data of the variable for the dateTime. |
|
118 | // we want to load data of the variable for the dateTime. | |
119 | // First we check if the cache contains some of them. |
|
119 | // First we check if the cache contains some of them. | |
120 | // For the other, we ask the provider to give them. |
|
120 | // For the other, we ask the provider to give them. | |
121 | if (variable) { |
|
121 | if (variable) { | |
122 |
|
122 | |||
123 | QElapsedTimer timer; |
|
123 | QElapsedTimer timer; | |
124 | timer.start(); |
|
124 | timer.start(); | |
125 | qCInfo(LOG_VariableController()) << "The slow s0 operation took" << timer.elapsed() |
|
125 | qCInfo(LOG_VariableController()) << "TORM: The slow s0 operation took" << timer.elapsed() | |
126 | << "milliseconds"; |
|
126 | << "milliseconds"; | |
127 | auto dateTimeListNotInCache |
|
127 | auto dateTimeListNotInCache | |
128 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); |
|
128 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); | |
129 | qCInfo(LOG_VariableController()) << "The slow s1 operation took" << timer.elapsed() |
|
129 | qCInfo(LOG_VariableController()) << "TORM: The slow s1 operation took" << timer.elapsed() | |
130 | << "milliseconds"; |
|
130 | << "milliseconds"; | |
131 |
|
131 | |||
132 | // Ask the provider for each data on the dateTimeListNotInCache |
|
132 | // Ask the provider for each data on the dateTimeListNotInCache | |
133 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading(dateTimeListNotInCache); |
|
133 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading(dateTimeListNotInCache); | |
134 |
|
134 | |||
135 | qCInfo(LOG_VariableController()) << "The slow s2 operation took" << timer.elapsed() |
|
135 | qCInfo(LOG_VariableController()) << "TORM: The slow s2 operation took" << timer.elapsed() | |
136 | << "milliseconds"; |
|
136 | << "milliseconds"; | |
137 |
|
137 | |||
138 | // store in cache |
|
138 | // store in cache | |
139 | impl->m_VariableCacheController->addDateTime(variable, dateTime); |
|
139 | impl->m_VariableCacheController->addDateTime(variable, dateTime); | |
140 | qCInfo(LOG_VariableController()) << "The slow s3 operation took" << timer.elapsed() |
|
140 | qCInfo(LOG_VariableController()) << "TORM: The slow s3 operation took" << timer.elapsed() | |
141 | << "milliseconds"; |
|
141 | << "milliseconds"; | |
142 | } |
|
142 | } | |
143 | else { |
|
143 | else { | |
144 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
|
144 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); | |
145 | } |
|
145 | } | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 |
|
148 | |||
149 | void VariableController::initialize() |
|
149 | void VariableController::initialize() | |
150 | { |
|
150 | { | |
151 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
151 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
152 | impl->m_WorkingMutex.lock(); |
|
152 | impl->m_WorkingMutex.lock(); | |
153 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
153 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void VariableController::finalize() |
|
156 | void VariableController::finalize() | |
157 | { |
|
157 | { | |
158 | impl->m_WorkingMutex.unlock(); |
|
158 | impl->m_WorkingMutex.unlock(); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void VariableController::waitForFinish() |
|
161 | void VariableController::waitForFinish() | |
162 | { |
|
162 | { | |
163 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
163 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
164 | } |
|
164 | } |
@@ -1,120 +1,125 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableModel.h> |
|
2 | #include <Variable/VariableModel.h> | |
3 |
|
3 | |||
4 | #include <Data/IDataSeries.h> |
|
4 | #include <Data/IDataSeries.h> | |
5 |
|
5 | |||
6 | Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") |
|
6 | Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") | |
7 |
|
7 | |||
8 | namespace { |
|
8 | namespace { | |
9 |
|
9 | |||
10 | // Column indexes |
|
10 | // Column indexes | |
11 | const auto NAME_COLUMN = 0; |
|
11 | const auto NAME_COLUMN = 0; | |
12 | const auto UNIT_COLUMN = 1; |
|
12 | const auto UNIT_COLUMN = 1; | |
13 | const auto MISSION_COLUMN = 2; |
|
13 | const auto MISSION_COLUMN = 2; | |
14 | const auto NB_COLUMNS = 3; |
|
14 | const auto NB_COLUMNS = 3; | |
15 |
|
15 | |||
16 | } // namespace |
|
16 | } // namespace | |
17 |
|
17 | |||
18 | struct VariableModel::VariableModelPrivate { |
|
18 | struct VariableModel::VariableModelPrivate { | |
19 | /// Variables created in SciQlop |
|
19 | /// Variables created in SciQlop | |
20 | std::vector<std::shared_ptr<Variable> > m_Variables; |
|
20 | std::vector<std::shared_ptr<Variable> > m_Variables; | |
21 | }; |
|
21 | }; | |
22 |
|
22 | |||
23 | VariableModel::VariableModel(QObject *parent) |
|
23 | VariableModel::VariableModel(QObject *parent) | |
24 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} |
|
24 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} | |
25 | { |
|
25 | { | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | std::shared_ptr<Variable> |
|
28 | std::shared_ptr<Variable> | |
29 | VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime, |
|
29 | VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime, | |
30 | std::unique_ptr<IDataSeries> defaultDataSeries) noexcept |
|
30 | std::unique_ptr<IDataSeries> defaultDataSeries) noexcept | |
31 | { |
|
31 | { | |
32 | auto insertIndex = rowCount(); |
|
32 | auto insertIndex = rowCount(); | |
33 | beginInsertRows({}, insertIndex, insertIndex); |
|
33 | beginInsertRows({}, insertIndex, insertIndex); | |
34 |
|
34 | |||
35 | /// @todo For the moment, the other data of the variable is initialized with default values |
|
35 | /// @todo For the moment, the other data of the variable is initialized with default values | |
36 | auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"), |
|
36 | auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"), | |
37 | QStringLiteral("mission"), dateTime); |
|
37 | QStringLiteral("mission"), dateTime); | |
38 | variable->setDataSeries(std::move(defaultDataSeries)); |
|
38 | variable->setDataSeries(std::move(defaultDataSeries)); | |
39 |
|
39 | |||
40 | impl->m_Variables.push_back(variable); |
|
40 | impl->m_Variables.push_back(variable); | |
41 |
|
41 | |||
42 | endInsertRows(); |
|
42 | endInsertRows(); | |
43 |
|
43 | |||
44 | return variable; |
|
44 | return variable; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
|
47 | std::shared_ptr<Variable> VariableModel::variable(int index) const | |||
|
48 | { | |||
|
49 | return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr; | |||
|
50 | } | |||
|
51 | ||||
47 | int VariableModel::columnCount(const QModelIndex &parent) const |
|
52 | int VariableModel::columnCount(const QModelIndex &parent) const | |
48 | { |
|
53 | { | |
49 | Q_UNUSED(parent); |
|
54 | Q_UNUSED(parent); | |
50 |
|
55 | |||
51 | return NB_COLUMNS; |
|
56 | return NB_COLUMNS; | |
52 | } |
|
57 | } | |
53 |
|
58 | |||
54 | int VariableModel::rowCount(const QModelIndex &parent) const |
|
59 | int VariableModel::rowCount(const QModelIndex &parent) const | |
55 | { |
|
60 | { | |
56 | Q_UNUSED(parent); |
|
61 | Q_UNUSED(parent); | |
57 |
|
62 | |||
58 | return impl->m_Variables.size(); |
|
63 | return impl->m_Variables.size(); | |
59 | } |
|
64 | } | |
60 |
|
65 | |||
61 | QVariant VariableModel::data(const QModelIndex &index, int role) const |
|
66 | QVariant VariableModel::data(const QModelIndex &index, int role) const | |
62 | { |
|
67 | { | |
63 | if (!index.isValid()) { |
|
68 | if (!index.isValid()) { | |
64 | return QVariant{}; |
|
69 | return QVariant{}; | |
65 | } |
|
70 | } | |
66 |
|
71 | |||
67 | if (index.row() < 0 || index.row() >= rowCount()) { |
|
72 | if (index.row() < 0 || index.row() >= rowCount()) { | |
68 | return QVariant{}; |
|
73 | return QVariant{}; | |
69 | } |
|
74 | } | |
70 |
|
75 | |||
71 | if (role == Qt::DisplayRole) { |
|
76 | if (role == Qt::DisplayRole) { | |
72 | if (auto variable = impl->m_Variables.at(index.row()).get()) { |
|
77 | if (auto variable = impl->m_Variables.at(index.row()).get()) { | |
73 | switch (index.column()) { |
|
78 | switch (index.column()) { | |
74 | case NAME_COLUMN: |
|
79 | case NAME_COLUMN: | |
75 | return variable->name(); |
|
80 | return variable->name(); | |
76 | case UNIT_COLUMN: |
|
81 | case UNIT_COLUMN: | |
77 | return variable->unit(); |
|
82 | return variable->unit(); | |
78 | case MISSION_COLUMN: |
|
83 | case MISSION_COLUMN: | |
79 | return variable->mission(); |
|
84 | return variable->mission(); | |
80 | default: |
|
85 | default: | |
81 | // No action |
|
86 | // No action | |
82 | break; |
|
87 | break; | |
83 | } |
|
88 | } | |
84 |
|
89 | |||
85 | qWarning(LOG_VariableModel()) |
|
90 | qWarning(LOG_VariableModel()) | |
86 | << tr("Can't get data (unknown column %1)").arg(index.column()); |
|
91 | << tr("Can't get data (unknown column %1)").arg(index.column()); | |
87 | } |
|
92 | } | |
88 | else { |
|
93 | else { | |
89 | qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)"); |
|
94 | qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)"); | |
90 | } |
|
95 | } | |
91 | } |
|
96 | } | |
92 |
|
97 | |||
93 | return QVariant{}; |
|
98 | return QVariant{}; | |
94 | } |
|
99 | } | |
95 |
|
100 | |||
96 | QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
101 | QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const | |
97 | { |
|
102 | { | |
98 | if (role != Qt::DisplayRole) { |
|
103 | if (role != Qt::DisplayRole) { | |
99 | return QVariant{}; |
|
104 | return QVariant{}; | |
100 | } |
|
105 | } | |
101 |
|
106 | |||
102 | if (orientation == Qt::Horizontal) { |
|
107 | if (orientation == Qt::Horizontal) { | |
103 | switch (section) { |
|
108 | switch (section) { | |
104 | case NAME_COLUMN: |
|
109 | case NAME_COLUMN: | |
105 | return tr("Name"); |
|
110 | return tr("Name"); | |
106 | case UNIT_COLUMN: |
|
111 | case UNIT_COLUMN: | |
107 | return tr("Unit"); |
|
112 | return tr("Unit"); | |
108 | case MISSION_COLUMN: |
|
113 | case MISSION_COLUMN: | |
109 | return tr("Mission"); |
|
114 | return tr("Mission"); | |
110 | default: |
|
115 | default: | |
111 | // No action |
|
116 | // No action | |
112 | break; |
|
117 | break; | |
113 | } |
|
118 | } | |
114 |
|
119 | |||
115 | qWarning(LOG_VariableModel()) |
|
120 | qWarning(LOG_VariableModel()) | |
116 | << tr("Can't get header data (unknown column %1)").arg(section); |
|
121 | << tr("Can't get header data (unknown column %1)").arg(section); | |
117 | } |
|
122 | } | |
118 |
|
123 | |||
119 | return QVariant{}; |
|
124 | return QVariant{}; | |
120 | } |
|
125 | } |
@@ -1,343 +1,343 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableCacheController.h> |
|
2 | #include <Variable/VariableCacheController.h> | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 | #include <QtTest> |
|
5 | #include <QtTest> | |
6 |
|
6 | |||
7 | #include <memory> |
|
7 | #include <memory> | |
8 |
|
8 | |||
9 | class TestVariableCacheController : public QObject { |
|
9 | class TestVariableCacheController : public QObject { | |
10 | Q_OBJECT |
|
10 | Q_OBJECT | |
11 |
|
11 | |||
12 | private slots: |
|
12 | private slots: | |
13 | void testProvideNotInCacheDateTimeList(); |
|
13 | void testProvideNotInCacheDateTimeList(); | |
14 |
|
14 | |||
15 | void testAddDateTime(); |
|
15 | void testAddDateTime(); | |
16 | }; |
|
16 | }; | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | void TestVariableCacheController::testProvideNotInCacheDateTimeList() |
|
19 | void TestVariableCacheController::testProvideNotInCacheDateTimeList() | |
20 | { |
|
20 | { | |
21 | VariableCacheController variableCacheController{}; |
|
21 | VariableCacheController variableCacheController{}; | |
22 |
|
22 | |||
23 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; |
|
23 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |
24 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
24 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
25 | auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()), |
|
25 | auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()), | |
26 | static_cast<double>(te0.toMSecsSinceEpoch())}; |
|
26 | static_cast<double>(te0.toMSecsSinceEpoch())}; | |
27 |
|
27 | |||
28 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; |
|
28 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; | |
29 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; |
|
29 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; | |
30 | auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()), |
|
30 | auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()), | |
31 | static_cast<double>(te1.toMSecsSinceEpoch())}; |
|
31 | static_cast<double>(te1.toMSecsSinceEpoch())}; | |
32 |
|
32 | |||
33 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; |
|
33 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; | |
34 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; |
|
34 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; | |
35 | auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()), |
|
35 | auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()), | |
36 | static_cast<double>(te2.toMSecsSinceEpoch())}; |
|
36 | static_cast<double>(te2.toMSecsSinceEpoch())}; | |
37 |
|
37 | |||
38 | auto var0 = std::make_shared<Variable>("", "", "", sqp0); |
|
38 | auto var0 = std::make_shared<Variable>("", "", "", sqp0); | |
39 |
|
39 | |||
40 | variableCacheController.addDateTime(var0, sqp0); |
|
40 | variableCacheController.addDateTime(var0, sqp0); | |
41 | variableCacheController.addDateTime(var0, sqp1); |
|
41 | variableCacheController.addDateTime(var0, sqp1); | |
42 | variableCacheController.addDateTime(var0, sqp2); |
|
42 | variableCacheController.addDateTime(var0, sqp2); | |
43 |
|
43 | |||
44 | // first case [ts,te] < ts0 |
|
44 | // first case [ts,te] < ts0 | |
45 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
45 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
46 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; |
|
46 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |
47 | auto sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
47 | auto sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
48 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
48 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
49 |
|
49 | |||
50 |
|
50 | |||
51 | auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
51 | auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
52 |
|
52 | |||
53 | QCOMPARE(notInCach.size(), 1); |
|
53 | QCOMPARE(notInCach.size(), 1); | |
54 |
auto notInCa |
|
54 | auto notInCacheSqp = notInCach.first(); | |
55 |
QCOMPARE(notInCa |
|
55 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
56 |
QCOMPARE(notInCa |
|
56 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
57 |
|
57 | |||
58 |
|
58 | |||
59 | // second case ts < ts0 && ts0 < te <= te0 |
|
59 | // second case ts < ts0 && ts0 < te <= te0 | |
60 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
60 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
61 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
61 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
62 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
62 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
63 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
63 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
64 |
|
64 | |||
65 |
|
65 | |||
66 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
66 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
67 |
|
67 | |||
68 | QCOMPARE(notInCach.size(), 1); |
|
68 | QCOMPARE(notInCach.size(), 1); | |
69 |
notInCa |
|
69 | notInCacheSqp = notInCach.first(); | |
70 |
QCOMPARE(notInCa |
|
70 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
71 |
QCOMPARE(notInCa |
|
71 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
72 |
|
72 | |||
73 | // 3th case ts < ts0 && te0 < te <= ts1 |
|
73 | // 3th case ts < ts0 && te0 < te <= ts1 | |
74 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
74 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
75 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
75 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
76 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
76 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
77 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
77 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
78 |
|
78 | |||
79 |
|
79 | |||
80 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
80 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
81 |
|
81 | |||
82 | QCOMPARE(notInCach.size(), 2); |
|
82 | QCOMPARE(notInCach.size(), 2); | |
83 |
notInCa |
|
83 | notInCacheSqp = notInCach.first(); | |
84 |
QCOMPARE(notInCa |
|
84 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
85 |
QCOMPARE(notInCa |
|
85 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
86 |
|
86 | |||
87 |
notInCa |
|
87 | notInCacheSqp = notInCach.at(1); | |
88 |
QCOMPARE(notInCa |
|
88 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
89 |
QCOMPARE(notInCa |
|
89 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
90 |
|
90 | |||
91 | // 4th case ts < ts0 && ts1 < te <= te1 |
|
91 | // 4th case ts < ts0 && ts1 < te <= te1 | |
92 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
92 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
93 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; |
|
93 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; | |
94 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
94 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
95 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
95 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
96 |
|
96 | |||
97 |
|
97 | |||
98 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
98 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
99 |
|
99 | |||
100 | QCOMPARE(notInCach.size(), 2); |
|
100 | QCOMPARE(notInCach.size(), 2); | |
101 |
notInCa |
|
101 | notInCacheSqp = notInCach.first(); | |
102 |
QCOMPARE(notInCa |
|
102 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
103 |
QCOMPARE(notInCa |
|
103 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
104 |
|
104 | |||
105 |
notInCa |
|
105 | notInCacheSqp = notInCach.at(1); | |
106 |
QCOMPARE(notInCa |
|
106 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
107 |
QCOMPARE(notInCa |
|
107 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
108 |
|
108 | |||
109 | // 5th case ts < ts0 && te3 < te |
|
109 | // 5th case ts < ts0 && te3 < te | |
110 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
110 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
111 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; |
|
111 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; | |
112 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
112 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
113 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
113 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
114 |
|
114 | |||
115 |
|
115 | |||
116 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
116 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
117 |
|
117 | |||
118 | QCOMPARE(notInCach.size(), 4); |
|
118 | QCOMPARE(notInCach.size(), 4); | |
119 |
notInCa |
|
119 | notInCacheSqp = notInCach.first(); | |
120 |
QCOMPARE(notInCa |
|
120 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
121 |
QCOMPARE(notInCa |
|
121 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
122 |
|
122 | |||
123 |
notInCa |
|
123 | notInCacheSqp = notInCach.at(1); | |
124 |
QCOMPARE(notInCa |
|
124 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
125 |
QCOMPARE(notInCa |
|
125 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
126 |
|
126 | |||
127 |
notInCa |
|
127 | notInCacheSqp = notInCach.at(2); | |
128 |
QCOMPARE(notInCa |
|
128 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); | |
129 |
QCOMPARE(notInCa |
|
129 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch())); | |
130 |
|
130 | |||
131 |
notInCa |
|
131 | notInCacheSqp = notInCach.at(3); | |
132 |
QCOMPARE(notInCa |
|
132 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch())); | |
133 |
QCOMPARE(notInCa |
|
133 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
134 |
|
134 | |||
135 |
|
135 | |||
136 | // 6th case ts2 < ts |
|
136 | // 6th case ts2 < ts | |
137 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 45, 0, 0}}; |
|
137 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 45, 0, 0}}; | |
138 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; |
|
138 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; | |
139 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
139 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
140 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
140 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
141 |
|
141 | |||
142 |
|
142 | |||
143 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
143 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
144 |
|
144 | |||
145 | QCOMPARE(notInCach.size(), 1); |
|
145 | QCOMPARE(notInCach.size(), 1); | |
146 |
notInCa |
|
146 | notInCacheSqp = notInCach.first(); | |
147 |
QCOMPARE(notInCa |
|
147 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
148 |
QCOMPARE(notInCa |
|
148 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
149 |
|
149 | |||
150 | // 7th case ts = te0 && te < ts1 |
|
150 | // 7th case ts = te0 && te < ts1 | |
151 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
151 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
152 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
152 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
153 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
153 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
154 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
154 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
155 |
|
155 | |||
156 |
|
156 | |||
157 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
157 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
158 |
|
158 | |||
159 | QCOMPARE(notInCach.size(), 1); |
|
159 | QCOMPARE(notInCach.size(), 1); | |
160 |
notInCa |
|
160 | notInCacheSqp = notInCach.first(); | |
161 |
QCOMPARE(notInCa |
|
161 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
162 |
QCOMPARE(notInCa |
|
162 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
163 |
|
163 | |||
164 | // 8th case ts0 < ts < te0 && te < ts1 |
|
164 | // 8th case ts0 < ts < te0 && te < ts1 | |
165 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
165 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
166 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
166 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
167 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
167 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
168 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
168 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
169 |
|
169 | |||
170 |
|
170 | |||
171 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
171 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
172 |
|
172 | |||
173 | QCOMPARE(notInCach.size(), 1); |
|
173 | QCOMPARE(notInCach.size(), 1); | |
174 |
notInCa |
|
174 | notInCacheSqp = notInCach.first(); | |
175 |
QCOMPARE(notInCa |
|
175 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
176 |
QCOMPARE(notInCa |
|
176 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
177 |
|
177 | |||
178 | // 9th case ts0 < ts < te0 && ts1 < te < te1 |
|
178 | // 9th case ts0 < ts < te0 && ts1 < te < te1 | |
179 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
179 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
180 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; |
|
180 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; | |
181 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
181 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
182 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
182 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
183 |
|
183 | |||
184 |
|
184 | |||
185 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
185 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
186 |
|
186 | |||
187 | QCOMPARE(notInCach.size(), 1); |
|
187 | QCOMPARE(notInCach.size(), 1); | |
188 |
notInCa |
|
188 | notInCacheSqp = notInCach.first(); | |
189 |
QCOMPARE(notInCa |
|
189 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
190 |
QCOMPARE(notInCa |
|
190 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
191 |
|
191 | |||
192 | // 10th case te1 < ts < te < ts2 |
|
192 | // 10th case te1 < ts < te < ts2 | |
193 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}}; |
|
193 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}}; | |
194 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; |
|
194 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; | |
195 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
195 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
196 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
196 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
197 |
|
197 | |||
198 |
|
198 | |||
199 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
199 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
200 |
|
200 | |||
201 | QCOMPARE(notInCach.size(), 1); |
|
201 | QCOMPARE(notInCach.size(), 1); | |
202 |
notInCa |
|
202 | notInCacheSqp = notInCach.first(); | |
203 |
QCOMPARE(notInCa |
|
203 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
204 |
QCOMPARE(notInCa |
|
204 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
205 |
|
205 | |||
206 | // 11th case te0 < ts < ts1 && te3 < te |
|
206 | // 11th case te0 < ts < ts1 && te3 < te | |
207 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
207 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
208 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; |
|
208 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; | |
209 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
209 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
210 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
210 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
211 |
|
211 | |||
212 |
|
212 | |||
213 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
213 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
214 |
|
214 | |||
215 | QCOMPARE(notInCach.size(), 3); |
|
215 | QCOMPARE(notInCach.size(), 3); | |
216 |
notInCa |
|
216 | notInCacheSqp = notInCach.first(); | |
217 |
QCOMPARE(notInCa |
|
217 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
218 |
QCOMPARE(notInCa |
|
218 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
219 |
|
219 | |||
220 |
notInCa |
|
220 | notInCacheSqp = notInCach.at(1); | |
221 |
QCOMPARE(notInCa |
|
221 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); | |
222 |
QCOMPARE(notInCa |
|
222 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch())); | |
223 |
|
223 | |||
224 |
notInCa |
|
224 | notInCacheSqp = notInCach.at(2); | |
225 |
QCOMPARE(notInCa |
|
225 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch())); | |
226 |
QCOMPARE(notInCa |
|
226 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
227 |
|
227 | |||
228 | // 12th case te0 < ts < ts1 && te3 < te |
|
228 | // 12th case te0 < ts < ts1 && te3 < te | |
229 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
229 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
230 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; |
|
230 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; | |
231 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
231 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
232 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
232 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
233 |
|
233 | |||
234 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
234 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
235 |
|
235 | |||
236 | QCOMPARE(notInCach.size(), 2); |
|
236 | QCOMPARE(notInCach.size(), 2); | |
237 |
notInCa |
|
237 | notInCacheSqp = notInCach.first(); | |
238 |
QCOMPARE(notInCa |
|
238 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
239 |
QCOMPARE(notInCa |
|
239 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
240 |
|
240 | |||
241 |
notInCa |
|
241 | notInCacheSqp = notInCach.at(1); | |
242 |
QCOMPARE(notInCa |
|
242 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); | |
243 |
QCOMPARE(notInCa |
|
243 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 |
|
246 | |||
247 | void TestVariableCacheController::testAddDateTime() |
|
247 | void TestVariableCacheController::testAddDateTime() | |
248 | { |
|
248 | { | |
249 | VariableCacheController variableCacheController{}; |
|
249 | VariableCacheController variableCacheController{}; | |
250 |
|
250 | |||
251 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; |
|
251 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |
252 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
252 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
253 | auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()), |
|
253 | auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()), | |
254 | static_cast<double>(te0.toMSecsSinceEpoch())}; |
|
254 | static_cast<double>(te0.toMSecsSinceEpoch())}; | |
255 |
|
255 | |||
256 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; |
|
256 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; | |
257 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; |
|
257 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; | |
258 | auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()), |
|
258 | auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()), | |
259 | static_cast<double>(te1.toMSecsSinceEpoch())}; |
|
259 | static_cast<double>(te1.toMSecsSinceEpoch())}; | |
260 |
|
260 | |||
261 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; |
|
261 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; | |
262 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; |
|
262 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; | |
263 | auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()), |
|
263 | auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()), | |
264 | static_cast<double>(te2.toMSecsSinceEpoch())}; |
|
264 | static_cast<double>(te2.toMSecsSinceEpoch())}; | |
265 |
|
265 | |||
266 | auto ts01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
266 | auto ts01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
267 | auto te01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; |
|
267 | auto te01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; | |
268 | auto sqp01 = SqpDateTime{static_cast<double>(ts01.toMSecsSinceEpoch()), |
|
268 | auto sqp01 = SqpDateTime{static_cast<double>(ts01.toMSecsSinceEpoch()), | |
269 | static_cast<double>(te01.toMSecsSinceEpoch())}; |
|
269 | static_cast<double>(te01.toMSecsSinceEpoch())}; | |
270 |
|
270 | |||
271 | auto ts3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 14, 0, 0}}; |
|
271 | auto ts3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 14, 0, 0}}; | |
272 | auto te3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 16, 0, 0}}; |
|
272 | auto te3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 16, 0, 0}}; | |
273 | auto sqp3 = SqpDateTime{static_cast<double>(ts3.toMSecsSinceEpoch()), |
|
273 | auto sqp3 = SqpDateTime{static_cast<double>(ts3.toMSecsSinceEpoch()), | |
274 | static_cast<double>(te3.toMSecsSinceEpoch())}; |
|
274 | static_cast<double>(te3.toMSecsSinceEpoch())}; | |
275 |
|
275 | |||
276 | auto ts03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
276 | auto ts03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
277 | auto te03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; |
|
277 | auto te03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; | |
278 | auto sqp03 = SqpDateTime{static_cast<double>(ts03.toMSecsSinceEpoch()), |
|
278 | auto sqp03 = SqpDateTime{static_cast<double>(ts03.toMSecsSinceEpoch()), | |
279 | static_cast<double>(te03.toMSecsSinceEpoch())}; |
|
279 | static_cast<double>(te03.toMSecsSinceEpoch())}; | |
280 |
|
280 | |||
281 |
|
281 | |||
282 | auto var0 = std::make_shared<Variable>("", "", "", sqp0); |
|
282 | auto var0 = std::make_shared<Variable>("", "", "", sqp0); | |
283 |
|
283 | |||
284 |
|
284 | |||
285 | // First case: add the first interval to the variable :sqp0 |
|
285 | // First case: add the first interval to the variable :sqp0 | |
286 | variableCacheController.addDateTime(var0, sqp0); |
|
286 | variableCacheController.addDateTime(var0, sqp0); | |
287 | auto dateCacheList = variableCacheController.dateCacheList(var0); |
|
287 | auto dateCacheList = variableCacheController.dateCacheList(var0); | |
288 | QCOMPARE(dateCacheList.count(), 1); |
|
288 | QCOMPARE(dateCacheList.count(), 1); | |
289 | auto dateCache = dateCacheList.at(0); |
|
289 | auto dateCache = dateCacheList.at(0); | |
290 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
290 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
291 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
291 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch())); | |
292 |
|
292 | |||
293 | // 2nd case: add a second interval : sqp1 > sqp0 |
|
293 | // 2nd case: add a second interval : sqp1 > sqp0 | |
294 | variableCacheController.addDateTime(var0, sqp1); |
|
294 | variableCacheController.addDateTime(var0, sqp1); | |
295 | dateCacheList = variableCacheController.dateCacheList(var0); |
|
295 | dateCacheList = variableCacheController.dateCacheList(var0); | |
296 | QCOMPARE(dateCacheList.count(), 2); |
|
296 | QCOMPARE(dateCacheList.count(), 2); | |
297 | dateCache = dateCacheList.at(0); |
|
297 | dateCache = dateCacheList.at(0); | |
298 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
298 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
299 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
299 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch())); | |
300 |
|
300 | |||
301 | dateCache = dateCacheList.at(1); |
|
301 | dateCache = dateCacheList.at(1); | |
302 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts1.toMSecsSinceEpoch())); |
|
302 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
303 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); |
|
303 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); | |
304 |
|
304 | |||
305 | // 3th case: merge sqp0 & sqp1 with sqp01 |
|
305 | // 3th case: merge sqp0 & sqp1 with sqp01 | |
306 | variableCacheController.addDateTime(var0, sqp01); |
|
306 | variableCacheController.addDateTime(var0, sqp01); | |
307 | dateCacheList = variableCacheController.dateCacheList(var0); |
|
307 | dateCacheList = variableCacheController.dateCacheList(var0); | |
308 | QCOMPARE(dateCacheList.count(), 1); |
|
308 | QCOMPARE(dateCacheList.count(), 1); | |
309 | dateCache = dateCacheList.at(0); |
|
309 | dateCache = dateCacheList.at(0); | |
310 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
310 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
311 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); |
|
311 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); | |
312 |
|
312 | |||
313 |
|
313 | |||
314 | // 4th case: add a second interval : sqp1 > sqp0 |
|
314 | // 4th case: add a second interval : sqp1 > sqp0 | |
315 | variableCacheController.addDateTime(var0, sqp2); |
|
315 | variableCacheController.addDateTime(var0, sqp2); | |
316 | variableCacheController.addDateTime(var0, sqp3); |
|
316 | variableCacheController.addDateTime(var0, sqp3); | |
317 | dateCacheList = variableCacheController.dateCacheList(var0); |
|
317 | dateCacheList = variableCacheController.dateCacheList(var0); | |
318 | QCOMPARE(dateCacheList.count(), 3); |
|
318 | QCOMPARE(dateCacheList.count(), 3); | |
319 | dateCache = dateCacheList.at(0); |
|
319 | dateCache = dateCacheList.at(0); | |
320 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
320 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
321 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); |
|
321 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); | |
322 |
|
322 | |||
323 | dateCache = dateCacheList.at(1); |
|
323 | dateCache = dateCacheList.at(1); | |
324 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts3.toMSecsSinceEpoch())); |
|
324 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts3.toMSecsSinceEpoch())); | |
325 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te3.toMSecsSinceEpoch())); |
|
325 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te3.toMSecsSinceEpoch())); | |
326 |
|
326 | |||
327 | dateCache = dateCacheList.at(2); |
|
327 | dateCache = dateCacheList.at(2); | |
328 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts2.toMSecsSinceEpoch())); |
|
328 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts2.toMSecsSinceEpoch())); | |
329 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te2.toMSecsSinceEpoch())); |
|
329 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te2.toMSecsSinceEpoch())); | |
330 |
|
330 | |||
331 |
|
331 | |||
332 | // 5th case: merge all interval |
|
332 | // 5th case: merge all interval | |
333 | variableCacheController.addDateTime(var0, sqp03); |
|
333 | variableCacheController.addDateTime(var0, sqp03); | |
334 | dateCacheList = variableCacheController.dateCacheList(var0); |
|
334 | dateCacheList = variableCacheController.dateCacheList(var0); | |
335 | QCOMPARE(dateCacheList.count(), 1); |
|
335 | QCOMPARE(dateCacheList.count(), 1); | |
336 | dateCache = dateCacheList.at(0); |
|
336 | dateCache = dateCacheList.at(0); | |
337 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
337 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
338 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te03.toMSecsSinceEpoch())); |
|
338 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te03.toMSecsSinceEpoch())); | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 |
|
341 | |||
342 | QTEST_MAIN(TestVariableCacheController) |
|
342 | QTEST_MAIN(TestVariableCacheController) | |
343 | #include "TestVariableCacheController.moc" |
|
343 | #include "TestVariableCacheController.moc" |
@@ -1,139 +1,138 | |||||
1 | # |
|
1 | # | |
2 | # use_clangformat.cmake |
|
2 | # use_clangformat.cmake | |
3 | # |
|
3 | # | |
4 | # The following functions are defined in this document: |
|
4 | # The following functions are defined in this document: | |
5 | # |
|
5 | # | |
6 |
|
6 | |||
7 | # ADD_CLANGFORMAT_TARGETS(<globExpression> ... |
|
7 | # ADD_CLANGFORMAT_TARGETS(<globExpression> ... | |
8 | # [ADD_TO_ALL] |
|
8 | # [ADD_TO_ALL] | |
9 | # [NAME <name>] |
|
9 | # [NAME <name>] | |
10 | # [NAME_ALL <nameall>] |
|
10 | # [NAME_ALL <nameall>] | |
11 | # [STYLE style] |
|
11 | # [STYLE style] | |
12 | # [RECURSE]) |
|
12 | # [RECURSE]) | |
13 | # |
|
13 | # | |
14 | # Two custom targets will be created: |
|
14 | # Two custom targets will be created: | |
15 | # * format_reports is run as part of the build, and is not rerun unless one of |
|
15 | # * format_reports is run as part of the build, and is not rerun unless one of | |
16 | # the file formatted is modified (only created if ADD_TO_ALL is provided); |
|
16 | # the file formatted is modified (only created if ADD_TO_ALL is provided); | |
17 | # * format must be explicitely called (make format) and is rerun even if the |
|
17 | # * format must be explicitely called (make format) and is rerun even if the | |
18 | # files to format have not been modified. To achieve this behavior, the commands |
|
18 | # files to format have not been modified. To achieve this behavior, the commands | |
19 | # used in this target pretend to produce a file without actually producing it. |
|
19 | # used in this target pretend to produce a file without actually producing it. | |
20 | # Because the output file is not there after the run, the command will be rerun |
|
20 | # Because the output file is not there after the run, the command will be rerun | |
21 | # again at the next target build. |
|
21 | # again at the next target build. | |
22 | # |
|
22 | # | |
23 | # If ADD_TO_ALL is provided then a target will be added to the default build |
|
23 | # If ADD_TO_ALL is provided then a target will be added to the default build | |
24 | # targets so that each time a source file is compiled, it is formatted with |
|
24 | # targets so that each time a source file is compiled, it is formatted with | |
25 | # clang-format. |
|
25 | # clang-format. | |
26 | # |
|
26 | # | |
27 | # NAME and NAME_ALL customize the name of the targets (format and format_reports |
|
27 | # NAME and NAME_ALL customize the name of the targets (format and format_reports | |
28 | # by default respectively). |
|
28 | # by default respectively). | |
29 | # |
|
29 | # | |
30 | # STYLE sets the style used by clang-format (default to "file"). |
|
30 | # STYLE sets the style used by clang-format (default to "file"). | |
31 | # |
|
31 | # | |
32 | # RECURSE selects if the glob expressions should be applied recursively or not. |
|
32 | # RECURSE selects if the glob expressions should be applied recursively or not. | |
33 | FUNCTION(ADD_CLANGFORMAT_TARGETS) |
|
33 | FUNCTION(ADD_CLANGFORMAT_TARGETS) | |
34 | # Default values |
|
34 | # Default values | |
35 | SET(target "format") |
|
35 | SET(target "format") | |
36 | SET(target_all "format_all") |
|
36 | SET(target_all "format_all") | |
37 | SET(style "file") |
|
37 | SET(style "file") | |
38 | SET(recurse OFF) |
|
38 | SET(recurse OFF) | |
39 | SET(addToAll OFF) |
|
39 | SET(addToAll OFF) | |
40 | SET(globs) |
|
40 | SET(globs) | |
41 |
|
41 | |||
42 | # Parse the options |
|
42 | # Parse the options | |
43 | MATH(EXPR lastIdx "${ARGC} - 1") |
|
43 | MATH(EXPR lastIdx "${ARGC} - 1") | |
44 | SET(i 0) |
|
44 | SET(i 0) | |
45 | WHILE(i LESS ${ARGC}) |
|
45 | WHILE(i LESS ${ARGC}) | |
46 | SET(arg "${ARGV${i}}") |
|
46 | SET(arg "${ARGV${i}}") | |
47 | IF("${arg}" STREQUAL "ADD_TO_ALL") |
|
47 | IF("${arg}" STREQUAL "ADD_TO_ALL") | |
48 | SET(addToAll ON) |
|
48 | SET(addToAll ON) | |
49 | ELSEIF("${arg}" STREQUAL "NAME") |
|
49 | ELSEIF("${arg}" STREQUAL "NAME") | |
50 | clangformat_incr(i) |
|
50 | clangformat_incr(i) | |
51 | SET(target "${ARGV${i}}") |
|
51 | SET(target "${ARGV${i}}") | |
52 | ELSEIF("${arg}" STREQUAL "NAME_ALL") |
|
52 | ELSEIF("${arg}" STREQUAL "NAME_ALL") | |
53 | clangformat_incr(i) |
|
53 | clangformat_incr(i) | |
54 | SET(target_all "${ARGV${i}}") |
|
54 | SET(target_all "${ARGV${i}}") | |
55 | ELSEIF("${arg}" STREQUAL "STYLE") |
|
55 | ELSEIF("${arg}" STREQUAL "STYLE") | |
56 | clangformat_incr(i) |
|
56 | clangformat_incr(i) | |
57 | SET(style "${ARGV${i}}") |
|
57 | SET(style "${ARGV${i}}") | |
58 | ELSEIF("${arg}" STREQUAL "RECURSE") |
|
58 | ELSEIF("${arg}" STREQUAL "RECURSE") | |
59 | SET(recurse ON) |
|
59 | SET(recurse ON) | |
60 | ELSE() |
|
60 | ELSE() | |
61 | LIST(APPEND globs ${arg}) |
|
61 | LIST(APPEND globs ${arg}) | |
62 | ENDIF() |
|
62 | ENDIF() | |
63 | clangformat_incr(i) |
|
63 | clangformat_incr(i) | |
64 | ENDWHILE() |
|
64 | ENDWHILE() | |
65 |
|
65 | |||
66 |
|
66 | |||
67 | # Retrieve source files to format |
|
67 | # Retrieve source files to format | |
68 | IF(recurse) |
|
68 | IF(recurse) | |
69 | FILE(GLOB_RECURSE srcs ${globs}) |
|
69 | FILE(GLOB_RECURSE srcs ${globs}) | |
70 | ELSE() |
|
70 | ELSE() | |
71 | FILE(GLOB srcs ${globs}) |
|
71 | FILE(GLOB srcs ${globs}) | |
72 | ENDIF() |
|
72 | ENDIF() | |
73 |
|
73 | |||
74 | IF(NOT CLANGFORMAT_EXECUTABLE) |
|
74 | IF(NOT CLANGFORMAT_EXECUTABLE) | |
75 | MESSAGE(FATAL_ERROR "Unable to find clang-format executable") |
|
75 | MESSAGE(FATAL_ERROR "Unable to find clang-format executable") | |
76 | ENDIF() |
|
76 | ENDIF() | |
77 |
|
77 | |||
78 | # Format each source file with clang-format |
|
78 | # Format each source file with clang-format | |
79 | SET(touchedFiles) |
|
79 | SET(touchedFiles) | |
80 | SET(fakedTouchedFiles) |
|
80 | SET(fakedTouchedFiles) | |
81 | SET(reportNb 0) |
|
81 | SET(reportNb 0) | |
82 | # Create the directory where the touched files will be saved |
|
82 | # Create the directory where the touched files will be saved | |
83 | SET(formatDirectory "${CMAKE_CURRENT_BINARY_DIR}/format") |
|
83 | SET(formatDirectory "${CMAKE_CURRENT_BINARY_DIR}/format") | |
84 | FILE(MAKE_DIRECTORY ${formatDirectory}) |
|
84 | FILE(MAKE_DIRECTORY ${formatDirectory}) | |
85 | # STRING(REPLACE "*.ui" "" srcs ${srcs}) |
|
85 | # STRING(REPLACE "*.ui" "" srcs ${srcs}) | |
86 | FOREACH(item ${globs}) |
|
86 | FOREACH(item ${globs}) | |
87 | STRING(REGEX MATCH ".*\.ui$" item ${item}) |
|
87 | STRING(REGEX MATCH ".*\.ui$" item ${item}) | |
88 | IF(item) |
|
88 | IF(item) | |
89 | LIST(APPEND UIS ${item}) |
|
89 | LIST(APPEND UIS ${item}) | |
90 | ENDIF(item) |
|
90 | ENDIF(item) | |
91 | ENDFOREACH(item ${globs}) |
|
91 | ENDFOREACH(item ${globs}) | |
92 |
|
92 | |||
93 | LIST(REMOVE_ITEM srcs ${UIS}) |
|
93 | LIST(REMOVE_ITEM srcs ${UIS}) | |
94 | message("format lang: ${srcs}" ) |
|
|||
95 | FOREACH (s ${srcs}) |
|
94 | FOREACH (s ${srcs}) | |
96 | SET(touchedFile ${formatDirectory}/format_touchedfile_${reportNb}) |
|
95 | SET(touchedFile ${formatDirectory}/format_touchedfile_${reportNb}) | |
97 | IF(addToAll) |
|
96 | IF(addToAll) | |
98 | ADD_CUSTOM_COMMAND( |
|
97 | ADD_CUSTOM_COMMAND( | |
99 | OUTPUT ${touchedFile} |
|
98 | OUTPUT ${touchedFile} | |
100 | COMMAND ${CLANGFORMAT_EXECUTABLE} |
|
99 | COMMAND ${CLANGFORMAT_EXECUTABLE} | |
101 | -style="${style}" |
|
100 | -style="${style}" | |
102 | -i |
|
101 | -i | |
103 | ${s} |
|
102 | ${s} | |
104 | # Create a file so that this command is executed only if the source |
|
103 | # Create a file so that this command is executed only if the source | |
105 | # file is modified |
|
104 | # file is modified | |
106 | COMMAND ${CMAKE_COMMAND} -E touch ${touchedFile} |
|
105 | COMMAND ${CMAKE_COMMAND} -E touch ${touchedFile} | |
107 | DEPENDS ${s} |
|
106 | DEPENDS ${s} | |
108 | COMMENT "Formatting code with clang-format of ${s}" |
|
107 | COMMENT "Formatting code with clang-format of ${s}" | |
109 | ) |
|
108 | ) | |
110 | ENDIF() |
|
109 | ENDIF() | |
111 |
|
110 | |||
112 | SET(fakedTouchedFile ${formatDirectory}/format_fakedtouchedfile_${reportNb}) |
|
111 | SET(fakedTouchedFile ${formatDirectory}/format_fakedtouchedfile_${reportNb}) | |
113 | ADD_CUSTOM_COMMAND( |
|
112 | ADD_CUSTOM_COMMAND( | |
114 | OUTPUT ${fakedTouchedFile} |
|
113 | OUTPUT ${fakedTouchedFile} | |
115 | COMMAND ${CLANGFORMAT_EXECUTABLE} |
|
114 | COMMAND ${CLANGFORMAT_EXECUTABLE} | |
116 | -style="${style}" |
|
115 | -style="${style}" | |
117 | -i |
|
116 | -i | |
118 | ${s} |
|
117 | ${s} | |
119 | DEPENDS ${s} |
|
118 | DEPENDS ${s} | |
120 | COMMENT "Formatting code with clang-format of ${s}" |
|
119 | COMMENT "Formatting code with clang-format of ${s}" | |
121 | ) |
|
120 | ) | |
122 |
|
121 | |||
123 | LIST(APPEND touchedFiles ${touchedFile}) |
|
122 | LIST(APPEND touchedFiles ${touchedFile}) | |
124 | LIST(APPEND fakedTouchedFiles ${fakedTouchedFile}) |
|
123 | LIST(APPEND fakedTouchedFiles ${fakedTouchedFile}) | |
125 | clangformat_incr(reportNb) |
|
124 | clangformat_incr(reportNb) | |
126 | ENDFOREACH() |
|
125 | ENDFOREACH() | |
127 |
|
126 | |||
128 | # Create the custom targets that will trigger the custom command created |
|
127 | # Create the custom targets that will trigger the custom command created | |
129 | # previously |
|
128 | # previously | |
130 | IF(addToAll) |
|
129 | IF(addToAll) | |
131 | ADD_CUSTOM_TARGET(${target_all} ALL DEPENDS ${touchedFiles}) |
|
130 | ADD_CUSTOM_TARGET(${target_all} ALL DEPENDS ${touchedFiles}) | |
132 | ENDIF() |
|
131 | ENDIF() | |
133 | ADD_CUSTOM_TARGET(${target} DEPENDS ${fakedTouchedFiles}) |
|
132 | ADD_CUSTOM_TARGET(${target} DEPENDS ${fakedTouchedFiles}) | |
134 |
|
133 | |||
135 | ENDFUNCTION(ADD_CLANGFORMAT_TARGETS) |
|
134 | ENDFUNCTION(ADD_CLANGFORMAT_TARGETS) | |
136 |
|
135 | |||
137 | macro(clangformat_incr var_name) |
|
136 | macro(clangformat_incr var_name) | |
138 | math(EXPR ${var_name} "${${var_name}} + 1") |
|
137 | math(EXPR ${var_name} "${${var_name}} + 1") | |
139 | endmacro() |
|
138 | endmacro() |
@@ -1,26 +1,49 | |||||
1 | #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H |
|
1 | #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H | |
2 | #define SCIQLOP_VARIABLEINSPECTORWIDGET_H |
|
2 | #define SCIQLOP_VARIABLEINSPECTORWIDGET_H | |
3 |
|
3 | |||
|
4 | #include <QLoggingCategory> | |||
|
5 | #include <QMenu> | |||
4 | #include <QWidget> |
|
6 | #include <QWidget> | |
5 |
|
7 | |||
|
8 | #include <memory> | |||
|
9 | ||||
|
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableInspectorWidget) | |||
|
11 | ||||
|
12 | class Variable; | |||
|
13 | ||||
6 | namespace Ui { |
|
14 | namespace Ui { | |
7 | class VariableInspectorWidget; |
|
15 | class VariableInspectorWidget; | |
8 | } // Ui |
|
16 | } // Ui | |
9 |
|
17 | |||
10 | /** |
|
18 | /** | |
11 | * @brief The VariableInspectorWidget class representes represents the variable inspector, from |
|
19 | * @brief The VariableInspectorWidget class representes represents the variable inspector, from | |
12 | * which it is possible to view the loaded variables, handle them or trigger their display in |
|
20 | * which it is possible to view the loaded variables, handle them or trigger their display in | |
13 | * visualization |
|
21 | * visualization | |
14 | */ |
|
22 | */ | |
15 | class VariableInspectorWidget : public QWidget { |
|
23 | class VariableInspectorWidget : public QWidget { | |
16 | Q_OBJECT |
|
24 | Q_OBJECT | |
17 |
|
25 | |||
18 | public: |
|
26 | public: | |
19 | explicit VariableInspectorWidget(QWidget *parent = 0); |
|
27 | explicit VariableInspectorWidget(QWidget *parent = 0); | |
20 | virtual ~VariableInspectorWidget(); |
|
28 | virtual ~VariableInspectorWidget(); | |
21 |
|
29 | |||
|
30 | signals: | |||
|
31 | /** | |||
|
32 | * Signal emitted before a menu concerning a variable is displayed. It is used for other widgets | |||
|
33 | * to complete the menu. | |||
|
34 | * @param tableMenu the menu to be completed | |||
|
35 | * @param variable the variable concerned by the menu | |||
|
36 | * @remarks To make the dynamic addition of menus work, the connections to this signal must be | |||
|
37 | * in Qt :: DirectConnection | |||
|
38 | */ | |||
|
39 | void tableMenuAboutToBeDisplayed(QMenu *tableMenu, std::shared_ptr<Variable> variable); | |||
|
40 | ||||
22 | private: |
|
41 | private: | |
23 | Ui::VariableInspectorWidget *ui; |
|
42 | Ui::VariableInspectorWidget *ui; | |
|
43 | ||||
|
44 | private slots: | |||
|
45 | /// Slot called when right clicking on an variable in the table (displays a menu) | |||
|
46 | void onTableMenuRequested(const QPoint &pos) noexcept; | |||
24 | }; |
|
47 | }; | |
25 |
|
48 | |||
26 | #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H |
|
49 | #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H |
@@ -1,38 +1,38 | |||||
1 |
#ifndef SCIQLOP_ |
|
1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHHELPER_H | |
2 |
#define SCIQLOP_ |
|
2 | #define SCIQLOP_VISUALIZATIONGRAPHHELPER_H | |
3 |
|
3 | |||
4 | #include <Data/SqpDateTime.h> |
|
4 | #include <Data/SqpDateTime.h> | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <QVector> |
|
7 | #include <QVector> | |
8 |
|
8 | |||
9 | #include <memory> |
|
9 | #include <memory> | |
10 |
|
10 | |||
11 |
Q_DECLARE_LOGGING_CATEGORY(LOG_ |
|
11 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphHelper) | |
12 |
|
12 | |||
13 | class IDataSeries; |
|
13 | class IDataSeries; | |
14 | class QCPAbstractPlottable; |
|
14 | class QCPAbstractPlottable; | |
15 | class QCustomPlot; |
|
15 | class QCustomPlot; | |
16 | class Variable; |
|
16 | class Variable; | |
17 |
|
17 | |||
18 | /** |
|
18 | /** | |
19 |
* @brief The |
|
19 | * @brief The VisualizationGraphHelper class aims to create the QCustomPlot components relative to a | |
20 | * variable, depending on the data series of this variable |
|
20 | * variable, depending on the data series of this variable | |
21 | */ |
|
21 | */ | |
22 | struct GraphPlottablesFactory { |
|
22 | struct VisualizationGraphHelper { | |
23 | /** |
|
23 | /** | |
24 | * Creates (if possible) the QCustomPlot components relative to the variable passed in |
|
24 | * Creates (if possible) the QCustomPlot components relative to the variable passed in | |
25 | * parameter, and adds these to the plot passed in parameter. |
|
25 | * parameter, and adds these to the plot passed in parameter. | |
26 | * @param variable the variable for which to create the components |
|
26 | * @param variable the variable for which to create the components | |
27 | * @param plot the plot in which to add the created components. It takes ownership of these |
|
27 | * @param plot the plot in which to add the created components. It takes ownership of these | |
28 | * components. |
|
28 | * components. | |
29 | * @return the list of the components created |
|
29 | * @return the list of the components created | |
30 | */ |
|
30 | */ | |
31 | static QVector<QCPAbstractPlottable *> create(std::shared_ptr<Variable> variable, |
|
31 | static QVector<QCPAbstractPlottable *> create(std::shared_ptr<Variable> variable, | |
32 | QCustomPlot &plot) noexcept; |
|
32 | QCustomPlot &plot) noexcept; | |
33 |
|
33 | |||
34 | static void updateData(QVector<QCPAbstractPlottable *> plotableVect, IDataSeries *dataSeries, |
|
34 | static void updateData(QVector<QCPAbstractPlottable *> plotableVect, IDataSeries *dataSeries, | |
35 | const SqpDateTime &dateTime); |
|
35 | const SqpDateTime &dateTime); | |
36 | }; |
|
36 | }; | |
37 |
|
37 | |||
38 |
#endif // SCIQLOP_ |
|
38 | #endif // SCIQLOP_VISUALIZATIONGRAPHHELPER_H |
@@ -1,53 +1,53 | |||||
1 | #ifndef SCIQLOP_VISUALIZATIONWIDGET_H |
|
1 | #ifndef SCIQLOP_VISUALIZATIONWIDGET_H | |
2 | #define SCIQLOP_VISUALIZATIONWIDGET_H |
|
2 | #define SCIQLOP_VISUALIZATIONWIDGET_H | |
3 |
|
3 | |||
4 | #include "Visualization/IVisualizationWidget.h" |
|
4 | #include "Visualization/IVisualizationWidget.h" | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <QWidget> |
|
7 | #include <QWidget> | |
8 |
|
8 | |||
9 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget) |
|
9 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget) | |
10 |
|
10 | |||
|
11 | class QMenu; | |||
11 | class Variable; |
|
12 | class Variable; | |
12 | class VisualizationTabWidget; |
|
13 | class VisualizationTabWidget; | |
13 |
|
14 | |||
14 | namespace Ui { |
|
15 | namespace Ui { | |
15 | class VisualizationWidget; |
|
16 | class VisualizationWidget; | |
16 | } // namespace Ui |
|
17 | } // namespace Ui | |
17 |
|
18 | |||
18 | class VisualizationWidget : public QWidget, public IVisualizationWidget { |
|
19 | class VisualizationWidget : public QWidget, public IVisualizationWidget { | |
19 | Q_OBJECT |
|
20 | Q_OBJECT | |
20 |
|
21 | |||
21 | public: |
|
22 | public: | |
22 | explicit VisualizationWidget(QWidget *parent = 0); |
|
23 | explicit VisualizationWidget(QWidget *parent = 0); | |
23 | virtual ~VisualizationWidget(); |
|
24 | virtual ~VisualizationWidget(); | |
24 |
|
25 | |||
25 | /// Add a zone widget |
|
26 | /// Add a zone widget | |
26 | virtual void addTab(VisualizationTabWidget *tabWidget); |
|
27 | virtual void addTab(VisualizationTabWidget *tabWidget); | |
27 |
|
28 | |||
28 | /// Create a tab using a Variable |
|
29 | /// Create a tab using a Variable | |
29 | VisualizationTabWidget *createTab(); |
|
30 | VisualizationTabWidget *createTab(); | |
30 |
|
31 | |||
31 | /// Remove a tab |
|
32 | /// Remove a tab | |
32 | void removeTab(VisualizationTabWidget *tab); |
|
33 | void removeTab(VisualizationTabWidget *tab); | |
33 |
|
34 | |||
34 | // IVisualizationWidget interface |
|
35 | // IVisualizationWidget interface | |
35 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
36 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
36 | bool canDrop(const Variable &variable) const override; |
|
37 | bool canDrop(const Variable &variable) const override; | |
37 | void close() override; |
|
38 | void close() override; | |
38 | QString name() const override; |
|
39 | QString name() const override; | |
39 |
|
40 | |||
40 | public slots: |
|
41 | public slots: | |
41 | /** |
|
42 | /** | |
42 | * Displays a variable in a new graph of a new zone of the current tab |
|
43 | * Attaches to a menu the menu relating to the visualization of a variable | |
43 | * @param variable the variable to display |
|
44 | * @param menu the parent menu of the generated menu | |
44 | * @todo this is a temporary method that will be replaced by own actions for each type of |
|
45 | * @param variable the variable for which to generate the menu | |
45 | * visualization widget |
|
|||
46 | */ |
|
46 | */ | |
47 |
void |
|
47 | void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept; | |
48 |
|
48 | |||
49 | private: |
|
49 | private: | |
50 | Ui::VisualizationWidget *ui; |
|
50 | Ui::VisualizationWidget *ui; | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 | #endif // VISUALIZATIONWIDGET_H |
|
53 | #endif // VISUALIZATIONWIDGET_H |
@@ -1,26 +1,57 | |||||
1 | #include <Variable/VariableController.h> |
|
1 | #include <Variable/VariableController.h> | |
2 | #include <Variable/VariableInspectorWidget.h> |
|
2 | #include <Variable/VariableInspectorWidget.h> | |
3 | #include <Variable/VariableModel.h> |
|
3 | #include <Variable/VariableModel.h> | |
4 |
|
4 | |||
5 | #include <ui_VariableInspectorWidget.h> |
|
5 | #include <ui_VariableInspectorWidget.h> | |
6 |
|
6 | |||
7 | #include <QSortFilterProxyModel> |
|
7 | #include <QSortFilterProxyModel> | |
8 |
|
8 | |||
9 | #include <SqpApplication.h> |
|
9 | #include <SqpApplication.h> | |
10 |
|
10 | |||
|
11 | Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") | |||
|
12 | ||||
11 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) |
|
13 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) | |
12 | : QWidget{parent}, ui{new Ui::VariableInspectorWidget} |
|
14 | : QWidget{parent}, ui{new Ui::VariableInspectorWidget} | |
13 | { |
|
15 | { | |
14 | ui->setupUi(this); |
|
16 | ui->setupUi(this); | |
15 |
|
17 | |||
16 | // Sets model for table |
|
18 | // Sets model for table | |
17 | auto sortFilterModel = new QSortFilterProxyModel{this}; |
|
19 | auto sortFilterModel = new QSortFilterProxyModel{this}; | |
18 | sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); |
|
20 | sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); | |
19 |
|
21 | |||
20 | ui->tableView->setModel(sortFilterModel); |
|
22 | ui->tableView->setModel(sortFilterModel); | |
|
23 | ||||
|
24 | // Connection to show a menu when right clicking on the tree | |||
|
25 | ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); | |||
|
26 | connect(ui->tableView, &QTableView::customContextMenuRequested, this, | |||
|
27 | &VariableInspectorWidget::onTableMenuRequested); | |||
21 | } |
|
28 | } | |
22 |
|
29 | |||
23 | VariableInspectorWidget::~VariableInspectorWidget() |
|
30 | VariableInspectorWidget::~VariableInspectorWidget() | |
24 | { |
|
31 | { | |
25 | delete ui; |
|
32 | delete ui; | |
26 | } |
|
33 | } | |
|
34 | ||||
|
35 | void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept | |||
|
36 | { | |||
|
37 | auto selectedIndex = ui->tableView->indexAt(pos); | |||
|
38 | if (selectedIndex.isValid()) { | |||
|
39 | // Gets the model to retrieve the underlying selected variable | |||
|
40 | auto model = sqpApp->variableController().variableModel(); | |||
|
41 | if (auto selectedVariable = model->variable(selectedIndex.row())) { | |||
|
42 | QMenu tableMenu{}; | |||
|
43 | ||||
|
44 | // Emit a signal so that potential receivers can populate the menu before displaying it | |||
|
45 | emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable); | |||
|
46 | ||||
|
47 | if (!tableMenu.isEmpty()) { | |||
|
48 | tableMenu.exec(mapToGlobal(pos)); | |||
|
49 | } | |||
|
50 | } | |||
|
51 | } | |||
|
52 | else { | |||
|
53 | qCCritical(LOG_VariableInspectorWidget()) | |||
|
54 | << tr("Can't display menu : invalid index (%1;%2)") | |||
|
55 | .arg(selectedIndex.row(), selectedIndex.column()); | |||
|
56 | } | |||
|
57 | } |
@@ -1,151 +1,151 | |||||
1 |
#include "Visualization/ |
|
1 | #include "Visualization/VisualizationGraphHelper.h" | |
2 | #include "Visualization/qcustomplot.h" |
|
2 | #include "Visualization/qcustomplot.h" | |
3 |
|
3 | |||
4 | #include <Data/ScalarSeries.h> |
|
4 | #include <Data/ScalarSeries.h> | |
5 |
|
5 | |||
6 | #include <Variable/Variable.h> |
|
6 | #include <Variable/Variable.h> | |
7 |
|
7 | |||
8 | #include <QElapsedTimer> |
|
8 | #include <QElapsedTimer> | |
9 |
|
9 | |||
10 | Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory") |
|
10 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper") | |
11 |
|
11 | |||
12 | namespace { |
|
12 | namespace { | |
13 |
|
13 | |||
14 | /// Format for datetimes on a axis |
|
14 | /// Format for datetimes on a axis | |
15 | const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss"); |
|
15 | const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss"); | |
16 |
|
16 | |||
17 | /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or |
|
17 | /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or | |
18 | /// non-time data |
|
18 | /// non-time data | |
19 | QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis) |
|
19 | QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis) | |
20 | { |
|
20 | { | |
21 | if (isTimeAxis) { |
|
21 | if (isTimeAxis) { | |
22 | auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create(); |
|
22 | auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create(); | |
23 | dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT); |
|
23 | dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT); | |
24 |
|
24 | |||
25 | return dateTicker; |
|
25 | return dateTicker; | |
26 | } |
|
26 | } | |
27 | else { |
|
27 | else { | |
28 | // default ticker |
|
28 | // default ticker | |
29 | return QSharedPointer<QCPAxisTicker>::create(); |
|
29 | return QSharedPointer<QCPAxisTicker>::create(); | |
30 | } |
|
30 | } | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries, |
|
33 | void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries, | |
34 | const SqpDateTime &dateTime) |
|
34 | const SqpDateTime &dateTime) | |
35 | { |
|
35 | { | |
36 | QElapsedTimer timer; |
|
36 | QElapsedTimer timer; | |
37 | timer.start(); |
|
37 | timer.start(); | |
38 | if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) { |
|
38 | if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) { | |
39 | // Clean the graph |
|
39 | // Clean the graph | |
40 |
qCDebug(LOG_ |
|
40 | qCDebug(LOG_VisualizationGraphHelper()) << "The slow s1 operation took" << timer.elapsed() | |
41 | << "milliseconds"; |
|
41 | << "milliseconds"; | |
42 | // NAIVE approch |
|
42 | // NAIVE approch | |
43 | const auto &xData = scalarSeries.xAxisData()->data(); |
|
43 | const auto &xData = scalarSeries.xAxisData()->data(); | |
44 | const auto &valuesData = scalarSeries.valuesData()->data(); |
|
44 | const auto &valuesData = scalarSeries.valuesData()->data(); | |
45 |
|
45 | |||
46 | auto xValue = QVector<double>(); |
|
46 | auto xValue = QVector<double>(); | |
47 | auto vValue = QVector<double>(); |
|
47 | auto vValue = QVector<double>(); | |
48 |
|
48 | |||
49 | const auto count = xData.count(); |
|
49 | const auto count = xData.count(); | |
50 | auto ite = 0; |
|
50 | auto ite = 0; | |
51 | for (auto i = 0; i < count; ++i) { |
|
51 | for (auto i = 0; i < count; ++i) { | |
52 | const auto x = xData.at(i); |
|
52 | const auto x = xData.at(i); | |
53 | if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) { |
|
53 | if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) { | |
54 | xValue.push_back(x); |
|
54 | xValue.push_back(x); | |
55 | vValue.push_back(valuesData.at(i)); |
|
55 | vValue.push_back(valuesData.at(i)); | |
56 | ++ite; |
|
56 | ++ite; | |
57 | } |
|
57 | } | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | qcpGraph->setData(xValue, vValue); |
|
60 | qcpGraph->setData(xValue, vValue); | |
61 |
|
61 | |||
62 |
qCDebug(LOG_ |
|
62 | qCDebug(LOG_VisualizationGraphHelper()) << "The slow s2 operation took" << timer.elapsed() | |
63 | << "milliseconds"; |
|
63 | << "milliseconds"; | |
64 | } |
|
64 | } | |
65 | else { |
|
65 | else { | |
66 | /// @todo DEBUG |
|
66 | /// @todo DEBUG | |
67 | } |
|
67 | } | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot, |
|
70 | QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot, | |
71 | const SqpDateTime &dateTime) |
|
71 | const SqpDateTime &dateTime) | |
72 | { |
|
72 | { | |
73 | auto component = plot.addGraph(); |
|
73 | auto component = plot.addGraph(); | |
74 |
|
74 | |||
75 | if (component) { |
|
75 | if (component) { | |
76 | // // Graph data |
|
76 | // // Graph data | |
77 | component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(), |
|
77 | component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(), | |
78 | true); |
|
78 | true); | |
79 |
|
79 | |||
80 | updateScalarData(component, scalarSeries, dateTime); |
|
80 | updateScalarData(component, scalarSeries, dateTime); | |
81 |
|
81 | |||
82 | // Axes properties |
|
82 | // Axes properties | |
83 | /// @todo : for the moment, no control is performed on the axes: the units and the tickers |
|
83 | /// @todo : for the moment, no control is performed on the axes: the units and the tickers | |
84 | /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph |
|
84 | /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph | |
85 |
|
85 | |||
86 | auto setAxisProperties = [](auto axis, const auto &unit) { |
|
86 | auto setAxisProperties = [](auto axis, const auto &unit) { | |
87 | // label (unit name) |
|
87 | // label (unit name) | |
88 | axis->setLabel(unit.m_Name); |
|
88 | axis->setLabel(unit.m_Name); | |
89 |
|
89 | |||
90 | // ticker (depending on the type of unit) |
|
90 | // ticker (depending on the type of unit) | |
91 | axis->setTicker(axisTicker(unit.m_TimeUnit)); |
|
91 | axis->setTicker(axisTicker(unit.m_TimeUnit)); | |
92 | }; |
|
92 | }; | |
93 | setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit()); |
|
93 | setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit()); | |
94 | setAxisProperties(plot.yAxis, scalarSeries.valuesUnit()); |
|
94 | setAxisProperties(plot.yAxis, scalarSeries.valuesUnit()); | |
95 |
|
95 | |||
96 | // Display all data |
|
96 | // Display all data | |
97 | component->rescaleAxes(); |
|
97 | component->rescaleAxes(); | |
98 |
|
98 | |||
99 | plot.replot(); |
|
99 | plot.replot(); | |
100 | } |
|
100 | } | |
101 | else { |
|
101 | else { | |
102 |
qCDebug(LOG_ |
|
102 | qCDebug(LOG_VisualizationGraphHelper()) | |
103 | << QObject::tr("Can't create graph for the scalar series"); |
|
103 | << QObject::tr("Can't create graph for the scalar series"); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | return component; |
|
106 | return component; | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | } // namespace |
|
109 | } // namespace | |
110 |
|
110 | |||
111 |
QVector<QCPAbstractPlottable *> |
|
111 | QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable, | |
112 | QCustomPlot &plot) noexcept |
|
112 | QCustomPlot &plot) noexcept | |
113 | { |
|
113 | { | |
114 | auto result = QVector<QCPAbstractPlottable *>{}; |
|
114 | auto result = QVector<QCPAbstractPlottable *>{}; | |
115 |
|
115 | |||
116 | if (variable) { |
|
116 | if (variable) { | |
117 | // Gets the data series of the variable to call the creation of the right components |
|
117 | // Gets the data series of the variable to call the creation of the right components | |
118 | // according to its type |
|
118 | // according to its type | |
119 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) { |
|
119 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) { | |
120 | result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime())); |
|
120 | result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime())); | |
121 | } |
|
121 | } | |
122 | else { |
|
122 | else { | |
123 |
qCDebug(LOG_ |
|
123 | qCDebug(LOG_VisualizationGraphHelper()) | |
124 | << QObject::tr("Can't create graph plottables : unmanaged data series type"); |
|
124 | << QObject::tr("Can't create graph plottables : unmanaged data series type"); | |
125 | } |
|
125 | } | |
126 | } |
|
126 | } | |
127 | else { |
|
127 | else { | |
128 |
qCDebug(LOG_ |
|
128 | qCDebug(LOG_VisualizationGraphHelper()) | |
129 | << QObject::tr("Can't create graph plottables : the variable is null"); |
|
129 | << QObject::tr("Can't create graph plottables : the variable is null"); | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | return result; |
|
132 | return result; | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 |
void |
|
135 | void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect, | |
136 | IDataSeries *dataSeries, const SqpDateTime &dateTime) |
|
136 | IDataSeries *dataSeries, const SqpDateTime &dateTime) | |
137 | { |
|
137 | { | |
138 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) { |
|
138 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) { | |
139 | if (plotableVect.size() == 1) { |
|
139 | if (plotableVect.size() == 1) { | |
140 | updateScalarData(plotableVect.at(0), *scalarSeries, dateTime); |
|
140 | updateScalarData(plotableVect.at(0), *scalarSeries, dateTime); | |
141 | } |
|
141 | } | |
142 | else { |
|
142 | else { | |
143 |
qCCritical(LOG_ |
|
143 | qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr( | |
144 | "Can't update Data of a scalarSeries because there is not only one component " |
|
144 | "Can't update Data of a scalarSeries because there is not only one component " | |
145 | "associated"); |
|
145 | "associated"); | |
146 | } |
|
146 | } | |
147 | } |
|
147 | } | |
148 | else { |
|
148 | else { | |
149 | /// @todo DEBUG |
|
149 | /// @todo DEBUG | |
150 | } |
|
150 | } | |
151 | } |
|
151 | } |
@@ -1,165 +1,173 | |||||
1 | #include "Visualization/VisualizationGraphWidget.h" |
|
1 | #include "Visualization/VisualizationGraphWidget.h" | |
2 | #include "Visualization/GraphPlottablesFactory.h" |
|
|||
3 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.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 | // 1 variable -> n qcpplot |
|
28 | // 1 variable -> n qcpplot | |
29 | std::unordered_multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> |
|
29 | std::unordered_multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> | |
30 | m_VariableToPlotMultiMap; |
|
30 | m_VariableToPlotMultiMap; | |
31 | }; |
|
31 | }; | |
32 |
|
32 | |||
33 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
33 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
34 | : QWidget{parent}, |
|
34 | : QWidget{parent}, | |
35 | ui{new Ui::VisualizationGraphWidget}, |
|
35 | ui{new Ui::VisualizationGraphWidget}, | |
36 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} |
|
36 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} | |
37 | { |
|
37 | { | |
38 | ui->setupUi(this); |
|
38 | ui->setupUi(this); | |
39 |
|
39 | |||
40 | // qcpplot title |
|
40 | // qcpplot title | |
41 | ui->widget->plotLayout()->insertRow(0); |
|
41 | ui->widget->plotLayout()->insertRow(0); | |
42 | ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name}); |
|
42 | ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name}); | |
43 |
|
43 | |||
44 | // Set qcpplot properties : |
|
44 | // Set qcpplot properties : | |
45 | // - Drag (on x-axis) and zoom are enabled |
|
45 | // - Drag (on x-axis) and zoom are enabled | |
46 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
46 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
47 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
47 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); | |
48 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
48 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); | |
49 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
49 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
50 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( |
|
50 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
51 | &QCPAxis::rangeChanged), |
|
51 | &QCPAxis::rangeChanged), | |
52 | this, &VisualizationGraphWidget::onRangeChanged); |
|
52 | this, &VisualizationGraphWidget::onRangeChanged); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
56 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
57 | { |
|
57 | { | |
58 | delete ui; |
|
58 | delete ui; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) |
|
61 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) | |
62 | { |
|
62 | { | |
63 | // Uses delegate to create the qcpplot components according to the variable |
|
63 | // Uses delegate to create the qcpplot components according to the variable | |
64 |
auto createdPlottables = |
|
64 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
65 |
|
65 | |||
66 | for (auto createdPlottable : qAsConst(createdPlottables)) { |
|
66 | for (auto createdPlottable : qAsConst(createdPlottables)) { | |
67 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); |
|
67 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | connect(variable.get(), SIGNAL(dataCacheUpdated()), this, SLOT(onDataCacheVariableUpdated())); |
|
70 | connect(variable.get(), SIGNAL(dataCacheUpdated()), this, SLOT(onDataCacheVariableUpdated())); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
73 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
74 | { |
|
74 | { | |
75 | if (visitor) { |
|
75 | if (visitor) { | |
76 | visitor->visit(this); |
|
76 | visitor->visit(this); | |
77 | } |
|
77 | } | |
78 | else { |
|
78 | else { | |
79 | qCCritical(LOG_VisualizationGraphWidget()) |
|
79 | qCCritical(LOG_VisualizationGraphWidget()) | |
80 | << tr("Can't visit widget : the visitor is null"); |
|
80 | << tr("Can't visit widget : the visitor is null"); | |
81 | } |
|
81 | } | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
84 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |
85 | { |
|
85 | { | |
86 | /// @todo : for the moment, a graph can always accomodate a variable |
|
86 | /// @todo : for the moment, a graph can always accomodate a variable | |
87 | Q_UNUSED(variable); |
|
87 | Q_UNUSED(variable); | |
88 | return true; |
|
88 | return true; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void VisualizationGraphWidget::close() |
|
91 | void VisualizationGraphWidget::close() | |
92 | { |
|
92 | { | |
93 | // The main view cannot be directly closed. |
|
93 | // The main view cannot be directly closed. | |
94 | return; |
|
94 | return; | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | QString VisualizationGraphWidget::name() const |
|
97 | QString VisualizationGraphWidget::name() const | |
98 | { |
|
98 | { | |
99 | if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) { |
|
99 | if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) { | |
100 | return title->text(); |
|
100 | return title->text(); | |
101 | } |
|
101 | } | |
102 | else { |
|
102 | else { | |
103 | return QString{}; |
|
103 | return QString{}; | |
104 | } |
|
104 | } | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
107 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
108 | { |
|
108 | { | |
109 |
|
109 | |||
110 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged"); |
|
110 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged"); | |
111 |
|
111 | |||
112 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
112 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); | |
113 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
113 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { | |
114 | auto variable = it->first; |
|
114 | auto variable = it->first; | |
115 | auto tolerance = 0.1 * (t2.upper - t2.lower); |
|
115 | auto tolerance = 0.1 * (t2.upper - t2.lower); | |
116 | auto dateTime = SqpDateTime{t2.lower - tolerance, t2.upper + tolerance}; |
|
116 | auto dateTime = SqpDateTime{t2.lower - tolerance, t2.upper + tolerance}; | |
117 |
|
117 | |||
118 | qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged") |
|
118 | qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged") | |
119 | << variable->dataSeries()->xAxisData()->size(); |
|
119 | << variable->dataSeries()->xAxisData()->size(); | |
120 | if (!variable->contains(dateTime)) { |
|
120 | if (!variable->contains(dateTime)) { | |
121 | sqpApp->variableController().requestDataLoading(variable, dateTime); |
|
121 | sqpApp->variableController().requestDataLoading(variable, dateTime); | |
122 | } |
|
122 | } | |
123 | } |
|
123 | } | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
126 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
127 | { |
|
127 | { | |
128 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
128 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
129 |
|
129 | |||
130 | // Lambda that enables a zoom orientation if the key modifier related to this orientation has |
|
130 | // Lambda that enables a zoom orientation if the key modifier related to this orientation has | |
131 | // been pressed |
|
131 | // been pressed | |
132 | auto enableOrientation |
|
132 | auto enableOrientation | |
133 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
133 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { | |
134 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
134 | auto orientationEnabled = event->modifiers().testFlag(modifier); | |
135 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
135 | zoomOrientations.setFlag(orientation, orientationEnabled); | |
136 | }; |
|
136 | }; | |
137 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
137 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); | |
138 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
138 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); | |
139 |
|
139 | |||
140 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
140 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
143 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
144 | { |
|
144 | { | |
|
145 | // NOTE: | |||
|
146 | // We don't want to call the method for each component of a variable unitarily, but for all | |||
|
147 | // its components at once (eg its three components in the case of a vector). | |||
|
148 | ||||
|
149 | // The unordered_multimap does not do this easily, so the question is whether to: | |||
|
150 | // - use an ordered_multimap and the algos of std to group the values by key | |||
|
151 | // - use a map (unique keys) and store as values directly the list of components | |||
|
152 | ||||
145 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
153 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); | |
146 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
154 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { | |
147 | auto variable = it->first; |
|
155 | auto variable = it->first; | |
148 |
|
|
156 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, | |
149 | variable->dataSeries(), variable->dateTime()); |
|
157 | variable->dataSeries(), variable->dateTime()); | |
150 | } |
|
158 | } | |
151 | } |
|
159 | } | |
152 |
|
160 | |||
153 | void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable) |
|
161 | void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable) | |
154 | { |
|
162 | { | |
155 | auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable); |
|
163 | auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable); | |
156 |
|
164 | |||
157 | auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{}; |
|
165 | auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{}; | |
158 |
|
166 | |||
159 | for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) { |
|
167 | for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) { | |
160 | abstractPlotableVect.push_back(it->second); |
|
168 | abstractPlotableVect.push_back(it->second); | |
161 | } |
|
169 | } | |
162 |
|
170 | |||
163 |
|
|
171 | VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(), | |
164 | variable->dateTime()); |
|
172 | variable->dateTime()); | |
165 | } |
|
173 | } |
@@ -1,136 +1,131 | |||||
1 | #include "Visualization/VisualizationWidget.h" |
|
1 | #include "Visualization/VisualizationWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "Visualization/VisualizationGraphWidget.h" |
|
3 | #include "Visualization/VisualizationGraphWidget.h" | |
4 | #include "Visualization/VisualizationTabWidget.h" |
|
4 | #include "Visualization/VisualizationTabWidget.h" | |
5 | #include "Visualization/VisualizationZoneWidget.h" |
|
5 | #include "Visualization/VisualizationZoneWidget.h" | |
|
6 | #include "Visualization/operations/GenerateVariableMenuOperation.h" | |||
6 | #include "Visualization/qcustomplot.h" |
|
7 | #include "Visualization/qcustomplot.h" | |
7 |
|
8 | |||
8 | #include "ui_VisualizationWidget.h" |
|
9 | #include "ui_VisualizationWidget.h" | |
9 |
|
10 | |||
10 | #include <QToolButton> |
|
11 | #include <QToolButton> | |
11 |
|
12 | |||
12 | Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") |
|
13 | Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") | |
13 |
|
14 | |||
14 | VisualizationWidget::VisualizationWidget(QWidget *parent) |
|
15 | VisualizationWidget::VisualizationWidget(QWidget *parent) | |
15 | : QWidget{parent}, ui{new Ui::VisualizationWidget} |
|
16 | : QWidget{parent}, ui{new Ui::VisualizationWidget} | |
16 | { |
|
17 | { | |
17 | ui->setupUi(this); |
|
18 | ui->setupUi(this); | |
18 |
|
19 | |||
19 | auto addTabViewButton = new QToolButton{ui->tabWidget}; |
|
20 | auto addTabViewButton = new QToolButton{ui->tabWidget}; | |
20 | addTabViewButton->setText(tr("Add View")); |
|
21 | addTabViewButton->setText(tr("Add View")); | |
21 | addTabViewButton->setCursor(Qt::ArrowCursor); |
|
22 | addTabViewButton->setCursor(Qt::ArrowCursor); | |
22 | ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); |
|
23 | ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); | |
23 |
|
24 | |||
24 | auto enableMinimumCornerWidgetSize = [this](bool enable) { |
|
25 | auto enableMinimumCornerWidgetSize = [this](bool enable) { | |
25 |
|
26 | |||
26 | auto tabViewCornerWidget = ui->tabWidget->cornerWidget(); |
|
27 | auto tabViewCornerWidget = ui->tabWidget->cornerWidget(); | |
27 | auto width = enable ? tabViewCornerWidget->width() : 0; |
|
28 | auto width = enable ? tabViewCornerWidget->width() : 0; | |
28 | auto height = enable ? tabViewCornerWidget->height() : 0; |
|
29 | auto height = enable ? tabViewCornerWidget->height() : 0; | |
29 | tabViewCornerWidget->setMinimumHeight(height); |
|
30 | tabViewCornerWidget->setMinimumHeight(height); | |
30 | tabViewCornerWidget->setMinimumWidth(width); |
|
31 | tabViewCornerWidget->setMinimumWidth(width); | |
31 | ui->tabWidget->setMinimumHeight(height); |
|
32 | ui->tabWidget->setMinimumHeight(height); | |
32 | ui->tabWidget->setMinimumWidth(width); |
|
33 | ui->tabWidget->setMinimumWidth(width); | |
33 | }; |
|
34 | }; | |
34 |
|
35 | |||
35 | auto addTabView = [this, enableMinimumCornerWidgetSize]() { |
|
36 | auto addTabView = [this, enableMinimumCornerWidgetSize]() { | |
36 | auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1), |
|
37 | auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1), | |
37 | ui->tabWidget}; |
|
38 | ui->tabWidget}; | |
38 | auto index = ui->tabWidget->addTab(widget, widget->name()); |
|
39 | auto index = ui->tabWidget->addTab(widget, widget->name()); | |
39 | if (ui->tabWidget->count() > 0) { |
|
40 | if (ui->tabWidget->count() > 0) { | |
40 | enableMinimumCornerWidgetSize(false); |
|
41 | enableMinimumCornerWidgetSize(false); | |
41 | } |
|
42 | } | |
42 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); |
|
43 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); | |
43 | }; |
|
44 | }; | |
44 |
|
45 | |||
45 | auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) { |
|
46 | auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) { | |
46 | if (ui->tabWidget->count() == 1) { |
|
47 | if (ui->tabWidget->count() == 1) { | |
47 | enableMinimumCornerWidgetSize(true); |
|
48 | enableMinimumCornerWidgetSize(true); | |
48 | } |
|
49 | } | |
49 |
|
50 | |||
50 | ui->tabWidget->removeTab(index); |
|
51 | ui->tabWidget->removeTab(index); | |
51 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); |
|
52 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); | |
52 |
|
53 | |||
53 | }; |
|
54 | }; | |
54 |
|
55 | |||
55 | ui->tabWidget->setTabsClosable(true); |
|
56 | ui->tabWidget->setTabsClosable(true); | |
56 |
|
57 | |||
57 | connect(addTabViewButton, &QToolButton::clicked, addTabView); |
|
58 | connect(addTabViewButton, &QToolButton::clicked, addTabView); | |
58 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); |
|
59 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); | |
59 |
|
60 | |||
60 | // Adds default tab |
|
61 | // Adds default tab | |
61 | addTabView(); |
|
62 | addTabView(); | |
62 | } |
|
63 | } | |
63 |
|
64 | |||
64 | VisualizationWidget::~VisualizationWidget() |
|
65 | VisualizationWidget::~VisualizationWidget() | |
65 | { |
|
66 | { | |
66 | delete ui; |
|
67 | delete ui; | |
67 | } |
|
68 | } | |
68 |
|
69 | |||
69 | void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget) |
|
70 | void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget) | |
70 | { |
|
71 | { | |
71 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
72 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as | |
72 | // lambda function (in the constructor) |
|
73 | // lambda function (in the constructor) | |
73 | } |
|
74 | } | |
74 |
|
75 | |||
75 | VisualizationTabWidget *VisualizationWidget::createTab() |
|
76 | VisualizationTabWidget *VisualizationWidget::createTab() | |
76 | { |
|
77 | { | |
77 | } |
|
78 | } | |
78 |
|
79 | |||
79 | void VisualizationWidget::removeTab(VisualizationTabWidget *tab) |
|
80 | void VisualizationWidget::removeTab(VisualizationTabWidget *tab) | |
80 | { |
|
81 | { | |
81 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
82 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as | |
82 | // lambda function (in the constructor) |
|
83 | // lambda function (in the constructor) | |
83 | } |
|
84 | } | |
84 |
|
85 | |||
85 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
86 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) | |
86 | { |
|
87 | { | |
87 | if (visitor) { |
|
88 | if (visitor) { | |
88 | visitor->visitEnter(this); |
|
89 | visitor->visitEnter(this); | |
89 |
|
90 | |||
90 | // Apply visitor for tab children |
|
91 | // Apply visitor for tab children | |
91 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { |
|
92 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { | |
92 | // Widgets different from tabs are not visited (no action) |
|
93 | // Widgets different from tabs are not visited (no action) | |
93 | if (auto visualizationTabWidget |
|
94 | if (auto visualizationTabWidget | |
94 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { |
|
95 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { | |
95 | visualizationTabWidget->accept(visitor); |
|
96 | visualizationTabWidget->accept(visitor); | |
96 | } |
|
97 | } | |
97 | } |
|
98 | } | |
98 |
|
99 | |||
99 | visitor->visitLeave(this); |
|
100 | visitor->visitLeave(this); | |
100 | } |
|
101 | } | |
101 | else { |
|
102 | else { | |
102 | qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null"); |
|
103 | qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null"); | |
103 | } |
|
104 | } | |
104 | } |
|
105 | } | |
105 |
|
106 | |||
106 | bool VisualizationWidget::canDrop(const Variable &variable) const |
|
107 | bool VisualizationWidget::canDrop(const Variable &variable) const | |
107 | { |
|
108 | { | |
108 | // The main widget can never accomodate a variable |
|
109 | // The main widget can never accomodate a variable | |
109 | Q_UNUSED(variable); |
|
110 | Q_UNUSED(variable); | |
110 | return false; |
|
111 | return false; | |
111 | } |
|
112 | } | |
112 |
|
113 | |||
113 | void VisualizationWidget::close() |
|
114 | void VisualizationWidget::close() | |
114 | { |
|
115 | { | |
115 | // The main view cannot be directly closed. |
|
116 | // The main view cannot be directly closed. | |
116 | return; |
|
117 | return; | |
117 | } |
|
118 | } | |
118 |
|
119 | |||
119 | QString VisualizationWidget::name() const |
|
120 | QString VisualizationWidget::name() const | |
120 | { |
|
121 | { | |
121 | return QStringLiteral("MainView"); |
|
122 | return QStringLiteral("MainView"); | |
122 | } |
|
123 | } | |
123 |
|
124 | |||
124 | void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept |
|
125 | void VisualizationWidget::attachVariableMenu(QMenu *menu, | |
|
126 | std::shared_ptr<Variable> variable) noexcept | |||
125 | { |
|
127 | { | |
126 | if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) { |
|
128 | // Generates the actions that make it possible to visualize the variable | |
127 | if (!currentTab->createZone(variable)) { |
|
129 | auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable}; | |
128 | qCCritical(LOG_VisualizationWidget()) |
|
130 | accept(&generateVariableMenuOperation); | |
129 | << tr("Can't display the variable : can't create a new zone in the current tab"); |
|
|||
130 | } |
|
|||
131 | } |
|
|||
132 | else { |
|
|||
133 | qCCritical(LOG_VisualizationWidget()) |
|
|||
134 | << tr("Can't display the variable : there is no current tab"); |
|
|||
135 | } |
|
|||
136 | } |
|
131 | } |
@@ -1,71 +1,71 | |||||
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 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") |
|
8 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") | |
9 |
|
9 | |||
10 | std::unique_ptr<IDataSeries> |
|
10 | std::unique_ptr<IDataSeries> | |
11 | CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const |
|
11 | CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const | |
12 | { |
|
12 | { | |
13 | auto dateTime = parameters.m_Time; |
|
13 | auto dateTime = parameters.m_Time; | |
14 |
|
14 | |||
15 | // Gets the timerange from the parameters |
|
15 | // Gets the timerange from the parameters | |
16 | auto start = dateTime.m_TStart; |
|
16 | auto start = dateTime.m_TStart; | |
17 | auto end = dateTime.m_TEnd; |
|
17 | auto end = dateTime.m_TEnd; | |
18 |
|
18 | |||
19 | // We assure that timerange is valid |
|
19 | // We assure that timerange is valid | |
20 | if (end < start) { |
|
20 | if (end < start) { | |
21 | std::swap(start, end); |
|
21 | std::swap(start, end); | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | // Generates scalar series containing cosinus values (one value per second) |
|
24 | // Generates scalar series containing cosinus values (one value per second) | |
25 | auto scalarSeries |
|
25 | auto scalarSeries | |
26 | = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); |
|
26 | = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); | |
27 |
|
27 | |||
28 | auto dataIndex = 0; |
|
28 | auto dataIndex = 0; | |
29 | for (auto time = start; time < end; ++time, ++dataIndex) { |
|
29 | for (auto time = start; time < end; ++time, ++dataIndex) { | |
30 | scalarSeries->setData(dataIndex, time, std::cos(time)); |
|
30 | scalarSeries->setData(dataIndex, time, std::cos(time)); | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | return scalarSeries; |
|
33 | return scalarSeries; | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList) |
|
36 | void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList) | |
37 | { |
|
37 | { | |
38 | // NOTE: Try to use multithread if possible |
|
38 | // NOTE: Try to use multithread if possible | |
39 |
for |
|
39 | for (const auto &dateTime : dateTimeList) { | |
40 |
|
40 | |||
41 | auto scalarSeries = this->retrieveDataSeries(dateTime); |
|
41 | auto scalarSeries = this->retrieveDataSeries(dateTime); | |
42 |
|
42 | |||
43 | emit dataProvided(scalarSeries, dateTime); |
|
43 | emit dataProvided(scalarSeries, dateTime); | |
44 | } |
|
44 | } | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTime &dateTime) |
|
48 | std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTime &dateTime) | |
49 | { |
|
49 | { | |
50 |
|
50 | |||
51 | // Gets the timerange from the parameters |
|
51 | // Gets the timerange from the parameters | |
52 | auto start = dateTime.m_TStart; |
|
52 | auto start = dateTime.m_TStart; | |
53 | auto end = dateTime.m_TEnd; |
|
53 | auto end = dateTime.m_TEnd; | |
54 |
|
54 | |||
55 | // We assure that timerange is valid |
|
55 | // We assure that timerange is valid | |
56 | if (end < start) { |
|
56 | if (end < start) { | |
57 | std::swap(start, end); |
|
57 | std::swap(start, end); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | // Generates scalar series containing cosinus values (one value per second) |
|
60 | // Generates scalar series containing cosinus values (one value per second) | |
61 | auto scalarSeries |
|
61 | auto scalarSeries | |
62 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); |
|
62 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); | |
63 |
|
63 | |||
64 | auto dataIndex = 0; |
|
64 | auto dataIndex = 0; | |
65 | for (auto time = start; time < end; ++time, ++dataIndex) { |
|
65 | for (auto time = start; time < end; ++time, ++dataIndex) { | |
66 | scalarSeries->setData(dataIndex, time, std::cos(time)); |
|
66 | scalarSeries->setData(dataIndex, time, std::cos(time)); | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 |
|
69 | |||
70 | return scalarSeries; |
|
70 | return scalarSeries; | |
71 | } |
|
71 | } |
General Comments 0
You need to be logged in to leave comments.
Login now