@@ -1,256 +1,261 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SciQLop Software |
|
2 | -- This file is a part of the SciQLop Software | |
3 | -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "MainWindow.h" |
|
22 | #include "MainWindow.h" | |
23 | #include "ui_MainWindow.h" |
|
23 | #include "ui_MainWindow.h" | |
24 |
|
24 | |||
25 | #include <DataSource/DataSourceController.h> |
|
25 | #include <DataSource/DataSourceController.h> | |
26 | #include <DataSource/DataSourceWidget.h> |
|
26 | #include <DataSource/DataSourceWidget.h> | |
27 | #include <SidePane/SqpSidePane.h> |
|
27 | #include <SidePane/SqpSidePane.h> | |
28 | #include <SqpApplication.h> |
|
28 | #include <SqpApplication.h> | |
29 | #include <Time/TimeController.h> |
|
29 | #include <Time/TimeController.h> | |
30 | #include <TimeWidget/TimeWidget.h> |
|
30 | #include <TimeWidget/TimeWidget.h> | |
31 | #include <Variable/Variable.h> |
|
31 | #include <Variable/Variable.h> | |
|
32 | #include <Variable/VariableController.h> | |||
32 | #include <Visualization/VisualizationController.h> |
|
33 | #include <Visualization/VisualizationController.h> | |
33 |
|
34 | |||
34 | #include <QAction> |
|
35 | #include <QAction> | |
35 | #include <QDate> |
|
36 | #include <QDate> | |
36 | #include <QDateTime> |
|
37 | #include <QDateTime> | |
37 | #include <QDir> |
|
38 | #include <QDir> | |
38 | #include <QFileDialog> |
|
39 | #include <QFileDialog> | |
39 | #include <QToolBar> |
|
40 | #include <QToolBar> | |
40 | #include <QToolButton> |
|
41 | #include <QToolButton> | |
41 | #include <memory.h> |
|
42 | #include <memory.h> | |
42 |
|
43 | |||
43 | //#include <omp.h> |
|
44 | //#include <omp.h> | |
44 | //#include <network/filedownloader.h> |
|
45 | //#include <network/filedownloader.h> | |
45 | //#include <qlopdatabase.h> |
|
46 | //#include <qlopdatabase.h> | |
46 | //#include <qlopsettings.h> |
|
47 | //#include <qlopsettings.h> | |
47 | //#include <qlopgui.h> |
|
48 | //#include <qlopgui.h> | |
48 | //#include <spacedata.h> |
|
49 | //#include <spacedata.h> | |
49 | //#include "qlopcore.h" |
|
50 | //#include "qlopcore.h" | |
50 | //#include "qlopcodecmanager.h" |
|
51 | //#include "qlopcodecmanager.h" | |
51 | //#include "cdfcodec.h" |
|
52 | //#include "cdfcodec.h" | |
52 | //#include "amdatxtcodec.h" |
|
53 | //#include "amdatxtcodec.h" | |
53 | //#include <qlopplotmanager.h> |
|
54 | //#include <qlopplotmanager.h> | |
54 |
|
55 | |||
55 | #include "iostream" |
|
56 | #include "iostream" | |
56 |
|
57 | |||
57 | Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") |
|
58 | Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") | |
58 |
|
59 | |||
59 | namespace { |
|
60 | namespace { | |
60 | const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; |
|
61 | const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; | |
61 | const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; |
|
62 | const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; | |
62 | const auto VIEWPLITTERINDEX = 2; |
|
63 | const auto VIEWPLITTERINDEX = 2; | |
63 | const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; |
|
64 | const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; | |
64 | const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; |
|
65 | const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; | |
65 | } |
|
66 | } | |
66 |
|
67 | |||
67 | class MainWindow::MainWindowPrivate { |
|
68 | class MainWindow::MainWindowPrivate { | |
68 | public: |
|
69 | public: | |
69 | QSize m_LastOpenLeftInspectorSize; |
|
70 | QSize m_LastOpenLeftInspectorSize; | |
70 | QSize m_LastOpenRightInspectorSize; |
|
71 | QSize m_LastOpenRightInspectorSize; | |
71 | }; |
|
72 | }; | |
72 |
|
73 | |||
73 | MainWindow::MainWindow(QWidget *parent) |
|
74 | MainWindow::MainWindow(QWidget *parent) | |
74 | : QMainWindow{parent}, |
|
75 | : QMainWindow{parent}, | |
75 | m_Ui{new Ui::MainWindow}, |
|
76 | m_Ui{new Ui::MainWindow}, | |
76 | impl{spimpl::make_unique_impl<MainWindowPrivate>()} |
|
77 | impl{spimpl::make_unique_impl<MainWindowPrivate>()} | |
77 | { |
|
78 | { | |
78 | m_Ui->setupUi(this); |
|
79 | m_Ui->setupUi(this); | |
79 |
|
80 | |||
80 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
81 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); | |
81 | m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
82 | m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); | |
82 |
|
83 | |||
83 |
|
84 | |||
84 | auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); |
|
85 | auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); | |
85 | auto openLeftInspectorAction = new QAction{QIcon{ |
|
86 | auto openLeftInspectorAction = new QAction{QIcon{ | |
86 | ":/icones/previous.png", |
|
87 | ":/icones/previous.png", | |
87 | }, |
|
88 | }, | |
88 | tr("Show/hide the left inspector"), this}; |
|
89 | tr("Show/hide the left inspector"), this}; | |
89 |
|
90 | |||
90 |
|
91 | |||
91 | auto spacerLeftTop = new QWidget{}; |
|
92 | auto spacerLeftTop = new QWidget{}; | |
92 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
93 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
93 |
|
94 | |||
94 | auto spacerLeftBottom = new QWidget{}; |
|
95 | auto spacerLeftBottom = new QWidget{}; | |
95 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
96 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
96 |
|
97 | |||
97 | leftSidePane->addWidget(spacerLeftTop); |
|
98 | leftSidePane->addWidget(spacerLeftTop); | |
98 | leftSidePane->addAction(openLeftInspectorAction); |
|
99 | leftSidePane->addAction(openLeftInspectorAction); | |
99 | leftSidePane->addWidget(spacerLeftBottom); |
|
100 | leftSidePane->addWidget(spacerLeftBottom); | |
100 |
|
101 | |||
101 |
|
102 | |||
102 | auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); |
|
103 | auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); | |
103 | auto openRightInspectorAction = new QAction{QIcon{ |
|
104 | auto openRightInspectorAction = new QAction{QIcon{ | |
104 | ":/icones/next.png", |
|
105 | ":/icones/next.png", | |
105 | }, |
|
106 | }, | |
106 | tr("Show/hide the right inspector"), this}; |
|
107 | tr("Show/hide the right inspector"), this}; | |
107 |
|
108 | |||
108 | auto spacerRightTop = new QWidget{}; |
|
109 | auto spacerRightTop = new QWidget{}; | |
109 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
110 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
110 |
|
111 | |||
111 | auto spacerRightBottom = new QWidget{}; |
|
112 | auto spacerRightBottom = new QWidget{}; | |
112 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
113 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
113 |
|
114 | |||
114 | rightSidePane->addWidget(spacerRightTop); |
|
115 | rightSidePane->addWidget(spacerRightTop); | |
115 | rightSidePane->addAction(openRightInspectorAction); |
|
116 | rightSidePane->addAction(openRightInspectorAction); | |
116 | rightSidePane->addWidget(spacerRightBottom); |
|
117 | rightSidePane->addWidget(spacerRightBottom); | |
117 |
|
118 | |||
118 | openLeftInspectorAction->setCheckable(true); |
|
119 | openLeftInspectorAction->setCheckable(true); | |
119 | openRightInspectorAction->setCheckable(true); |
|
120 | openRightInspectorAction->setCheckable(true); | |
120 |
|
121 | |||
121 | auto openInspector = [this](bool checked, bool right, auto action) { |
|
122 | auto openInspector = [this](bool checked, bool right, auto action) { | |
122 |
|
123 | |||
123 | action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"}); |
|
124 | action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"}); | |
124 |
|
125 | |||
125 | auto &lastInspectorSize |
|
126 | auto &lastInspectorSize | |
126 | = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize; |
|
127 | = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize; | |
127 |
|
128 | |||
128 | auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size() |
|
129 | auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size() | |
129 | : m_Ui->leftMainInspectorWidget->size(); |
|
130 | : m_Ui->leftMainInspectorWidget->size(); | |
130 |
|
131 | |||
131 | // Update of the last opened geometry |
|
132 | // Update of the last opened geometry | |
132 | if (checked) { |
|
133 | if (checked) { | |
133 | lastInspectorSize = nextInspectorSize; |
|
134 | lastInspectorSize = nextInspectorSize; | |
134 | } |
|
135 | } | |
135 |
|
136 | |||
136 | auto startSize = lastInspectorSize; |
|
137 | auto startSize = lastInspectorSize; | |
137 | auto endSize = startSize; |
|
138 | auto endSize = startSize; | |
138 | endSize.setWidth(0); |
|
139 | endSize.setWidth(0); | |
139 |
|
140 | |||
140 | auto splitterInspectorIndex |
|
141 | auto splitterInspectorIndex | |
141 | = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX; |
|
142 | = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX; | |
142 |
|
143 | |||
143 | auto currentSizes = m_Ui->splitter->sizes(); |
|
144 | auto currentSizes = m_Ui->splitter->sizes(); | |
144 | if (checked) { |
|
145 | if (checked) { | |
145 | // adjust sizes individually here, e.g. |
|
146 | // adjust sizes individually here, e.g. | |
146 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); |
|
147 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); | |
147 | currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); |
|
148 | currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); | |
148 | m_Ui->splitter->setSizes(currentSizes); |
|
149 | m_Ui->splitter->setSizes(currentSizes); | |
149 | } |
|
150 | } | |
150 | else { |
|
151 | else { | |
151 | // adjust sizes individually here, e.g. |
|
152 | // adjust sizes individually here, e.g. | |
152 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); |
|
153 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); | |
153 | currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); |
|
154 | currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); | |
154 | m_Ui->splitter->setSizes(currentSizes); |
|
155 | m_Ui->splitter->setSizes(currentSizes); | |
155 | } |
|
156 | } | |
156 |
|
157 | |||
157 | }; |
|
158 | }; | |
158 |
|
159 | |||
159 |
|
160 | |||
160 | connect(openLeftInspectorAction, &QAction::triggered, |
|
161 | connect(openLeftInspectorAction, &QAction::triggered, | |
161 | [openInspector, openLeftInspectorAction](bool checked) { |
|
162 | [openInspector, openLeftInspectorAction](bool checked) { | |
162 | openInspector(checked, false, openLeftInspectorAction); |
|
163 | openInspector(checked, false, openLeftInspectorAction); | |
163 | }); |
|
164 | }); | |
164 | connect(openRightInspectorAction, &QAction::triggered, |
|
165 | connect(openRightInspectorAction, &QAction::triggered, | |
165 | [openInspector, openRightInspectorAction](bool checked) { |
|
166 | [openInspector, openRightInspectorAction](bool checked) { | |
166 | openInspector(checked, true, openRightInspectorAction); |
|
167 | openInspector(checked, true, openRightInspectorAction); | |
167 | }); |
|
168 | }); | |
168 |
|
169 | |||
169 | this->menuBar()->addAction(tr("File")); |
|
170 | this->menuBar()->addAction(tr("File")); | |
170 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); |
|
171 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); | |
171 |
|
172 | |||
172 | auto timeWidget = new TimeWidget{}; |
|
173 | auto timeWidget = new TimeWidget{}; | |
173 | mainToolBar->addWidget(timeWidget); |
|
174 | mainToolBar->addWidget(timeWidget); | |
174 |
|
175 | |||
175 | // Widgets / controllers connections |
|
176 | // Widgets / controllers connections | |
176 |
|
177 | |||
177 | // DataSource |
|
178 | // DataSource | |
178 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), |
|
179 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), | |
179 | m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); |
|
180 | m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); | |
180 |
|
181 | |||
181 | // Time |
|
182 | // Time | |
182 | connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(), |
|
183 | connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(), | |
183 | SLOT(onTimeToUpdate(SqpDateTime))); |
|
184 | SLOT(onTimeToUpdate(SqpDateTime))); | |
184 |
|
185 | |||
|
186 | qRegisterMetaType<SqpDateTime>(); | |||
|
187 | connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)), | |||
|
188 | &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime))); | |||
|
189 | ||||
185 | // Widgets / widgets connections |
|
190 | // Widgets / widgets connections | |
186 | qRegisterMetaType<std::shared_ptr<Variable> >(); |
|
191 | qRegisterMetaType<std::shared_ptr<Variable> >(); | |
187 |
|
192 | |||
188 | // For the following connections, we use DirectConnection to allow each widget that can |
|
193 | // 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. |
|
194 | // 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 |
|
195 | // The order of connections is also important, since it determines the order in which each | |
191 | // widget will attach its menu |
|
196 | // widget will attach its menu | |
192 | connect( |
|
197 | connect( | |
193 | m_Ui->variableInspectorWidget, |
|
198 | m_Ui->variableInspectorWidget, | |
194 | SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)), |
|
199 | SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)), | |
195 | m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)), |
|
200 | m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)), | |
196 | Qt::DirectConnection); |
|
201 | Qt::DirectConnection); | |
197 |
|
202 | |||
198 | /* QLopGUI::registerMenuBar(menuBar()); |
|
203 | /* QLopGUI::registerMenuBar(menuBar()); | |
199 | this->setWindowIcon(QIcon(":/sciqlopLOGO.svg")); |
|
204 | this->setWindowIcon(QIcon(":/sciqlopLOGO.svg")); | |
200 | this->m_progressWidget = new QWidget(); |
|
205 | this->m_progressWidget = new QWidget(); | |
201 | this->m_progressLayout = new QVBoxLayout(this->m_progressWidget); |
|
206 | this->m_progressLayout = new QVBoxLayout(this->m_progressWidget); | |
202 | this->m_progressWidget->setLayout(this->m_progressLayout); |
|
207 | this->m_progressWidget->setLayout(this->m_progressLayout); | |
203 | this->m_progressWidget->setWindowModality(Qt::WindowModal); |
|
208 | this->m_progressWidget->setWindowModality(Qt::WindowModal); | |
204 | m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); |
|
209 | m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); | |
205 | for(int i=0;i<OMP_THREADS;i++) |
|
210 | for(int i=0;i<OMP_THREADS;i++) | |
206 | { |
|
211 | { | |
207 | this->m_progress.append(new QProgressBar(this->m_progressWidget)); |
|
212 | this->m_progress.append(new QProgressBar(this->m_progressWidget)); | |
208 | this->m_progress.last()->setMinimum(0); |
|
213 | this->m_progress.last()->setMinimum(0); | |
209 | this->m_progress.last()->setMaximum(100); |
|
214 | this->m_progress.last()->setMaximum(100); | |
210 | this->m_progressLayout->addWidget(this->m_progress.last()); |
|
215 | this->m_progressLayout->addWidget(this->m_progress.last()); | |
211 | this->m_progressWidget->hide(); |
|
216 | this->m_progressWidget->hide(); | |
212 | this->m_progressThreadIds[i] = -1; |
|
217 | this->m_progressThreadIds[i] = -1; | |
213 | } |
|
218 | } | |
214 | this->m_progressWidget->setWindowTitle("Loading File"); |
|
219 | this->m_progressWidget->setWindowTitle("Loading File"); | |
215 | const QList<QLopService*>ServicesToLoad=QList<QLopService*>() |
|
220 | const QList<QLopService*>ServicesToLoad=QList<QLopService*>() | |
216 | << QLopCore::self() |
|
221 | << QLopCore::self() | |
217 | << QLopPlotManager::self() |
|
222 | << QLopPlotManager::self() | |
218 | << QLopCodecManager::self() |
|
223 | << QLopCodecManager::self() | |
219 | << FileDownloader::self() |
|
224 | << FileDownloader::self() | |
220 | << QLopDataBase::self() |
|
225 | << QLopDataBase::self() | |
221 | << SpaceData::self(); |
|
226 | << SpaceData::self(); | |
222 |
|
227 | |||
223 | CDFCodec::registerToManager(); |
|
228 | CDFCodec::registerToManager(); | |
224 | AMDATXTCodec::registerToManager(); |
|
229 | AMDATXTCodec::registerToManager(); | |
225 |
|
230 | |||
226 |
|
231 | |||
227 | for(int i=0;i<ServicesToLoad.count();i++) |
|
232 | for(int i=0;i<ServicesToLoad.count();i++) | |
228 | { |
|
233 | { | |
229 | qDebug()<<ServicesToLoad.at(i)->serviceName(); |
|
234 | qDebug()<<ServicesToLoad.at(i)->serviceName(); | |
230 | ServicesToLoad.at(i)->initialize(); //must be called before getGUI |
|
235 | ServicesToLoad.at(i)->initialize(); //must be called before getGUI | |
231 | QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI(); |
|
236 | QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI(); | |
232 | if(wdgt) |
|
237 | if(wdgt) | |
233 | { |
|
238 | { | |
234 | wdgt->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
239 | wdgt->setAllowedAreas(Qt::AllDockWidgetAreas); | |
235 | this->addDockWidget(Qt::TopDockWidgetArea,wdgt); |
|
240 | this->addDockWidget(Qt::TopDockWidgetArea,wdgt); | |
236 | } |
|
241 | } | |
237 | PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i)); |
|
242 | PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i)); | |
238 | }*/ |
|
243 | }*/ | |
239 | } |
|
244 | } | |
240 |
|
245 | |||
241 | MainWindow::~MainWindow() |
|
246 | MainWindow::~MainWindow() | |
242 | { |
|
247 | { | |
243 | } |
|
248 | } | |
244 |
|
249 | |||
245 |
|
250 | |||
246 | void MainWindow::changeEvent(QEvent *e) |
|
251 | void MainWindow::changeEvent(QEvent *e) | |
247 | { |
|
252 | { | |
248 | QMainWindow::changeEvent(e); |
|
253 | QMainWindow::changeEvent(e); | |
249 | switch (e->type()) { |
|
254 | switch (e->type()) { | |
250 | case QEvent::LanguageChange: |
|
255 | case QEvent::LanguageChange: | |
251 | m_Ui->retranslateUi(this); |
|
256 | m_Ui->retranslateUi(this); | |
252 | break; |
|
257 | break; | |
253 | default: |
|
258 | default: | |
254 | break; |
|
259 | break; | |
255 | } |
|
260 | } | |
256 | } |
|
261 | } |
@@ -1,37 +1,40 | |||||
1 | #ifndef SCIQLOP_TIMECONTROLLER_H |
|
1 | #ifndef SCIQLOP_TIMECONTROLLER_H | |
2 | #define SCIQLOP_TIMECONTROLLER_H |
|
2 | #define SCIQLOP_TIMECONTROLLER_H | |
3 |
|
3 | |||
4 | #include <Data/SqpDateTime.h> |
|
4 | #include <Data/SqpDateTime.h> | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <QObject> |
|
7 | #include <QObject> | |
8 |
|
8 | |||
9 | #include <Common/spimpl.h> |
|
9 | #include <Common/spimpl.h> | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_TimeController) |
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_TimeController) | |
13 |
|
13 | |||
14 | /** |
|
14 | /** | |
15 | * @brief The TimeController class aims to handle the Time parameters notification in SciQlop. |
|
15 | * @brief The TimeController class aims to handle the Time parameters notification in SciQlop. | |
16 | */ |
|
16 | */ | |
17 | class TimeController : public QObject { |
|
17 | class TimeController : public QObject { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 | public: |
|
19 | public: | |
20 | explicit TimeController(QObject *parent = 0); |
|
20 | explicit TimeController(QObject *parent = 0); | |
21 |
|
21 | |||
22 | SqpDateTime dateTime() const noexcept; |
|
22 | SqpDateTime dateTime() const noexcept; | |
23 |
|
23 | |||
24 | signals: |
|
24 | signals: | |
25 | /// Signal emitted to notify that time parameters has beed updated |
|
25 | /// Signal emitted to notify that time parameters has beed updated | |
26 | void timeUpdated(SqpDateTime time); |
|
26 | void timeUpdated(SqpDateTime time); | |
27 |
|
27 | |||
28 | public slots: |
|
28 | public slots: | |
29 |
/// Slot called when a new dateTime has been defined. |
|
29 | /// Slot called when a new dateTime has been defined. | |
30 | void onTimeToUpdate(SqpDateTime dateTime); |
|
30 | void onTimeToUpdate(SqpDateTime dateTime); | |
31 |
|
31 | |||
|
32 | /// Slot called when the dateTime has to be notified. Call timeUpdated signal | |||
|
33 | void onTimeNotify(); | |||
|
34 | ||||
32 | private: |
|
35 | private: | |
33 | class TimeControllerPrivate; |
|
36 | class TimeControllerPrivate; | |
34 | spimpl::unique_impl_ptr<TimeControllerPrivate> impl; |
|
37 | spimpl::unique_impl_ptr<TimeControllerPrivate> impl; | |
35 | }; |
|
38 | }; | |
36 |
|
39 | |||
37 | #endif // SCIQLOP_TIMECONTROLLER_H |
|
40 | #endif // SCIQLOP_TIMECONTROLLER_H |
@@ -1,56 +1,55 | |||||
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 | void setDateTime(const SqpDateTime &dateTime) noexcept; |
|
32 | void setDateTime(const SqpDateTime &dateTime) noexcept; | |
33 |
|
33 | |||
34 | /// @return the data of the variable, nullptr if there is no data |
|
34 | /// @return the data of the variable, nullptr if there is no data | |
35 | IDataSeries *dataSeries() const noexcept; |
|
35 | IDataSeries *dataSeries() const noexcept; | |
36 |
|
36 | |||
37 | bool contains(const SqpDateTime &dateTime); |
|
37 | bool contains(const SqpDateTime &dateTime); | |
38 | bool intersect(const SqpDateTime &dateTime); |
|
38 | bool intersect(const SqpDateTime &dateTime); | |
39 | void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept; |
|
39 | void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept; | |
40 |
|
40 | |||
41 | public slots: |
|
41 | public slots: | |
42 | void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; |
|
42 | void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; | |
43 |
|
43 | |||
44 | signals: |
|
44 | signals: | |
45 | void updated(); |
|
45 | void updated(); | |
46 |
|
46 | |||
47 |
|
||||
48 | private: |
|
47 | private: | |
49 | class VariablePrivate; |
|
48 | class VariablePrivate; | |
50 | spimpl::unique_impl_ptr<VariablePrivate> impl; |
|
49 | spimpl::unique_impl_ptr<VariablePrivate> impl; | |
51 | }; |
|
50 | }; | |
52 |
|
51 | |||
53 | // Required for using shared_ptr in signals/slots |
|
52 | // Required for using shared_ptr in signals/slots | |
54 | Q_DECLARE_METATYPE(std::shared_ptr<Variable>) |
|
53 | Q_DECLARE_METATYPE(std::shared_ptr<Variable>) | |
55 |
|
54 | |||
56 | #endif // SCIQLOP_VARIABLE_H |
|
55 | #endif // SCIQLOP_VARIABLE_H |
@@ -1,57 +1,61 | |||||
1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H |
|
1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H | |
2 | #define SCIQLOP_VARIABLECONTROLLER_H |
|
2 | #define SCIQLOP_VARIABLECONTROLLER_H | |
3 |
|
3 | |||
4 | #include <Data/SqpDateTime.h> |
|
4 | #include <Data/SqpDateTime.h> | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <QObject> |
|
7 | #include <QObject> | |
8 |
|
8 | |||
9 | #include <Common/spimpl.h> |
|
9 | #include <Common/spimpl.h> | |
10 |
|
10 | |||
11 |
|
||||
12 | class IDataProvider; |
|
11 | class IDataProvider; | |
|
12 | class QItemSelectionModel; | |||
13 | class TimeController; |
|
13 | class TimeController; | |
14 | class Variable; |
|
14 | class Variable; | |
15 | class VariableModel; |
|
15 | class VariableModel; | |
16 |
|
16 | |||
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) |
|
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) | |
18 |
|
18 | |||
19 | /** |
|
19 | /** | |
20 | * @brief The VariableController class aims to handle the variables in SciQlop. |
|
20 | * @brief The VariableController class aims to handle the variables in SciQlop. | |
21 | */ |
|
21 | */ | |
22 | class VariableController : public QObject { |
|
22 | class VariableController : public QObject { | |
23 | Q_OBJECT |
|
23 | Q_OBJECT | |
24 | public: |
|
24 | public: | |
25 | explicit VariableController(QObject *parent = 0); |
|
25 | explicit VariableController(QObject *parent = 0); | |
26 | virtual ~VariableController(); |
|
26 | virtual ~VariableController(); | |
27 |
|
27 | |||
28 | VariableModel *variableModel() noexcept; |
|
28 | VariableModel *variableModel() noexcept; | |
|
29 | QItemSelectionModel *variableSelectionModel() noexcept; | |||
29 |
|
30 | |||
30 | void setTimeController(TimeController *timeController) noexcept; |
|
31 | void setTimeController(TimeController *timeController) noexcept; | |
31 |
|
32 | |||
32 |
|
33 | |||
33 | signals: |
|
34 | signals: | |
34 | /// Signal emitted when a variable has been created |
|
35 | /// Signal emitted when a variable has been created | |
35 | void variableCreated(std::shared_ptr<Variable> variable); |
|
36 | void variableCreated(std::shared_ptr<Variable> variable); | |
36 |
|
37 | |||
37 | public slots: |
|
38 | public slots: | |
38 | /// Request the data loading of the variable whithin dateTime |
|
39 | /// Request the data loading of the variable whithin dateTime | |
39 | void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); |
|
40 | void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); | |
40 | /** |
|
41 | /** | |
41 | * Creates a new variable and adds it to the model |
|
42 | * Creates a new variable and adds it to the model | |
42 | * @param name the name of the new variable |
|
43 | * @param name the name of the new variable | |
43 | * @param provider the data provider for the new variable |
|
44 | * @param provider the data provider for the new variable | |
44 | */ |
|
45 | */ | |
45 | void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept; |
|
46 | void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept; | |
46 |
|
47 | |||
|
48 | /// Update the temporal parameters of every selected variable to dateTime | |||
|
49 | void onDateTimeOnSelection(const SqpDateTime &dateTime); | |||
|
50 | ||||
47 | void initialize(); |
|
51 | void initialize(); | |
48 | void finalize(); |
|
52 | void finalize(); | |
49 |
|
53 | |||
50 | private: |
|
54 | private: | |
51 | void waitForFinish(); |
|
55 | void waitForFinish(); | |
52 |
|
56 | |||
53 | class VariableControllerPrivate; |
|
57 | class VariableControllerPrivate; | |
54 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; |
|
58 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; | |
55 | }; |
|
59 | }; | |
56 |
|
60 | |||
57 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
|
61 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
@@ -1,26 +1,29 | |||||
1 | #include "Time/TimeController.h" |
|
1 | #include "Time/TimeController.h" | |
2 |
|
2 | |||
3 | Q_LOGGING_CATEGORY(LOG_TimeController, "TimeController") |
|
3 | Q_LOGGING_CATEGORY(LOG_TimeController, "TimeController") | |
4 |
|
4 | |||
5 | struct TimeController::TimeControllerPrivate { |
|
5 | struct TimeController::TimeControllerPrivate { | |
6 |
|
6 | |||
7 | SqpDateTime m_DateTime; |
|
7 | SqpDateTime m_DateTime; | |
8 | }; |
|
8 | }; | |
9 |
|
9 | |||
10 | TimeController::TimeController(QObject *parent) |
|
10 | TimeController::TimeController(QObject *parent) | |
11 | : QObject{parent}, impl{spimpl::make_unique_impl<TimeControllerPrivate>()} |
|
11 | : QObject{parent}, impl{spimpl::make_unique_impl<TimeControllerPrivate>()} | |
12 | { |
|
12 | { | |
13 | qCDebug(LOG_TimeController()) << tr("TimeController construction"); |
|
13 | qCDebug(LOG_TimeController()) << tr("TimeController construction"); | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | SqpDateTime TimeController::dateTime() const noexcept |
|
16 | SqpDateTime TimeController::dateTime() const noexcept | |
17 | { |
|
17 | { | |
18 | return impl->m_DateTime; |
|
18 | return impl->m_DateTime; | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | void TimeController::onTimeToUpdate(SqpDateTime dateTime) |
|
21 | void TimeController::onTimeToUpdate(SqpDateTime dateTime) | |
22 | { |
|
22 | { | |
23 | impl->m_DateTime = dateTime; |
|
23 | impl->m_DateTime = dateTime; | |
|
24 | } | |||
24 |
|
25 | |||
25 | emit timeUpdated(dateTime); |
|
26 | void TimeController::onTimeNotify() | |
|
27 | { | |||
|
28 | emit timeUpdated(impl->m_DateTime); | |||
26 | } |
|
29 | } |
@@ -1,205 +1,205 | |||||
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 | Q_LOGGING_CATEGORY(LOG_VariableCacheController, "VariableCacheController") |
|
6 | Q_LOGGING_CATEGORY(LOG_VariableCacheController, "VariableCacheController") | |
7 |
|
7 | |||
8 | struct VariableCacheController::VariableCacheControllerPrivate { |
|
8 | struct VariableCacheController::VariableCacheControllerPrivate { | |
9 |
|
9 | |||
10 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> > |
|
10 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> > | |
11 | m_VariableToSqpDateTimeListMap; |
|
11 | m_VariableToSqpDateTimeListMap; | |
12 |
|
12 | |||
13 | void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
13 | void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
14 | QVector<SqpDateTime> ¬InCache, int cacheIndex, |
|
14 | QVector<SqpDateTime> ¬InCache, int cacheIndex, | |
15 | double currentTStart); |
|
15 | double currentTStart); | |
16 |
|
16 | |||
17 | void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
17 | void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
18 | QVector<SqpDateTime> ¬InCache, int cacheIndex, |
|
18 | QVector<SqpDateTime> ¬InCache, int cacheIndex, | |
19 | double currentTStart); |
|
19 | double currentTStart); | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
22 | void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
23 | int cacheIndex); |
|
23 | int cacheIndex); | |
24 | }; |
|
24 | }; | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | VariableCacheController::VariableCacheController(QObject *parent) |
|
27 | VariableCacheController::VariableCacheController(QObject *parent) | |
28 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()} |
|
28 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()} | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable, |
|
32 | void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable, | |
33 | const SqpDateTime &dateTime) |
|
33 | const SqpDateTime &dateTime) | |
34 | { |
|
34 | { | |
35 | if (variable) { |
|
35 | if (variable) { | |
36 | auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable); |
|
36 | auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable); | |
37 | if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) { |
|
37 | if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) { | |
38 | impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime); |
|
38 | impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime); | |
39 | } |
|
39 | } | |
40 | else { |
|
40 | else { | |
41 |
|
41 | |||
42 | // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure |
|
42 | // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure | |
43 | // that the list is ordered : l(0) < l(1). We assume also a < b |
|
43 | // that the list is ordered : l(0) < l(1). We assume also a < b | |
44 | // (with a & b of type SqpDateTime) means ts(b) > te(a) |
|
44 | // (with a & b of type SqpDateTime) means ts(b) > te(a) | |
45 |
|
45 | |||
46 | // The algorithm will try the merge of two interval: |
|
46 | // The algorithm will try the merge of two interval: | |
47 | // - dateTime will be compare with the first interval of the list: |
|
47 | // - dateTime will be compare with the first interval of the list: | |
48 | // A: if it is inferior, it will be inserted and it's finished. |
|
48 | // A: if it is inferior, it will be inserted and it's finished. | |
49 | // B: if it is in intersection, it will be merge then the merged one |
|
49 | // B: if it is in intersection, it will be merge then the merged one | |
50 | // will be compared to the next interval. The old one is remove from the list |
|
50 | // will be compared to the next interval. The old one is remove from the list | |
51 | // C: if it is superior, we do the same with the next interval of the list |
|
51 | // C: if it is superior, we do the same with the next interval of the list | |
52 |
|
52 | |||
53 | try { |
|
53 | try { | |
54 | impl->addDateTimeRecurse(dateTime, |
|
54 | impl->addDateTimeRecurse(dateTime, | |
55 | impl->m_VariableToSqpDateTimeListMap.at(variable), 0); |
|
55 | impl->m_VariableToSqpDateTimeListMap.at(variable), 0); | |
56 | } |
|
56 | } | |
57 | catch (const std::out_of_range &e) { |
|
57 | catch (const std::out_of_range &e) { | |
58 |
qC |
|
58 | qCWarning(LOG_VariableCacheController()) << e.what(); | |
59 | } |
|
59 | } | |
60 | } |
|
60 | } | |
61 | } |
|
61 | } | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | QVector<SqpDateTime> |
|
64 | QVector<SqpDateTime> | |
65 | VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, |
|
65 | VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, | |
66 | const SqpDateTime &dateTime) |
|
66 | const SqpDateTime &dateTime) | |
67 | { |
|
67 | { | |
68 | auto notInCache = QVector<SqpDateTime>{}; |
|
68 | auto notInCache = QVector<SqpDateTime>{}; | |
69 |
|
69 | |||
70 | // This algorithm is recursif. The idea is to localise the start time then the end time in the |
|
70 | // This algorithm is recursif. The idea is to localise the start time then the end time in the | |
71 | // list of date time request associated to the variable |
|
71 | // list of date time request associated to the variable | |
72 | // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b |
|
72 | // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b | |
73 | // (with a & b of type SqpDateTime) means ts(b) > te(a) |
|
73 | // (with a & b of type SqpDateTime) means ts(b) > te(a) | |
74 |
|
74 | |||
75 | try { |
|
75 | try { | |
76 | impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), |
|
76 | impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), | |
77 | notInCache, 0, dateTime.m_TStart); |
|
77 | notInCache, 0, dateTime.m_TStart); | |
78 | } |
|
78 | } | |
79 | catch (const std::out_of_range &e) { |
|
79 | catch (const std::out_of_range &e) { | |
80 |
qC |
|
80 | qCWarning(LOG_VariableCacheController()) << e.what(); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | return notInCache; |
|
83 | return notInCache; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | QVector<SqpDateTime> |
|
86 | QVector<SqpDateTime> | |
87 | VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept |
|
87 | VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept | |
88 | { |
|
88 | { | |
89 | try { |
|
89 | try { | |
90 | return impl->m_VariableToSqpDateTimeListMap.at(variable); |
|
90 | return impl->m_VariableToSqpDateTimeListMap.at(variable); | |
91 | } |
|
91 | } | |
92 | catch (const std::out_of_range &e) { |
|
92 | catch (const std::out_of_range &e) { | |
93 |
qC |
|
93 | qCWarning(LOG_VariableCacheController()) << e.what(); | |
94 | return QVector<SqpDateTime>{}; |
|
94 | return QVector<SqpDateTime>{}; | |
95 | } |
|
95 | } | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse( |
|
98 | void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse( | |
99 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex) |
|
99 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex) | |
100 | { |
|
100 | { | |
101 | const auto dateTimeListSize = dateTimeList.count(); |
|
101 | const auto dateTimeListSize = dateTimeList.count(); | |
102 | if (cacheIndex >= dateTimeListSize) { |
|
102 | if (cacheIndex >= dateTimeListSize) { | |
103 | dateTimeList.push_back(dateTime); |
|
103 | dateTimeList.push_back(dateTime); | |
104 | // there is no anymore interval to compore, we can just push_back it |
|
104 | // there is no anymore interval to compore, we can just push_back it | |
105 | return; |
|
105 | return; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | auto currentDateTime = dateTimeList[cacheIndex]; |
|
108 | auto currentDateTime = dateTimeList[cacheIndex]; | |
109 |
|
109 | |||
110 | if (dateTime.m_TEnd < currentDateTime.m_TStart) { |
|
110 | if (dateTime.m_TEnd < currentDateTime.m_TStart) { | |
111 | // The compared one is < to current one compared, we can insert it |
|
111 | // The compared one is < to current one compared, we can insert it | |
112 | dateTimeList.insert(cacheIndex, dateTime); |
|
112 | dateTimeList.insert(cacheIndex, dateTime); | |
113 | } |
|
113 | } | |
114 | else if (dateTime.m_TStart > currentDateTime.m_TEnd) { |
|
114 | else if (dateTime.m_TStart > currentDateTime.m_TEnd) { | |
115 | // The compared one is > to current one compared we can comparet if to the next one |
|
115 | // The compared one is > to current one compared we can comparet if to the next one | |
116 | addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex); |
|
116 | addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex); | |
117 | } |
|
117 | } | |
118 | else { |
|
118 | else { | |
119 | // Merge cases: we need to merge the two interval, remove the old one from the list then |
|
119 | // Merge cases: we need to merge the two interval, remove the old one from the list then | |
120 | // rerun the algo from this index with the merged interval |
|
120 | // rerun the algo from this index with the merged interval | |
121 | auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart); |
|
121 | auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart); | |
122 | auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd); |
|
122 | auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd); | |
123 | auto mergeDateTime = SqpDateTime{mTStart, mTEnd}; |
|
123 | auto mergeDateTime = SqpDateTime{mTStart, mTEnd}; | |
124 |
|
124 | |||
125 | dateTimeList.remove(cacheIndex); |
|
125 | dateTimeList.remove(cacheIndex); | |
126 | addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex); |
|
126 | addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex); | |
127 | } |
|
127 | } | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 |
|
130 | |||
131 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd( |
|
131 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd( | |
132 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
132 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
133 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) |
|
133 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) | |
134 | { |
|
134 | { | |
135 | const auto dateTimeListSize = dateTimeList.count(); |
|
135 | const auto dateTimeListSize = dateTimeList.count(); | |
136 | if (cacheIndex >= dateTimeListSize) { |
|
136 | if (cacheIndex >= dateTimeListSize) { | |
137 | if (currentTStart < dateTime.m_TEnd) { |
|
137 | if (currentTStart < dateTime.m_TEnd) { | |
138 |
|
138 | |||
139 | // te localised after all other interval: The last interval is [currentTsart, te] |
|
139 | // te localised after all other interval: The last interval is [currentTsart, te] | |
140 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
140 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
141 | } |
|
141 | } | |
142 | return; |
|
142 | return; | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | auto currentDateTimeJ = dateTimeList[cacheIndex]; |
|
145 | auto currentDateTimeJ = dateTimeList[cacheIndex]; | |
146 | if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) { |
|
146 | if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) { | |
147 | // te localised between to interval: The last interval is [currentTsart, te] |
|
147 | // te localised between to interval: The last interval is [currentTsart, te] | |
148 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
148 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
149 | } |
|
149 | } | |
150 | else { |
|
150 | else { | |
151 | notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart}); |
|
151 | notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart}); | |
152 | if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) { |
|
152 | if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) { | |
153 | // te not localised before the current interval: we need to look at the next interval |
|
153 | // te not localised before the current interval: we need to look at the next interval | |
154 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex, |
|
154 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex, | |
155 | currentDateTimeJ.m_TEnd); |
|
155 | currentDateTimeJ.m_TEnd); | |
156 | } |
|
156 | } | |
157 | } |
|
157 | } | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart( |
|
160 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart( | |
161 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
161 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
162 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) |
|
162 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) | |
163 | { |
|
163 | { | |
164 | const auto dateTimeListSize = dateTimeList.count(); |
|
164 | const auto dateTimeListSize = dateTimeList.count(); | |
165 | if (cacheIndex >= dateTimeListSize) { |
|
165 | if (cacheIndex >= dateTimeListSize) { | |
166 | // ts localised after all other interval: The last interval is [ts, te] |
|
166 | // ts localised after all other interval: The last interval is [ts, te] | |
167 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
167 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
168 | return; |
|
168 | return; | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | auto currentDateTimeI = dateTimeList[cacheIndex]; |
|
171 | auto currentDateTimeI = dateTimeList[cacheIndex]; | |
172 | if (currentTStart < currentDateTimeI.m_TStart) { |
|
172 | if (currentTStart < currentDateTimeI.m_TStart) { | |
173 |
|
173 | |||
174 | // ts localised between to interval: let's localized te |
|
174 | // ts localised between to interval: let's localized te | |
175 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart); |
|
175 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart); | |
176 | } |
|
176 | } | |
177 | else if (currentTStart < currentDateTimeI.m_TEnd) { |
|
177 | else if (currentTStart < currentDateTimeI.m_TEnd) { | |
178 | if (dateTime.m_TEnd > currentDateTimeI.m_TEnd) { |
|
178 | if (dateTime.m_TEnd > currentDateTimeI.m_TEnd) { | |
179 | // ts not localised before the current interval: we need to look at the next interval |
|
179 | // ts not localised before the current interval: we need to look at the next interval | |
180 | // We can assume now current tstart is the last interval tend, because data between them |
|
180 | // We can assume now current tstart is the last interval tend, because data between them | |
181 | // are |
|
181 | // are | |
182 | // in the cache |
|
182 | // in the cache | |
183 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, |
|
183 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, | |
184 | currentDateTimeI.m_TEnd); |
|
184 | currentDateTimeI.m_TEnd); | |
185 | } |
|
185 | } | |
186 | } |
|
186 | } | |
187 | else { |
|
187 | else { | |
188 | // ts not localised before the current interval: we need to look at the next interval |
|
188 | // ts not localised before the current interval: we need to look at the next interval | |
189 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart); |
|
189 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart); | |
190 | } |
|
190 | } | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 |
|
193 | |||
194 | void VariableCacheController::displayCache(std::shared_ptr<Variable> variable) const |
|
194 | void VariableCacheController::displayCache(std::shared_ptr<Variable> variable) const | |
195 | { |
|
195 | { | |
196 | auto variableDateTimeList = impl->m_VariableToSqpDateTimeListMap.find(variable); |
|
196 | auto variableDateTimeList = impl->m_VariableToSqpDateTimeListMap.find(variable); | |
197 | if (variableDateTimeList != impl->m_VariableToSqpDateTimeListMap.end()) { |
|
197 | if (variableDateTimeList != impl->m_VariableToSqpDateTimeListMap.end()) { | |
198 | qCInfo(LOG_VariableCacheController()) << tr("VariableCacheController::displayCache") |
|
198 | qCInfo(LOG_VariableCacheController()) << tr("VariableCacheController::displayCache") | |
199 | << variableDateTimeList->second; |
|
199 | << variableDateTimeList->second; | |
200 | } |
|
200 | } | |
201 | else { |
|
201 | else { | |
202 | qCWarning(LOG_VariableCacheController()) |
|
202 | qCWarning(LOG_VariableCacheController()) | |
203 | << tr("Cannot display a variable that is not in the cache"); |
|
203 | << tr("Cannot display a variable that is not in the cache"); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } |
@@ -1,157 +1,177 | |||||
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 <QMutex> |
|
12 | #include <QMutex> | |
13 | #include <QThread> |
|
13 | #include <QThread> | |
|
14 | #include <QtCore/QItemSelectionModel> | |||
14 |
|
15 | |||
15 | #include <unordered_map> |
|
16 | #include <unordered_map> | |
16 |
|
17 | |||
17 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
18 |
|
19 | |||
19 | namespace { |
|
20 | namespace { | |
20 |
|
21 | |||
21 | /// @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 | |
22 | /// will be deleted when the timerange is recovered from SciQlop |
|
23 | /// will be deleted when the timerange is recovered from SciQlop | |
23 | std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, |
|
24 | std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, | |
24 | const SqpDateTime &dateTime) noexcept |
|
25 | const SqpDateTime &dateTime) noexcept | |
25 | { |
|
26 | { | |
26 | auto parameters = DataProviderParameters{dateTime}; |
|
27 | auto parameters = DataProviderParameters{dateTime}; | |
27 |
|
28 | |||
28 | return provider.retrieveData(parameters); |
|
29 | return provider.retrieveData(parameters); | |
29 | } |
|
30 | } | |
30 |
|
31 | |||
31 | } // namespace |
|
32 | } // namespace | |
32 |
|
33 | |||
33 | struct VariableController::VariableControllerPrivate { |
|
34 | struct VariableController::VariableControllerPrivate { | |
34 | explicit VariableControllerPrivate(VariableController *parent) |
|
35 | explicit VariableControllerPrivate(VariableController *parent) | |
35 | : m_WorkingMutex{}, |
|
36 | : m_WorkingMutex{}, | |
36 | m_VariableModel{new VariableModel{parent}}, |
|
37 | m_VariableModel{new VariableModel{parent}}, | |
|
38 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, | |||
37 | m_VariableCacheController{std::make_unique<VariableCacheController>()} |
|
39 | m_VariableCacheController{std::make_unique<VariableCacheController>()} | |
38 | { |
|
40 | { | |
39 | } |
|
41 | } | |
40 |
|
42 | |||
41 | QMutex m_WorkingMutex; |
|
43 | QMutex m_WorkingMutex; | |
42 | /// Variable model. The VariableController has the ownership |
|
44 | /// Variable model. The VariableController has the ownership | |
43 | VariableModel *m_VariableModel; |
|
45 | VariableModel *m_VariableModel; | |
|
46 | QItemSelectionModel *m_VariableSelectionModel; | |||
44 |
|
47 | |||
45 |
|
48 | |||
46 | TimeController *m_TimeController{nullptr}; |
|
49 | TimeController *m_TimeController{nullptr}; | |
47 | std::unique_ptr<VariableCacheController> m_VariableCacheController; |
|
50 | std::unique_ptr<VariableCacheController> m_VariableCacheController; | |
48 |
|
51 | |||
49 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
52 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
50 | m_VariableToProviderMap; |
|
53 | m_VariableToProviderMap; | |
51 | }; |
|
54 | }; | |
52 |
|
55 | |||
53 | VariableController::VariableController(QObject *parent) |
|
56 | VariableController::VariableController(QObject *parent) | |
54 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
57 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
55 | { |
|
58 | { | |
56 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
59 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
57 | << QThread::currentThread(); |
|
60 | << QThread::currentThread(); | |
58 | } |
|
61 | } | |
59 |
|
62 | |||
60 | VariableController::~VariableController() |
|
63 | VariableController::~VariableController() | |
61 | { |
|
64 | { | |
62 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
65 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
63 | << QThread::currentThread(); |
|
66 | << QThread::currentThread(); | |
64 | this->waitForFinish(); |
|
67 | this->waitForFinish(); | |
65 | } |
|
68 | } | |
66 |
|
69 | |||
67 | VariableModel *VariableController::variableModel() noexcept |
|
70 | VariableModel *VariableController::variableModel() noexcept | |
68 | { |
|
71 | { | |
69 | return impl->m_VariableModel; |
|
72 | return impl->m_VariableModel; | |
70 | } |
|
73 | } | |
71 |
|
74 | |||
|
75 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept | |||
|
76 | { | |||
|
77 | return impl->m_VariableSelectionModel; | |||
|
78 | } | |||
|
79 | ||||
72 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
80 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
73 | { |
|
81 | { | |
74 | impl->m_TimeController = timeController; |
|
82 | impl->m_TimeController = timeController; | |
75 | } |
|
83 | } | |
76 |
|
84 | |||
77 | void VariableController::createVariable(const QString &name, |
|
85 | void VariableController::createVariable(const QString &name, | |
78 | std::shared_ptr<IDataProvider> provider) noexcept |
|
86 | std::shared_ptr<IDataProvider> provider) noexcept | |
79 | { |
|
87 | { | |
80 |
|
88 | |||
81 | if (!impl->m_TimeController) { |
|
89 | if (!impl->m_TimeController) { | |
82 | qCCritical(LOG_VariableController()) |
|
90 | qCCritical(LOG_VariableController()) | |
83 | << tr("Impossible to create variable: The time controller is null"); |
|
91 | << tr("Impossible to create variable: The time controller is null"); | |
84 | return; |
|
92 | return; | |
85 | } |
|
93 | } | |
86 |
|
94 | |||
87 |
|
95 | |||
88 | /// @todo : for the moment : |
|
96 | /// @todo : for the moment : | |
89 | /// - the provider is only used to retrieve data from the variable for its initialization, but |
|
97 | /// - the provider is only used to retrieve data from the variable for its initialization, but | |
90 | /// it will be retained later |
|
98 | /// it will be retained later | |
91 | /// - default data are generated for the variable, without taking into account the timerange set |
|
99 | /// - default data are generated for the variable, without taking into account the timerange set | |
92 | /// in sciqlop |
|
100 | /// in sciqlop | |
93 | auto dateTime = impl->m_TimeController->dateTime(); |
|
101 | auto dateTime = impl->m_TimeController->dateTime(); | |
94 | if (auto newVariable = impl->m_VariableModel->createVariable( |
|
102 | if (auto newVariable = impl->m_VariableModel->createVariable( | |
95 | name, dateTime, generateDefaultDataSeries(*provider, dateTime))) { |
|
103 | name, dateTime, generateDefaultDataSeries(*provider, dateTime))) { | |
96 |
|
104 | |||
97 | // store the provider |
|
105 | // store the provider | |
98 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
106 | impl->m_VariableToProviderMap[newVariable] = provider; | |
99 | qRegisterMetaType<std::shared_ptr<IDataSeries> >(); |
|
107 | qRegisterMetaType<std::shared_ptr<IDataSeries> >(); | |
100 | qRegisterMetaType<SqpDateTime>(); |
|
108 | qRegisterMetaType<SqpDateTime>(); | |
101 | connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(), |
|
109 | connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(), | |
102 | &Variable::onAddDataSeries); |
|
110 | &Variable::onAddDataSeries); | |
103 |
|
111 | |||
104 |
|
112 | |||
105 | // store in cache |
|
113 | // store in cache | |
106 | impl->m_VariableCacheController->addDateTime(newVariable, dateTime); |
|
114 | impl->m_VariableCacheController->addDateTime(newVariable, dateTime); | |
107 |
|
115 | |||
108 | // notify the creation |
|
116 | // notify the creation | |
109 | emit variableCreated(newVariable); |
|
117 | emit variableCreated(newVariable); | |
110 | } |
|
118 | } | |
111 | } |
|
119 | } | |
112 |
|
120 | |||
|
121 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) | |||
|
122 | { | |||
|
123 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); | |||
|
124 | ||||
|
125 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |||
|
126 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { | |||
|
127 | selectedVariable->setDateTime(dateTime); | |||
|
128 | this->onRequestDataLoading(selectedVariable, dateTime); | |||
|
129 | } | |||
|
130 | } | |||
|
131 | } | |||
|
132 | ||||
113 |
|
133 | |||
114 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, |
|
134 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, | |
115 | const SqpDateTime &dateTime) |
|
135 | const SqpDateTime &dateTime) | |
116 | { |
|
136 | { | |
117 | // we want to load data of the variable for the dateTime. |
|
137 | // we want to load data of the variable for the dateTime. | |
118 | // First we check if the cache contains some of them. |
|
138 | // First we check if the cache contains some of them. | |
119 | // For the other, we ask the provider to give them. |
|
139 | // For the other, we ask the provider to give them. | |
120 | if (variable) { |
|
140 | if (variable) { | |
121 |
|
141 | |||
122 | auto dateTimeListNotInCache |
|
142 | auto dateTimeListNotInCache | |
123 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); |
|
143 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); | |
124 |
|
144 | |||
125 | if (!dateTimeListNotInCache.empty()) { |
|
145 | if (!dateTimeListNotInCache.empty()) { | |
126 | // Ask the provider for each data on the dateTimeListNotInCache |
|
146 | // Ask the provider for each data on the dateTimeListNotInCache | |
127 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( |
|
147 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( | |
128 | std::move(dateTimeListNotInCache)); |
|
148 | std::move(dateTimeListNotInCache)); | |
129 | // store in cache |
|
149 | // store in cache | |
130 | impl->m_VariableCacheController->addDateTime(variable, dateTime); |
|
150 | impl->m_VariableCacheController->addDateTime(variable, dateTime); | |
131 | } |
|
151 | } | |
132 | else { |
|
152 | else { | |
133 | emit variable->updated(); |
|
153 | emit variable->updated(); | |
134 | } |
|
154 | } | |
135 | } |
|
155 | } | |
136 | else { |
|
156 | else { | |
137 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
|
157 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); | |
138 | } |
|
158 | } | |
139 | } |
|
159 | } | |
140 |
|
160 | |||
141 |
|
161 | |||
142 | void VariableController::initialize() |
|
162 | void VariableController::initialize() | |
143 | { |
|
163 | { | |
144 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
164 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
145 | impl->m_WorkingMutex.lock(); |
|
165 | impl->m_WorkingMutex.lock(); | |
146 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
166 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
147 | } |
|
167 | } | |
148 |
|
168 | |||
149 | void VariableController::finalize() |
|
169 | void VariableController::finalize() | |
150 | { |
|
170 | { | |
151 | impl->m_WorkingMutex.unlock(); |
|
171 | impl->m_WorkingMutex.unlock(); | |
152 | } |
|
172 | } | |
153 |
|
173 | |||
154 | void VariableController::waitForFinish() |
|
174 | void VariableController::waitForFinish() | |
155 | { |
|
175 | { | |
156 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
176 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
157 | } |
|
177 | } |
@@ -1,29 +1,48 | |||||
1 | #include "TimeWidget/TimeWidget.h" |
|
1 | #include "TimeWidget/TimeWidget.h" | |
2 | #include "ui_TimeWidget.h" |
|
2 | #include "ui_TimeWidget.h" | |
3 |
|
3 | |||
|
4 | #include <SqpApplication.h> | |||
|
5 | #include <Time/TimeController.h> | |||
4 |
|
6 | |||
5 | TimeWidget::TimeWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::TimeWidget} |
|
7 | TimeWidget::TimeWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::TimeWidget} | |
6 | { |
|
8 | { | |
7 | ui->setupUi(this); |
|
9 | ui->setupUi(this); | |
8 |
|
10 | |||
|
11 | ui->applyToolButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_DialogApplyButton)); | |||
|
12 | ||||
9 | // Connection |
|
13 | // Connection | |
10 | connect(ui->startDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, |
|
14 | connect(ui->startDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, | |
11 | &TimeWidget::onTimeUpdateRequested); |
|
15 | &TimeWidget::onTimeUpdateRequested); | |
12 |
|
16 | |||
13 | connect(ui->endDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, |
|
17 | connect(ui->endDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, | |
14 | &TimeWidget::onTimeUpdateRequested); |
|
18 | &TimeWidget::onTimeUpdateRequested); | |
|
19 | ||||
|
20 | ||||
|
21 | connect(ui->applyToolButton, &QToolButton::clicked, &sqpApp->timeController(), | |||
|
22 | &TimeController::onTimeNotify); | |||
|
23 | ||||
|
24 | // Initialisation | |||
|
25 | ui->startDateTimeEdit->setDateTime( | |||
|
26 | QDateTime::currentDateTime().addSecs(-3600)); // one hour berefore | |||
|
27 | ui->endDateTimeEdit->setDateTime(QDateTime::currentDateTime()); | |||
|
28 | ||||
|
29 | auto dateTime | |||
|
30 | = SqpDateTime{QDateTime::currentDateTime().addSecs(-3600).toMSecsSinceEpoch() / 1000.0, | |||
|
31 | QDateTime::currentDateTime().toMSecsSinceEpoch() / 1000.0}; | |||
|
32 | sqpApp->timeController().onTimeToUpdate(dateTime); | |||
15 | } |
|
33 | } | |
16 |
|
34 | |||
|
35 | ||||
17 | TimeWidget::~TimeWidget() |
|
36 | TimeWidget::~TimeWidget() | |
18 | { |
|
37 | { | |
19 | delete ui; |
|
38 | delete ui; | |
20 | } |
|
39 | } | |
21 |
|
40 | |||
22 | void TimeWidget::onTimeUpdateRequested() |
|
41 | void TimeWidget::onTimeUpdateRequested() | |
23 | { |
|
42 | { | |
24 | auto dateTime = SqpDateTime{ |
|
43 | auto dateTime = SqpDateTime{ | |
25 | static_cast<double>(ui->startDateTimeEdit->dateTime().toMSecsSinceEpoch() / 1000.), |
|
44 | static_cast<double>(ui->startDateTimeEdit->dateTime().toMSecsSinceEpoch() / 1000.), | |
26 | static_cast<double>(ui->endDateTimeEdit->dateTime().toMSecsSinceEpoch()) / 1000.}; |
|
45 | static_cast<double>(ui->endDateTimeEdit->dateTime().toMSecsSinceEpoch()) / 1000.}; | |
27 |
|
46 | |||
28 | emit timeUpdated(std::move(dateTime)); |
|
47 | emit timeUpdated(std::move(dateTime)); | |
29 | } |
|
48 | } |
@@ -1,88 +1,89 | |||||
1 | #include <Variable/VariableController.h> |
|
1 | #include <Variable/VariableController.h> | |
2 | #include <Variable/VariableInspectorWidget.h> |
|
2 | #include <Variable/VariableInspectorWidget.h> | |
3 | #include <Variable/VariableMenuHeaderWidget.h> |
|
3 | #include <Variable/VariableMenuHeaderWidget.h> | |
4 | #include <Variable/VariableModel.h> |
|
4 | #include <Variable/VariableModel.h> | |
5 |
|
5 | |||
6 | #include <ui_VariableInspectorWidget.h> |
|
6 | #include <ui_VariableInspectorWidget.h> | |
7 |
|
7 | |||
8 | #include <QSortFilterProxyModel> |
|
8 | #include <QSortFilterProxyModel> | |
9 | #include <QWidgetAction> |
|
9 | #include <QWidgetAction> | |
10 |
|
10 | |||
11 | #include <SqpApplication.h> |
|
11 | #include <SqpApplication.h> | |
12 |
|
12 | |||
13 | Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") |
|
13 | Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") | |
14 |
|
14 | |||
15 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) |
|
15 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) | |
16 | : QWidget{parent}, ui{new Ui::VariableInspectorWidget} |
|
16 | : QWidget{parent}, ui{new Ui::VariableInspectorWidget} | |
17 | { |
|
17 | { | |
18 | ui->setupUi(this); |
|
18 | ui->setupUi(this); | |
19 |
|
19 | |||
20 | // Sets model for table |
|
20 | // Sets model for table | |
21 | auto sortFilterModel = new QSortFilterProxyModel{this}; |
|
21 | // auto sortFilterModel = new QSortFilterProxyModel{this}; | |
22 | sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); |
|
22 | // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); | |
23 |
|
23 | |||
24 |
ui->tableView->setModel(s |
|
24 | ui->tableView->setModel(sqpApp->variableController().variableModel()); | |
|
25 | ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel()); | |||
25 |
|
26 | |||
26 | // Fixes column sizes |
|
27 | // Fixes column sizes | |
27 | auto model = ui->tableView->model(); |
|
28 | auto model = ui->tableView->model(); | |
28 | const auto count = model->columnCount(); |
|
29 | const auto count = model->columnCount(); | |
29 | for (auto i = 0; i < count; ++i) { |
|
30 | for (auto i = 0; i < count; ++i) { | |
30 | ui->tableView->setColumnWidth( |
|
31 | ui->tableView->setColumnWidth( | |
31 | i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width()); |
|
32 | i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width()); | |
32 | } |
|
33 | } | |
33 |
|
34 | |||
34 | // Sets selection options |
|
35 | // Sets selection options | |
35 | ui->tableView->setSelectionBehavior(QTableView::SelectRows); |
|
36 | ui->tableView->setSelectionBehavior(QTableView::SelectRows); | |
36 | ui->tableView->setSelectionMode(QTableView::ExtendedSelection); |
|
37 | ui->tableView->setSelectionMode(QTableView::ExtendedSelection); | |
37 |
|
38 | |||
38 | // Connection to show a menu when right clicking on the tree |
|
39 | // Connection to show a menu when right clicking on the tree | |
39 | ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); |
|
40 | ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); | |
40 | connect(ui->tableView, &QTableView::customContextMenuRequested, this, |
|
41 | connect(ui->tableView, &QTableView::customContextMenuRequested, this, | |
41 | &VariableInspectorWidget::onTableMenuRequested); |
|
42 | &VariableInspectorWidget::onTableMenuRequested); | |
42 | } |
|
43 | } | |
43 |
|
44 | |||
44 | VariableInspectorWidget::~VariableInspectorWidget() |
|
45 | VariableInspectorWidget::~VariableInspectorWidget() | |
45 | { |
|
46 | { | |
46 | delete ui; |
|
47 | delete ui; | |
47 | } |
|
48 | } | |
48 |
|
49 | |||
49 | void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept |
|
50 | void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept | |
50 | { |
|
51 | { | |
51 | auto selectedRows = ui->tableView->selectionModel()->selectedRows(); |
|
52 | auto selectedRows = ui->tableView->selectionModel()->selectedRows(); | |
52 |
|
53 | |||
53 | // Gets the model to retrieve the underlying selected variables |
|
54 | // Gets the model to retrieve the underlying selected variables | |
54 | auto model = sqpApp->variableController().variableModel(); |
|
55 | auto model = sqpApp->variableController().variableModel(); | |
55 | auto selectedVariables = QVector<std::shared_ptr<Variable> >{}; |
|
56 | auto selectedVariables = QVector<std::shared_ptr<Variable> >{}; | |
56 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
57 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
57 | if (auto selectedVariable = model->variable(selectedRow.row())) { |
|
58 | if (auto selectedVariable = model->variable(selectedRow.row())) { | |
58 | selectedVariables.push_back(selectedVariable); |
|
59 | selectedVariables.push_back(selectedVariable); | |
59 | } |
|
60 | } | |
60 | } |
|
61 | } | |
61 |
|
62 | |||
62 | QMenu tableMenu{}; |
|
63 | QMenu tableMenu{}; | |
63 |
|
64 | |||
64 | // Emits a signal so that potential receivers can populate the menu before displaying it |
|
65 | // Emits a signal so that potential receivers can populate the menu before displaying it | |
65 | emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables); |
|
66 | emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables); | |
66 |
|
67 | |||
67 | // Adds menu-specific actions |
|
68 | // Adds menu-specific actions | |
68 | if (!selectedVariables.isEmpty()) { |
|
69 | if (!selectedVariables.isEmpty()) { | |
69 | // 'Delete' action |
|
70 | // 'Delete' action | |
70 | auto deleteFun = []() { |
|
71 | auto deleteFun = []() { | |
71 | /// @todo ALX : call variable deletion |
|
72 | /// @todo ALX : call variable deletion | |
72 | }; |
|
73 | }; | |
73 |
|
74 | |||
74 | tableMenu.addSeparator(); |
|
75 | tableMenu.addSeparator(); | |
75 | tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun); |
|
76 | tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun); | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | if (!tableMenu.isEmpty()) { |
|
79 | if (!tableMenu.isEmpty()) { | |
79 | // Generates menu header (inserted before first action) |
|
80 | // Generates menu header (inserted before first action) | |
80 | auto firstAction = tableMenu.actions().first(); |
|
81 | auto firstAction = tableMenu.actions().first(); | |
81 | auto headerAction = new QWidgetAction{&tableMenu}; |
|
82 | auto headerAction = new QWidgetAction{&tableMenu}; | |
82 | headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu}); |
|
83 | headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu}); | |
83 | tableMenu.insertAction(firstAction, headerAction); |
|
84 | tableMenu.insertAction(firstAction, headerAction); | |
84 |
|
85 | |||
85 | // Displays menu |
|
86 | // Displays menu | |
86 | tableMenu.exec(mapToGlobal(pos)); |
|
87 | tableMenu.exec(mapToGlobal(pos)); | |
87 | } |
|
88 | } | |
88 | } |
|
89 | } |
@@ -1,85 +1,92 | |||||
1 | <?xml version="1.0" encoding="UTF-8"?> |
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <ui version="4.0"> |
|
2 | <ui version="4.0"> | |
3 | <class>TimeWidget</class> |
|
3 | <class>TimeWidget</class> | |
4 | <widget class="QWidget" name="TimeWidget"> |
|
4 | <widget class="QWidget" name="TimeWidget"> | |
5 | <property name="geometry"> |
|
5 | <property name="geometry"> | |
6 | <rect> |
|
6 | <rect> | |
7 | <x>0</x> |
|
7 | <x>0</x> | |
8 | <y>0</y> |
|
8 | <y>0</y> | |
9 | <width>716</width> |
|
9 | <width>716</width> | |
10 | <height>48</height> |
|
10 | <height>48</height> | |
11 | </rect> |
|
11 | </rect> | |
12 | </property> |
|
12 | </property> | |
13 | <property name="sizePolicy"> |
|
13 | <property name="sizePolicy"> | |
14 | <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> |
|
14 | <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> | |
15 | <horstretch>0</horstretch> |
|
15 | <horstretch>0</horstretch> | |
16 | <verstretch>0</verstretch> |
|
16 | <verstretch>0</verstretch> | |
17 | </sizepolicy> |
|
17 | </sizepolicy> | |
18 | </property> |
|
18 | </property> | |
19 | <property name="windowTitle"> |
|
19 | <property name="windowTitle"> | |
20 | <string>Form</string> |
|
20 | <string>Form</string> | |
21 | </property> |
|
21 | </property> | |
22 | <layout class="QHBoxLayout" name="horizontalLayout_2"> |
|
22 | <layout class="QHBoxLayout" name="horizontalLayout_2"> | |
23 | <item> |
|
23 | <item> | |
24 | <widget class="QLabel" name="label"> |
|
24 | <widget class="QLabel" name="label"> | |
25 | <property name="sizePolicy"> |
|
25 | <property name="sizePolicy"> | |
26 | <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> |
|
26 | <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> | |
27 | <horstretch>0</horstretch> |
|
27 | <horstretch>0</horstretch> | |
28 | <verstretch>0</verstretch> |
|
28 | <verstretch>0</verstretch> | |
29 | </sizepolicy> |
|
29 | </sizepolicy> | |
30 | </property> |
|
30 | </property> | |
31 | <property name="text"> |
|
31 | <property name="text"> | |
32 | <string>TStart :</string> |
|
32 | <string>TStart :</string> | |
33 | </property> |
|
33 | </property> | |
34 | </widget> |
|
34 | </widget> | |
35 | </item> |
|
35 | </item> | |
36 | <item> |
|
36 | <item> | |
37 | <widget class="QDateTimeEdit" name="startDateTimeEdit"> |
|
37 | <widget class="QDateTimeEdit" name="startDateTimeEdit"> | |
38 | <property name="sizePolicy"> |
|
38 | <property name="sizePolicy"> | |
39 | <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> |
|
39 | <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> | |
40 | <horstretch>0</horstretch> |
|
40 | <horstretch>0</horstretch> | |
41 | <verstretch>0</verstretch> |
|
41 | <verstretch>0</verstretch> | |
42 | </sizepolicy> |
|
42 | </sizepolicy> | |
43 | </property> |
|
43 | </property> | |
44 | <property name="displayFormat"> |
|
44 | <property name="displayFormat"> | |
45 | <string>dd/MM/yyyy HH:mm:ss:zzz</string> |
|
45 | <string>dd/MM/yyyy HH:mm:ss:zzz</string> | |
46 | </property> |
|
46 | </property> | |
47 | <property name="calendarPopup"> |
|
47 | <property name="calendarPopup"> | |
48 | <bool>true</bool> |
|
48 | <bool>true</bool> | |
49 | </property> |
|
49 | </property> | |
50 | </widget> |
|
50 | </widget> | |
51 | </item> |
|
51 | </item> | |
52 | <item> |
|
52 | <item> | |
53 | <widget class="QLabel" name="label_2"> |
|
53 | <widget class="QLabel" name="label_2"> | |
54 | <property name="sizePolicy"> |
|
54 | <property name="sizePolicy"> | |
55 | <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> |
|
55 | <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> | |
56 | <horstretch>0</horstretch> |
|
56 | <horstretch>0</horstretch> | |
57 | <verstretch>0</verstretch> |
|
57 | <verstretch>0</verstretch> | |
58 | </sizepolicy> |
|
58 | </sizepolicy> | |
59 | </property> |
|
59 | </property> | |
60 | <property name="text"> |
|
60 | <property name="text"> | |
61 | <string>TEnd :</string> |
|
61 | <string>TEnd :</string> | |
62 | </property> |
|
62 | </property> | |
63 | </widget> |
|
63 | </widget> | |
64 | </item> |
|
64 | </item> | |
65 | <item> |
|
65 | <item> | |
66 | <widget class="QDateTimeEdit" name="endDateTimeEdit"> |
|
66 | <widget class="QDateTimeEdit" name="endDateTimeEdit"> | |
67 | <property name="sizePolicy"> |
|
67 | <property name="sizePolicy"> | |
68 | <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> |
|
68 | <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> | |
69 | <horstretch>0</horstretch> |
|
69 | <horstretch>0</horstretch> | |
70 | <verstretch>0</verstretch> |
|
70 | <verstretch>0</verstretch> | |
71 | </sizepolicy> |
|
71 | </sizepolicy> | |
72 | </property> |
|
72 | </property> | |
73 | <property name="displayFormat"> |
|
73 | <property name="displayFormat"> | |
74 | <string>dd/MM/yyyy HH:mm:ss:zzz</string> |
|
74 | <string>dd/MM/yyyy HH:mm:ss:zzz</string> | |
75 | </property> |
|
75 | </property> | |
76 | <property name="calendarPopup"> |
|
76 | <property name="calendarPopup"> | |
77 | <bool>true</bool> |
|
77 | <bool>true</bool> | |
78 | </property> |
|
78 | </property> | |
79 | </widget> |
|
79 | </widget> | |
80 | </item> |
|
80 | </item> | |
|
81 | <item> | |||
|
82 | <widget class="QToolButton" name="applyToolButton"> | |||
|
83 | <property name="text"> | |||
|
84 | <string>...</string> | |||
|
85 | </property> | |||
|
86 | </widget> | |||
|
87 | </item> | |||
81 | </layout> |
|
88 | </layout> | |
82 | </widget> |
|
89 | </widget> | |
83 | <resources/> |
|
90 | <resources/> | |
84 | <connections/> |
|
91 | <connections/> | |
85 | </ui> |
|
92 | </ui> |
General Comments 0
You need to be logged in to leave comments.
Login now