##// END OF EJS Templates
Merge branch 'feature/VariousCorrections' into develop
Alexandre Leroux -
r288:1ae4a887fc77 merge
parent child
Show More
@@ -0,0 +1,46
1 #ifndef SCIQLOP_METATYPES_H
2 #define SCIQLOP_METATYPES_H
3
4 #include <QMetaType>
5
6 /**
7 * Struct used to create an instance that registers a type in Qt for signals / slots mechanism
8 * @tparam T the type to register
9 */
10 template <typename T>
11 struct MetaTypeRegistry {
12 explicit MetaTypeRegistry() { qRegisterMetaType<T>(); }
13 };
14
15 /**
16 * This macro can be used to :
17 * - declare a type as a Qt meta type
18 * - and register it (through a static instance) at the launch of SciQlop, so it can be passed in
19 * Qt signals/slots
20 *
21 * It can be used both in .h or in .cpp files
22 *
23 * @param NAME name of the instance under which the type will be registered (in uppercase)
24 * @param TYPE type to register
25 *
26 * Example:
27 * ~~~cpp
28 * // The following macro :
29 * // - declares std::shared_ptr<Variable> as a Qt meta type
30 * // - registers it through an instance named VAR_SHARED_PTR
31 * SCIQLOP_REGISTER_META_TYPE(VAR_SHARED_PTR, std::shared_ptr<Variable>)
32 *
33 * // The following macro :
34 * // - declares a raw pointer of Variable as a Qt meta type
35 * // - registers it through an instance named VAR_RAW_PTR
36 * SCIQLOP_REGISTER_META_TYPE(VAR_RAW_PTR, Variable*)
37 * ~~~
38 *
39 */
40 // clang-format off
41 #define SCIQLOP_REGISTER_META_TYPE(NAME, TYPE) \
42 Q_DECLARE_METATYPE(TYPE) \
43 const auto NAME = MetaTypeRegistry<TYPE>{}; \
44 // clang-format on
45
46 #endif // SCIQLOP_METATYPES_H
@@ -1,261 +1,259
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SciQLop Software
2 -- This file is a part of the SciQLop Software
3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "MainWindow.h"
22 #include "MainWindow.h"
23 #include "ui_MainWindow.h"
23 #include "ui_MainWindow.h"
24
24
25 #include <DataSource/DataSourceController.h>
25 #include <DataSource/DataSourceController.h>
26 #include <DataSource/DataSourceWidget.h>
26 #include <DataSource/DataSourceWidget.h>
27 #include <SidePane/SqpSidePane.h>
27 #include <SidePane/SqpSidePane.h>
28 #include <SqpApplication.h>
28 #include <SqpApplication.h>
29 #include <Time/TimeController.h>
29 #include <Time/TimeController.h>
30 #include <TimeWidget/TimeWidget.h>
30 #include <TimeWidget/TimeWidget.h>
31 #include <Variable/Variable.h>
31 #include <Variable/Variable.h>
32 #include <Variable/VariableController.h>
32 #include <Variable/VariableController.h>
33 #include <Visualization/VisualizationController.h>
33 #include <Visualization/VisualizationController.h>
34
34
35 #include <QAction>
35 #include <QAction>
36 #include <QDate>
36 #include <QDate>
37 #include <QDateTime>
37 #include <QDateTime>
38 #include <QDir>
38 #include <QDir>
39 #include <QFileDialog>
39 #include <QFileDialog>
40 #include <QToolBar>
40 #include <QToolBar>
41 #include <QToolButton>
41 #include <QToolButton>
42 #include <memory.h>
42 #include <memory.h>
43
43
44 //#include <omp.h>
44 //#include <omp.h>
45 //#include <network/filedownloader.h>
45 //#include <network/filedownloader.h>
46 //#include <qlopdatabase.h>
46 //#include <qlopdatabase.h>
47 //#include <qlopsettings.h>
47 //#include <qlopsettings.h>
48 //#include <qlopgui.h>
48 //#include <qlopgui.h>
49 //#include <spacedata.h>
49 //#include <spacedata.h>
50 //#include "qlopcore.h"
50 //#include "qlopcore.h"
51 //#include "qlopcodecmanager.h"
51 //#include "qlopcodecmanager.h"
52 //#include "cdfcodec.h"
52 //#include "cdfcodec.h"
53 //#include "amdatxtcodec.h"
53 //#include "amdatxtcodec.h"
54 //#include <qlopplotmanager.h>
54 //#include <qlopplotmanager.h>
55
55
56 #include "iostream"
56 #include "iostream"
57
57
58 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
58 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
59
59
60 namespace {
60 namespace {
61 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
61 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
62 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
62 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
63 const auto VIEWPLITTERINDEX = 2;
63 const auto VIEWPLITTERINDEX = 2;
64 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
64 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
65 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
65 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
66 }
66 }
67
67
68 class MainWindow::MainWindowPrivate {
68 class MainWindow::MainWindowPrivate {
69 public:
69 public:
70 QSize m_LastOpenLeftInspectorSize;
70 QSize m_LastOpenLeftInspectorSize;
71 QSize m_LastOpenRightInspectorSize;
71 QSize m_LastOpenRightInspectorSize;
72 };
72 };
73
73
74 MainWindow::MainWindow(QWidget *parent)
74 MainWindow::MainWindow(QWidget *parent)
75 : QMainWindow{parent},
75 : QMainWindow{parent},
76 m_Ui{new Ui::MainWindow},
76 m_Ui{new Ui::MainWindow},
77 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
77 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
78 {
78 {
79 m_Ui->setupUi(this);
79 m_Ui->setupUi(this);
80
80
81 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
81 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
82 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
82 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
83
83
84
84
85 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
85 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
86 auto openLeftInspectorAction = new QAction{QIcon{
86 auto openLeftInspectorAction = new QAction{QIcon{
87 ":/icones/previous.png",
87 ":/icones/previous.png",
88 },
88 },
89 tr("Show/hide the left inspector"), this};
89 tr("Show/hide the left inspector"), this};
90
90
91
91
92 auto spacerLeftTop = new QWidget{};
92 auto spacerLeftTop = new QWidget{};
93 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
93 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
94
94
95 auto spacerLeftBottom = new QWidget{};
95 auto spacerLeftBottom = new QWidget{};
96 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
96 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
97
97
98 leftSidePane->addWidget(spacerLeftTop);
98 leftSidePane->addWidget(spacerLeftTop);
99 leftSidePane->addAction(openLeftInspectorAction);
99 leftSidePane->addAction(openLeftInspectorAction);
100 leftSidePane->addWidget(spacerLeftBottom);
100 leftSidePane->addWidget(spacerLeftBottom);
101
101
102
102
103 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
103 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
104 auto openRightInspectorAction = new QAction{QIcon{
104 auto openRightInspectorAction = new QAction{QIcon{
105 ":/icones/next.png",
105 ":/icones/next.png",
106 },
106 },
107 tr("Show/hide the right inspector"), this};
107 tr("Show/hide the right inspector"), this};
108
108
109 auto spacerRightTop = new QWidget{};
109 auto spacerRightTop = new QWidget{};
110 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
110 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
111
111
112 auto spacerRightBottom = new QWidget{};
112 auto spacerRightBottom = new QWidget{};
113 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
113 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
114
114
115 rightSidePane->addWidget(spacerRightTop);
115 rightSidePane->addWidget(spacerRightTop);
116 rightSidePane->addAction(openRightInspectorAction);
116 rightSidePane->addAction(openRightInspectorAction);
117 rightSidePane->addWidget(spacerRightBottom);
117 rightSidePane->addWidget(spacerRightBottom);
118
118
119 openLeftInspectorAction->setCheckable(true);
119 openLeftInspectorAction->setCheckable(true);
120 openRightInspectorAction->setCheckable(true);
120 openRightInspectorAction->setCheckable(true);
121
121
122 auto openInspector = [this](bool checked, bool right, auto action) {
122 auto openInspector = [this](bool checked, bool right, auto action) {
123
123
124 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"});
125
125
126 auto &lastInspectorSize
126 auto &lastInspectorSize
127 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
127 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
128
128
129 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
129 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
130 : m_Ui->leftMainInspectorWidget->size();
130 : m_Ui->leftMainInspectorWidget->size();
131
131
132 // Update of the last opened geometry
132 // Update of the last opened geometry
133 if (checked) {
133 if (checked) {
134 lastInspectorSize = nextInspectorSize;
134 lastInspectorSize = nextInspectorSize;
135 }
135 }
136
136
137 auto startSize = lastInspectorSize;
137 auto startSize = lastInspectorSize;
138 auto endSize = startSize;
138 auto endSize = startSize;
139 endSize.setWidth(0);
139 endSize.setWidth(0);
140
140
141 auto splitterInspectorIndex
141 auto splitterInspectorIndex
142 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
142 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
143
143
144 auto currentSizes = m_Ui->splitter->sizes();
144 auto currentSizes = m_Ui->splitter->sizes();
145 if (checked) {
145 if (checked) {
146 // adjust sizes individually here, e.g.
146 // adjust sizes individually here, e.g.
147 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
147 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
148 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
148 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
149 m_Ui->splitter->setSizes(currentSizes);
149 m_Ui->splitter->setSizes(currentSizes);
150 }
150 }
151 else {
151 else {
152 // adjust sizes individually here, e.g.
152 // adjust sizes individually here, e.g.
153 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
153 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
154 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
154 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
155 m_Ui->splitter->setSizes(currentSizes);
155 m_Ui->splitter->setSizes(currentSizes);
156 }
156 }
157
157
158 };
158 };
159
159
160
160
161 connect(openLeftInspectorAction, &QAction::triggered,
161 connect(openLeftInspectorAction, &QAction::triggered,
162 [openInspector, openLeftInspectorAction](bool checked) {
162 [openInspector, openLeftInspectorAction](bool checked) {
163 openInspector(checked, false, openLeftInspectorAction);
163 openInspector(checked, false, openLeftInspectorAction);
164 });
164 });
165 connect(openRightInspectorAction, &QAction::triggered,
165 connect(openRightInspectorAction, &QAction::triggered,
166 [openInspector, openRightInspectorAction](bool checked) {
166 [openInspector, openRightInspectorAction](bool checked) {
167 openInspector(checked, true, openRightInspectorAction);
167 openInspector(checked, true, openRightInspectorAction);
168 });
168 });
169
169
170 this->menuBar()->addAction(tr("File"));
170 this->menuBar()->addAction(tr("File"));
171 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
171 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
172
172
173 auto timeWidget = new TimeWidget{};
173 auto timeWidget = new TimeWidget{};
174 mainToolBar->addWidget(timeWidget);
174 mainToolBar->addWidget(timeWidget);
175
175
176 // Widgets / controllers connections
176 // Widgets / controllers connections
177
177
178 // DataSource
178 // DataSource
179 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
179 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
180 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
180 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
181
181
182 // Time
182 // Time
183 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
183 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
184 SLOT(onTimeToUpdate(SqpDateTime)));
184 SLOT(onTimeToUpdate(SqpDateTime)));
185
185
186 qRegisterMetaType<SqpDateTime>();
187 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
186 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
188 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
187 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
189
188
190 // Widgets / widgets connections
189 // Widgets / widgets connections
191 qRegisterMetaType<std::shared_ptr<Variable> >();
192
190
193 // For the following connections, we use DirectConnection to allow each widget that can
191 // For the following connections, we use DirectConnection to allow each widget that can
194 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
192 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
195 // The order of connections is also important, since it determines the order in which each
193 // The order of connections is also important, since it determines the order in which each
196 // widget will attach its menu
194 // widget will attach its menu
197 connect(
195 connect(
198 m_Ui->variableInspectorWidget,
196 m_Ui->variableInspectorWidget,
199 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
197 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
200 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
198 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
201 Qt::DirectConnection);
199 Qt::DirectConnection);
202
200
203 /* QLopGUI::registerMenuBar(menuBar());
201 /* QLopGUI::registerMenuBar(menuBar());
204 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
202 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
205 this->m_progressWidget = new QWidget();
203 this->m_progressWidget = new QWidget();
206 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
204 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
207 this->m_progressWidget->setLayout(this->m_progressLayout);
205 this->m_progressWidget->setLayout(this->m_progressLayout);
208 this->m_progressWidget->setWindowModality(Qt::WindowModal);
206 this->m_progressWidget->setWindowModality(Qt::WindowModal);
209 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
207 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
210 for(int i=0;i<OMP_THREADS;i++)
208 for(int i=0;i<OMP_THREADS;i++)
211 {
209 {
212 this->m_progress.append(new QProgressBar(this->m_progressWidget));
210 this->m_progress.append(new QProgressBar(this->m_progressWidget));
213 this->m_progress.last()->setMinimum(0);
211 this->m_progress.last()->setMinimum(0);
214 this->m_progress.last()->setMaximum(100);
212 this->m_progress.last()->setMaximum(100);
215 this->m_progressLayout->addWidget(this->m_progress.last());
213 this->m_progressLayout->addWidget(this->m_progress.last());
216 this->m_progressWidget->hide();
214 this->m_progressWidget->hide();
217 this->m_progressThreadIds[i] = -1;
215 this->m_progressThreadIds[i] = -1;
218 }
216 }
219 this->m_progressWidget->setWindowTitle("Loading File");
217 this->m_progressWidget->setWindowTitle("Loading File");
220 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
218 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
221 << QLopCore::self()
219 << QLopCore::self()
222 << QLopPlotManager::self()
220 << QLopPlotManager::self()
223 << QLopCodecManager::self()
221 << QLopCodecManager::self()
224 << FileDownloader::self()
222 << FileDownloader::self()
225 << QLopDataBase::self()
223 << QLopDataBase::self()
226 << SpaceData::self();
224 << SpaceData::self();
227
225
228 CDFCodec::registerToManager();
226 CDFCodec::registerToManager();
229 AMDATXTCodec::registerToManager();
227 AMDATXTCodec::registerToManager();
230
228
231
229
232 for(int i=0;i<ServicesToLoad.count();i++)
230 for(int i=0;i<ServicesToLoad.count();i++)
233 {
231 {
234 qDebug()<<ServicesToLoad.at(i)->serviceName();
232 qDebug()<<ServicesToLoad.at(i)->serviceName();
235 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
233 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
236 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
234 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
237 if(wdgt)
235 if(wdgt)
238 {
236 {
239 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
237 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
240 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
238 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
241 }
239 }
242 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
240 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
243 }*/
241 }*/
244 }
242 }
245
243
246 MainWindow::~MainWindow()
244 MainWindow::~MainWindow()
247 {
245 {
248 }
246 }
249
247
250
248
251 void MainWindow::changeEvent(QEvent *e)
249 void MainWindow::changeEvent(QEvent *e)
252 {
250 {
253 QMainWindow::changeEvent(e);
251 QMainWindow::changeEvent(e);
254 switch (e->type()) {
252 switch (e->type()) {
255 case QEvent::LanguageChange:
253 case QEvent::LanguageChange:
256 m_Ui->retranslateUi(this);
254 m_Ui->retranslateUi(this);
257 break;
255 break;
258 default:
256 default:
259 break;
257 break;
260 }
258 }
261 }
259 }
@@ -1,70 +1,93
1 #ifndef SCIQLOP_DATASERIES_H
1 #ifndef SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
3
3
4 #include <Data/ArrayData.h>
4 #include <Data/ArrayData.h>
5 #include <Data/IDataSeries.h>
5 #include <Data/IDataSeries.h>
6
6
7 #include <QLoggingCategory>
7 #include <QLoggingCategory>
8
8
9 #include <memory>
9 #include <memory>
10
10
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSeries)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSeries)
13 Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries")
13 Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries")
14
14
15
15
16 /**
16 /**
17 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
17 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
18 *
18 *
19 * It proposes to set a dimension for the values ​​data
19 * It proposes to set a dimension for the values ​​data
20 *
20 *
21 * @tparam Dim The dimension of the values data
21 * @tparam Dim The dimension of the values data
22 *
22 *
23 */
23 */
24 template <int Dim>
24 template <int Dim>
25 class DataSeries : public IDataSeries {
25 class DataSeries : public IDataSeries {
26 public:
26 public:
27 /// @sa IDataSeries::xAxisData()
27 /// @sa IDataSeries::xAxisData()
28 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
28 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
29 const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; }
29
30
30 /// @sa IDataSeries::xAxisUnit()
31 /// @sa IDataSeries::xAxisUnit()
31 Unit xAxisUnit() const override { return m_XAxisUnit; }
32 Unit xAxisUnit() const override { return m_XAxisUnit; }
32
33
33 /// @return the values dataset
34 /// @return the values dataset
34 std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
35 std::shared_ptr<ArrayData<Dim> > valuesData() { return m_ValuesData; }
36 const std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
35
37
36 /// @sa IDataSeries::valuesUnit()
38 /// @sa IDataSeries::valuesUnit()
37 Unit valuesUnit() const override { return m_ValuesUnit; }
39 Unit valuesUnit() const override { return m_ValuesUnit; }
38
40
39 /// @sa IDataSeries::merge()
41 /// @sa IDataSeries::merge()
40 void merge(IDataSeries *dataSeries) override
42 void merge(IDataSeries *dataSeries) override
41 {
43 {
42 if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
44 if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
43 m_XAxisData->merge(*dimDataSeries->xAxisData());
45 m_XAxisData->merge(*dimDataSeries->xAxisData());
44 m_ValuesData->merge(*dimDataSeries->valuesData());
46 m_ValuesData->merge(*dimDataSeries->valuesData());
45 }
47 }
46 else {
48 else {
47 qCWarning(LOG_DataSeries())
49 qCWarning(LOG_DataSeries())
48 << QObject::tr("Dection of a type of IDataSeries we cannot merge with !");
50 << QObject::tr("Dection of a type of IDataSeries we cannot merge with !");
49 }
51 }
50 }
52 }
51
53
52 protected:
54 protected:
53 /// Protected ctor (DataSeries is abstract)
55 /// Protected ctor (DataSeries is abstract)
54 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
56 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
55 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
57 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
56 : m_XAxisData{xAxisData},
58 : m_XAxisData{xAxisData},
57 m_XAxisUnit{xAxisUnit},
59 m_XAxisUnit{xAxisUnit},
58 m_ValuesData{valuesData},
60 m_ValuesData{valuesData},
59 m_ValuesUnit{valuesUnit}
61 m_ValuesUnit{valuesUnit}
60 {
62 {
61 }
63 }
62
64
65 /// Copy ctor
66 explicit DataSeries(const DataSeries<Dim> &other)
67 : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)},
68 m_XAxisUnit{other.m_XAxisUnit},
69 m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)},
70 m_ValuesUnit{other.m_ValuesUnit}
71 {
72 }
73
74 /// Assignment operator
75 template <int D>
76 DataSeries &operator=(DataSeries<D> other)
77 {
78 std::swap(m_XAxisData, other.m_XAxisData);
79 std::swap(m_XAxisUnit, other.m_XAxisUnit);
80 std::swap(m_ValuesData, other.m_ValuesData);
81 std::swap(m_ValuesUnit, other.m_ValuesUnit);
82
83 return *this;
84 }
85
63 private:
86 private:
64 std::shared_ptr<ArrayData<1> > m_XAxisData;
87 std::shared_ptr<ArrayData<1> > m_XAxisData;
65 Unit m_XAxisUnit;
88 Unit m_XAxisUnit;
66 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
89 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
67 Unit m_ValuesUnit;
90 Unit m_ValuesUnit;
68 };
91 };
69
92
70 #endif // SCIQLOP_DATASERIES_H
93 #endif // SCIQLOP_DATASERIES_H
@@ -1,39 +1,42
1 #ifndef SCIQLOP_IDATAPROVIDER_H
1 #ifndef SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
3
3
4 #include <memory>
4 #include <memory>
5
5
6 #include <QObject>
6 #include <QObject>
7
7
8 #include <Common/MetaTypes.h>
9
8 #include <Data/SqpDateTime.h>
10 #include <Data/SqpDateTime.h>
9
11
10 class DataProviderParameters;
12 class DataProviderParameters;
11 class IDataSeries;
13 class IDataSeries;
12
14
13 /**
15 /**
14 * @brief The IDataProvider interface aims to declare a data provider.
16 * @brief The IDataProvider interface aims to declare a data provider.
15 *
17 *
16 * A data provider is an entity that generates data and returns it according to various parameters
18 * A data provider is an entity that generates data and returns it according to various parameters
17 * (time interval, product to retrieve the data, etc.)
19 * (time interval, product to retrieve the data, etc.)
18 *
20 *
19 * @sa IDataSeries
21 * @sa IDataSeries
20 */
22 */
21 class IDataProvider : public QObject {
23 class IDataProvider : public QObject {
22
24
23 Q_OBJECT
25 Q_OBJECT
24 public:
26 public:
25 virtual ~IDataProvider() noexcept = default;
27 virtual ~IDataProvider() noexcept = default;
26
28
27 virtual std::unique_ptr<IDataSeries>
29 virtual std::shared_ptr<IDataSeries>
28 retrieveData(const DataProviderParameters &parameters) const = 0;
30 retrieveData(const DataProviderParameters &parameters) const = 0;
29
31
30
32
31 virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0;
33 virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0;
32
34
33 signals:
35 signals:
34 void dataProvided(std::shared_ptr<IDataSeries> dateSerie, const SqpDateTime &dateTime);
36 void dataProvided(std::shared_ptr<IDataSeries> dateSerie, const SqpDateTime &dateTime);
35 };
37 };
38
36 // Required for using shared_ptr in signals/slots
39 // Required for using shared_ptr in signals/slots
37 Q_DECLARE_METATYPE(std::shared_ptr<IDataProvider>)
40 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>)
38
41
39 #endif // SCIQLOP_IDATAPROVIDER_H
42 #endif // SCIQLOP_IDATAPROVIDER_H
@@ -1,54 +1,59
1 #ifndef SCIQLOP_IDATASERIES_H
1 #ifndef SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
3
3
4 #include <Common/MetaTypes.h>
4
5
5 #include <memory>
6 #include <memory>
6
7
7 #include <QObject>
8 #include <QString>
8 #include <QString>
9
9
10 template <int Dim>
10 template <int Dim>
11 class ArrayData;
11 class ArrayData;
12
12
13 struct Unit {
13 struct Unit {
14 explicit Unit(const QString &name = {}, bool timeUnit = false)
14 explicit Unit(const QString &name = {}, bool timeUnit = false)
15 : m_Name{name}, m_TimeUnit{timeUnit}
15 : m_Name{name}, m_TimeUnit{timeUnit}
16 {
16 {
17 }
17 }
18
18
19 QString m_Name; ///< Unit name
19 QString m_Name; ///< Unit name
20 bool m_TimeUnit; ///< The unit is a unit of time
20 bool m_TimeUnit; ///< The unit is a unit of time
21 };
21 };
22
22
23 /**
23 /**
24 * @brief The IDataSeries aims to declare a data series.
24 * @brief The IDataSeries aims to declare a data series.
25 *
25 *
26 * A data series is an entity that contains at least :
26 * A data series is an entity that contains at least :
27 * - one dataset representing the x-axis
27 * - one dataset representing the x-axis
28 * - one dataset representing the values
28 * - one dataset representing the values
29 *
29 *
30 * Each dataset is represented by an ArrayData, and is associated with a unit.
30 * Each dataset is represented by an ArrayData, and is associated with a unit.
31 *
31 *
32 * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the
32 * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the
33 * IDataSeries. The x-axis dataset is always unidimensional.
33 * IDataSeries. The x-axis dataset is always unidimensional.
34 *
34 *
35 * @sa ArrayData
35 * @sa ArrayData
36 */
36 */
37 class IDataSeries {
37 class IDataSeries {
38 public:
38 public:
39 virtual ~IDataSeries() noexcept = default;
39 virtual ~IDataSeries() noexcept = default;
40
40
41 /// Returns the x-axis dataset
41 /// Returns the x-axis dataset
42 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
42 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
43
43
44 /// Returns the x-axis dataset (as const)
45 virtual const std::shared_ptr<ArrayData<1> > xAxisData() const = 0;
46
44 virtual Unit xAxisUnit() const = 0;
47 virtual Unit xAxisUnit() const = 0;
45
48
46 virtual Unit valuesUnit() const = 0;
49 virtual Unit valuesUnit() const = 0;
47
50
48 virtual void merge(IDataSeries *dataSeries) = 0;
51 virtual void merge(IDataSeries *dataSeries) = 0;
52
53 virtual std::unique_ptr<IDataSeries> clone() const = 0;
49 };
54 };
50
55
51 // Required for using shared_ptr in signals/slots
56 // Required for using shared_ptr in signals/slots
52 Q_DECLARE_METATYPE(std::shared_ptr<IDataSeries>)
57 SCIQLOP_REGISTER_META_TYPE(IDATASERIES_PTR_REGISTRY, std::shared_ptr<IDataSeries>)
53
58
54 #endif // SCIQLOP_IDATASERIES_H
59 #endif // SCIQLOP_IDATASERIES_H
@@ -1,28 +1,30
1 #ifndef SCIQLOP_SCALARSERIES_H
1 #ifndef SCIQLOP_SCALARSERIES_H
2 #define SCIQLOP_SCALARSERIES_H
2 #define SCIQLOP_SCALARSERIES_H
3
3
4 #include <Data/DataSeries.h>
4 #include <Data/DataSeries.h>
5
5
6 /**
6 /**
7 * @brief The ScalarSeries class is the implementation for a data series representing a scalar.
7 * @brief The ScalarSeries class is the implementation for a data series representing a scalar.
8 */
8 */
9 class ScalarSeries : public DataSeries<1> {
9 class ScalarSeries : public DataSeries<1> {
10 public:
10 public:
11 /**
11 /**
12 * Ctor
12 * Ctor
13 * @param size the number of data the series will hold
13 * @param size the number of data the series will hold
14 * @param xAxisUnit x-axis unit
14 * @param xAxisUnit x-axis unit
15 * @param valuesUnit values unit
15 * @param valuesUnit values unit
16 */
16 */
17 explicit ScalarSeries(int size, const Unit &xAxisUnit, const Unit &valuesUnit);
17 explicit ScalarSeries(int size, const Unit &xAxisUnit, const Unit &valuesUnit);
18
18
19 /**
19 /**
20 * Sets data for a specific index. The index has to be valid to be effective
20 * Sets data for a specific index. The index has to be valid to be effective
21 * @param index the index to which the data will be set
21 * @param index the index to which the data will be set
22 * @param x the x-axis data
22 * @param x the x-axis data
23 * @param value the value data
23 * @param value the value data
24 */
24 */
25 void setData(int index, double x, double value) noexcept;
25 void setData(int index, double x, double value) noexcept;
26
27 std::unique_ptr<IDataSeries> clone() const;
26 };
28 };
27
29
28 #endif // SCIQLOP_SCALARSERIES_H
30 #endif // SCIQLOP_SCALARSERIES_H
@@ -1,42 +1,44
1 #ifndef SCIQLOP_SQPDATETIME_H
1 #ifndef SCIQLOP_SQPDATETIME_H
2 #define SCIQLOP_SQPDATETIME_H
2 #define SCIQLOP_SQPDATETIME_H
3
3
4 #include <QObject>
4 #include <QObject>
5
5
6 #include <QDateTime>
6 #include <QDateTime>
7 #include <QDebug>
7 #include <QDebug>
8
8
9 #include <Common/MetaTypes.h>
10
9 /**
11 /**
10 * @brief The SqpDateTime struct holds the information of time parameters
12 * @brief The SqpDateTime struct holds the information of time parameters
11 */
13 */
12 struct SqpDateTime {
14 struct SqpDateTime {
13 /// Start time
15 /// Start time
14 double m_TStart;
16 double m_TStart;
15 /// End time
17 /// End time
16 double m_TEnd;
18 double m_TEnd;
17
19
18 bool contains(const SqpDateTime &dateTime)
20 bool contains(const SqpDateTime &dateTime)
19 {
21 {
20 return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd);
22 return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd);
21 }
23 }
22
24
23 bool intersect(const SqpDateTime &dateTime)
25 bool intersect(const SqpDateTime &dateTime)
24 {
26 {
25 return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd);
27 return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd);
26 }
28 }
27 };
29 };
28
30
29 inline QDebug operator<<(QDebug d, SqpDateTime obj)
31 inline QDebug operator<<(QDebug d, SqpDateTime obj)
30 {
32 {
31 auto tendDateTimeStart = QDateTime::fromMSecsSinceEpoch(obj.m_TStart * 1000);
33 auto tendDateTimeStart = QDateTime::fromMSecsSinceEpoch(obj.m_TStart * 1000);
32 auto tendDateTimeEnd = QDateTime::fromMSecsSinceEpoch(obj.m_TEnd * 1000);
34 auto tendDateTimeEnd = QDateTime::fromMSecsSinceEpoch(obj.m_TEnd * 1000);
33
35
34 // QDebug << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd;
36 // QDebug << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd;
35 d << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd;
37 d << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd;
36 return d;
38 return d;
37 }
39 }
38
40
39 // Required for using shared_ptr in signals/slots
41 // Required for using shared_ptr in signals/slots
40 Q_DECLARE_METATYPE(SqpDateTime)
42 SCIQLOP_REGISTER_META_TYPE(SQPDATETIME_REGISTRY, SqpDateTime)
41
43
42 #endif // SCIQLOP_SQPDATETIME_H
44 #endif // SCIQLOP_SQPDATETIME_H
@@ -1,55 +1,54
1 #ifndef SCIQLOP_VARIABLE_H
1 #ifndef SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
3
3
4 #include <Data/SqpDateTime.h>
4 #include <Data/SqpDateTime.h>
5
5
6
7 #include <QLoggingCategory>
6 #include <QLoggingCategory>
8 #include <QObject>
7 #include <QObject>
9
8
9 #include <Common/MetaTypes.h>
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;
40
39
41 public slots:
40 public slots:
42 void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
41 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
43
42
44 signals:
43 signals:
45 void updated();
44 void updated();
46
45
47 private:
46 private:
48 class VariablePrivate;
47 class VariablePrivate;
49 spimpl::unique_impl_ptr<VariablePrivate> impl;
48 spimpl::unique_impl_ptr<VariablePrivate> impl;
50 };
49 };
51
50
52 // Required for using shared_ptr in signals/slots
51 // Required for using shared_ptr in signals/slots
53 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
52 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
54
53
55 #endif // SCIQLOP_VARIABLE_H
54 #endif // SCIQLOP_VARIABLE_H
@@ -1,51 +1,51
1 #ifndef SCIQLOP_VARIABLEMODEL_H
1 #ifndef SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
3
3
4
4
5 #include <Data/SqpDateTime.h>
5 #include <Data/SqpDateTime.h>
6
6
7 #include <QAbstractTableModel>
7 #include <QAbstractTableModel>
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9
9
10 #include <Common/spimpl.h>
10 #include <Common/spimpl.h>
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
13
13
14 class IDataSeries;
14 class IDataSeries;
15 class Variable;
15 class Variable;
16
16
17 /**
17 /**
18 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
18 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
19 */
19 */
20 class VariableModel : public QAbstractTableModel {
20 class VariableModel : public QAbstractTableModel {
21 public:
21 public:
22 explicit VariableModel(QObject *parent = nullptr);
22 explicit VariableModel(QObject *parent = nullptr);
23
23
24 /**
24 /**
25 * Creates a new variable in the model
25 * Creates a new variable in the model
26 * @param name the name of the new variable
26 * @param name the name of the new variable
27 * @param dateTime the dateTime of the new variable
27 * @param dateTime the dateTime of the new variable
28 * @param defaultDataSeries the default data of the new variable
28 * @param defaultDataSeries the default data of the new variable
29 * @return the pointer to the new variable
29 * @return the pointer to the new variable
30 */
30 */
31 std::shared_ptr<Variable>
31 std::shared_ptr<Variable>
32 createVariable(const QString &name, const SqpDateTime &dateTime,
32 createVariable(const QString &name, const SqpDateTime &dateTime,
33 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept;
33 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept;
34
34
35 std::shared_ptr<Variable> variable(int index) const;
35 std::shared_ptr<Variable> variable(int index) const;
36
36
37 // /////////////////////////// //
37 // /////////////////////////// //
38 // QAbstractTableModel methods //
38 // QAbstractTableModel methods //
39 // /////////////////////////// //
39 // /////////////////////////// //
40 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
40 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
41 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
41 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
42 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
42 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
43 virtual QVariant headerData(int section, Qt::Orientation orientation,
43 virtual QVariant headerData(int section, Qt::Orientation orientation,
44 int role = Qt::DisplayRole) const override;
44 int role = Qt::DisplayRole) const override;
45
45
46 private:
46 private:
47 class VariableModelPrivate;
47 class VariableModelPrivate;
48 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
48 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
49 };
49 };
50
50
51 #endif // SCIQLOP_VARIABLEMODEL_H
51 #endif // SCIQLOP_VARIABLEMODEL_H
@@ -1,13 +1,18
1 #include <Data/ScalarSeries.h>
1 #include <Data/ScalarSeries.h>
2
2
3 ScalarSeries::ScalarSeries(int size, const Unit &xAxisUnit, const Unit &valuesUnit)
3 ScalarSeries::ScalarSeries(int size, const Unit &xAxisUnit, const Unit &valuesUnit)
4 : DataSeries{std::make_shared<ArrayData<1> >(size), xAxisUnit,
4 : DataSeries{std::make_shared<ArrayData<1> >(size), xAxisUnit,
5 std::make_shared<ArrayData<1> >(size), valuesUnit}
5 std::make_shared<ArrayData<1> >(size), valuesUnit}
6 {
6 {
7 }
7 }
8
8
9 void ScalarSeries::setData(int index, double x, double value) noexcept
9 void ScalarSeries::setData(int index, double x, double value) noexcept
10 {
10 {
11 xAxisData()->setData(index, x);
11 xAxisData()->setData(index, x);
12 valuesData()->setData(index, value);
12 valuesData()->setData(index, value);
13 }
13 }
14
15 std::unique_ptr<IDataSeries> ScalarSeries::clone() const
16 {
17 return std::make_unique<ScalarSeries>(*this);
18 }
@@ -1,87 +1,89
1 #include "Variable/Variable.h"
1 #include "Variable/Variable.h"
2
2
3 #include <Data/IDataSeries.h>
3 #include <Data/IDataSeries.h>
4 #include <Data/SqpDateTime.h>
4 #include <Data/SqpDateTime.h>
5
5
6 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
6 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
7
7
8 struct Variable::VariablePrivate {
8 struct Variable::VariablePrivate {
9 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission,
9 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission,
10 const SqpDateTime &dateTime)
10 const SqpDateTime &dateTime)
11 : m_Name{name},
11 : m_Name{name},
12 m_Unit{unit},
12 m_Unit{unit},
13 m_Mission{mission},
13 m_Mission{mission},
14 m_DateTime{dateTime},
14 m_DateTime{dateTime},
15 m_DataSeries{nullptr}
15 m_DataSeries{nullptr}
16 {
16 {
17 }
17 }
18
18
19 QString m_Name;
19 QString m_Name;
20 QString m_Unit;
20 QString m_Unit;
21 QString m_Mission;
21 QString m_Mission;
22
22
23 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
23 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
24 std::unique_ptr<IDataSeries> m_DataSeries;
24 std::unique_ptr<IDataSeries> m_DataSeries;
25 };
25 };
26
26
27 Variable::Variable(const QString &name, const QString &unit, const QString &mission,
27 Variable::Variable(const QString &name, const QString &unit, const QString &mission,
28 const SqpDateTime &dateTime)
28 const SqpDateTime &dateTime)
29 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)}
29 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)}
30 {
30 {
31 }
31 }
32
32
33 QString Variable::name() const noexcept
33 QString Variable::name() const noexcept
34 {
34 {
35 return impl->m_Name;
35 return impl->m_Name;
36 }
36 }
37
37
38 QString Variable::mission() const noexcept
38 QString Variable::mission() const noexcept
39 {
39 {
40 return impl->m_Mission;
40 return impl->m_Mission;
41 }
41 }
42
42
43 QString Variable::unit() const noexcept
43 QString Variable::unit() const noexcept
44 {
44 {
45 return impl->m_Unit;
45 return impl->m_Unit;
46 }
46 }
47
47
48 SqpDateTime Variable::dateTime() const noexcept
48 SqpDateTime Variable::dateTime() const noexcept
49 {
49 {
50 return impl->m_DateTime;
50 return impl->m_DateTime;
51 }
51 }
52
52
53 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
53 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
54 {
54 {
55 impl->m_DateTime = dateTime;
55 impl->m_DateTime = dateTime;
56 }
56 }
57
57
58 void Variable::setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
58 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
59 {
59 {
60 if (!impl->m_DataSeries) {
60 if (!dataSeries) {
61 impl->m_DataSeries = std::move(dataSeries);
61 /// @todo ALX : log
62 return;
62 }
63 }
63 }
64
64
65 void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
65 // Inits the data series of the variable
66 {
66 if (!impl->m_DataSeries) {
67 if (impl->m_DataSeries) {
67 impl->m_DataSeries = dataSeries->clone();
68 }
69 else {
68 impl->m_DataSeries->merge(dataSeries.get());
70 impl->m_DataSeries->merge(dataSeries.get());
69
71
70 emit updated();
72 emit updated();
71 }
73 }
72 }
74 }
73
75
74 IDataSeries *Variable::dataSeries() const noexcept
76 IDataSeries *Variable::dataSeries() const noexcept
75 {
77 {
76 return impl->m_DataSeries.get();
78 return impl->m_DataSeries.get();
77 }
79 }
78
80
79 bool Variable::contains(const SqpDateTime &dateTime)
81 bool Variable::contains(const SqpDateTime &dateTime)
80 {
82 {
81 return impl->m_DateTime.contains(dateTime);
83 return impl->m_DateTime.contains(dateTime);
82 }
84 }
83
85
84 bool Variable::intersect(const SqpDateTime &dateTime)
86 bool Variable::intersect(const SqpDateTime &dateTime)
85 {
87 {
86 return impl->m_DateTime.intersect(dateTime);
88 return impl->m_DateTime.intersect(dateTime);
87 }
89 }
@@ -1,177 +1,175
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 #include <QtCore/QItemSelectionModel>
15
15
16 #include <unordered_map>
16 #include <unordered_map>
17
17
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
19
19
20 namespace {
20 namespace {
21
21
22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
23 /// will be deleted when the timerange is recovered from SciQlop
23 /// will be deleted when the timerange is recovered from SciQlop
24 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
24 std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
25 const SqpDateTime &dateTime) noexcept
25 const SqpDateTime &dateTime) noexcept
26 {
26 {
27 auto parameters = DataProviderParameters{dateTime};
27 auto parameters = DataProviderParameters{dateTime};
28
28
29 return provider.retrieveData(parameters);
29 return provider.retrieveData(parameters);
30 }
30 }
31
31
32 } // namespace
32 } // namespace
33
33
34 struct VariableController::VariableControllerPrivate {
34 struct VariableController::VariableControllerPrivate {
35 explicit VariableControllerPrivate(VariableController *parent)
35 explicit VariableControllerPrivate(VariableController *parent)
36 : m_WorkingMutex{},
36 : m_WorkingMutex{},
37 m_VariableModel{new VariableModel{parent}},
37 m_VariableModel{new VariableModel{parent}},
38 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
38 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
39 m_VariableCacheController{std::make_unique<VariableCacheController>()}
39 m_VariableCacheController{std::make_unique<VariableCacheController>()}
40 {
40 {
41 }
41 }
42
42
43 QMutex m_WorkingMutex;
43 QMutex m_WorkingMutex;
44 /// Variable model. The VariableController has the ownership
44 /// Variable model. The VariableController has the ownership
45 VariableModel *m_VariableModel;
45 VariableModel *m_VariableModel;
46 QItemSelectionModel *m_VariableSelectionModel;
46 QItemSelectionModel *m_VariableSelectionModel;
47
47
48
48
49 TimeController *m_TimeController{nullptr};
49 TimeController *m_TimeController{nullptr};
50 std::unique_ptr<VariableCacheController> m_VariableCacheController;
50 std::unique_ptr<VariableCacheController> m_VariableCacheController;
51
51
52 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
52 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
53 m_VariableToProviderMap;
53 m_VariableToProviderMap;
54 };
54 };
55
55
56 VariableController::VariableController(QObject *parent)
56 VariableController::VariableController(QObject *parent)
57 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
57 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
58 {
58 {
59 qCDebug(LOG_VariableController()) << tr("VariableController construction")
59 qCDebug(LOG_VariableController()) << tr("VariableController construction")
60 << QThread::currentThread();
60 << QThread::currentThread();
61 }
61 }
62
62
63 VariableController::~VariableController()
63 VariableController::~VariableController()
64 {
64 {
65 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
65 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
66 << QThread::currentThread();
66 << QThread::currentThread();
67 this->waitForFinish();
67 this->waitForFinish();
68 }
68 }
69
69
70 VariableModel *VariableController::variableModel() noexcept
70 VariableModel *VariableController::variableModel() noexcept
71 {
71 {
72 return impl->m_VariableModel;
72 return impl->m_VariableModel;
73 }
73 }
74
74
75 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
75 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
76 {
76 {
77 return impl->m_VariableSelectionModel;
77 return impl->m_VariableSelectionModel;
78 }
78 }
79
79
80 void VariableController::setTimeController(TimeController *timeController) noexcept
80 void VariableController::setTimeController(TimeController *timeController) noexcept
81 {
81 {
82 impl->m_TimeController = timeController;
82 impl->m_TimeController = timeController;
83 }
83 }
84
84
85 void VariableController::createVariable(const QString &name,
85 void VariableController::createVariable(const QString &name,
86 std::shared_ptr<IDataProvider> provider) noexcept
86 std::shared_ptr<IDataProvider> provider) noexcept
87 {
87 {
88
88
89 if (!impl->m_TimeController) {
89 if (!impl->m_TimeController) {
90 qCCritical(LOG_VariableController())
90 qCCritical(LOG_VariableController())
91 << tr("Impossible to create variable: The time controller is null");
91 << tr("Impossible to create variable: The time controller is null");
92 return;
92 return;
93 }
93 }
94
94
95
95
96 /// @todo : for the moment :
96 /// @todo : for the moment :
97 /// - 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
98 /// it will be retained later
98 /// it will be retained later
99 /// - 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
100 /// in sciqlop
100 /// in sciqlop
101 auto dateTime = impl->m_TimeController->dateTime();
101 auto dateTime = impl->m_TimeController->dateTime();
102 if (auto newVariable = impl->m_VariableModel->createVariable(
102 if (auto newVariable = impl->m_VariableModel->createVariable(
103 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
103 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
104
104
105 // store the provider
105 // store the provider
106 impl->m_VariableToProviderMap[newVariable] = provider;
106 impl->m_VariableToProviderMap[newVariable] = provider;
107 qRegisterMetaType<std::shared_ptr<IDataSeries> >();
108 qRegisterMetaType<SqpDateTime>();
109 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
107 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
110 &Variable::onAddDataSeries);
108 &Variable::setDataSeries);
111
109
112
110
113 // store in cache
111 // store in cache
114 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
112 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
115
113
116 // notify the creation
114 // notify the creation
117 emit variableCreated(newVariable);
115 emit variableCreated(newVariable);
118 }
116 }
119 }
117 }
120
118
121 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
119 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
122 {
120 {
123 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
121 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
124
122
125 for (const auto &selectedRow : qAsConst(selectedRows)) {
123 for (const auto &selectedRow : qAsConst(selectedRows)) {
126 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
124 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
127 selectedVariable->setDateTime(dateTime);
125 selectedVariable->setDateTime(dateTime);
128 this->onRequestDataLoading(selectedVariable, dateTime);
126 this->onRequestDataLoading(selectedVariable, dateTime);
129 }
127 }
130 }
128 }
131 }
129 }
132
130
133
131
134 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
132 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
135 const SqpDateTime &dateTime)
133 const SqpDateTime &dateTime)
136 {
134 {
137 // we want to load data of the variable for the dateTime.
135 // we want to load data of the variable for the dateTime.
138 // First we check if the cache contains some of them.
136 // First we check if the cache contains some of them.
139 // For the other, we ask the provider to give them.
137 // For the other, we ask the provider to give them.
140 if (variable) {
138 if (variable) {
141
139
142 auto dateTimeListNotInCache
140 auto dateTimeListNotInCache
143 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
141 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
144
142
145 if (!dateTimeListNotInCache.empty()) {
143 if (!dateTimeListNotInCache.empty()) {
146 // Ask the provider for each data on the dateTimeListNotInCache
144 // Ask the provider for each data on the dateTimeListNotInCache
147 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
145 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
148 std::move(dateTimeListNotInCache));
146 std::move(dateTimeListNotInCache));
149 // store in cache
147 // store in cache
150 impl->m_VariableCacheController->addDateTime(variable, dateTime);
148 impl->m_VariableCacheController->addDateTime(variable, dateTime);
151 }
149 }
152 else {
150 else {
153 emit variable->updated();
151 emit variable->updated();
154 }
152 }
155 }
153 }
156 else {
154 else {
157 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
155 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
158 }
156 }
159 }
157 }
160
158
161
159
162 void VariableController::initialize()
160 void VariableController::initialize()
163 {
161 {
164 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
162 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
165 impl->m_WorkingMutex.lock();
163 impl->m_WorkingMutex.lock();
166 qCDebug(LOG_VariableController()) << tr("VariableController init END");
164 qCDebug(LOG_VariableController()) << tr("VariableController init END");
167 }
165 }
168
166
169 void VariableController::finalize()
167 void VariableController::finalize()
170 {
168 {
171 impl->m_WorkingMutex.unlock();
169 impl->m_WorkingMutex.unlock();
172 }
170 }
173
171
174 void VariableController::waitForFinish()
172 void VariableController::waitForFinish()
175 {
173 {
176 QMutexLocker locker{&impl->m_WorkingMutex};
174 QMutexLocker locker{&impl->m_WorkingMutex};
177 }
175 }
@@ -1,155 +1,155
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableModel.h>
2 #include <Variable/VariableModel.h>
3
3
4 #include <Data/IDataSeries.h>
4 #include <Data/IDataSeries.h>
5
5
6 #include <QDateTime>
6 #include <QDateTime>
7 #include <QSize>
7 #include <QSize>
8
8
9 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
9 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
10
10
11 namespace {
11 namespace {
12
12
13 // Column indexes
13 // Column indexes
14 const auto NAME_COLUMN = 0;
14 const auto NAME_COLUMN = 0;
15 const auto TSTART_COLUMN = 1;
15 const auto TSTART_COLUMN = 1;
16 const auto TEND_COLUMN = 2;
16 const auto TEND_COLUMN = 2;
17 const auto NB_COLUMNS = 3;
17 const auto NB_COLUMNS = 3;
18
18
19 // Column properties
19 // Column properties
20 const auto DEFAULT_HEIGHT = 25;
20 const auto DEFAULT_HEIGHT = 25;
21 const auto DEFAULT_WIDTH = 100;
21 const auto DEFAULT_WIDTH = 100;
22
22
23 struct ColumnProperties {
23 struct ColumnProperties {
24 ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH,
24 ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH,
25 int height = DEFAULT_HEIGHT)
25 int height = DEFAULT_HEIGHT)
26 : m_Name{name}, m_Width{width}, m_Height{height}
26 : m_Name{name}, m_Width{width}, m_Height{height}
27 {
27 {
28 }
28 }
29
29
30 QString m_Name;
30 QString m_Name;
31 int m_Width;
31 int m_Width;
32 int m_Height;
32 int m_Height;
33 };
33 };
34
34
35 const auto COLUMN_PROPERTIES
35 const auto COLUMN_PROPERTIES
36 = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}},
36 = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}},
37 {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
37 {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
38 {TEND_COLUMN, {QObject::tr("tEnd"), 180}}};
38 {TEND_COLUMN, {QObject::tr("tEnd"), 180}}};
39
39
40 /// Format for datetimes
40 /// Format for datetimes
41 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
41 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
42
42
43 } // namespace
43 } // namespace
44
44
45 struct VariableModel::VariableModelPrivate {
45 struct VariableModel::VariableModelPrivate {
46 /// Variables created in SciQlop
46 /// Variables created in SciQlop
47 std::vector<std::shared_ptr<Variable> > m_Variables;
47 std::vector<std::shared_ptr<Variable> > m_Variables;
48 };
48 };
49
49
50 VariableModel::VariableModel(QObject *parent)
50 VariableModel::VariableModel(QObject *parent)
51 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
51 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
52 {
52 {
53 }
53 }
54
54
55 std::shared_ptr<Variable>
55 std::shared_ptr<Variable>
56 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
56 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
57 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
57 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept
58 {
58 {
59 auto insertIndex = rowCount();
59 auto insertIndex = rowCount();
60 beginInsertRows({}, insertIndex, insertIndex);
60 beginInsertRows({}, insertIndex, insertIndex);
61
61
62 /// @todo For the moment, the other data of the variable is initialized with default values
62 /// @todo For the moment, the other data of the variable is initialized with default values
63 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
63 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
64 QStringLiteral("mission"), dateTime);
64 QStringLiteral("mission"), dateTime);
65 variable->setDataSeries(std::move(defaultDataSeries));
65 variable->setDataSeries(std::move(defaultDataSeries));
66
66
67 impl->m_Variables.push_back(variable);
67 impl->m_Variables.push_back(variable);
68
68
69 endInsertRows();
69 endInsertRows();
70
70
71 return variable;
71 return variable;
72 }
72 }
73
73
74 std::shared_ptr<Variable> VariableModel::variable(int index) const
74 std::shared_ptr<Variable> VariableModel::variable(int index) const
75 {
75 {
76 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
76 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
77 }
77 }
78
78
79 int VariableModel::columnCount(const QModelIndex &parent) const
79 int VariableModel::columnCount(const QModelIndex &parent) const
80 {
80 {
81 Q_UNUSED(parent);
81 Q_UNUSED(parent);
82
82
83 return NB_COLUMNS;
83 return NB_COLUMNS;
84 }
84 }
85
85
86 int VariableModel::rowCount(const QModelIndex &parent) const
86 int VariableModel::rowCount(const QModelIndex &parent) const
87 {
87 {
88 Q_UNUSED(parent);
88 Q_UNUSED(parent);
89
89
90 return impl->m_Variables.size();
90 return impl->m_Variables.size();
91 }
91 }
92
92
93 QVariant VariableModel::data(const QModelIndex &index, int role) const
93 QVariant VariableModel::data(const QModelIndex &index, int role) const
94 {
94 {
95 if (!index.isValid()) {
95 if (!index.isValid()) {
96 return QVariant{};
96 return QVariant{};
97 }
97 }
98
98
99 if (index.row() < 0 || index.row() >= rowCount()) {
99 if (index.row() < 0 || index.row() >= rowCount()) {
100 return QVariant{};
100 return QVariant{};
101 }
101 }
102
102
103 if (role == Qt::DisplayRole) {
103 if (role == Qt::DisplayRole) {
104 if (auto variable = impl->m_Variables.at(index.row()).get()) {
104 if (auto variable = impl->m_Variables.at(index.row()).get()) {
105 /// Lambda function that builds the variant to return for a time value
105 /// Lambda function that builds the variant to return for a time value
106 auto dateTimeVariant = [](double time) {
106 auto dateTimeVariant = [](double time) {
107 auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.);
107 auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.);
108 return dateTime.toString(DATETIME_FORMAT);
108 return dateTime.toString(DATETIME_FORMAT);
109 };
109 };
110
110
111 switch (index.column()) {
111 switch (index.column()) {
112 case NAME_COLUMN:
112 case NAME_COLUMN:
113 return variable->name();
113 return variable->name();
114 case TSTART_COLUMN:
114 case TSTART_COLUMN:
115 return dateTimeVariant(variable->dateTime().m_TStart);
115 return dateTimeVariant(variable->dateTime().m_TStart);
116 case TEND_COLUMN:
116 case TEND_COLUMN:
117 return dateTimeVariant(variable->dateTime().m_TEnd);
117 return dateTimeVariant(variable->dateTime().m_TEnd);
118 default:
118 default:
119 // No action
119 // No action
120 break;
120 break;
121 }
121 }
122
122
123 qWarning(LOG_VariableModel())
123 qWarning(LOG_VariableModel())
124 << tr("Can't get data (unknown column %1)").arg(index.column());
124 << tr("Can't get data (unknown column %1)").arg(index.column());
125 }
125 }
126 else {
126 else {
127 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
127 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
128 }
128 }
129 }
129 }
130
130
131 return QVariant{};
131 return QVariant{};
132 }
132 }
133
133
134 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
134 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
135 {
135 {
136 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
136 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
137 return QVariant{};
137 return QVariant{};
138 }
138 }
139
139
140 if (orientation == Qt::Horizontal) {
140 if (orientation == Qt::Horizontal) {
141 auto propertiesIt = COLUMN_PROPERTIES.find(section);
141 auto propertiesIt = COLUMN_PROPERTIES.find(section);
142 if (propertiesIt != COLUMN_PROPERTIES.cend()) {
142 if (propertiesIt != COLUMN_PROPERTIES.cend()) {
143 // Role is either DisplayRole or SizeHintRole
143 // Role is either DisplayRole or SizeHintRole
144 return (role == Qt::DisplayRole)
144 return (role == Qt::DisplayRole)
145 ? QVariant{propertiesIt->m_Name}
145 ? QVariant{propertiesIt->m_Name}
146 : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
146 : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
147 }
147 }
148 else {
148 else {
149 qWarning(LOG_VariableModel())
149 qWarning(LOG_VariableModel())
150 << tr("Can't get header data (unknown column %1)").arg(section);
150 << tr("Can't get header data (unknown column %1)").arg(section);
151 }
151 }
152 }
152 }
153
153
154 return QVariant{};
154 return QVariant{};
155 }
155 }
@@ -1,50 +1,53
1 #ifndef SCIQLOP_VISUALIZATIONTABWIDGET_H
1 #ifndef SCIQLOP_VISUALIZATIONTABWIDGET_H
2 #define SCIQLOP_VISUALIZATIONTABWIDGET_H
2 #define SCIQLOP_VISUALIZATIONTABWIDGET_H
3
3
4 #include "Visualization/IVisualizationWidget.h"
4 #include "Visualization/IVisualizationWidget.h"
5
5
6 #include <Common/spimpl.h>
6 #include <Common/spimpl.h>
7
7
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9 #include <QWidget>
9 #include <QWidget>
10
10
11 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget)
11 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget)
12
12
13 class Variable;
13 class Variable;
14 class VisualizationZoneWidget;
14 class VisualizationZoneWidget;
15
15
16 namespace Ui {
16 namespace Ui {
17 class VisualizationTabWidget;
17 class VisualizationTabWidget;
18 } // namespace Ui
18 } // namespace Ui
19
19
20 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
20 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
21 Q_OBJECT
21 Q_OBJECT
22
22
23 public:
23 public:
24 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
24 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
25 virtual ~VisualizationTabWidget();
25 virtual ~VisualizationTabWidget();
26
26
27 /// Add a zone widget
27 /// Add a zone widget
28 void addZone(VisualizationZoneWidget *zoneWidget);
28 void addZone(VisualizationZoneWidget *zoneWidget);
29
29
30 /**
30 /**
31 * Creates a zone using a variable. The variable will be displayed in a new graph of the new
31 * Creates a zone using a variable. The variable will be displayed in a new graph of the new
32 * zone.
32 * zone.
33 * @param variable the variable for which to create the zone
33 * @param variable the variable for which to create the zone
34 * @return the pointer to the created zone
34 * @return the pointer to the created zone
35 */
35 */
36 VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable);
36 VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable);
37
37
38 // IVisualizationWidget interface
38 // IVisualizationWidget interface
39 void accept(IVisualizationWidgetVisitor *visitor) override;
39 void accept(IVisualizationWidgetVisitor *visitor) override;
40 bool canDrop(const Variable &variable) const override;
40 bool canDrop(const Variable &variable) const override;
41 QString name() const override;
41 QString name() const override;
42
42
43 private:
43 private:
44 /// @return the layout of tab in which zones are added
45 QLayout &tabLayout() const noexcept;
46
44 Ui::VisualizationTabWidget *ui;
47 Ui::VisualizationTabWidget *ui;
45
48
46 class VisualizationTabWidgetPrivate;
49 class VisualizationTabWidgetPrivate;
47 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
50 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
48 };
51 };
49
52
50 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
53 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
@@ -1,120 +1,118
1 #include "SqpApplication.h"
1 #include "SqpApplication.h"
2
2
3 #include <Data/IDataProvider.h>
3 #include <Data/IDataProvider.h>
4 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceController.h>
5 #include <QThread>
5 #include <QThread>
6 #include <Time/TimeController.h>
6 #include <Time/TimeController.h>
7 #include <Variable/Variable.h>
7 #include <Variable/Variable.h>
8 #include <Variable/VariableController.h>
8 #include <Variable/VariableController.h>
9 #include <Visualization/VisualizationController.h>
9 #include <Visualization/VisualizationController.h>
10
10
11 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
11 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
12
12
13 class SqpApplication::SqpApplicationPrivate {
13 class SqpApplication::SqpApplicationPrivate {
14 public:
14 public:
15 SqpApplicationPrivate()
15 SqpApplicationPrivate()
16 : m_DataSourceController{std::make_unique<DataSourceController>()},
16 : m_DataSourceController{std::make_unique<DataSourceController>()},
17 m_TimeController{std::make_unique<TimeController>()},
17 m_TimeController{std::make_unique<TimeController>()},
18 m_VariableController{std::make_unique<VariableController>()},
18 m_VariableController{std::make_unique<VariableController>()},
19 m_VisualizationController{std::make_unique<VisualizationController>()}
19 m_VisualizationController{std::make_unique<VisualizationController>()}
20 {
20 {
21 // /////////////////////////////// //
21 // /////////////////////////////// //
22 // Connections between controllers //
22 // Connections between controllers //
23 // /////////////////////////////// //
23 // /////////////////////////////// //
24
24
25 // VariableController <-> DataSourceController
25 // VariableController <-> DataSourceController
26 qRegisterMetaType<std::shared_ptr<IDataProvider> >();
27 connect(m_DataSourceController.get(),
26 connect(m_DataSourceController.get(),
28 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
27 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
29 m_VariableController.get(),
28 m_VariableController.get(),
30 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
29 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
31
30
32 // VariableController <-> VisualizationController
31 // VariableController <-> VisualizationController
33 qRegisterMetaType<std::shared_ptr<Variable> >();
34 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
32 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
35 m_VisualizationController.get(),
33 m_VisualizationController.get(),
36 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
34 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
37
35
38 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
36 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
39 m_VariableController->moveToThread(&m_VariableControllerThread);
37 m_VariableController->moveToThread(&m_VariableControllerThread);
40 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
38 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
41
39
42 // Additionnal init
40 // Additionnal init
43 m_VariableController->setTimeController(m_TimeController.get());
41 m_VariableController->setTimeController(m_TimeController.get());
44 }
42 }
45
43
46 virtual ~SqpApplicationPrivate()
44 virtual ~SqpApplicationPrivate()
47 {
45 {
48 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
46 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
49 m_DataSourceControllerThread.quit();
47 m_DataSourceControllerThread.quit();
50 m_DataSourceControllerThread.wait();
48 m_DataSourceControllerThread.wait();
51
49
52 m_VariableControllerThread.quit();
50 m_VariableControllerThread.quit();
53 m_VariableControllerThread.wait();
51 m_VariableControllerThread.wait();
54
52
55 m_VisualizationControllerThread.quit();
53 m_VisualizationControllerThread.quit();
56 m_VisualizationControllerThread.wait();
54 m_VisualizationControllerThread.wait();
57 }
55 }
58
56
59 std::unique_ptr<DataSourceController> m_DataSourceController;
57 std::unique_ptr<DataSourceController> m_DataSourceController;
60 std::unique_ptr<VariableController> m_VariableController;
58 std::unique_ptr<VariableController> m_VariableController;
61 std::unique_ptr<TimeController> m_TimeController;
59 std::unique_ptr<TimeController> m_TimeController;
62 std::unique_ptr<VisualizationController> m_VisualizationController;
60 std::unique_ptr<VisualizationController> m_VisualizationController;
63 QThread m_DataSourceControllerThread;
61 QThread m_DataSourceControllerThread;
64 QThread m_VariableControllerThread;
62 QThread m_VariableControllerThread;
65 QThread m_VisualizationControllerThread;
63 QThread m_VisualizationControllerThread;
66 };
64 };
67
65
68
66
69 SqpApplication::SqpApplication(int &argc, char **argv)
67 SqpApplication::SqpApplication(int &argc, char **argv)
70 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
68 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
71 {
69 {
72 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
70 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
73
71
74 connect(&impl->m_DataSourceControllerThread, &QThread::started,
72 connect(&impl->m_DataSourceControllerThread, &QThread::started,
75 impl->m_DataSourceController.get(), &DataSourceController::initialize);
73 impl->m_DataSourceController.get(), &DataSourceController::initialize);
76 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
74 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
77 impl->m_DataSourceController.get(), &DataSourceController::finalize);
75 impl->m_DataSourceController.get(), &DataSourceController::finalize);
78
76
79 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
77 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
80 &VariableController::initialize);
78 &VariableController::initialize);
81 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
79 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
82 &VariableController::finalize);
80 &VariableController::finalize);
83
81
84 connect(&impl->m_VisualizationControllerThread, &QThread::started,
82 connect(&impl->m_VisualizationControllerThread, &QThread::started,
85 impl->m_VisualizationController.get(), &VisualizationController::initialize);
83 impl->m_VisualizationController.get(), &VisualizationController::initialize);
86 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
84 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
87 impl->m_VisualizationController.get(), &VisualizationController::finalize);
85 impl->m_VisualizationController.get(), &VisualizationController::finalize);
88
86
89 impl->m_DataSourceControllerThread.start();
87 impl->m_DataSourceControllerThread.start();
90 impl->m_VariableControllerThread.start();
88 impl->m_VariableControllerThread.start();
91 impl->m_VisualizationControllerThread.start();
89 impl->m_VisualizationControllerThread.start();
92 }
90 }
93
91
94 SqpApplication::~SqpApplication()
92 SqpApplication::~SqpApplication()
95 {
93 {
96 }
94 }
97
95
98 void SqpApplication::initialize()
96 void SqpApplication::initialize()
99 {
97 {
100 }
98 }
101
99
102 DataSourceController &SqpApplication::dataSourceController() noexcept
100 DataSourceController &SqpApplication::dataSourceController() noexcept
103 {
101 {
104 return *impl->m_DataSourceController;
102 return *impl->m_DataSourceController;
105 }
103 }
106
104
107 TimeController &SqpApplication::timeController() noexcept
105 TimeController &SqpApplication::timeController() noexcept
108 {
106 {
109 return *impl->m_TimeController;
107 return *impl->m_TimeController;
110 }
108 }
111
109
112 VariableController &SqpApplication::variableController() noexcept
110 VariableController &SqpApplication::variableController() noexcept
113 {
111 {
114 return *impl->m_VariableController;
112 return *impl->m_VariableController;
115 }
113 }
116
114
117 VisualizationController &SqpApplication::visualizationController() noexcept
115 VisualizationController &SqpApplication::visualizationController() noexcept
118 {
116 {
119 return *impl->m_VisualizationController;
117 return *impl->m_VisualizationController;
120 }
118 }
@@ -1,98 +1,104
1 #include "Visualization/VisualizationTabWidget.h"
1 #include "Visualization/VisualizationTabWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "ui_VisualizationTabWidget.h"
3 #include "ui_VisualizationTabWidget.h"
4
4
5 #include "Visualization/VisualizationZoneWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
6
6
7 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
7 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
8
8
9 namespace {
9 namespace {
10
10
11 /// Generates a default name for a new zone, according to the number of zones already displayed in
11 /// Generates a default name for a new zone, according to the number of zones already displayed in
12 /// the tab
12 /// the tab
13 QString defaultZoneName(const QLayout &layout)
13 QString defaultZoneName(const QLayout &layout)
14 {
14 {
15 auto count = 0;
15 auto count = 0;
16 for (auto i = 0; i < layout.count(); ++i) {
16 for (auto i = 0; i < layout.count(); ++i) {
17 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
17 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
18 count++;
18 count++;
19 }
19 }
20 }
20 }
21
21
22 return QObject::tr("Zone %1").arg(count + 1);
22 return QObject::tr("Zone %1").arg(count + 1);
23 }
23 }
24
24
25 } // namespace
25 } // namespace
26
26
27 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
27 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
28 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
28 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
29
29
30 QString m_Name;
30 QString m_Name;
31 };
31 };
32
32
33 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
33 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
34 : QWidget{parent},
34 : QWidget{parent},
35 ui{new Ui::VisualizationTabWidget},
35 ui{new Ui::VisualizationTabWidget},
36 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
36 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
37 {
37 {
38 ui->setupUi(this);
38 ui->setupUi(this);
39
39
40 // Widget is deleted when closed
40 // Widget is deleted when closed
41 setAttribute(Qt::WA_DeleteOnClose);
41 setAttribute(Qt::WA_DeleteOnClose);
42 }
42 }
43
43
44 VisualizationTabWidget::~VisualizationTabWidget()
44 VisualizationTabWidget::~VisualizationTabWidget()
45 {
45 {
46 delete ui;
46 delete ui;
47 }
47 }
48
48
49 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
49 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
50 {
50 {
51 this->layout()->addWidget(zoneWidget);
51 tabLayout().addWidget(zoneWidget);
52 }
52 }
53
53
54 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
54 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
55 {
55 {
56 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this};
56 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(tabLayout()), this};
57 this->addZone(zoneWidget);
57 this->addZone(zoneWidget);
58
58
59 // Creates a new graph into the zone
59 // Creates a new graph into the zone
60 zoneWidget->createGraph(variable);
60 zoneWidget->createGraph(variable);
61
61
62 return zoneWidget;
62 return zoneWidget;
63 }
63 }
64
64
65 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
65 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
66 {
66 {
67 if (visitor) {
67 if (visitor) {
68 visitor->visitEnter(this);
68 visitor->visitEnter(this);
69
69
70 // Apply visitor to zone children
70 // Apply visitor to zone children
71 for (auto i = 0; i < layout()->count(); ++i) {
71 auto &layout = tabLayout();
72 if (auto item = layout()->itemAt(i)) {
72 for (auto i = 0; i < layout.count(); ++i) {
73 if (auto item = layout.itemAt(i)) {
73 // Widgets different from zones are not visited (no action)
74 // Widgets different from zones are not visited (no action)
74 if (auto visualizationZoneWidget
75 if (auto visualizationZoneWidget
75 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
76 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
76 visualizationZoneWidget->accept(visitor);
77 visualizationZoneWidget->accept(visitor);
77 }
78 }
78 }
79 }
79 }
80 }
80
81
81 visitor->visitLeave(this);
82 visitor->visitLeave(this);
82 }
83 }
83 else {
84 else {
84 qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null");
85 qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null");
85 }
86 }
86 }
87 }
87
88
88 bool VisualizationTabWidget::canDrop(const Variable &variable) const
89 bool VisualizationTabWidget::canDrop(const Variable &variable) const
89 {
90 {
90 // A tab can always accomodate a variable
91 // A tab can always accomodate a variable
91 Q_UNUSED(variable);
92 Q_UNUSED(variable);
92 return true;
93 return true;
93 }
94 }
94
95
95 QString VisualizationTabWidget::name() const
96 QString VisualizationTabWidget::name() const
96 {
97 {
97 return impl->m_Name;
98 return impl->m_Name;
98 }
99 }
100
101 QLayout &VisualizationTabWidget::tabLayout() const noexcept
102 {
103 return *ui->scrollAreaWidgetContents->layout();
104 }
@@ -1,97 +1,105
1 #include "Visualization/VisualizationZoneWidget.h"
1 #include "Visualization/VisualizationZoneWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "ui_VisualizationZoneWidget.h"
3 #include "ui_VisualizationZoneWidget.h"
4
4
5 #include "Visualization/VisualizationGraphWidget.h"
5 #include "Visualization/VisualizationGraphWidget.h"
6
6
7 #include <SqpApplication.h>
7 #include <SqpApplication.h>
8
8
9 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
9 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
10
10
11 namespace {
11 namespace {
12
12
13 /// Minimum height for graph added in zones (in pixels)
14 const auto GRAPH_MINIMUM_HEIGHT = 300;
15
13 /// Generates a default name for a new graph, according to the number of graphs already displayed in
16 /// Generates a default name for a new graph, according to the number of graphs already displayed in
14 /// the zone
17 /// the zone
15 QString defaultGraphName(const QLayout &layout)
18 QString defaultGraphName(const QLayout &layout)
16 {
19 {
17 auto count = 0;
20 auto count = 0;
18 for (auto i = 0; i < layout.count(); ++i) {
21 for (auto i = 0; i < layout.count(); ++i) {
19 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
22 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
20 count++;
23 count++;
21 }
24 }
22 }
25 }
23
26
24 return QObject::tr("Graph %1").arg(count + 1);
27 return QObject::tr("Graph %1").arg(count + 1);
25 }
28 }
26
29
27 } // namespace
30 } // namespace
28
31
29 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
32 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
30 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
33 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
31 {
34 {
32 ui->setupUi(this);
35 ui->setupUi(this);
33
36
34 ui->zoneNameLabel->setText(name);
37 ui->zoneNameLabel->setText(name);
35
38
36 // 'Close' options : widget is deleted when closed
39 // 'Close' options : widget is deleted when closed
37 setAttribute(Qt::WA_DeleteOnClose);
40 setAttribute(Qt::WA_DeleteOnClose);
38 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
41 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
39 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
42 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
40 }
43 }
41
44
42 VisualizationZoneWidget::~VisualizationZoneWidget()
45 VisualizationZoneWidget::~VisualizationZoneWidget()
43 {
46 {
44 delete ui;
47 delete ui;
45 }
48 }
46
49
47 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
50 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
48 {
51 {
49 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
52 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
50 }
53 }
51
54
52 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
55 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
53 {
56 {
54 auto graphWidget = new VisualizationGraphWidget{
57 auto graphWidget = new VisualizationGraphWidget{
55 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
58 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
59
60 // Set graph properties
61 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
62 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
63
56 this->addGraph(graphWidget);
64 this->addGraph(graphWidget);
57
65
58 graphWidget->addVariable(variable);
66 graphWidget->addVariable(variable);
59
67
60 return graphWidget;
68 return graphWidget;
61 }
69 }
62
70
63 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
71 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
64 {
72 {
65 if (visitor) {
73 if (visitor) {
66 visitor->visitEnter(this);
74 visitor->visitEnter(this);
67
75
68 // Apply visitor to graph children
76 // Apply visitor to graph children
69 auto layout = ui->visualizationZoneFrame->layout();
77 auto layout = ui->visualizationZoneFrame->layout();
70 for (auto i = 0; i < layout->count(); ++i) {
78 for (auto i = 0; i < layout->count(); ++i) {
71 if (auto item = layout->itemAt(i)) {
79 if (auto item = layout->itemAt(i)) {
72 // Widgets different from graphs are not visited (no action)
80 // Widgets different from graphs are not visited (no action)
73 if (auto visualizationGraphWidget
81 if (auto visualizationGraphWidget
74 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
82 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
75 visualizationGraphWidget->accept(visitor);
83 visualizationGraphWidget->accept(visitor);
76 }
84 }
77 }
85 }
78 }
86 }
79
87
80 visitor->visitLeave(this);
88 visitor->visitLeave(this);
81 }
89 }
82 else {
90 else {
83 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
91 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
84 }
92 }
85 }
93 }
86
94
87 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
95 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
88 {
96 {
89 // A tab can always accomodate a variable
97 // A tab can always accomodate a variable
90 Q_UNUSED(variable);
98 Q_UNUSED(variable);
91 return true;
99 return true;
92 }
100 }
93
101
94 QString VisualizationZoneWidget::name() const
102 QString VisualizationZoneWidget::name() const
95 {
103 {
96 return ui->zoneNameLabel->text();
104 return ui->zoneNameLabel->text();
97 }
105 }
@@ -1,130 +1,146
1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
2 #include "Visualization/operations/MenuBuilder.h"
2 #include "Visualization/operations/MenuBuilder.h"
3
3
4 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/VisualizationGraphWidget.h"
5 #include "Visualization/VisualizationTabWidget.h"
5 #include "Visualization/VisualizationTabWidget.h"
6 #include "Visualization/VisualizationZoneWidget.h"
6 #include "Visualization/VisualizationZoneWidget.h"
7
7
8 #include <Variable/Variable.h>
8 #include <Variable/Variable.h>
9
9
10 #include <QMenu>
10 #include <QMenu>
11 #include <QStack>
11 #include <QStack>
12
12
13 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
13 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
14
14
15 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
15 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
16 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
16 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
17 : m_Variable{variable}, m_MenuBuilder{menu}
17 : m_Variable{variable}, m_MenuBuilder{menu}
18 {
18 {
19 }
19 }
20
20
21 void visitRootEnter()
22 {
23 // Creates the root menu
24 m_MenuBuilder.addMenu(QObject::tr("Plot"));
25 }
26
27 void visitRootLeave()
28 {
29 // Closes the root menu
30 m_MenuBuilder.closeMenu();
31 }
32
21 void visitNodeEnter(const IVisualizationWidget &container)
33 void visitNodeEnter(const IVisualizationWidget &container)
22 {
34 {
23 // Opens a new menu associated to the node
35 // Opens a new menu associated to the node
24 m_MenuBuilder.addMenu(container.name());
36 m_MenuBuilder.addMenu(container.name());
25 }
37 }
26
38
27 template <typename ActionFun>
39 template <typename ActionFun>
28 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
40 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
29 ActionFun actionFunction)
41 ActionFun actionFunction)
30 {
42 {
31 if (m_Variable && container.canDrop(*m_Variable)) {
43 if (m_Variable && container.canDrop(*m_Variable)) {
32 m_MenuBuilder.addSeparator();
44 m_MenuBuilder.addSeparator();
33 m_MenuBuilder.addAction(actionName, actionFunction);
45 m_MenuBuilder.addAction(actionName, actionFunction);
34 }
46 }
35
47
36 // Closes the menu associated to the node
48 // Closes the menu associated to the node
37 m_MenuBuilder.closeMenu();
49 m_MenuBuilder.closeMenu();
38 }
50 }
39
51
40 template <typename ActionFun>
52 template <typename ActionFun>
41 void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
53 void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
42 ActionFun actionFunction)
54 ActionFun actionFunction)
43 {
55 {
44 if (m_Variable && container.canDrop(*m_Variable)) {
56 if (m_Variable && container.canDrop(*m_Variable)) {
45 m_MenuBuilder.addAction(actionName, actionFunction);
57 m_MenuBuilder.addAction(actionName, actionFunction);
46 }
58 }
47 }
59 }
48
60
49 std::shared_ptr<Variable> m_Variable;
61 std::shared_ptr<Variable> m_Variable;
50 MenuBuilder m_MenuBuilder;
62 MenuBuilder m_MenuBuilder;
51 };
63 };
52
64
53 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
65 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
54 std::shared_ptr<Variable> variable)
66 std::shared_ptr<Variable> variable)
55 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
67 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
56 {
68 {
57 }
69 }
58
70
59 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
71 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
60 {
72 {
61 // VisualizationWidget is not intended to accommodate a variable
73 // VisualizationWidget is not intended to accommodate a variable
62 Q_UNUSED(widget)
74 Q_UNUSED(widget)
75
76 impl->visitRootEnter();
63 }
77 }
64
78
65 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
79 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
66 {
80 {
67 // VisualizationWidget is not intended to accommodate a variable
81 // VisualizationWidget is not intended to accommodate a variable
68 Q_UNUSED(widget)
82 Q_UNUSED(widget)
83
84 impl->visitRootLeave();
69 }
85 }
70
86
71 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
87 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
72 {
88 {
73 if (tabWidget) {
89 if (tabWidget) {
74 impl->visitNodeEnter(*tabWidget);
90 impl->visitNodeEnter(*tabWidget);
75 }
91 }
76 else {
92 else {
77 qCCritical(LOG_GenerateVariableMenuOperation(),
93 qCCritical(LOG_GenerateVariableMenuOperation(),
78 "Can't visit enter VisualizationTabWidget : the widget is null");
94 "Can't visit enter VisualizationTabWidget : the widget is null");
79 }
95 }
80 }
96 }
81
97
82 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
98 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
83 {
99 {
84 if (tabWidget) {
100 if (tabWidget) {
85 impl->visitNodeLeave(
101 impl->visitNodeLeave(
86 *tabWidget, QObject::tr("Open in a new zone"),
102 *tabWidget, QObject::tr("Open in a new zone"),
87 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
103 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
88 }
104 }
89 else {
105 else {
90 qCCritical(LOG_GenerateVariableMenuOperation(),
106 qCCritical(LOG_GenerateVariableMenuOperation(),
91 "Can't visit leave VisualizationTabWidget : the widget is null");
107 "Can't visit leave VisualizationTabWidget : the widget is null");
92 }
108 }
93 }
109 }
94
110
95 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
111 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
96 {
112 {
97 if (zoneWidget) {
113 if (zoneWidget) {
98 impl->visitNodeEnter(*zoneWidget);
114 impl->visitNodeEnter(*zoneWidget);
99 }
115 }
100 else {
116 else {
101 qCCritical(LOG_GenerateVariableMenuOperation(),
117 qCCritical(LOG_GenerateVariableMenuOperation(),
102 "Can't visit enter VisualizationZoneWidget : the widget is null");
118 "Can't visit enter VisualizationZoneWidget : the widget is null");
103 }
119 }
104 }
120 }
105
121
106 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
122 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
107 {
123 {
108 if (zoneWidget) {
124 if (zoneWidget) {
109 impl->visitNodeLeave(
125 impl->visitNodeLeave(
110 *zoneWidget, QObject::tr("Open in a new graph"),
126 *zoneWidget, QObject::tr("Open in a new graph"),
111 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
127 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
112 }
128 }
113 else {
129 else {
114 qCCritical(LOG_GenerateVariableMenuOperation(),
130 qCCritical(LOG_GenerateVariableMenuOperation(),
115 "Can't visit leave VisualizationZoneWidget : the widget is null");
131 "Can't visit leave VisualizationZoneWidget : the widget is null");
116 }
132 }
117 }
133 }
118
134
119 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
135 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
120 {
136 {
121 if (graphWidget) {
137 if (graphWidget) {
122 impl->visitLeaf(
138 impl->visitLeaf(
123 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
139 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
124 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariable(var); });
140 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariable(var); });
125 }
141 }
126 else {
142 else {
127 qCCritical(LOG_GenerateVariableMenuOperation(),
143 qCCritical(LOG_GenerateVariableMenuOperation(),
128 "Can't visit VisualizationGraphWidget : the widget is null");
144 "Can't visit VisualizationGraphWidget : the widget is null");
129 }
145 }
130 }
146 }
@@ -1,20 +1,60
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>VisualizationTabWidget</class>
3 <class>VisualizationTabWidget</class>
4 <widget class="QWidget" name="VisualizationTabWidget">
4 <widget class="QWidget" name="VisualizationTabWidget">
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>400</width>
9 <width>400</width>
10 <height>300</height>
10 <height>300</height>
11 </rect>
11 </rect>
12 </property>
12 </property>
13 <property name="windowTitle">
13 <property name="windowTitle">
14 <string>Form</string>
14 <string>Form</string>
15 </property>
15 </property>
16 <layout class="QVBoxLayout" name="verticalLayout"/>
16 <layout class="QVBoxLayout" name="verticalLayout">
17 <property name="leftMargin">
18 <number>0</number>
19 </property>
20 <property name="topMargin">
21 <number>0</number>
22 </property>
23 <property name="rightMargin">
24 <number>0</number>
25 </property>
26 <property name="bottomMargin">
27 <number>0</number>
28 </property>
29 <item>
30 <widget class="QScrollArea" name="scrollArea">
31 <property name="styleSheet">
32 <string notr="true">background-color: transparent;</string>
33 </property>
34 <property name="frameShape">
35 <enum>QFrame::NoFrame</enum>
36 </property>
37 <property name="frameShadow">
38 <enum>QFrame::Sunken</enum>
39 </property>
40 <property name="widgetResizable">
41 <bool>true</bool>
42 </property>
43 <widget class="QWidget" name="scrollAreaWidgetContents">
44 <property name="geometry">
45 <rect>
46 <x>0</x>
47 <y>0</y>
48 <width>400</width>
49 <height>300</height>
50 </rect>
51 </property>
52 <layout class="QVBoxLayout" name="verticalLayout_3"/>
53 </widget>
54 </widget>
55 </item>
56 </layout>
17 </widget>
57 </widget>
18 <resources/>
58 <resources/>
19 <connections/>
59 <connections/>
20 </ui>
60 </ui>
@@ -1,26 +1,26
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
3
3
4 #include <Data/IDataProvider.h>
4 #include <Data/IDataProvider.h>
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7
7
8 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
8 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
9
9
10 /**
10 /**
11 * @brief The CosinusProvider class is an example of how a data provider can generate data
11 * @brief The CosinusProvider class is an example of how a data provider can generate data
12 */
12 */
13 class CosinusProvider : public IDataProvider {
13 class CosinusProvider : public IDataProvider {
14 public:
14 public:
15 /// @sa IDataProvider::retrieveData()
15 /// @sa IDataProvider::retrieveData()
16 std::unique_ptr<IDataSeries>
16 std::shared_ptr<IDataSeries>
17 retrieveData(const DataProviderParameters &parameters) const override;
17 retrieveData(const DataProviderParameters &parameters) const override;
18
18
19 void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override;
19 void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override;
20
20
21
21
22 private:
22 private:
23 std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime);
23 std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime);
24 };
24 };
25
25
26 #endif // SCIQLOP_COSINUSPROVIDER_H
26 #endif // SCIQLOP_COSINUSPROVIDER_H
@@ -1,74 +1,47
1 #include "CosinusProvider.h"
1 #include "CosinusProvider.h"
2
2
3 #include <Data/DataProviderParameters.h>
3 #include <Data/DataProviderParameters.h>
4 #include <Data/ScalarSeries.h>
4 #include <Data/ScalarSeries.h>
5
5
6 #include <cmath>
6 #include <cmath>
7
7
8 #include <QDateTime>
8 #include <QDateTime>
9
9
10 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
10 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
11
11
12 std::unique_ptr<IDataSeries>
12 std::shared_ptr<IDataSeries>
13 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
13 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
14 {
14 {
15 auto dateTime = parameters.m_Time;
15 auto dateTime = parameters.m_Time;
16
16
17 // Gets the timerange from the parameters
18 auto start = dateTime.m_TStart;
19 auto end = dateTime.m_TEnd;
20
21
22 // We assure that timerange is valid
23 if (end < start) {
24 std::swap(start, end);
25 }
26
27 // Generates scalar series containing cosinus values (one value per second)
28 auto scalarSeries
29 = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
30
31 auto dataIndex = 0;
32 for (auto time = start; time < end; ++time, ++dataIndex) {
33 scalarSeries->setData(dataIndex, time, std::cos(time));
34 }
35
36 return scalarSeries;
37 }
38
39 void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList)
40 {
41 // NOTE: Try to use multithread if possible
42 for (const auto &dateTime : dateTimeList) {
43
44 auto scalarSeries = this->retrieveDataSeries(dateTime);
45
46 emit dataProvided(scalarSeries, dateTime);
47 }
48 }
49
50
51 std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTime &dateTime)
52 {
53 auto dataIndex = 0;
17 auto dataIndex = 0;
54
18
55 // Gets the timerange from the parameters
19 // Gets the timerange from the parameters
56 double freq = 100.0;
20 double freq = 100.0;
57 double start = dateTime.m_TStart * freq; // 100 htz
21 double start = dateTime.m_TStart * freq; // 100 htz
58 double end = dateTime.m_TEnd * freq; // 100 htz
22 double end = dateTime.m_TEnd * freq; // 100 htz
59
23
60 // We assure that timerange is valid
24 // We assure that timerange is valid
61 if (end < start) {
25 if (end < start) {
62 std::swap(start, end);
26 std::swap(start, end);
63 }
27 }
64
28
65 // Generates scalar series containing cosinus values (one value per second)
29 // Generates scalar series containing cosinus values (one value per second)
66 auto scalarSeries
30 auto scalarSeries
67 = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
31 = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
68
32
69 for (auto time = start; time < end; ++time, ++dataIndex) {
33 for (auto time = start; time < end; ++time, ++dataIndex) {
70 const auto timeOnFreq = time / freq;
34 const auto timeOnFreq = time / freq;
71 scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq));
35 scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq));
72 }
36 }
73 return scalarSeries;
37 return scalarSeries;
74 }
38 }
39
40 void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList)
41 {
42 // NOTE: Try to use multithread if possible
43 for (const auto &dateTime : dateTimeList) {
44 auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime});
45 emit dataProvided(scalarSeries, dateTime);
46 }
47 }
General Comments 0
You need to be logged in to leave comments. Login now