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