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