@@ -0,0 +1,37 | |||||
|
1 | #ifndef SCIQLOP_VARIABLEMENUHEADERWIDGET_H | |||
|
2 | #define SCIQLOP_VARIABLEMENUHEADERWIDGET_H | |||
|
3 | ||||
|
4 | #include <QLoggingCategory> | |||
|
5 | #include <QWidget> | |||
|
6 | ||||
|
7 | #include <memory> | |||
|
8 | ||||
|
9 | namespace Ui { | |||
|
10 | class VariableMenuHeaderWidget; | |||
|
11 | } // Ui | |||
|
12 | ||||
|
13 | class Variable; | |||
|
14 | ||||
|
15 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableMenuHeaderWidget) | |||
|
16 | ||||
|
17 | /** | |||
|
18 | * @brief The VariableMenuHeaderWidget class represents the widget used as a header of a menu in the | |||
|
19 | * variable inspector | |||
|
20 | * @sa VariableInspectorWidget | |||
|
21 | */ | |||
|
22 | class VariableMenuHeaderWidget : public QWidget { | |||
|
23 | public: | |||
|
24 | /** | |||
|
25 | * Ctor | |||
|
26 | * @param variables the list of variables used to generate the header | |||
|
27 | * @param parent the parent widget | |||
|
28 | */ | |||
|
29 | explicit VariableMenuHeaderWidget(const QVector<std::shared_ptr<Variable> > &variables, | |||
|
30 | QWidget *parent = 0); | |||
|
31 | virtual ~VariableMenuHeaderWidget() noexcept; | |||
|
32 | ||||
|
33 | private: | |||
|
34 | Ui::VariableMenuHeaderWidget *ui; | |||
|
35 | }; | |||
|
36 | ||||
|
37 | #endif // SCIQLOP_VARIABLEMENUHEADERWIDGET_H |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
@@ -0,0 +1,38 | |||||
|
1 | #include "Variable/VariableMenuHeaderWidget.h" | |||
|
2 | #include "Variable/Variable.h" | |||
|
3 | ||||
|
4 | #include <ui_VariableMenuHeaderWidget.h> | |||
|
5 | ||||
|
6 | Q_LOGGING_CATEGORY(LOG_VariableMenuHeaderWidget, "VariableMenuHeaderWidget") | |||
|
7 | ||||
|
8 | VariableMenuHeaderWidget::VariableMenuHeaderWidget( | |||
|
9 | const QVector<std::shared_ptr<Variable> > &variables, QWidget *parent) | |||
|
10 | : QWidget{parent}, ui{new Ui::VariableMenuHeaderWidget} | |||
|
11 | { | |||
|
12 | ui->setupUi(this); | |||
|
13 | ||||
|
14 | // Generates label according to the state of the variables. The label contains : | |||
|
15 | // - the variable name if there is only one variable in the list | |||
|
16 | // - 'x variables' where x is the number of variables otherwise | |||
|
17 | const auto nbVariables = variables.size(); | |||
|
18 | if (nbVariables == 1) { | |||
|
19 | if (auto variable = variables.first()) { | |||
|
20 | ui->label->setText(variable->name()); | |||
|
21 | } | |||
|
22 | else { | |||
|
23 | qCCritical(LOG_VariableMenuHeaderWidget()) | |||
|
24 | << tr("Can't get the name of the variable : variable is null"); | |||
|
25 | } | |||
|
26 | } | |||
|
27 | else if (nbVariables > 1) { | |||
|
28 | ui->label->setText(tr("%1 variables").arg(nbVariables)); | |||
|
29 | } | |||
|
30 | else { | |||
|
31 | ui->label->setText(tr("No variable")); | |||
|
32 | } | |||
|
33 | } | |||
|
34 | ||||
|
35 | VariableMenuHeaderWidget::~VariableMenuHeaderWidget() noexcept | |||
|
36 | { | |||
|
37 | delete ui; | |||
|
38 | } |
@@ -0,0 +1,31 | |||||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |||
|
2 | <ui version="4.0"> | |||
|
3 | <class>VariableMenuHeaderWidget</class> | |||
|
4 | <widget class="QWidget" name="VariableMenuHeaderWidget"> | |||
|
5 | <property name="geometry"> | |||
|
6 | <rect> | |||
|
7 | <x>0</x> | |||
|
8 | <y>0</y> | |||
|
9 | <width>110</width> | |||
|
10 | <height>34</height> | |||
|
11 | </rect> | |||
|
12 | </property> | |||
|
13 | <layout class="QGridLayout" name="gridLayout"> | |||
|
14 | <item row="0" column="0"> | |||
|
15 | <widget class="QLabel" name="label"> | |||
|
16 | <property name="styleSheet"> | |||
|
17 | <string notr="true">background-color: rgba(127, 127, 127, 127);</string> | |||
|
18 | </property> | |||
|
19 | <property name="text"> | |||
|
20 | <string>TextLabel</string> | |||
|
21 | </property> | |||
|
22 | <property name="alignment"> | |||
|
23 | <set>Qt::AlignCenter</set> | |||
|
24 | </property> | |||
|
25 | </widget> | |||
|
26 | </item> | |||
|
27 | </layout> | |||
|
28 | </widget> | |||
|
29 | <resources/> | |||
|
30 | <connections/> | |||
|
31 | </ui> |
@@ -1,254 +1,256 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SciQLop Software |
|
2 | -- This file is a part of the SciQLop Software | |
3 | -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "MainWindow.h" |
|
22 | #include "MainWindow.h" | |
23 | #include "ui_MainWindow.h" |
|
23 | #include "ui_MainWindow.h" | |
24 |
|
24 | |||
25 | #include <DataSource/DataSourceController.h> |
|
25 | #include <DataSource/DataSourceController.h> | |
26 | #include <DataSource/DataSourceWidget.h> |
|
26 | #include <DataSource/DataSourceWidget.h> | |
27 | #include <SidePane/SqpSidePane.h> |
|
27 | #include <SidePane/SqpSidePane.h> | |
28 | #include <SqpApplication.h> |
|
28 | #include <SqpApplication.h> | |
29 | #include <Time/TimeController.h> |
|
29 | #include <Time/TimeController.h> | |
30 | #include <TimeWidget/TimeWidget.h> |
|
30 | #include <TimeWidget/TimeWidget.h> | |
31 | #include <Variable/Variable.h> |
|
31 | #include <Variable/Variable.h> | |
32 | #include <Visualization/VisualizationController.h> |
|
32 | #include <Visualization/VisualizationController.h> | |
33 |
|
33 | |||
34 | #include <QAction> |
|
34 | #include <QAction> | |
35 | #include <QDate> |
|
35 | #include <QDate> | |
36 | #include <QDateTime> |
|
36 | #include <QDateTime> | |
37 | #include <QDir> |
|
37 | #include <QDir> | |
38 | #include <QFileDialog> |
|
38 | #include <QFileDialog> | |
39 | #include <QToolBar> |
|
39 | #include <QToolBar> | |
40 | #include <QToolButton> |
|
40 | #include <QToolButton> | |
41 | #include <memory.h> |
|
41 | #include <memory.h> | |
42 |
|
42 | |||
43 | //#include <omp.h> |
|
43 | //#include <omp.h> | |
44 | //#include <network/filedownloader.h> |
|
44 | //#include <network/filedownloader.h> | |
45 | //#include <qlopdatabase.h> |
|
45 | //#include <qlopdatabase.h> | |
46 | //#include <qlopsettings.h> |
|
46 | //#include <qlopsettings.h> | |
47 | //#include <qlopgui.h> |
|
47 | //#include <qlopgui.h> | |
48 | //#include <spacedata.h> |
|
48 | //#include <spacedata.h> | |
49 | //#include "qlopcore.h" |
|
49 | //#include "qlopcore.h" | |
50 | //#include "qlopcodecmanager.h" |
|
50 | //#include "qlopcodecmanager.h" | |
51 | //#include "cdfcodec.h" |
|
51 | //#include "cdfcodec.h" | |
52 | //#include "amdatxtcodec.h" |
|
52 | //#include "amdatxtcodec.h" | |
53 | //#include <qlopplotmanager.h> |
|
53 | //#include <qlopplotmanager.h> | |
54 |
|
54 | |||
55 | #include "iostream" |
|
55 | #include "iostream" | |
56 |
|
56 | |||
57 | Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") |
|
57 | Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") | |
58 |
|
58 | |||
59 | namespace { |
|
59 | namespace { | |
60 | const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; |
|
60 | const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; | |
61 | const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; |
|
61 | const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; | |
62 | const auto VIEWPLITTERINDEX = 2; |
|
62 | const auto VIEWPLITTERINDEX = 2; | |
63 | const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; |
|
63 | const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; | |
64 | const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; |
|
64 | const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | class MainWindow::MainWindowPrivate { |
|
67 | class MainWindow::MainWindowPrivate { | |
68 | public: |
|
68 | public: | |
69 | QSize m_LastOpenLeftInspectorSize; |
|
69 | QSize m_LastOpenLeftInspectorSize; | |
70 | QSize m_LastOpenRightInspectorSize; |
|
70 | QSize m_LastOpenRightInspectorSize; | |
71 | }; |
|
71 | }; | |
72 |
|
72 | |||
73 | MainWindow::MainWindow(QWidget *parent) |
|
73 | MainWindow::MainWindow(QWidget *parent) | |
74 | : QMainWindow{parent}, |
|
74 | : QMainWindow{parent}, | |
75 | m_Ui{new Ui::MainWindow}, |
|
75 | m_Ui{new Ui::MainWindow}, | |
76 | impl{spimpl::make_unique_impl<MainWindowPrivate>()} |
|
76 | impl{spimpl::make_unique_impl<MainWindowPrivate>()} | |
77 | { |
|
77 | { | |
78 | m_Ui->setupUi(this); |
|
78 | m_Ui->setupUi(this); | |
79 |
|
79 | |||
80 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
80 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); | |
81 | m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
81 | m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); | |
82 |
|
82 | |||
83 |
|
83 | |||
84 | auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); |
|
84 | auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); | |
85 | auto openLeftInspectorAction = new QAction{QIcon{ |
|
85 | auto openLeftInspectorAction = new QAction{QIcon{ | |
86 | ":/icones/previous.png", |
|
86 | ":/icones/previous.png", | |
87 | }, |
|
87 | }, | |
88 | tr("Show/hide the left inspector"), this}; |
|
88 | tr("Show/hide the left inspector"), this}; | |
89 |
|
89 | |||
90 |
|
90 | |||
91 | auto spacerLeftTop = new QWidget{}; |
|
91 | auto spacerLeftTop = new QWidget{}; | |
92 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
92 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
93 |
|
93 | |||
94 | auto spacerLeftBottom = new QWidget{}; |
|
94 | auto spacerLeftBottom = new QWidget{}; | |
95 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
95 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
96 |
|
96 | |||
97 | leftSidePane->addWidget(spacerLeftTop); |
|
97 | leftSidePane->addWidget(spacerLeftTop); | |
98 | leftSidePane->addAction(openLeftInspectorAction); |
|
98 | leftSidePane->addAction(openLeftInspectorAction); | |
99 | leftSidePane->addWidget(spacerLeftBottom); |
|
99 | leftSidePane->addWidget(spacerLeftBottom); | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); |
|
102 | auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); | |
103 | auto openRightInspectorAction = new QAction{QIcon{ |
|
103 | auto openRightInspectorAction = new QAction{QIcon{ | |
104 | ":/icones/next.png", |
|
104 | ":/icones/next.png", | |
105 | }, |
|
105 | }, | |
106 | tr("Show/hide the right inspector"), this}; |
|
106 | tr("Show/hide the right inspector"), this}; | |
107 |
|
107 | |||
108 | auto spacerRightTop = new QWidget{}; |
|
108 | auto spacerRightTop = new QWidget{}; | |
109 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
109 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
110 |
|
110 | |||
111 | auto spacerRightBottom = new QWidget{}; |
|
111 | auto spacerRightBottom = new QWidget{}; | |
112 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
112 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
113 |
|
113 | |||
114 | rightSidePane->addWidget(spacerRightTop); |
|
114 | rightSidePane->addWidget(spacerRightTop); | |
115 | rightSidePane->addAction(openRightInspectorAction); |
|
115 | rightSidePane->addAction(openRightInspectorAction); | |
116 | rightSidePane->addWidget(spacerRightBottom); |
|
116 | rightSidePane->addWidget(spacerRightBottom); | |
117 |
|
117 | |||
118 | openLeftInspectorAction->setCheckable(true); |
|
118 | openLeftInspectorAction->setCheckable(true); | |
119 | openRightInspectorAction->setCheckable(true); |
|
119 | openRightInspectorAction->setCheckable(true); | |
120 |
|
120 | |||
121 | auto openInspector = [this](bool checked, bool right, auto action) { |
|
121 | auto openInspector = [this](bool checked, bool right, auto action) { | |
122 |
|
122 | |||
123 | action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"}); |
|
123 | action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"}); | |
124 |
|
124 | |||
125 | auto &lastInspectorSize |
|
125 | auto &lastInspectorSize | |
126 | = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize; |
|
126 | = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize; | |
127 |
|
127 | |||
128 | auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size() |
|
128 | auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size() | |
129 | : m_Ui->leftMainInspectorWidget->size(); |
|
129 | : m_Ui->leftMainInspectorWidget->size(); | |
130 |
|
130 | |||
131 | // Update of the last opened geometry |
|
131 | // Update of the last opened geometry | |
132 | if (checked) { |
|
132 | if (checked) { | |
133 | lastInspectorSize = nextInspectorSize; |
|
133 | lastInspectorSize = nextInspectorSize; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | auto startSize = lastInspectorSize; |
|
136 | auto startSize = lastInspectorSize; | |
137 | auto endSize = startSize; |
|
137 | auto endSize = startSize; | |
138 | endSize.setWidth(0); |
|
138 | endSize.setWidth(0); | |
139 |
|
139 | |||
140 | auto splitterInspectorIndex |
|
140 | auto splitterInspectorIndex | |
141 | = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX; |
|
141 | = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX; | |
142 |
|
142 | |||
143 | auto currentSizes = m_Ui->splitter->sizes(); |
|
143 | auto currentSizes = m_Ui->splitter->sizes(); | |
144 | if (checked) { |
|
144 | if (checked) { | |
145 | // adjust sizes individually here, e.g. |
|
145 | // adjust sizes individually here, e.g. | |
146 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); |
|
146 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); | |
147 | currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); |
|
147 | currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); | |
148 | m_Ui->splitter->setSizes(currentSizes); |
|
148 | m_Ui->splitter->setSizes(currentSizes); | |
149 | } |
|
149 | } | |
150 | else { |
|
150 | else { | |
151 | // adjust sizes individually here, e.g. |
|
151 | // adjust sizes individually here, e.g. | |
152 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); |
|
152 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); | |
153 | currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); |
|
153 | currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); | |
154 | m_Ui->splitter->setSizes(currentSizes); |
|
154 | m_Ui->splitter->setSizes(currentSizes); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | }; |
|
157 | }; | |
158 |
|
158 | |||
159 |
|
159 | |||
160 | connect(openLeftInspectorAction, &QAction::triggered, |
|
160 | connect(openLeftInspectorAction, &QAction::triggered, | |
161 | [openInspector, openLeftInspectorAction](bool checked) { |
|
161 | [openInspector, openLeftInspectorAction](bool checked) { | |
162 | openInspector(checked, false, openLeftInspectorAction); |
|
162 | openInspector(checked, false, openLeftInspectorAction); | |
163 | }); |
|
163 | }); | |
164 | connect(openRightInspectorAction, &QAction::triggered, |
|
164 | connect(openRightInspectorAction, &QAction::triggered, | |
165 | [openInspector, openRightInspectorAction](bool checked) { |
|
165 | [openInspector, openRightInspectorAction](bool checked) { | |
166 | openInspector(checked, true, openRightInspectorAction); |
|
166 | openInspector(checked, true, openRightInspectorAction); | |
167 | }); |
|
167 | }); | |
168 |
|
168 | |||
169 | this->menuBar()->addAction(tr("File")); |
|
169 | this->menuBar()->addAction(tr("File")); | |
170 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); |
|
170 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); | |
171 |
|
171 | |||
172 | auto timeWidget = new TimeWidget{}; |
|
172 | auto timeWidget = new TimeWidget{}; | |
173 | mainToolBar->addWidget(timeWidget); |
|
173 | mainToolBar->addWidget(timeWidget); | |
174 |
|
174 | |||
175 | // Widgets / controllers connections |
|
175 | // Widgets / controllers connections | |
176 |
|
176 | |||
177 | // DataSource |
|
177 | // DataSource | |
178 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), |
|
178 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), | |
179 | m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); |
|
179 | m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); | |
180 |
|
180 | |||
181 | // Time |
|
181 | // Time | |
182 | connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(), |
|
182 | connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(), | |
183 | SLOT(onTimeToUpdate(SqpDateTime))); |
|
183 | SLOT(onTimeToUpdate(SqpDateTime))); | |
184 |
|
184 | |||
185 | // Widgets / widgets connections |
|
185 | // Widgets / widgets connections | |
186 | qRegisterMetaType<std::shared_ptr<Variable> >(); |
|
186 | qRegisterMetaType<std::shared_ptr<Variable> >(); | |
187 |
|
187 | |||
188 | // For the following connections, we use DirectConnection to allow each widget that can |
|
188 | // For the following connections, we use DirectConnection to allow each widget that can | |
189 | // potentially attach a menu to the variable's menu to do so before this menu is displayed. |
|
189 | // potentially attach a menu to the variable's menu to do so before this menu is displayed. | |
190 | // The order of connections is also important, since it determines the order in which each |
|
190 | // The order of connections is also important, since it determines the order in which each | |
191 | // widget will attach its menu |
|
191 | // widget will attach its menu | |
192 | connect(m_Ui->variableInspectorWidget, |
|
192 | connect( | |
193 | SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, std::shared_ptr<Variable>)), m_Ui->view, |
|
193 | m_Ui->variableInspectorWidget, | |
194 | SLOT(attachVariableMenu(QMenu *, std::shared_ptr<Variable>)), Qt::DirectConnection); |
|
194 | SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)), | |
|
195 | m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)), | |||
|
196 | Qt::DirectConnection); | |||
195 |
|
197 | |||
196 | /* QLopGUI::registerMenuBar(menuBar()); |
|
198 | /* QLopGUI::registerMenuBar(menuBar()); | |
197 | this->setWindowIcon(QIcon(":/sciqlopLOGO.svg")); |
|
199 | this->setWindowIcon(QIcon(":/sciqlopLOGO.svg")); | |
198 | this->m_progressWidget = new QWidget(); |
|
200 | this->m_progressWidget = new QWidget(); | |
199 | this->m_progressLayout = new QVBoxLayout(this->m_progressWidget); |
|
201 | this->m_progressLayout = new QVBoxLayout(this->m_progressWidget); | |
200 | this->m_progressWidget->setLayout(this->m_progressLayout); |
|
202 | this->m_progressWidget->setLayout(this->m_progressLayout); | |
201 | this->m_progressWidget->setWindowModality(Qt::WindowModal); |
|
203 | this->m_progressWidget->setWindowModality(Qt::WindowModal); | |
202 | m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); |
|
204 | m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); | |
203 | for(int i=0;i<OMP_THREADS;i++) |
|
205 | for(int i=0;i<OMP_THREADS;i++) | |
204 | { |
|
206 | { | |
205 | this->m_progress.append(new QProgressBar(this->m_progressWidget)); |
|
207 | this->m_progress.append(new QProgressBar(this->m_progressWidget)); | |
206 | this->m_progress.last()->setMinimum(0); |
|
208 | this->m_progress.last()->setMinimum(0); | |
207 | this->m_progress.last()->setMaximum(100); |
|
209 | this->m_progress.last()->setMaximum(100); | |
208 | this->m_progressLayout->addWidget(this->m_progress.last()); |
|
210 | this->m_progressLayout->addWidget(this->m_progress.last()); | |
209 | this->m_progressWidget->hide(); |
|
211 | this->m_progressWidget->hide(); | |
210 | this->m_progressThreadIds[i] = -1; |
|
212 | this->m_progressThreadIds[i] = -1; | |
211 | } |
|
213 | } | |
212 | this->m_progressWidget->setWindowTitle("Loading File"); |
|
214 | this->m_progressWidget->setWindowTitle("Loading File"); | |
213 | const QList<QLopService*>ServicesToLoad=QList<QLopService*>() |
|
215 | const QList<QLopService*>ServicesToLoad=QList<QLopService*>() | |
214 | << QLopCore::self() |
|
216 | << QLopCore::self() | |
215 | << QLopPlotManager::self() |
|
217 | << QLopPlotManager::self() | |
216 | << QLopCodecManager::self() |
|
218 | << QLopCodecManager::self() | |
217 | << FileDownloader::self() |
|
219 | << FileDownloader::self() | |
218 | << QLopDataBase::self() |
|
220 | << QLopDataBase::self() | |
219 | << SpaceData::self(); |
|
221 | << SpaceData::self(); | |
220 |
|
222 | |||
221 | CDFCodec::registerToManager(); |
|
223 | CDFCodec::registerToManager(); | |
222 | AMDATXTCodec::registerToManager(); |
|
224 | AMDATXTCodec::registerToManager(); | |
223 |
|
225 | |||
224 |
|
226 | |||
225 | for(int i=0;i<ServicesToLoad.count();i++) |
|
227 | for(int i=0;i<ServicesToLoad.count();i++) | |
226 | { |
|
228 | { | |
227 | qDebug()<<ServicesToLoad.at(i)->serviceName(); |
|
229 | qDebug()<<ServicesToLoad.at(i)->serviceName(); | |
228 | ServicesToLoad.at(i)->initialize(); //must be called before getGUI |
|
230 | ServicesToLoad.at(i)->initialize(); //must be called before getGUI | |
229 | QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI(); |
|
231 | QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI(); | |
230 | if(wdgt) |
|
232 | if(wdgt) | |
231 | { |
|
233 | { | |
232 | wdgt->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
234 | wdgt->setAllowedAreas(Qt::AllDockWidgetAreas); | |
233 | this->addDockWidget(Qt::TopDockWidgetArea,wdgt); |
|
235 | this->addDockWidget(Qt::TopDockWidgetArea,wdgt); | |
234 | } |
|
236 | } | |
235 | PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i)); |
|
237 | PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i)); | |
236 | }*/ |
|
238 | }*/ | |
237 | } |
|
239 | } | |
238 |
|
240 | |||
239 | MainWindow::~MainWindow() |
|
241 | MainWindow::~MainWindow() | |
240 | { |
|
242 | { | |
241 | } |
|
243 | } | |
242 |
|
244 | |||
243 |
|
245 | |||
244 | void MainWindow::changeEvent(QEvent *e) |
|
246 | void MainWindow::changeEvent(QEvent *e) | |
245 | { |
|
247 | { | |
246 | QMainWindow::changeEvent(e); |
|
248 | QMainWindow::changeEvent(e); | |
247 | switch (e->type()) { |
|
249 | switch (e->type()) { | |
248 | case QEvent::LanguageChange: |
|
250 | case QEvent::LanguageChange: | |
249 | m_Ui->retranslateUi(this); |
|
251 | m_Ui->retranslateUi(this); | |
250 | break; |
|
252 | break; | |
251 | default: |
|
253 | default: | |
252 | break; |
|
254 | break; | |
253 | } |
|
255 | } | |
254 | } |
|
256 | } |
@@ -1,82 +1,82 | |||||
1 | #ifndef SCIQLOP_ARRAYDATA_H |
|
1 | #ifndef SCIQLOP_ARRAYDATA_H | |
2 | #define SCIQLOP_ARRAYDATA_H |
|
2 | #define SCIQLOP_ARRAYDATA_H | |
3 |
|
3 | |||
4 | #include <QVector> |
|
4 | #include <QVector> | |
5 |
|
5 | |||
6 | /** |
|
6 | /** | |
7 | * @brief The ArrayData class represents a dataset for a data series. |
|
7 | * @brief The ArrayData class represents a dataset for a data series. | |
8 | * |
|
8 | * | |
9 | * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim |
|
9 | * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim | |
10 | * template-parameter. |
|
10 | * template-parameter. | |
11 | * |
|
11 | * | |
12 | * @tparam Dim the dimension of the ArrayData (one or two) |
|
12 | * @tparam Dim the dimension of the ArrayData (one or two) | |
13 | * @sa IDataSeries |
|
13 | * @sa IDataSeries | |
14 | */ |
|
14 | */ | |
15 | template <int Dim> |
|
15 | template <int Dim> | |
16 | class ArrayData { |
|
16 | class ArrayData { | |
17 | public: |
|
17 | public: | |
18 | /** |
|
18 | /** | |
19 | * Ctor for a unidimensional ArrayData |
|
19 | * Ctor for a unidimensional ArrayData | |
20 | * @param nbColumns the number of values the ArrayData will hold |
|
20 | * @param nbColumns the number of values the ArrayData will hold | |
21 | */ |
|
21 | */ | |
22 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
22 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
23 | explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}} |
|
23 | explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}} | |
24 | { |
|
24 | { | |
25 | m_Data[0].resize(nbColumns); |
|
25 | m_Data[0].resize(nbColumns); | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | /** |
|
28 | /** | |
29 | * Sets a data at a specified index. The index has to be valid to be effective |
|
29 | * Sets a data at a specified index. The index has to be valid to be effective | |
30 | * @param index the index to which the data will be set |
|
30 | * @param index the index to which the data will be set | |
31 | * @param data the data to set |
|
31 | * @param data the data to set | |
32 | * @remarks this method is only available for a unidimensional ArrayData |
|
32 | * @remarks this method is only available for a unidimensional ArrayData | |
33 | */ |
|
33 | */ | |
34 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
34 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
35 | void setData(int index, double data) noexcept |
|
35 | void setData(int index, double data) noexcept | |
36 | { |
|
36 | { | |
37 | if (index >= 0 && index < m_Data.at(0).size()) { |
|
37 | if (index >= 0 && index < m_Data.at(0).size()) { | |
38 | m_Data[0].replace(index, data); |
|
38 | m_Data[0].replace(index, data); | |
39 | } |
|
39 | } | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | /** |
|
42 | /** | |
43 | * @return the data as a vector |
|
43 | * @return the data as a vector | |
44 | * @remarks this method is only available for a unidimensional ArrayData |
|
44 | * @remarks this method is only available for a unidimensional ArrayData | |
45 | */ |
|
45 | */ | |
46 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
46 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
47 | QVector<double> data() const noexcept |
|
47 | const QVector<double> &data() const noexcept | |
48 | { |
|
48 | { | |
49 |
return m_Data |
|
49 | return m_Data[0]; | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | /** |
|
52 | /** | |
53 | * @return the data as a vector |
|
53 | * @return the data as a vector | |
54 | * @remarks this method is only available for a unidimensional ArrayData |
|
54 | * @remarks this method is only available for a unidimensional ArrayData | |
55 | */ |
|
55 | */ | |
56 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
56 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
57 | const QVector<double> &data(double tStart, double tEnd) const noexcept |
|
57 | const QVector<double> &data(double tStart, double tEnd) const noexcept | |
58 | { |
|
58 | { | |
59 | return m_Data.at(tStart); |
|
59 | return m_Data.at(tStart); | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | // TODO Comment |
|
62 | // TODO Comment | |
63 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
63 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
64 |
void merge(ArrayData<1> |
|
64 | void merge(const ArrayData<1> &arrayData) | |
65 | { |
|
65 | { | |
66 | if (!m_Data.empty()) { |
|
66 | if (!m_Data.empty()) { | |
67 |
m_Data[0] += arrayData |
|
67 | m_Data[0] += arrayData.data(); | |
68 | } |
|
68 | } | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
71 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
72 | int size() |
|
72 | int size() | |
73 | { |
|
73 | { | |
74 | return m_Data[0].size(); |
|
74 | return m_Data[0].size(); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | private: |
|
78 | private: | |
79 | QVector<QVector<double> > m_Data; |
|
79 | QVector<QVector<double> > m_Data; | |
80 | }; |
|
80 | }; | |
81 |
|
81 | |||
82 | #endif // SCIQLOP_ARRAYDATA_H |
|
82 | #endif // SCIQLOP_ARRAYDATA_H |
@@ -1,70 +1,70 | |||||
1 | #ifndef SCIQLOP_DATASERIES_H |
|
1 | #ifndef SCIQLOP_DATASERIES_H | |
2 | #define SCIQLOP_DATASERIES_H |
|
2 | #define SCIQLOP_DATASERIES_H | |
3 |
|
3 | |||
4 | #include <Data/ArrayData.h> |
|
4 | #include <Data/ArrayData.h> | |
5 | #include <Data/IDataSeries.h> |
|
5 | #include <Data/IDataSeries.h> | |
6 |
|
6 | |||
7 | #include <QLoggingCategory> |
|
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 |
|
29 | |||
30 | /// @sa IDataSeries::xAxisUnit() |
|
30 | /// @sa IDataSeries::xAxisUnit() | |
31 | Unit xAxisUnit() const override { return m_XAxisUnit; } |
|
31 | Unit xAxisUnit() const override { return m_XAxisUnit; } | |
32 |
|
32 | |||
33 | /// @return the values dataset |
|
33 | /// @return the values dataset | |
34 | std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; } |
|
34 | std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; } | |
35 |
|
35 | |||
36 | /// @sa IDataSeries::valuesUnit() |
|
36 | /// @sa IDataSeries::valuesUnit() | |
37 | Unit valuesUnit() const override { return m_ValuesUnit; } |
|
37 | Unit valuesUnit() const override { return m_ValuesUnit; } | |
38 |
|
38 | |||
39 | /// @sa IDataSeries::merge() |
|
39 | /// @sa IDataSeries::merge() | |
40 | void merge(IDataSeries *dataSeries) override |
|
40 | void merge(IDataSeries *dataSeries) override | |
41 | { |
|
41 | { | |
42 | if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) { |
|
42 | if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) { | |
43 |
m_XAxisData->merge(dimDataSeries->xAxisData() |
|
43 | m_XAxisData->merge(*dimDataSeries->xAxisData()); | |
44 |
m_ValuesData->merge(dimDataSeries->valuesData() |
|
44 | m_ValuesData->merge(*dimDataSeries->valuesData()); | |
45 | } |
|
45 | } | |
46 | else { |
|
46 | else { | |
47 | qCWarning(LOG_DataSeries()) |
|
47 | qCWarning(LOG_DataSeries()) | |
48 | << QObject::tr("Dection of a type of IDataSeries we cannot merge with !"); |
|
48 | << QObject::tr("Dection of a type of IDataSeries we cannot merge with !"); | |
49 | } |
|
49 | } | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | protected: |
|
52 | protected: | |
53 | /// Protected ctor (DataSeries is abstract) |
|
53 | /// Protected ctor (DataSeries is abstract) | |
54 | explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit, |
|
54 | explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit, | |
55 | std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit) |
|
55 | std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit) | |
56 | : m_XAxisData{xAxisData}, |
|
56 | : m_XAxisData{xAxisData}, | |
57 | m_XAxisUnit{xAxisUnit}, |
|
57 | m_XAxisUnit{xAxisUnit}, | |
58 | m_ValuesData{valuesData}, |
|
58 | m_ValuesData{valuesData}, | |
59 | m_ValuesUnit{valuesUnit} |
|
59 | m_ValuesUnit{valuesUnit} | |
60 | { |
|
60 | { | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | private: |
|
63 | private: | |
64 | std::shared_ptr<ArrayData<1> > m_XAxisData; |
|
64 | std::shared_ptr<ArrayData<1> > m_XAxisData; | |
65 | Unit m_XAxisUnit; |
|
65 | Unit m_XAxisUnit; | |
66 | std::shared_ptr<ArrayData<Dim> > m_ValuesData; |
|
66 | std::shared_ptr<ArrayData<Dim> > m_ValuesData; | |
67 | Unit m_ValuesUnit; |
|
67 | Unit m_ValuesUnit; | |
68 | }; |
|
68 | }; | |
69 |
|
69 | |||
70 | #endif // SCIQLOP_DATASERIES_H |
|
70 | #endif // SCIQLOP_DATASERIES_H |
@@ -1,28 +1,42 | |||||
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 | ||||
|
6 | #include <QDateTime> | |||
|
7 | #include <QDebug> | |||
|
8 | ||||
5 | /** |
|
9 | /** | |
6 | * @brief The SqpDateTime struct holds the information of time parameters |
|
10 | * @brief The SqpDateTime struct holds the information of time parameters | |
7 | */ |
|
11 | */ | |
8 | struct SqpDateTime { |
|
12 | struct SqpDateTime { | |
9 | /// Start time |
|
13 | /// Start time | |
10 | double m_TStart; |
|
14 | double m_TStart; | |
11 | /// End time |
|
15 | /// End time | |
12 | double m_TEnd; |
|
16 | double m_TEnd; | |
13 |
|
17 | |||
14 | bool contains(const SqpDateTime &dateTime) |
|
18 | bool contains(const SqpDateTime &dateTime) | |
15 | { |
|
19 | { | |
16 | return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd); |
|
20 | return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd); | |
17 | } |
|
21 | } | |
18 |
|
22 | |||
19 | bool intersect(const SqpDateTime &dateTime) |
|
23 | bool intersect(const SqpDateTime &dateTime) | |
20 | { |
|
24 | { | |
21 | return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd); |
|
25 | return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd); | |
22 | } |
|
26 | } | |
23 | }; |
|
27 | }; | |
24 |
|
28 | |||
|
29 | inline QDebug operator<<(QDebug d, SqpDateTime obj) | |||
|
30 | { | |||
|
31 | auto tendDateTimeStart = QDateTime::fromMSecsSinceEpoch(obj.m_TStart * 1000); | |||
|
32 | auto tendDateTimeEnd = QDateTime::fromMSecsSinceEpoch(obj.m_TEnd * 1000); | |||
|
33 | ||||
|
34 | // QDebug << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd; | |||
|
35 | d << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd; | |||
|
36 | return d; | |||
|
37 | } | |||
|
38 | ||||
25 | // Required for using shared_ptr in signals/slots |
|
39 | // Required for using shared_ptr in signals/slots | |
26 | Q_DECLARE_METATYPE(SqpDateTime) |
|
40 | Q_DECLARE_METATYPE(SqpDateTime) | |
27 |
|
41 | |||
28 | #endif // SCIQLOP_SQPDATETIME_H |
|
42 | #endif // SCIQLOP_SQPDATETIME_H |
@@ -1,56 +1,56 | |||||
1 | #ifndef SCIQLOP_VARIABLE_H |
|
1 | #ifndef SCIQLOP_VARIABLE_H | |
2 | #define SCIQLOP_VARIABLE_H |
|
2 | #define SCIQLOP_VARIABLE_H | |
3 |
|
3 | |||
4 | #include <Data/SqpDateTime.h> |
|
4 | #include <Data/SqpDateTime.h> | |
5 |
|
5 | |||
6 |
|
6 | |||
7 | #include <QLoggingCategory> |
|
7 | #include <QLoggingCategory> | |
8 | #include <QObject> |
|
8 | #include <QObject> | |
9 |
|
9 | |||
10 | #include <Common/spimpl.h> |
|
10 | #include <Common/spimpl.h> | |
11 |
|
11 | |||
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_Variable) |
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_Variable) | |
13 |
|
13 | |||
14 | class IDataSeries; |
|
14 | class IDataSeries; | |
15 | class QString; |
|
15 | class QString; | |
16 |
|
16 | |||
17 | /** |
|
17 | /** | |
18 | * @brief The Variable class represents a variable in SciQlop. |
|
18 | * @brief The Variable class represents a variable in SciQlop. | |
19 | */ |
|
19 | */ | |
20 | class Variable : public QObject { |
|
20 | class Variable : public QObject { | |
21 |
|
21 | |||
22 | Q_OBJECT |
|
22 | Q_OBJECT | |
23 |
|
23 | |||
24 | public: |
|
24 | public: | |
25 | explicit Variable(const QString &name, const QString &unit, const QString &mission, |
|
25 | explicit Variable(const QString &name, const QString &unit, const QString &mission, | |
26 | const SqpDateTime &dateTime); |
|
26 | const SqpDateTime &dateTime); | |
27 |
|
27 | |||
28 | QString name() const noexcept; |
|
28 | QString name() const noexcept; | |
29 | QString mission() const noexcept; |
|
29 | QString mission() const noexcept; | |
30 | QString unit() const noexcept; |
|
30 | QString unit() const noexcept; | |
31 | SqpDateTime dateTime() const noexcept; |
|
31 | SqpDateTime dateTime() const noexcept; | |
32 | void setDateTime(const SqpDateTime &dateTime) noexcept; |
|
32 | void setDateTime(const SqpDateTime &dateTime) noexcept; | |
33 |
|
33 | |||
34 | /// @return the data of the variable, nullptr if there is no data |
|
34 | /// @return the data of the variable, nullptr if there is no data | |
35 | IDataSeries *dataSeries() const noexcept; |
|
35 | IDataSeries *dataSeries() const noexcept; | |
36 |
|
36 | |||
37 | bool contains(const SqpDateTime &dateTime); |
|
37 | bool contains(const SqpDateTime &dateTime); | |
38 | bool intersect(const SqpDateTime &dateTime); |
|
38 | bool intersect(const SqpDateTime &dateTime); | |
39 | void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept; |
|
39 | void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept; | |
40 |
|
40 | |||
41 | public slots: |
|
41 | public slots: | |
42 | void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; |
|
42 | void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; | |
43 |
|
43 | |||
44 | signals: |
|
44 | signals: | |
45 |
void |
|
45 | void updated(); | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | private: |
|
48 | private: | |
49 | class VariablePrivate; |
|
49 | class VariablePrivate; | |
50 | spimpl::unique_impl_ptr<VariablePrivate> impl; |
|
50 | spimpl::unique_impl_ptr<VariablePrivate> impl; | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 | // Required for using shared_ptr in signals/slots |
|
53 | // Required for using shared_ptr in signals/slots | |
54 | Q_DECLARE_METATYPE(std::shared_ptr<Variable>) |
|
54 | Q_DECLARE_METATYPE(std::shared_ptr<Variable>) | |
55 |
|
55 | |||
56 | #endif // SCIQLOP_VARIABLE_H |
|
56 | #endif // SCIQLOP_VARIABLE_H |
@@ -1,33 +1,40 | |||||
1 | #ifndef SCIQLOP_VARIABLECACHECONTROLLER_H |
|
1 | #ifndef SCIQLOP_VARIABLECACHECONTROLLER_H | |
2 | #define SCIQLOP_VARIABLECACHECONTROLLER_H |
|
2 | #define SCIQLOP_VARIABLECACHECONTROLLER_H | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 |
|
5 | |||
6 | #include <Data/SqpDateTime.h> |
|
6 | #include <Data/SqpDateTime.h> | |
7 |
|
7 | |||
|
8 | #include <QLoggingCategory> | |||
|
9 | ||||
8 | #include <Common/spimpl.h> |
|
10 | #include <Common/spimpl.h> | |
9 |
|
11 | |||
10 | class Variable; |
|
12 | class Variable; | |
11 |
|
13 | |||
|
14 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheController) | |||
|
15 | ||||
|
16 | ||||
12 | /// This class aims to store in the cache all of the dateTime already requested to the variable. |
|
17 | /// This class aims to store in the cache all of the dateTime already requested to the variable. | |
13 | class VariableCacheController : public QObject { |
|
18 | class VariableCacheController : public QObject { | |
14 | Q_OBJECT |
|
19 | Q_OBJECT | |
15 | public: |
|
20 | public: | |
16 | explicit VariableCacheController(QObject *parent = 0); |
|
21 | explicit VariableCacheController(QObject *parent = 0); | |
17 |
|
22 | |||
18 |
|
23 | |||
19 | void addDateTime(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); |
|
24 | void addDateTime(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); | |
20 |
|
25 | |||
21 | /// Return all of the SqpDataTime part of the dateTime whose are not in the cache |
|
26 | /// Return all of the SqpDataTime part of the dateTime whose are not in the cache | |
22 | QVector<SqpDateTime> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, |
|
27 | QVector<SqpDateTime> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, | |
23 | const SqpDateTime &dateTime); |
|
28 | const SqpDateTime &dateTime); | |
24 |
|
29 | |||
25 |
|
30 | |||
26 | QVector<SqpDateTime> dateCacheList(std::shared_ptr<Variable> variable) const noexcept; |
|
31 | QVector<SqpDateTime> dateCacheList(std::shared_ptr<Variable> variable) const noexcept; | |
27 |
|
32 | |||
|
33 | void displayCache(std::shared_ptr<Variable> variable); | |||
|
34 | ||||
28 | private: |
|
35 | private: | |
29 | class VariableCacheControllerPrivate; |
|
36 | class VariableCacheControllerPrivate; | |
30 | spimpl::unique_impl_ptr<VariableCacheControllerPrivate> impl; |
|
37 | spimpl::unique_impl_ptr<VariableCacheControllerPrivate> impl; | |
31 | }; |
|
38 | }; | |
32 |
|
39 | |||
33 | #endif // SCIQLOP_VARIABLECACHECONTROLLER_H |
|
40 | #endif // SCIQLOP_VARIABLECACHECONTROLLER_H |
@@ -1,58 +1,57 | |||||
1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H |
|
1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H | |
2 | #define SCIQLOP_VARIABLECONTROLLER_H |
|
2 | #define SCIQLOP_VARIABLECONTROLLER_H | |
3 |
|
3 | |||
4 | #include <Data/SqpDateTime.h> |
|
4 | #include <Data/SqpDateTime.h> | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <QObject> |
|
7 | #include <QObject> | |
8 |
|
8 | |||
9 | #include <Common/spimpl.h> |
|
9 | #include <Common/spimpl.h> | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | class IDataProvider; |
|
12 | class IDataProvider; | |
13 | class TimeController; |
|
13 | class TimeController; | |
14 | class Variable; |
|
14 | class Variable; | |
15 | class VariableModel; |
|
15 | class VariableModel; | |
16 |
|
16 | |||
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) |
|
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) | |
18 |
|
18 | |||
19 | /** |
|
19 | /** | |
20 | * @brief The VariableController class aims to handle the variables in SciQlop. |
|
20 | * @brief The VariableController class aims to handle the variables in SciQlop. | |
21 | */ |
|
21 | */ | |
22 | class VariableController : public QObject { |
|
22 | class VariableController : public QObject { | |
23 | Q_OBJECT |
|
23 | Q_OBJECT | |
24 | public: |
|
24 | public: | |
25 | explicit VariableController(QObject *parent = 0); |
|
25 | explicit VariableController(QObject *parent = 0); | |
26 | virtual ~VariableController(); |
|
26 | virtual ~VariableController(); | |
27 |
|
27 | |||
28 | VariableModel *variableModel() noexcept; |
|
28 | VariableModel *variableModel() noexcept; | |
29 |
|
29 | |||
30 | void setTimeController(TimeController *timeController) noexcept; |
|
30 | void setTimeController(TimeController *timeController) noexcept; | |
31 |
|
31 | |||
32 |
|
32 | |||
33 | /// Request the data loading of the variable whithin dateTime |
|
|||
34 | void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); |
|
|||
35 |
|
||||
36 | signals: |
|
33 | signals: | |
37 | /// Signal emitted when a variable has been created |
|
34 | /// Signal emitted when a variable has been created | |
38 | void variableCreated(std::shared_ptr<Variable> variable); |
|
35 | void variableCreated(std::shared_ptr<Variable> variable); | |
39 |
|
36 | |||
40 | public slots: |
|
37 | public slots: | |
|
38 | /// Request the data loading of the variable whithin dateTime | |||
|
39 | void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); | |||
41 | /** |
|
40 | /** | |
42 | * Creates a new variable and adds it to the model |
|
41 | * Creates a new variable and adds it to the model | |
43 | * @param name the name of the new variable |
|
42 | * @param name the name of the new variable | |
44 | * @param provider the data provider for the new variable |
|
43 | * @param provider the data provider for the new variable | |
45 | */ |
|
44 | */ | |
46 | void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept; |
|
45 | void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept; | |
47 |
|
46 | |||
48 | void initialize(); |
|
47 | void initialize(); | |
49 | void finalize(); |
|
48 | void finalize(); | |
50 |
|
49 | |||
51 | private: |
|
50 | private: | |
52 | void waitForFinish(); |
|
51 | void waitForFinish(); | |
53 |
|
52 | |||
54 | class VariableControllerPrivate; |
|
53 | class VariableControllerPrivate; | |
55 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; |
|
54 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; | |
56 | }; |
|
55 | }; | |
57 |
|
56 | |||
58 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
|
57 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
@@ -1,87 +1,87 | |||||
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::unique_ptr<IDataSeries> dataSeries) noexcept | |
59 | { |
|
59 | { | |
60 | if (!impl->m_DataSeries) { |
|
60 | if (!impl->m_DataSeries) { | |
61 | impl->m_DataSeries = std::move(dataSeries); |
|
61 | impl->m_DataSeries = std::move(dataSeries); | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept |
|
65 | void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |
66 | { |
|
66 | { | |
67 | if (impl->m_DataSeries) { |
|
67 | if (impl->m_DataSeries) { | |
68 | impl->m_DataSeries->merge(dataSeries.get()); |
|
68 | impl->m_DataSeries->merge(dataSeries.get()); | |
69 |
|
69 | |||
70 |
emit |
|
70 | emit updated(); | |
71 | } |
|
71 | } | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | IDataSeries *Variable::dataSeries() const noexcept |
|
74 | IDataSeries *Variable::dataSeries() const noexcept | |
75 | { |
|
75 | { | |
76 | return impl->m_DataSeries.get(); |
|
76 | return impl->m_DataSeries.get(); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | bool Variable::contains(const SqpDateTime &dateTime) |
|
79 | bool Variable::contains(const SqpDateTime &dateTime) | |
80 | { |
|
80 | { | |
81 | return impl->m_DateTime.contains(dateTime); |
|
81 | return impl->m_DateTime.contains(dateTime); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | bool Variable::intersect(const SqpDateTime &dateTime) |
|
84 | bool Variable::intersect(const SqpDateTime &dateTime) | |
85 | { |
|
85 | { | |
86 | return impl->m_DateTime.intersect(dateTime); |
|
86 | return impl->m_DateTime.intersect(dateTime); | |
87 | } |
|
87 | } |
@@ -1,170 +1,183 | |||||
1 | #include "Variable/VariableCacheController.h" |
|
1 | #include "Variable/VariableCacheController.h" | |
2 |
|
2 | |||
3 | #include "Variable/Variable.h" |
|
3 | #include "Variable/Variable.h" | |
4 | #include <unordered_map> |
|
4 | #include <unordered_map> | |
5 |
|
5 | |||
|
6 | Q_LOGGING_CATEGORY(LOG_VariableCacheController, "VariableCacheController") | |||
|
7 | ||||
6 | struct VariableCacheController::VariableCacheControllerPrivate { |
|
8 | struct VariableCacheController::VariableCacheControllerPrivate { | |
7 |
|
9 | |||
8 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> > |
|
10 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> > | |
9 | m_VariableToSqpDateTimeListMap; |
|
11 | m_VariableToSqpDateTimeListMap; | |
10 |
|
12 | |||
11 | void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
13 | void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
12 | QVector<SqpDateTime> ¬InCache, int cacheIndex, |
|
14 | QVector<SqpDateTime> ¬InCache, int cacheIndex, | |
13 | double currentTStart); |
|
15 | double currentTStart); | |
14 |
|
16 | |||
15 | void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
17 | void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
16 | QVector<SqpDateTime> ¬InCache, int cacheIndex, |
|
18 | QVector<SqpDateTime> ¬InCache, int cacheIndex, | |
17 | double currentTStart); |
|
19 | double currentTStart); | |
18 |
|
20 | |||
19 |
|
21 | |||
20 | void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
22 | void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
21 | int cacheIndex); |
|
23 | int cacheIndex); | |
22 | }; |
|
24 | }; | |
23 |
|
25 | |||
24 |
|
26 | |||
25 | VariableCacheController::VariableCacheController(QObject *parent) |
|
27 | VariableCacheController::VariableCacheController(QObject *parent) | |
26 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()} |
|
28 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()} | |
27 | { |
|
29 | { | |
28 | } |
|
30 | } | |
29 |
|
31 | |||
30 | void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable, |
|
32 | void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable, | |
31 | const SqpDateTime &dateTime) |
|
33 | const SqpDateTime &dateTime) | |
32 | { |
|
34 | { | |
33 | if (variable) { |
|
35 | if (variable) { | |
34 | auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable); |
|
36 | auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable); | |
35 | if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) { |
|
37 | if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) { | |
36 | impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime); |
|
38 | impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime); | |
37 | } |
|
39 | } | |
38 | else { |
|
40 | else { | |
39 |
|
41 | |||
40 | // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure |
|
42 | // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure | |
41 | // that the list is ordered : l(0) < l(1). We assume also a < b |
|
43 | // that the list is ordered : l(0) < l(1). We assume also a < b | |
42 | // (with a & b of type SqpDateTime) means ts(b) > te(a) |
|
44 | // (with a & b of type SqpDateTime) means ts(b) > te(a) | |
43 |
|
45 | |||
44 | // The algorithm will try the merge of two interval: |
|
46 | // The algorithm will try the merge of two interval: | |
45 | // - dateTime will be compare with the first interval of the list: |
|
47 | // - dateTime will be compare with the first interval of the list: | |
46 | // A: if it is inferior, it will be inserted and it's finished. |
|
48 | // A: if it is inferior, it will be inserted and it's finished. | |
47 | // B: if it is in intersection, it will be merge then the merged one |
|
49 | // B: if it is in intersection, it will be merge then the merged one | |
48 | // will be compared to the next interval. The old one is remove from the list |
|
50 | // will be compared to the next interval. The old one is remove from the list | |
49 | // C: if it is superior, we do the same with the next interval of the list |
|
51 | // C: if it is superior, we do the same with the next interval of the list | |
50 |
|
52 | |||
51 | impl->addDateTimeRecurse(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), |
|
53 | impl->addDateTimeRecurse(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), | |
52 | 0); |
|
54 | 0); | |
53 | } |
|
55 | } | |
54 | } |
|
56 | } | |
55 | } |
|
57 | } | |
56 |
|
58 | |||
57 | QVector<SqpDateTime> |
|
59 | QVector<SqpDateTime> | |
58 | VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, |
|
60 | VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, | |
59 | const SqpDateTime &dateTime) |
|
61 | const SqpDateTime &dateTime) | |
60 | { |
|
62 | { | |
61 | auto notInCache = QVector<SqpDateTime>{}; |
|
63 | auto notInCache = QVector<SqpDateTime>{}; | |
62 |
|
64 | |||
63 | // This algorithm is recursif. The idea is to localise the start time then the end time in the |
|
65 | // This algorithm is recursif. The idea is to localise the start time then the end time in the | |
64 | // list of date time request associated to the variable |
|
66 | // list of date time request associated to the variable | |
65 | // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b |
|
67 | // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b | |
66 | // (with a & b of type SqpDateTime) means ts(b) > te(a) |
|
68 | // (with a & b of type SqpDateTime) means ts(b) > te(a) | |
67 |
|
69 | |||
68 | impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), |
|
70 | impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), | |
69 | notInCache, 0, dateTime.m_TStart); |
|
71 | notInCache, 0, dateTime.m_TStart); | |
70 |
|
72 | |||
71 | return notInCache; |
|
73 | return notInCache; | |
72 | } |
|
74 | } | |
73 |
|
75 | |||
74 | QVector<SqpDateTime> |
|
76 | QVector<SqpDateTime> | |
75 | VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept |
|
77 | VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept | |
76 | { |
|
78 | { | |
77 | return impl->m_VariableToSqpDateTimeListMap.at(variable); |
|
79 | return impl->m_VariableToSqpDateTimeListMap.at(variable); | |
78 | } |
|
80 | } | |
79 |
|
81 | |||
80 | void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse( |
|
82 | void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse( | |
81 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex) |
|
83 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex) | |
82 | { |
|
84 | { | |
83 | const auto dateTimeListSize = dateTimeList.count(); |
|
85 | const auto dateTimeListSize = dateTimeList.count(); | |
84 | if (cacheIndex >= dateTimeListSize) { |
|
86 | if (cacheIndex >= dateTimeListSize) { | |
85 | dateTimeList.push_back(dateTime); |
|
87 | dateTimeList.push_back(dateTime); | |
86 | // there is no anymore interval to compore, we can just push_back it |
|
88 | // there is no anymore interval to compore, we can just push_back it | |
87 | return; |
|
89 | return; | |
88 | } |
|
90 | } | |
89 |
|
91 | |||
90 | auto currentDateTime = dateTimeList[cacheIndex]; |
|
92 | auto currentDateTime = dateTimeList[cacheIndex]; | |
91 |
|
93 | |||
92 | if (dateTime.m_TEnd < currentDateTime.m_TStart) { |
|
94 | if (dateTime.m_TEnd < currentDateTime.m_TStart) { | |
93 | // The compared one is < to current one compared, we can insert it |
|
95 | // The compared one is < to current one compared, we can insert it | |
94 | dateTimeList.insert(cacheIndex, dateTime); |
|
96 | dateTimeList.insert(cacheIndex, dateTime); | |
95 | } |
|
97 | } | |
96 | else if (dateTime.m_TStart > currentDateTime.m_TEnd) { |
|
98 | else if (dateTime.m_TStart > currentDateTime.m_TEnd) { | |
97 | // The compared one is > to current one compared we can comparet if to the next one |
|
99 | // The compared one is > to current one compared we can comparet if to the next one | |
98 | addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex); |
|
100 | addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex); | |
99 | } |
|
101 | } | |
100 | else { |
|
102 | else { | |
101 | // Merge cases: we need to merge the two interval, remove the old one from the list then |
|
103 | // Merge cases: we need to merge the two interval, remove the old one from the list then | |
102 | // rerun the algo from this index with the merged interval |
|
104 | // rerun the algo from this index with the merged interval | |
103 | auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart); |
|
105 | auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart); | |
104 | auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd); |
|
106 | auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd); | |
105 | auto mergeDateTime = SqpDateTime{mTStart, mTEnd}; |
|
107 | auto mergeDateTime = SqpDateTime{mTStart, mTEnd}; | |
106 |
|
108 | |||
107 | dateTimeList.remove(cacheIndex); |
|
109 | dateTimeList.remove(cacheIndex); | |
108 | addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex); |
|
110 | addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex); | |
109 | } |
|
111 | } | |
110 | } |
|
112 | } | |
111 |
|
113 | |||
112 |
|
114 | |||
113 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd( |
|
115 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd( | |
114 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
116 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
115 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) |
|
117 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) | |
116 | { |
|
118 | { | |
117 | const auto dateTimeListSize = dateTimeList.count(); |
|
119 | const auto dateTimeListSize = dateTimeList.count(); | |
118 | if (cacheIndex >= dateTimeListSize) { |
|
120 | if (cacheIndex >= dateTimeListSize) { | |
119 | if (currentTStart < dateTime.m_TEnd) { |
|
121 | if (currentTStart < dateTime.m_TEnd) { | |
120 |
|
122 | |||
121 | // te localised after all other interval: The last interval is [currentTsart, te] |
|
123 | // te localised after all other interval: The last interval is [currentTsart, te] | |
122 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
124 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
123 | } |
|
125 | } | |
124 | return; |
|
126 | return; | |
125 | } |
|
127 | } | |
126 |
|
128 | |||
127 | auto currentDateTimeJ = dateTimeList[cacheIndex]; |
|
129 | auto currentDateTimeJ = dateTimeList[cacheIndex]; | |
128 | if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) { |
|
130 | if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) { | |
129 | // te localised between to interval: The last interval is [currentTsart, te] |
|
131 | // te localised between to interval: The last interval is [currentTsart, te] | |
130 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
132 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
131 | } |
|
133 | } | |
132 | else { |
|
134 | else { | |
133 | notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart}); |
|
135 | notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart}); | |
134 | if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) { |
|
136 | if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) { | |
135 | // te not localised before the current interval: we need to look at the next interval |
|
137 | // te not localised before the current interval: we need to look at the next interval | |
136 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex, |
|
138 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex, | |
137 | currentDateTimeJ.m_TEnd); |
|
139 | currentDateTimeJ.m_TEnd); | |
138 | } |
|
140 | } | |
139 | } |
|
141 | } | |
140 | } |
|
142 | } | |
141 |
|
143 | |||
142 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart( |
|
144 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart( | |
143 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
145 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
144 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) |
|
146 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) | |
145 | { |
|
147 | { | |
146 | const auto dateTimeListSize = dateTimeList.count(); |
|
148 | const auto dateTimeListSize = dateTimeList.count(); | |
147 | if (cacheIndex >= dateTimeListSize) { |
|
149 | if (cacheIndex >= dateTimeListSize) { | |
148 | // ts localised after all other interval: The last interval is [ts, te] |
|
150 | // ts localised after all other interval: The last interval is [ts, te] | |
149 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
151 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
150 | return; |
|
152 | return; | |
151 | } |
|
153 | } | |
152 |
|
154 | |||
153 | auto currentDateTimeI = dateTimeList[cacheIndex]; |
|
155 | auto currentDateTimeI = dateTimeList[cacheIndex]; | |
154 | if (currentTStart < currentDateTimeI.m_TStart) { |
|
156 | if (currentTStart < currentDateTimeI.m_TStart) { | |
155 |
|
157 | |||
156 | // ts localised between to interval: let's localized te |
|
158 | // ts localised between to interval: let's localized te | |
157 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart); |
|
159 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart); | |
158 | } |
|
160 | } | |
159 |
else if ( |
|
161 | else if (currentTStart < currentDateTimeI.m_TEnd) { | |
160 | // ts not localised before the current interval: we need to look at the next interval |
|
162 | if (dateTime.m_TEnd > currentDateTimeI.m_TEnd) { | |
161 | // We can assume now current tstart is the last interval tend, because data between them are |
|
163 | // ts not localised before the current interval: we need to look at the next interval | |
162 | // in the cache |
|
164 | // We can assume now current tstart is the last interval tend, because data between them | |
163 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, |
|
165 | // are | |
164 | currentDateTimeI.m_TEnd); |
|
166 | // in the cache | |
|
167 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, | |||
|
168 | currentDateTimeI.m_TEnd); | |||
|
169 | } | |||
165 | } |
|
170 | } | |
166 | else { |
|
171 | else { | |
167 | // ts not localised before the current interval: we need to look at the next interval |
|
172 | // ts not localised before the current interval: we need to look at the next interval | |
168 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart); |
|
173 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart); | |
169 | } |
|
174 | } | |
170 | } |
|
175 | } | |
|
176 | ||||
|
177 | ||||
|
178 | void VariableCacheController::displayCache(std::shared_ptr<Variable> variable) | |||
|
179 | { | |||
|
180 | auto variableDateTimeList = impl->m_VariableToSqpDateTimeListMap.at(variable); | |||
|
181 | qCInfo(LOG_VariableCacheController()) << tr("VariableCacheController::displayCache") | |||
|
182 | << variableDateTimeList; | |||
|
183 | } |
@@ -1,164 +1,157 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableCacheController.h> |
|
2 | #include <Variable/VariableCacheController.h> | |
3 | #include <Variable/VariableController.h> |
|
3 | #include <Variable/VariableController.h> | |
4 | #include <Variable/VariableModel.h> |
|
4 | #include <Variable/VariableModel.h> | |
5 |
|
5 | |||
6 | #include <Data/DataProviderParameters.h> |
|
6 | #include <Data/DataProviderParameters.h> | |
7 | #include <Data/IDataProvider.h> |
|
7 | #include <Data/IDataProvider.h> | |
8 | #include <Data/IDataSeries.h> |
|
8 | #include <Data/IDataSeries.h> | |
9 | #include <Time/TimeController.h> |
|
9 | #include <Time/TimeController.h> | |
10 |
|
10 | |||
11 | #include <QDateTime> |
|
11 | #include <QDateTime> | |
12 | #include <QElapsedTimer> |
|
|||
13 | #include <QMutex> |
|
12 | #include <QMutex> | |
14 | #include <QThread> |
|
13 | #include <QThread> | |
15 |
|
14 | |||
16 | #include <unordered_map> |
|
15 | #include <unordered_map> | |
17 |
|
16 | |||
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
17 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
19 |
|
18 | |||
20 | namespace { |
|
19 | namespace { | |
21 |
|
20 | |||
22 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method |
|
21 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method | |
23 | /// will be deleted when the timerange is recovered from SciQlop |
|
22 | /// will be deleted when the timerange is recovered from SciQlop | |
24 | std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, |
|
23 | std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, | |
25 | const SqpDateTime &dateTime) noexcept |
|
24 | const SqpDateTime &dateTime) noexcept | |
26 | { |
|
25 | { | |
27 | auto parameters = DataProviderParameters{dateTime}; |
|
26 | auto parameters = DataProviderParameters{dateTime}; | |
28 |
|
27 | |||
29 | return provider.retrieveData(parameters); |
|
28 | return provider.retrieveData(parameters); | |
30 | } |
|
29 | } | |
31 |
|
30 | |||
32 | } // namespace |
|
31 | } // namespace | |
33 |
|
32 | |||
34 | struct VariableController::VariableControllerPrivate { |
|
33 | struct VariableController::VariableControllerPrivate { | |
35 | explicit VariableControllerPrivate(VariableController *parent) |
|
34 | explicit VariableControllerPrivate(VariableController *parent) | |
36 | : m_WorkingMutex{}, |
|
35 | : m_WorkingMutex{}, | |
37 | m_VariableModel{new VariableModel{parent}}, |
|
36 | m_VariableModel{new VariableModel{parent}}, | |
38 | m_VariableCacheController{std::make_unique<VariableCacheController>()} |
|
37 | m_VariableCacheController{std::make_unique<VariableCacheController>()} | |
39 | { |
|
38 | { | |
40 | } |
|
39 | } | |
41 |
|
40 | |||
42 | QMutex m_WorkingMutex; |
|
41 | QMutex m_WorkingMutex; | |
43 | /// Variable model. The VariableController has the ownership |
|
42 | /// Variable model. The VariableController has the ownership | |
44 | VariableModel *m_VariableModel; |
|
43 | VariableModel *m_VariableModel; | |
45 |
|
44 | |||
46 |
|
45 | |||
47 | TimeController *m_TimeController{nullptr}; |
|
46 | TimeController *m_TimeController{nullptr}; | |
48 | std::unique_ptr<VariableCacheController> m_VariableCacheController; |
|
47 | std::unique_ptr<VariableCacheController> m_VariableCacheController; | |
49 |
|
48 | |||
50 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
49 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
51 | m_VariableToProviderMap; |
|
50 | m_VariableToProviderMap; | |
52 | }; |
|
51 | }; | |
53 |
|
52 | |||
54 | VariableController::VariableController(QObject *parent) |
|
53 | VariableController::VariableController(QObject *parent) | |
55 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
54 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
56 | { |
|
55 | { | |
57 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
56 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
58 | << QThread::currentThread(); |
|
57 | << QThread::currentThread(); | |
59 | } |
|
58 | } | |
60 |
|
59 | |||
61 | VariableController::~VariableController() |
|
60 | VariableController::~VariableController() | |
62 | { |
|
61 | { | |
63 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
62 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
64 | << QThread::currentThread(); |
|
63 | << QThread::currentThread(); | |
65 | this->waitForFinish(); |
|
64 | this->waitForFinish(); | |
66 | } |
|
65 | } | |
67 |
|
66 | |||
68 | VariableModel *VariableController::variableModel() noexcept |
|
67 | VariableModel *VariableController::variableModel() noexcept | |
69 | { |
|
68 | { | |
70 | return impl->m_VariableModel; |
|
69 | return impl->m_VariableModel; | |
71 | } |
|
70 | } | |
72 |
|
71 | |||
73 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
72 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
74 | { |
|
73 | { | |
75 | impl->m_TimeController = timeController; |
|
74 | impl->m_TimeController = timeController; | |
76 | } |
|
75 | } | |
77 |
|
76 | |||
78 | void VariableController::createVariable(const QString &name, |
|
77 | void VariableController::createVariable(const QString &name, | |
79 | std::shared_ptr<IDataProvider> provider) noexcept |
|
78 | std::shared_ptr<IDataProvider> provider) noexcept | |
80 | { |
|
79 | { | |
81 |
|
80 | |||
82 | if (!impl->m_TimeController) { |
|
81 | if (!impl->m_TimeController) { | |
83 | qCCritical(LOG_VariableController()) |
|
82 | qCCritical(LOG_VariableController()) | |
84 | << tr("Impossible to create variable: The time controller is null"); |
|
83 | << tr("Impossible to create variable: The time controller is null"); | |
85 | return; |
|
84 | return; | |
86 | } |
|
85 | } | |
87 |
|
86 | |||
88 |
|
87 | |||
89 | /// @todo : for the moment : |
|
88 | /// @todo : for the moment : | |
90 | /// - the provider is only used to retrieve data from the variable for its initialization, but |
|
89 | /// - the provider is only used to retrieve data from the variable for its initialization, but | |
91 | /// it will be retained later |
|
90 | /// it will be retained later | |
92 | /// - default data are generated for the variable, without taking into account the timerange set |
|
91 | /// - default data are generated for the variable, without taking into account the timerange set | |
93 | /// in sciqlop |
|
92 | /// in sciqlop | |
94 | auto dateTime = impl->m_TimeController->dateTime(); |
|
93 | auto dateTime = impl->m_TimeController->dateTime(); | |
95 | if (auto newVariable = impl->m_VariableModel->createVariable( |
|
94 | if (auto newVariable = impl->m_VariableModel->createVariable( | |
96 | name, dateTime, generateDefaultDataSeries(*provider, dateTime))) { |
|
95 | name, dateTime, generateDefaultDataSeries(*provider, dateTime))) { | |
97 |
|
96 | |||
98 | // store the provider |
|
97 | // store the provider | |
99 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
98 | impl->m_VariableToProviderMap[newVariable] = provider; | |
100 | qRegisterMetaType<std::shared_ptr<IDataSeries> >(); |
|
99 | qRegisterMetaType<std::shared_ptr<IDataSeries> >(); | |
101 | qRegisterMetaType<SqpDateTime>(); |
|
100 | qRegisterMetaType<SqpDateTime>(); | |
102 | connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(), |
|
101 | connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(), | |
103 | &Variable::onAddDataSeries); |
|
102 | &Variable::onAddDataSeries); | |
104 |
|
103 | |||
105 |
|
104 | |||
106 | // store in cache |
|
105 | // store in cache | |
107 | impl->m_VariableCacheController->addDateTime(newVariable, dateTime); |
|
106 | impl->m_VariableCacheController->addDateTime(newVariable, dateTime); | |
108 |
|
107 | |||
109 | // notify the creation |
|
108 | // notify the creation | |
110 | emit variableCreated(newVariable); |
|
109 | emit variableCreated(newVariable); | |
111 | } |
|
110 | } | |
112 | } |
|
111 | } | |
113 |
|
112 | |||
114 |
|
113 | |||
115 |
void VariableController:: |
|
114 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, | |
116 | const SqpDateTime &dateTime) |
|
115 | const SqpDateTime &dateTime) | |
117 | { |
|
116 | { | |
118 | // we want to load data of the variable for the dateTime. |
|
117 | // we want to load data of the variable for the dateTime. | |
119 | // First we check if the cache contains some of them. |
|
118 | // First we check if the cache contains some of them. | |
120 | // For the other, we ask the provider to give them. |
|
119 | // For the other, we ask the provider to give them. | |
121 | if (variable) { |
|
120 | if (variable) { | |
122 |
|
121 | |||
123 | QElapsedTimer timer; |
|
|||
124 | timer.start(); |
|
|||
125 | qCInfo(LOG_VariableController()) << "TORM: The slow s0 operation took" << timer.elapsed() |
|
|||
126 | << "milliseconds"; |
|
|||
127 | auto dateTimeListNotInCache |
|
122 | auto dateTimeListNotInCache | |
128 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); |
|
123 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); | |
129 | qCInfo(LOG_VariableController()) << "TORM: The slow s1 operation took" << timer.elapsed() |
|
|||
130 | << "milliseconds"; |
|
|||
131 |
|
124 | |||
132 | // Ask the provider for each data on the dateTimeListNotInCache |
|
125 | if (!dateTimeListNotInCache.empty()) { | |
133 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading(dateTimeListNotInCache); |
|
126 | // Ask the provider for each data on the dateTimeListNotInCache | |
134 |
|
127 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( | ||
135 | qCInfo(LOG_VariableController()) << "TORM: The slow s2 operation took" << timer.elapsed() |
|
128 | std::move(dateTimeListNotInCache)); | |
136 | << "milliseconds"; |
|
129 | // store in cache | |
137 |
|
130 | impl->m_VariableCacheController->addDateTime(variable, dateTime); | ||
138 | // store in cache |
|
131 | } | |
139 | impl->m_VariableCacheController->addDateTime(variable, dateTime); |
|
132 | else { | |
140 | qCInfo(LOG_VariableController()) << "TORM: The slow s3 operation took" << timer.elapsed() |
|
133 | emit variable->updated(); | |
141 | << "milliseconds"; |
|
134 | } | |
142 | } |
|
135 | } | |
143 | else { |
|
136 | else { | |
144 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
|
137 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); | |
145 | } |
|
138 | } | |
146 | } |
|
139 | } | |
147 |
|
140 | |||
148 |
|
141 | |||
149 | void VariableController::initialize() |
|
142 | void VariableController::initialize() | |
150 | { |
|
143 | { | |
151 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
144 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
152 | impl->m_WorkingMutex.lock(); |
|
145 | impl->m_WorkingMutex.lock(); | |
153 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
146 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
154 | } |
|
147 | } | |
155 |
|
148 | |||
156 | void VariableController::finalize() |
|
149 | void VariableController::finalize() | |
157 | { |
|
150 | { | |
158 | impl->m_WorkingMutex.unlock(); |
|
151 | impl->m_WorkingMutex.unlock(); | |
159 | } |
|
152 | } | |
160 |
|
153 | |||
161 | void VariableController::waitForFinish() |
|
154 | void VariableController::waitForFinish() | |
162 | { |
|
155 | { | |
163 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
156 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
164 | } |
|
157 | } |
@@ -1,343 +1,353 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableCacheController.h> |
|
2 | #include <Variable/VariableCacheController.h> | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 | #include <QtTest> |
|
5 | #include <QtTest> | |
6 |
|
6 | |||
7 | #include <memory> |
|
7 | #include <memory> | |
8 |
|
8 | |||
9 | class TestVariableCacheController : public QObject { |
|
9 | class TestVariableCacheController : public QObject { | |
10 | Q_OBJECT |
|
10 | Q_OBJECT | |
11 |
|
11 | |||
12 | private slots: |
|
12 | private slots: | |
13 | void testProvideNotInCacheDateTimeList(); |
|
13 | void testProvideNotInCacheDateTimeList(); | |
14 |
|
14 | |||
15 | void testAddDateTime(); |
|
15 | void testAddDateTime(); | |
16 | }; |
|
16 | }; | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | void TestVariableCacheController::testProvideNotInCacheDateTimeList() |
|
19 | void TestVariableCacheController::testProvideNotInCacheDateTimeList() | |
20 | { |
|
20 | { | |
21 | VariableCacheController variableCacheController{}; |
|
21 | VariableCacheController variableCacheController{}; | |
22 |
|
22 | |||
23 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; |
|
23 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |
24 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
24 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
25 | auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()), |
|
25 | auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()), | |
26 | static_cast<double>(te0.toMSecsSinceEpoch())}; |
|
26 | static_cast<double>(te0.toMSecsSinceEpoch())}; | |
27 |
|
27 | |||
28 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; |
|
28 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; | |
29 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; |
|
29 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; | |
30 | auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()), |
|
30 | auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()), | |
31 | static_cast<double>(te1.toMSecsSinceEpoch())}; |
|
31 | static_cast<double>(te1.toMSecsSinceEpoch())}; | |
32 |
|
32 | |||
33 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; |
|
33 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; | |
34 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; |
|
34 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; | |
35 | auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()), |
|
35 | auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()), | |
36 | static_cast<double>(te2.toMSecsSinceEpoch())}; |
|
36 | static_cast<double>(te2.toMSecsSinceEpoch())}; | |
37 |
|
37 | |||
38 | auto var0 = std::make_shared<Variable>("", "", "", sqp0); |
|
38 | auto var0 = std::make_shared<Variable>("", "", "", sqp0); | |
39 |
|
39 | |||
40 | variableCacheController.addDateTime(var0, sqp0); |
|
40 | variableCacheController.addDateTime(var0, sqp0); | |
41 | variableCacheController.addDateTime(var0, sqp1); |
|
41 | variableCacheController.addDateTime(var0, sqp1); | |
42 | variableCacheController.addDateTime(var0, sqp2); |
|
42 | variableCacheController.addDateTime(var0, sqp2); | |
43 |
|
43 | |||
44 | // first case [ts,te] < ts0 |
|
44 | // first case [ts,te] < ts0 | |
45 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
45 | auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
46 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; |
|
46 | auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}}; | |
47 | auto sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
47 | auto sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
48 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
48 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
49 |
|
49 | |||
50 |
|
50 | |||
51 | auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
51 | auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
52 |
|
52 | |||
53 | QCOMPARE(notInCach.size(), 1); |
|
53 | QCOMPARE(notInCach.size(), 1); | |
54 | auto notInCacheSqp = notInCach.first(); |
|
54 | auto notInCacheSqp = notInCach.first(); | |
55 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
55 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
56 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
56 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
57 |
|
57 | |||
58 |
|
58 | |||
59 | // second case ts < ts0 && ts0 < te <= te0 |
|
59 | // second case ts < ts0 && ts0 < te <= te0 | |
60 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
60 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
61 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
61 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
62 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
62 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
63 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
63 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
64 |
|
64 | |||
65 |
|
65 | |||
66 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
66 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
67 |
|
67 | |||
68 | QCOMPARE(notInCach.size(), 1); |
|
68 | QCOMPARE(notInCach.size(), 1); | |
69 | notInCacheSqp = notInCach.first(); |
|
69 | notInCacheSqp = notInCach.first(); | |
70 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
70 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
71 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
71 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
72 |
|
72 | |||
73 | // 3th case ts < ts0 && te0 < te <= ts1 |
|
73 | // 3th case ts < ts0 && te0 < te <= ts1 | |
74 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
74 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
75 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
75 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
76 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
76 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
77 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
77 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
78 |
|
78 | |||
79 |
|
79 | |||
80 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
80 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
81 |
|
81 | |||
82 | QCOMPARE(notInCach.size(), 2); |
|
82 | QCOMPARE(notInCach.size(), 2); | |
83 | notInCacheSqp = notInCach.first(); |
|
83 | notInCacheSqp = notInCach.first(); | |
84 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
84 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
85 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
85 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
86 |
|
86 | |||
87 | notInCacheSqp = notInCach.at(1); |
|
87 | notInCacheSqp = notInCach.at(1); | |
88 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
88 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
89 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
89 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
90 |
|
90 | |||
91 | // 4th case ts < ts0 && ts1 < te <= te1 |
|
91 | // 4th case ts < ts0 && ts1 < te <= te1 | |
92 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
92 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
93 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; |
|
93 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; | |
94 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
94 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
95 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
95 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
96 |
|
96 | |||
97 |
|
97 | |||
98 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
98 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
99 |
|
99 | |||
100 | QCOMPARE(notInCach.size(), 2); |
|
100 | QCOMPARE(notInCach.size(), 2); | |
101 | notInCacheSqp = notInCach.first(); |
|
101 | notInCacheSqp = notInCach.first(); | |
102 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
102 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
103 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
103 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
104 |
|
104 | |||
105 | notInCacheSqp = notInCach.at(1); |
|
105 | notInCacheSqp = notInCach.at(1); | |
106 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
106 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
107 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); |
|
107 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
108 |
|
108 | |||
109 | // 5th case ts < ts0 && te3 < te |
|
109 | // 5th case ts < ts0 && te3 < te | |
110 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; |
|
110 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}}; | |
111 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; |
|
111 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; | |
112 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
112 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
113 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
113 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
114 |
|
114 | |||
115 |
|
115 | |||
116 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
116 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
117 |
|
117 | |||
118 | QCOMPARE(notInCach.size(), 4); |
|
118 | QCOMPARE(notInCach.size(), 4); | |
119 | notInCacheSqp = notInCach.first(); |
|
119 | notInCacheSqp = notInCach.first(); | |
120 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
120 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
121 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
121 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
122 |
|
122 | |||
123 | notInCacheSqp = notInCach.at(1); |
|
123 | notInCacheSqp = notInCach.at(1); | |
124 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
124 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
125 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); |
|
125 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
126 |
|
126 | |||
127 | notInCacheSqp = notInCach.at(2); |
|
127 | notInCacheSqp = notInCach.at(2); | |
128 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); |
|
128 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); | |
129 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch())); |
|
129 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch())); | |
130 |
|
130 | |||
131 | notInCacheSqp = notInCach.at(3); |
|
131 | notInCacheSqp = notInCach.at(3); | |
132 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch())); |
|
132 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch())); | |
133 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
133 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
134 |
|
134 | |||
135 |
|
135 | |||
136 | // 6th case ts2 < ts |
|
136 | // 6th case ts2 < ts | |
137 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 45, 0, 0}}; |
|
137 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 45, 0, 0}}; | |
138 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; |
|
138 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; | |
139 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
139 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
140 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
140 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
141 |
|
141 | |||
142 |
|
142 | |||
143 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
143 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
144 |
|
144 | |||
145 | QCOMPARE(notInCach.size(), 1); |
|
145 | QCOMPARE(notInCach.size(), 1); | |
146 | notInCacheSqp = notInCach.first(); |
|
146 | notInCacheSqp = notInCach.first(); | |
147 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
147 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
148 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
148 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
149 |
|
149 | |||
150 | // 7th case ts = te0 && te < ts1 |
|
150 | // 7th case ts = te0 && te < ts1 | |
151 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
151 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
152 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
152 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
153 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
153 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
154 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
154 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
155 |
|
155 | |||
156 |
|
156 | |||
157 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
157 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
158 |
|
158 | |||
159 | QCOMPARE(notInCach.size(), 1); |
|
159 | QCOMPARE(notInCach.size(), 1); | |
160 | notInCacheSqp = notInCach.first(); |
|
160 | notInCacheSqp = notInCach.first(); | |
161 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
161 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
162 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
162 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
163 |
|
163 | |||
164 | // 8th case ts0 < ts < te0 && te < ts1 |
|
164 | // 8th case ts0 < ts < te0 && te < ts1 | |
165 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
165 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
166 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
166 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
167 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
167 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
168 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
168 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
169 |
|
169 | |||
170 |
|
170 | |||
171 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
171 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
172 |
|
172 | |||
173 | QCOMPARE(notInCach.size(), 1); |
|
173 | QCOMPARE(notInCach.size(), 1); | |
174 | notInCacheSqp = notInCach.first(); |
|
174 | notInCacheSqp = notInCach.first(); | |
175 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
175 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
176 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
176 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
177 |
|
177 | |||
178 | // 9th case ts0 < ts < te0 && ts1 < te < te1 |
|
178 | // 9th case ts0 < ts < te0 && ts1 < te < te1 | |
179 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; |
|
179 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}}; | |
180 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; |
|
180 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}}; | |
181 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
181 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
182 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
182 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
183 |
|
183 | |||
184 |
|
184 | |||
185 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
185 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
186 |
|
186 | |||
187 | QCOMPARE(notInCach.size(), 1); |
|
187 | QCOMPARE(notInCach.size(), 1); | |
188 | notInCacheSqp = notInCach.first(); |
|
188 | notInCacheSqp = notInCach.first(); | |
189 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
189 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch())); | |
190 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); |
|
190 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
191 |
|
191 | |||
192 | // 10th case te1 < ts < te < ts2 |
|
192 | // 10th case te1 < ts < te < ts2 | |
193 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}}; |
|
193 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}}; | |
194 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; |
|
194 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; | |
195 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
195 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
196 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
196 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
197 |
|
197 | |||
198 |
|
198 | |||
199 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
199 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
200 |
|
200 | |||
201 | QCOMPARE(notInCach.size(), 1); |
|
201 | QCOMPARE(notInCach.size(), 1); | |
202 | notInCacheSqp = notInCach.first(); |
|
202 | notInCacheSqp = notInCach.first(); | |
203 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
203 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
204 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
204 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
205 |
|
205 | |||
206 | // 11th case te0 < ts < ts1 && te3 < te |
|
206 | // 11th case te0 < ts < ts1 && te3 < te | |
207 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
207 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
208 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; |
|
208 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}}; | |
209 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
209 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
210 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
210 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
211 |
|
211 | |||
212 |
|
212 | |||
213 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
213 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
214 |
|
214 | |||
215 | QCOMPARE(notInCach.size(), 3); |
|
215 | QCOMPARE(notInCach.size(), 3); | |
216 | notInCacheSqp = notInCach.first(); |
|
216 | notInCacheSqp = notInCach.first(); | |
217 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
217 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
218 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); |
|
218 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
219 |
|
219 | |||
220 | notInCacheSqp = notInCach.at(1); |
|
220 | notInCacheSqp = notInCach.at(1); | |
221 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); |
|
221 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); | |
222 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch())); |
|
222 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch())); | |
223 |
|
223 | |||
224 | notInCacheSqp = notInCach.at(2); |
|
224 | notInCacheSqp = notInCach.at(2); | |
225 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch())); |
|
225 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch())); | |
226 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
226 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
227 |
|
227 | |||
228 | // 12th case te0 < ts < ts1 && te3 < te |
|
228 | // 12th case te0 < ts < ts1 && te3 < te | |
229 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; |
|
229 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}}; | |
230 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; |
|
230 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}}; | |
231 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), |
|
231 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |
232 | static_cast<double>(te.toMSecsSinceEpoch())}; |
|
232 | static_cast<double>(te.toMSecsSinceEpoch())}; | |
233 |
|
233 | |||
234 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); |
|
234 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |
235 |
|
235 | |||
236 | QCOMPARE(notInCach.size(), 2); |
|
236 | QCOMPARE(notInCach.size(), 2); | |
237 | notInCacheSqp = notInCach.first(); |
|
237 | notInCacheSqp = notInCach.first(); | |
238 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); |
|
238 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch())); | |
239 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); |
|
239 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
240 |
|
240 | |||
241 | notInCacheSqp = notInCach.at(1); |
|
241 | notInCacheSqp = notInCach.at(1); | |
242 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); |
|
242 | QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch())); | |
243 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); |
|
243 | QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch())); | |
|
244 | ||||
|
245 | ||||
|
246 | // 12th case ts0 < ts < te0 | |||
|
247 | ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 10, 0}}; | |||
|
248 | te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 50, 0}}; | |||
|
249 | sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()), | |||
|
250 | static_cast<double>(te.toMSecsSinceEpoch())}; | |||
|
251 | ||||
|
252 | notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp); | |||
|
253 | QCOMPARE(notInCach.size(), 0); | |||
244 | } |
|
254 | } | |
245 |
|
255 | |||
246 |
|
256 | |||
247 | void TestVariableCacheController::testAddDateTime() |
|
257 | void TestVariableCacheController::testAddDateTime() | |
248 | { |
|
258 | { | |
249 | VariableCacheController variableCacheController{}; |
|
259 | VariableCacheController variableCacheController{}; | |
250 |
|
260 | |||
251 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; |
|
261 | auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}}; | |
252 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
262 | auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
253 | auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()), |
|
263 | auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()), | |
254 | static_cast<double>(te0.toMSecsSinceEpoch())}; |
|
264 | static_cast<double>(te0.toMSecsSinceEpoch())}; | |
255 |
|
265 | |||
256 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; |
|
266 | auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; | |
257 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; |
|
267 | auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}}; | |
258 | auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()), |
|
268 | auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()), | |
259 | static_cast<double>(te1.toMSecsSinceEpoch())}; |
|
269 | static_cast<double>(te1.toMSecsSinceEpoch())}; | |
260 |
|
270 | |||
261 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; |
|
271 | auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}}; | |
262 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; |
|
272 | auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}}; | |
263 | auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()), |
|
273 | auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()), | |
264 | static_cast<double>(te2.toMSecsSinceEpoch())}; |
|
274 | static_cast<double>(te2.toMSecsSinceEpoch())}; | |
265 |
|
275 | |||
266 | auto ts01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
276 | auto ts01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
267 | auto te01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; |
|
277 | auto te01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}}; | |
268 | auto sqp01 = SqpDateTime{static_cast<double>(ts01.toMSecsSinceEpoch()), |
|
278 | auto sqp01 = SqpDateTime{static_cast<double>(ts01.toMSecsSinceEpoch()), | |
269 | static_cast<double>(te01.toMSecsSinceEpoch())}; |
|
279 | static_cast<double>(te01.toMSecsSinceEpoch())}; | |
270 |
|
280 | |||
271 | auto ts3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 14, 0, 0}}; |
|
281 | auto ts3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 14, 0, 0}}; | |
272 | auto te3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 16, 0, 0}}; |
|
282 | auto te3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 16, 0, 0}}; | |
273 | auto sqp3 = SqpDateTime{static_cast<double>(ts3.toMSecsSinceEpoch()), |
|
283 | auto sqp3 = SqpDateTime{static_cast<double>(ts3.toMSecsSinceEpoch()), | |
274 | static_cast<double>(te3.toMSecsSinceEpoch())}; |
|
284 | static_cast<double>(te3.toMSecsSinceEpoch())}; | |
275 |
|
285 | |||
276 | auto ts03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; |
|
286 | auto ts03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}}; | |
277 | auto te03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; |
|
287 | auto te03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}}; | |
278 | auto sqp03 = SqpDateTime{static_cast<double>(ts03.toMSecsSinceEpoch()), |
|
288 | auto sqp03 = SqpDateTime{static_cast<double>(ts03.toMSecsSinceEpoch()), | |
279 | static_cast<double>(te03.toMSecsSinceEpoch())}; |
|
289 | static_cast<double>(te03.toMSecsSinceEpoch())}; | |
280 |
|
290 | |||
281 |
|
291 | |||
282 | auto var0 = std::make_shared<Variable>("", "", "", sqp0); |
|
292 | auto var0 = std::make_shared<Variable>("", "", "", sqp0); | |
283 |
|
293 | |||
284 |
|
294 | |||
285 | // First case: add the first interval to the variable :sqp0 |
|
295 | // First case: add the first interval to the variable :sqp0 | |
286 | variableCacheController.addDateTime(var0, sqp0); |
|
296 | variableCacheController.addDateTime(var0, sqp0); | |
287 | auto dateCacheList = variableCacheController.dateCacheList(var0); |
|
297 | auto dateCacheList = variableCacheController.dateCacheList(var0); | |
288 | QCOMPARE(dateCacheList.count(), 1); |
|
298 | QCOMPARE(dateCacheList.count(), 1); | |
289 | auto dateCache = dateCacheList.at(0); |
|
299 | auto dateCache = dateCacheList.at(0); | |
290 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
300 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
291 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
301 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch())); | |
292 |
|
302 | |||
293 | // 2nd case: add a second interval : sqp1 > sqp0 |
|
303 | // 2nd case: add a second interval : sqp1 > sqp0 | |
294 | variableCacheController.addDateTime(var0, sqp1); |
|
304 | variableCacheController.addDateTime(var0, sqp1); | |
295 | dateCacheList = variableCacheController.dateCacheList(var0); |
|
305 | dateCacheList = variableCacheController.dateCacheList(var0); | |
296 | QCOMPARE(dateCacheList.count(), 2); |
|
306 | QCOMPARE(dateCacheList.count(), 2); | |
297 | dateCache = dateCacheList.at(0); |
|
307 | dateCache = dateCacheList.at(0); | |
298 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
308 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
299 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch())); |
|
309 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch())); | |
300 |
|
310 | |||
301 | dateCache = dateCacheList.at(1); |
|
311 | dateCache = dateCacheList.at(1); | |
302 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts1.toMSecsSinceEpoch())); |
|
312 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts1.toMSecsSinceEpoch())); | |
303 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); |
|
313 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); | |
304 |
|
314 | |||
305 | // 3th case: merge sqp0 & sqp1 with sqp01 |
|
315 | // 3th case: merge sqp0 & sqp1 with sqp01 | |
306 | variableCacheController.addDateTime(var0, sqp01); |
|
316 | variableCacheController.addDateTime(var0, sqp01); | |
307 | dateCacheList = variableCacheController.dateCacheList(var0); |
|
317 | dateCacheList = variableCacheController.dateCacheList(var0); | |
308 | QCOMPARE(dateCacheList.count(), 1); |
|
318 | QCOMPARE(dateCacheList.count(), 1); | |
309 | dateCache = dateCacheList.at(0); |
|
319 | dateCache = dateCacheList.at(0); | |
310 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
320 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
311 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); |
|
321 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); | |
312 |
|
322 | |||
313 |
|
323 | |||
314 | // 4th case: add a second interval : sqp1 > sqp0 |
|
324 | // 4th case: add a second interval : sqp1 > sqp0 | |
315 | variableCacheController.addDateTime(var0, sqp2); |
|
325 | variableCacheController.addDateTime(var0, sqp2); | |
316 | variableCacheController.addDateTime(var0, sqp3); |
|
326 | variableCacheController.addDateTime(var0, sqp3); | |
317 | dateCacheList = variableCacheController.dateCacheList(var0); |
|
327 | dateCacheList = variableCacheController.dateCacheList(var0); | |
318 | QCOMPARE(dateCacheList.count(), 3); |
|
328 | QCOMPARE(dateCacheList.count(), 3); | |
319 | dateCache = dateCacheList.at(0); |
|
329 | dateCache = dateCacheList.at(0); | |
320 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
330 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
321 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); |
|
331 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch())); | |
322 |
|
332 | |||
323 | dateCache = dateCacheList.at(1); |
|
333 | dateCache = dateCacheList.at(1); | |
324 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts3.toMSecsSinceEpoch())); |
|
334 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts3.toMSecsSinceEpoch())); | |
325 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te3.toMSecsSinceEpoch())); |
|
335 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te3.toMSecsSinceEpoch())); | |
326 |
|
336 | |||
327 | dateCache = dateCacheList.at(2); |
|
337 | dateCache = dateCacheList.at(2); | |
328 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts2.toMSecsSinceEpoch())); |
|
338 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts2.toMSecsSinceEpoch())); | |
329 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te2.toMSecsSinceEpoch())); |
|
339 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te2.toMSecsSinceEpoch())); | |
330 |
|
340 | |||
331 |
|
341 | |||
332 | // 5th case: merge all interval |
|
342 | // 5th case: merge all interval | |
333 | variableCacheController.addDateTime(var0, sqp03); |
|
343 | variableCacheController.addDateTime(var0, sqp03); | |
334 | dateCacheList = variableCacheController.dateCacheList(var0); |
|
344 | dateCacheList = variableCacheController.dateCacheList(var0); | |
335 | QCOMPARE(dateCacheList.count(), 1); |
|
345 | QCOMPARE(dateCacheList.count(), 1); | |
336 | dateCache = dateCacheList.at(0); |
|
346 | dateCache = dateCacheList.at(0); | |
337 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); |
|
347 | QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch())); | |
338 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te03.toMSecsSinceEpoch())); |
|
348 | QCOMPARE(dateCache.m_TEnd, static_cast<double>(te03.toMSecsSinceEpoch())); | |
339 | } |
|
349 | } | |
340 |
|
350 | |||
341 |
|
351 | |||
342 | QTEST_MAIN(TestVariableCacheController) |
|
352 | QTEST_MAIN(TestVariableCacheController) | |
343 | #include "TestVariableCacheController.moc" |
|
353 | #include "TestVariableCacheController.moc" |
@@ -1,49 +1,50 | |||||
1 | #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H |
|
1 | #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H | |
2 | #define SCIQLOP_VARIABLEINSPECTORWIDGET_H |
|
2 | #define SCIQLOP_VARIABLEINSPECTORWIDGET_H | |
3 |
|
3 | |||
4 | #include <QLoggingCategory> |
|
4 | #include <QLoggingCategory> | |
5 | #include <QMenu> |
|
5 | #include <QMenu> | |
6 | #include <QWidget> |
|
6 | #include <QWidget> | |
7 |
|
7 | |||
8 | #include <memory> |
|
8 | #include <memory> | |
9 |
|
9 | |||
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableInspectorWidget) |
|
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableInspectorWidget) | |
11 |
|
11 | |||
12 | class Variable; |
|
12 | class Variable; | |
13 |
|
13 | |||
14 | namespace Ui { |
|
14 | namespace Ui { | |
15 | class VariableInspectorWidget; |
|
15 | class VariableInspectorWidget; | |
16 | } // Ui |
|
16 | } // Ui | |
17 |
|
17 | |||
18 | /** |
|
18 | /** | |
19 | * @brief The VariableInspectorWidget class representes represents the variable inspector, from |
|
19 | * @brief The VariableInspectorWidget class representes represents the variable inspector, from | |
20 | * which it is possible to view the loaded variables, handle them or trigger their display in |
|
20 | * which it is possible to view the loaded variables, handle them or trigger their display in | |
21 | * visualization |
|
21 | * visualization | |
22 | */ |
|
22 | */ | |
23 | class VariableInspectorWidget : public QWidget { |
|
23 | class VariableInspectorWidget : public QWidget { | |
24 | Q_OBJECT |
|
24 | Q_OBJECT | |
25 |
|
25 | |||
26 | public: |
|
26 | public: | |
27 | explicit VariableInspectorWidget(QWidget *parent = 0); |
|
27 | explicit VariableInspectorWidget(QWidget *parent = 0); | |
28 | virtual ~VariableInspectorWidget(); |
|
28 | virtual ~VariableInspectorWidget(); | |
29 |
|
29 | |||
30 | signals: |
|
30 | signals: | |
31 | /** |
|
31 | /** | |
32 |
* Signal emitted before a menu concerning |
|
32 | * Signal emitted before a menu concerning variables is displayed. It is used for other widgets | |
33 | * to complete the menu. |
|
33 | * to complete the menu. | |
34 | * @param tableMenu the menu to be completed |
|
34 | * @param tableMenu the menu to be completed | |
35 | * @param variable the variable concerned by the menu |
|
35 | * @param variables the variables concerned by the menu | |
36 | * @remarks To make the dynamic addition of menus work, the connections to this signal must be |
|
36 | * @remarks To make the dynamic addition of menus work, the connections to this signal must be | |
37 | * in Qt :: DirectConnection |
|
37 | * in Qt :: DirectConnection | |
38 | */ |
|
38 | */ | |
39 |
void tableMenuAboutToBeDisplayed(QMenu *tableMenu, |
|
39 | void tableMenuAboutToBeDisplayed(QMenu *tableMenu, | |
|
40 | const QVector<std::shared_ptr<Variable> > &variables); | |||
40 |
|
41 | |||
41 | private: |
|
42 | private: | |
42 | Ui::VariableInspectorWidget *ui; |
|
43 | Ui::VariableInspectorWidget *ui; | |
43 |
|
44 | |||
44 | private slots: |
|
45 | private slots: | |
45 | /// Slot called when right clicking on an variable in the table (displays a menu) |
|
46 | /// Slot called when right clicking on an variable in the table (displays a menu) | |
46 | void onTableMenuRequested(const QPoint &pos) noexcept; |
|
47 | void onTableMenuRequested(const QPoint &pos) noexcept; | |
47 | }; |
|
48 | }; | |
48 |
|
49 | |||
49 | #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H |
|
50 | #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H |
@@ -1,59 +1,63 | |||||
1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H | |
2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H | |
3 |
|
3 | |||
4 | #include "Visualization/IVisualizationWidget.h" |
|
4 | #include "Visualization/IVisualizationWidget.h" | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <QWidget> |
|
7 | #include <QWidget> | |
8 |
|
8 | |||
9 | #include <memory> |
|
9 | #include <memory> | |
10 |
|
10 | |||
11 | #include <Common/spimpl.h> |
|
11 | #include <Common/spimpl.h> | |
12 |
|
12 | |||
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) |
|
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) | |
14 |
|
14 | |||
15 | class QCPRange; |
|
15 | class QCPRange; | |
|
16 | class SqpDateTime; | |||
16 | class Variable; |
|
17 | class Variable; | |
17 |
|
18 | |||
18 | namespace Ui { |
|
19 | namespace Ui { | |
19 | class VisualizationGraphWidget; |
|
20 | class VisualizationGraphWidget; | |
20 | } // namespace Ui |
|
21 | } // namespace Ui | |
21 |
|
22 | |||
22 | class VisualizationGraphWidget : public QWidget, public IVisualizationWidget { |
|
23 | class VisualizationGraphWidget : public QWidget, public IVisualizationWidget { | |
23 | Q_OBJECT |
|
24 | Q_OBJECT | |
24 |
|
25 | |||
25 | public: |
|
26 | public: | |
26 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
27 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); | |
27 | virtual ~VisualizationGraphWidget(); |
|
28 | virtual ~VisualizationGraphWidget(); | |
28 |
|
29 | |||
29 | void addVariable(std::shared_ptr<Variable> variable); |
|
30 | void addVariable(std::shared_ptr<Variable> variable); | |
30 | /// Removes a variable from the graph |
|
31 | /// Removes a variable from the graph | |
31 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; |
|
32 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; | |
32 |
|
33 | |||
33 | // IVisualizationWidget interface |
|
34 | // IVisualizationWidget interface | |
34 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
35 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
35 | bool canDrop(const Variable &variable) const override; |
|
36 | bool canDrop(const Variable &variable) const override; | |
36 | QString name() const override; |
|
37 | QString name() const override; | |
37 |
|
38 | |||
38 | void updateDisplay(std::shared_ptr<Variable> variable); |
|
39 | void updateDisplay(std::shared_ptr<Variable> variable); | |
39 |
|
40 | |||
|
41 | signals: | |||
|
42 | void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); | |||
|
43 | ||||
40 |
|
44 | |||
41 | private: |
|
45 | private: | |
42 | Ui::VisualizationGraphWidget *ui; |
|
46 | Ui::VisualizationGraphWidget *ui; | |
43 |
|
47 | |||
44 | class VisualizationGraphWidgetPrivate; |
|
48 | class VisualizationGraphWidgetPrivate; | |
45 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; |
|
49 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; | |
46 |
|
50 | |||
47 | private slots: |
|
51 | private slots: | |
48 | /// Slot called when right clicking on the graph (displays a menu) |
|
52 | /// Slot called when right clicking on the graph (displays a menu) | |
49 | void onGraphMenuRequested(const QPoint &pos) noexcept; |
|
53 | void onGraphMenuRequested(const QPoint &pos) noexcept; | |
50 |
|
54 | |||
51 | void onRangeChanged(const QCPRange &t1, const QCPRange &t2); |
|
55 | void onRangeChanged(const QCPRange &t1, const QCPRange &t2); | |
52 |
|
56 | |||
53 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done |
|
57 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done | |
54 | void onMouseWheel(QWheelEvent *event) noexcept; |
|
58 | void onMouseWheel(QWheelEvent *event) noexcept; | |
55 |
|
59 | |||
56 | void onDataCacheVariableUpdated(); |
|
60 | void onDataCacheVariableUpdated(); | |
57 | }; |
|
61 | }; | |
58 |
|
62 | |||
59 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
63 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
@@ -1,43 +1,44 | |||||
1 | #ifndef SCIQLOP_VISUALIZATIONWIDGET_H |
|
1 | #ifndef SCIQLOP_VISUALIZATIONWIDGET_H | |
2 | #define SCIQLOP_VISUALIZATIONWIDGET_H |
|
2 | #define SCIQLOP_VISUALIZATIONWIDGET_H | |
3 |
|
3 | |||
4 | #include "Visualization/IVisualizationWidget.h" |
|
4 | #include "Visualization/IVisualizationWidget.h" | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <QWidget> |
|
7 | #include <QWidget> | |
8 |
|
8 | |||
9 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget) |
|
9 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget) | |
10 |
|
10 | |||
11 | class QMenu; |
|
11 | class QMenu; | |
12 | class Variable; |
|
12 | class Variable; | |
13 | class VisualizationTabWidget; |
|
13 | class VisualizationTabWidget; | |
14 |
|
14 | |||
15 | namespace Ui { |
|
15 | namespace Ui { | |
16 | class VisualizationWidget; |
|
16 | class VisualizationWidget; | |
17 | } // namespace Ui |
|
17 | } // namespace Ui | |
18 |
|
18 | |||
19 | class VisualizationWidget : public QWidget, public IVisualizationWidget { |
|
19 | class VisualizationWidget : public QWidget, public IVisualizationWidget { | |
20 | Q_OBJECT |
|
20 | Q_OBJECT | |
21 |
|
21 | |||
22 | public: |
|
22 | public: | |
23 | explicit VisualizationWidget(QWidget *parent = 0); |
|
23 | explicit VisualizationWidget(QWidget *parent = 0); | |
24 | virtual ~VisualizationWidget(); |
|
24 | virtual ~VisualizationWidget(); | |
25 |
|
25 | |||
26 | // IVisualizationWidget interface |
|
26 | // IVisualizationWidget interface | |
27 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
27 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
28 | bool canDrop(const Variable &variable) const override; |
|
28 | bool canDrop(const Variable &variable) const override; | |
29 | QString name() const override; |
|
29 | QString name() const override; | |
30 |
|
30 | |||
31 | public slots: |
|
31 | public slots: | |
32 | /** |
|
32 | /** | |
33 |
* Attaches to a menu the menu relati |
|
33 | * Attaches to a menu the menu relative to the visualization of variables | |
34 | * @param menu the parent menu of the generated menu |
|
34 | * @param menu the parent menu of the generated menu | |
35 | * @param variable the variable for which to generate the menu |
|
35 | * @param variables the variables for which to generate the menu | |
36 | */ |
|
36 | */ | |
37 |
void attachVariableMenu(QMenu *menu, |
|
37 | void attachVariableMenu(QMenu *menu, | |
|
38 | const QVector<std::shared_ptr<Variable> > &variables) noexcept; | |||
38 |
|
39 | |||
39 | private: |
|
40 | private: | |
40 | Ui::VisualizationWidget *ui; |
|
41 | Ui::VisualizationWidget *ui; | |
41 | }; |
|
42 | }; | |
42 |
|
43 | |||
43 | #endif // VISUALIZATIONWIDGET_H |
|
44 | #endif // VISUALIZATIONWIDGET_H |
@@ -1,7 +1,8 | |||||
1 | <RCC> |
|
1 | <RCC> | |
2 | <qresource prefix="/"> |
|
2 | <qresource prefix="/"> | |
|
3 | <file>icones/delete.png</file> | |||
3 | <file>icones/openInspector.png</file> |
|
4 | <file>icones/openInspector.png</file> | |
4 | <file>icones/next.png</file> |
|
5 | <file>icones/next.png</file> | |
5 | <file>icones/previous.png</file> |
|
6 | <file>icones/previous.png</file> | |
6 | </qresource> |
|
7 | </qresource> | |
7 | </RCC> |
|
8 | </RCC> |
@@ -1,65 +1,88 | |||||
1 | #include <Variable/VariableController.h> |
|
1 | #include <Variable/VariableController.h> | |
2 | #include <Variable/VariableInspectorWidget.h> |
|
2 | #include <Variable/VariableInspectorWidget.h> | |
|
3 | #include <Variable/VariableMenuHeaderWidget.h> | |||
3 | #include <Variable/VariableModel.h> |
|
4 | #include <Variable/VariableModel.h> | |
4 |
|
5 | |||
5 | #include <ui_VariableInspectorWidget.h> |
|
6 | #include <ui_VariableInspectorWidget.h> | |
6 |
|
7 | |||
7 | #include <QSortFilterProxyModel> |
|
8 | #include <QSortFilterProxyModel> | |
|
9 | #include <QWidgetAction> | |||
8 |
|
10 | |||
9 | #include <SqpApplication.h> |
|
11 | #include <SqpApplication.h> | |
10 |
|
12 | |||
11 | Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") |
|
13 | Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") | |
12 |
|
14 | |||
13 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) |
|
15 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) | |
14 | : QWidget{parent}, ui{new Ui::VariableInspectorWidget} |
|
16 | : QWidget{parent}, ui{new Ui::VariableInspectorWidget} | |
15 | { |
|
17 | { | |
16 | ui->setupUi(this); |
|
18 | ui->setupUi(this); | |
17 |
|
19 | |||
18 | // Sets model for table |
|
20 | // Sets model for table | |
19 | auto sortFilterModel = new QSortFilterProxyModel{this}; |
|
21 | auto sortFilterModel = new QSortFilterProxyModel{this}; | |
20 | sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); |
|
22 | sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); | |
21 |
|
23 | |||
22 | ui->tableView->setModel(sortFilterModel); |
|
24 | ui->tableView->setModel(sortFilterModel); | |
23 |
|
25 | |||
24 | // Fixes column sizes |
|
26 | // Fixes column sizes | |
25 | auto model = ui->tableView->model(); |
|
27 | auto model = ui->tableView->model(); | |
26 | const auto count = model->columnCount(); |
|
28 | const auto count = model->columnCount(); | |
27 | for (auto i = 0; i < count; ++i) { |
|
29 | for (auto i = 0; i < count; ++i) { | |
28 | ui->tableView->setColumnWidth( |
|
30 | ui->tableView->setColumnWidth( | |
29 | i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width()); |
|
31 | i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width()); | |
30 | } |
|
32 | } | |
31 |
|
33 | |||
|
34 | // Sets selection options | |||
|
35 | ui->tableView->setSelectionBehavior(QTableView::SelectRows); | |||
|
36 | ui->tableView->setSelectionMode(QTableView::ExtendedSelection); | |||
|
37 | ||||
32 | // Connection to show a menu when right clicking on the tree |
|
38 | // Connection to show a menu when right clicking on the tree | |
33 | ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); |
|
39 | ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); | |
34 | connect(ui->tableView, &QTableView::customContextMenuRequested, this, |
|
40 | connect(ui->tableView, &QTableView::customContextMenuRequested, this, | |
35 | &VariableInspectorWidget::onTableMenuRequested); |
|
41 | &VariableInspectorWidget::onTableMenuRequested); | |
36 | } |
|
42 | } | |
37 |
|
43 | |||
38 | VariableInspectorWidget::~VariableInspectorWidget() |
|
44 | VariableInspectorWidget::~VariableInspectorWidget() | |
39 | { |
|
45 | { | |
40 | delete ui; |
|
46 | delete ui; | |
41 | } |
|
47 | } | |
42 |
|
48 | |||
43 | void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept |
|
49 | void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept | |
44 | { |
|
50 | { | |
45 |
auto selected |
|
51 | auto selectedRows = ui->tableView->selectionModel()->selectedRows(); | |
46 | if (selectedIndex.isValid()) { |
|
52 | ||
47 |
|
|
53 | // Gets the model to retrieve the underlying selected variables | |
48 |
|
|
54 | auto model = sqpApp->variableController().variableModel(); | |
49 | if (auto selectedVariable = model->variable(selectedIndex.row())) { |
|
55 | auto selectedVariables = QVector<std::shared_ptr<Variable> >{}; | |
50 | QMenu tableMenu{}; |
|
56 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
51 |
|
57 | if (auto selectedVariable = model->variable(selectedRow.row())) { | ||
52 | // Emit a signal so that potential receivers can populate the menu before displaying it |
|
58 | selectedVariables.push_back(selectedVariable); | |
53 | emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable); |
|
|||
54 |
|
||||
55 | if (!tableMenu.isEmpty()) { |
|
|||
56 | tableMenu.exec(mapToGlobal(pos)); |
|
|||
57 | } |
|
|||
58 | } |
|
59 | } | |
59 | } |
|
60 | } | |
60 | else { |
|
61 | ||
61 | qCCritical(LOG_VariableInspectorWidget()) |
|
62 | QMenu tableMenu{}; | |
62 | << tr("Can't display menu : invalid index (%1;%2)") |
|
63 | ||
63 | .arg(selectedIndex.row(), selectedIndex.column()); |
|
64 | // Emits a signal so that potential receivers can populate the menu before displaying it | |
|
65 | emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables); | |||
|
66 | ||||
|
67 | // Adds menu-specific actions | |||
|
68 | if (!selectedVariables.isEmpty()) { | |||
|
69 | // 'Delete' action | |||
|
70 | auto deleteFun = []() { | |||
|
71 | /// @todo ALX : call variable deletion | |||
|
72 | }; | |||
|
73 | ||||
|
74 | tableMenu.addSeparator(); | |||
|
75 | tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun); | |||
|
76 | } | |||
|
77 | ||||
|
78 | if (!tableMenu.isEmpty()) { | |||
|
79 | // Generates menu header (inserted before first action) | |||
|
80 | auto firstAction = tableMenu.actions().first(); | |||
|
81 | auto headerAction = new QWidgetAction{&tableMenu}; | |||
|
82 | headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu}); | |||
|
83 | tableMenu.insertAction(firstAction, headerAction); | |||
|
84 | ||||
|
85 | // Displays menu | |||
|
86 | tableMenu.exec(mapToGlobal(pos)); | |||
64 | } |
|
87 | } | |
65 | } |
|
88 | } |
@@ -1,151 +1,153 | |||||
1 | #include "Visualization/VisualizationGraphHelper.h" |
|
1 | #include "Visualization/VisualizationGraphHelper.h" | |
2 | #include "Visualization/qcustomplot.h" |
|
2 | #include "Visualization/qcustomplot.h" | |
3 |
|
3 | |||
4 | #include <Data/ScalarSeries.h> |
|
4 | #include <Data/ScalarSeries.h> | |
5 |
|
5 | |||
6 | #include <Variable/Variable.h> |
|
6 | #include <Variable/Variable.h> | |
7 |
|
7 | |||
8 | #include <QElapsedTimer> |
|
8 | #include <QElapsedTimer> | |
9 |
|
9 | |||
10 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper") |
|
10 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper") | |
11 |
|
11 | |||
12 | namespace { |
|
12 | namespace { | |
13 |
|
13 | |||
14 | /// Format for datetimes on a axis |
|
14 | /// Format for datetimes on a axis | |
15 | const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss"); |
|
15 | const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss"); | |
16 |
|
16 | |||
17 | /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or |
|
17 | /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or | |
18 | /// non-time data |
|
18 | /// non-time data | |
19 | QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis) |
|
19 | QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis) | |
20 | { |
|
20 | { | |
21 | if (isTimeAxis) { |
|
21 | if (isTimeAxis) { | |
22 | auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create(); |
|
22 | auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create(); | |
23 | dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT); |
|
23 | dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT); | |
24 |
|
24 | |||
25 | return dateTicker; |
|
25 | return dateTicker; | |
26 | } |
|
26 | } | |
27 | else { |
|
27 | else { | |
28 | // default ticker |
|
28 | // default ticker | |
29 | return QSharedPointer<QCPAxisTicker>::create(); |
|
29 | return QSharedPointer<QCPAxisTicker>::create(); | |
30 | } |
|
30 | } | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries, |
|
33 | void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries, | |
34 | const SqpDateTime &dateTime) |
|
34 | const SqpDateTime &dateTime) | |
35 | { |
|
35 | { | |
36 | QElapsedTimer timer; |
|
36 | QElapsedTimer timer; | |
37 | timer.start(); |
|
37 | timer.start(); | |
38 | if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) { |
|
38 | if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) { | |
39 | // Clean the graph |
|
39 | // Clean the graph | |
40 | qCDebug(LOG_VisualizationGraphHelper()) << "The slow s1 operation took" << timer.elapsed() |
|
|||
41 | << "milliseconds"; |
|
|||
42 | // NAIVE approch |
|
40 | // NAIVE approch | |
43 | const auto &xData = scalarSeries.xAxisData()->data(); |
|
41 | const auto &xData = scalarSeries.xAxisData()->data(); | |
44 | const auto &valuesData = scalarSeries.valuesData()->data(); |
|
42 | const auto &valuesData = scalarSeries.valuesData()->data(); | |
|
43 | const auto count = xData.count(); | |||
|
44 | qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count(); | |||
45 |
|
45 | |||
46 | auto xValue = QVector<double>(); |
|
46 | auto xValue = QVector<double>(count); | |
47 | auto vValue = QVector<double>(); |
|
47 | auto vValue = QVector<double>(count); | |
48 |
|
48 | |||
49 | const auto count = xData.count(); |
|
49 | int n = 0; | |
50 | auto ite = 0; |
|
|||
51 | for (auto i = 0; i < count; ++i) { |
|
50 | for (auto i = 0; i < count; ++i) { | |
52 |
const auto x = xData |
|
51 | const auto x = xData[i]; | |
53 | if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) { |
|
52 | if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) { | |
54 |
xValue |
|
53 | xValue[n] = x; | |
55 |
vValue |
|
54 | vValue[n] = valuesData[i]; | |
56 |
++ |
|
55 | ++n; | |
57 | } |
|
56 | } | |
58 | } |
|
57 | } | |
59 |
|
58 | |||
60 | qcpGraph->setData(xValue, vValue); |
|
59 | xValue.resize(n); | |
|
60 | vValue.resize(n); | |||
61 |
|
61 | |||
62 |
qC |
|
62 | qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed" | |
63 |
|
|
63 | << xValue.count(); | |
|
64 | ||||
|
65 | qcpGraph->setData(xValue, vValue); | |||
64 | } |
|
66 | } | |
65 | else { |
|
67 | else { | |
66 | /// @todo DEBUG |
|
68 | /// @todo DEBUG | |
67 | } |
|
69 | } | |
68 | } |
|
70 | } | |
69 |
|
71 | |||
70 | QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot, |
|
72 | QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot, | |
71 | const SqpDateTime &dateTime) |
|
73 | const SqpDateTime &dateTime) | |
72 | { |
|
74 | { | |
73 | auto component = plot.addGraph(); |
|
75 | auto component = plot.addGraph(); | |
74 |
|
76 | |||
75 | if (component) { |
|
77 | if (component) { | |
76 | // // Graph data |
|
78 | // // Graph data | |
77 | component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(), |
|
79 | component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(), | |
78 | true); |
|
80 | true); | |
79 |
|
81 | |||
80 | updateScalarData(component, scalarSeries, dateTime); |
|
82 | updateScalarData(component, scalarSeries, dateTime); | |
81 |
|
83 | |||
82 | // Axes properties |
|
84 | // Axes properties | |
83 | /// @todo : for the moment, no control is performed on the axes: the units and the tickers |
|
85 | /// @todo : for the moment, no control is performed on the axes: the units and the tickers | |
84 | /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph |
|
86 | /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph | |
85 |
|
87 | |||
86 | auto setAxisProperties = [](auto axis, const auto &unit) { |
|
88 | auto setAxisProperties = [](auto axis, const auto &unit) { | |
87 | // label (unit name) |
|
89 | // label (unit name) | |
88 | axis->setLabel(unit.m_Name); |
|
90 | axis->setLabel(unit.m_Name); | |
89 |
|
91 | |||
90 | // ticker (depending on the type of unit) |
|
92 | // ticker (depending on the type of unit) | |
91 | axis->setTicker(axisTicker(unit.m_TimeUnit)); |
|
93 | axis->setTicker(axisTicker(unit.m_TimeUnit)); | |
92 | }; |
|
94 | }; | |
93 | setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit()); |
|
95 | setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit()); | |
94 | setAxisProperties(plot.yAxis, scalarSeries.valuesUnit()); |
|
96 | setAxisProperties(plot.yAxis, scalarSeries.valuesUnit()); | |
95 |
|
97 | |||
96 | // Display all data |
|
98 | // Display all data | |
97 | component->rescaleAxes(); |
|
99 | component->rescaleAxes(); | |
98 |
|
100 | |||
99 | plot.replot(); |
|
101 | plot.replot(); | |
100 | } |
|
102 | } | |
101 | else { |
|
103 | else { | |
102 | qCDebug(LOG_VisualizationGraphHelper()) |
|
104 | qCDebug(LOG_VisualizationGraphHelper()) | |
103 | << QObject::tr("Can't create graph for the scalar series"); |
|
105 | << QObject::tr("Can't create graph for the scalar series"); | |
104 | } |
|
106 | } | |
105 |
|
107 | |||
106 | return component; |
|
108 | return component; | |
107 | } |
|
109 | } | |
108 |
|
110 | |||
109 | } // namespace |
|
111 | } // namespace | |
110 |
|
112 | |||
111 | QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable, |
|
113 | QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable, | |
112 | QCustomPlot &plot) noexcept |
|
114 | QCustomPlot &plot) noexcept | |
113 | { |
|
115 | { | |
114 | auto result = QVector<QCPAbstractPlottable *>{}; |
|
116 | auto result = QVector<QCPAbstractPlottable *>{}; | |
115 |
|
117 | |||
116 | if (variable) { |
|
118 | if (variable) { | |
117 | // Gets the data series of the variable to call the creation of the right components |
|
119 | // Gets the data series of the variable to call the creation of the right components | |
118 | // according to its type |
|
120 | // according to its type | |
119 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) { |
|
121 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) { | |
120 | result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime())); |
|
122 | result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime())); | |
121 | } |
|
123 | } | |
122 | else { |
|
124 | else { | |
123 | qCDebug(LOG_VisualizationGraphHelper()) |
|
125 | qCDebug(LOG_VisualizationGraphHelper()) | |
124 | << QObject::tr("Can't create graph plottables : unmanaged data series type"); |
|
126 | << QObject::tr("Can't create graph plottables : unmanaged data series type"); | |
125 | } |
|
127 | } | |
126 | } |
|
128 | } | |
127 | else { |
|
129 | else { | |
128 | qCDebug(LOG_VisualizationGraphHelper()) |
|
130 | qCDebug(LOG_VisualizationGraphHelper()) | |
129 | << QObject::tr("Can't create graph plottables : the variable is null"); |
|
131 | << QObject::tr("Can't create graph plottables : the variable is null"); | |
130 | } |
|
132 | } | |
131 |
|
133 | |||
132 | return result; |
|
134 | return result; | |
133 | } |
|
135 | } | |
134 |
|
136 | |||
135 | void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect, |
|
137 | void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect, | |
136 | IDataSeries *dataSeries, const SqpDateTime &dateTime) |
|
138 | IDataSeries *dataSeries, const SqpDateTime &dateTime) | |
137 | { |
|
139 | { | |
138 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) { |
|
140 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) { | |
139 | if (plotableVect.size() == 1) { |
|
141 | if (plotableVect.size() == 1) { | |
140 | updateScalarData(plotableVect.at(0), *scalarSeries, dateTime); |
|
142 | updateScalarData(plotableVect.at(0), *scalarSeries, dateTime); | |
141 | } |
|
143 | } | |
142 | else { |
|
144 | else { | |
143 | qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr( |
|
145 | qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr( | |
144 | "Can't update Data of a scalarSeries because there is not only one component " |
|
146 | "Can't update Data of a scalarSeries because there is not only one component " | |
145 | "associated"); |
|
147 | "associated"); | |
146 | } |
|
148 | } | |
147 | } |
|
149 | } | |
148 | else { |
|
150 | else { | |
149 | /// @todo DEBUG |
|
151 | /// @todo DEBUG | |
150 | } |
|
152 | } | |
151 | } |
|
153 | } |
@@ -1,237 +1,236 | |||||
1 | #include "Visualization/VisualizationGraphWidget.h" |
|
1 | #include "Visualization/VisualizationGraphWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "Visualization/VisualizationGraphHelper.h" |
|
3 | #include "Visualization/VisualizationGraphHelper.h" | |
4 | #include "ui_VisualizationGraphWidget.h" |
|
4 | #include "ui_VisualizationGraphWidget.h" | |
5 |
|
5 | |||
6 | #include <Data/ArrayData.h> |
|
6 | #include <Data/ArrayData.h> | |
7 | #include <Data/IDataSeries.h> |
|
7 | #include <Data/IDataSeries.h> | |
8 | #include <SqpApplication.h> |
|
8 | #include <SqpApplication.h> | |
9 | #include <Variable/Variable.h> |
|
9 | #include <Variable/Variable.h> | |
10 | #include <Variable/VariableController.h> |
|
10 | #include <Variable/VariableController.h> | |
11 |
|
11 | |||
12 | #include <unordered_map> |
|
12 | #include <unordered_map> | |
13 |
|
13 | |||
14 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") |
|
14 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") | |
15 |
|
15 | |||
16 | namespace { |
|
16 | namespace { | |
17 |
|
17 | |||
18 | /// Key pressed to enable zoom on horizontal axis |
|
18 | /// Key pressed to enable zoom on horizontal axis | |
19 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; |
|
19 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; | |
20 |
|
20 | |||
21 | /// Key pressed to enable zoom on vertical axis |
|
21 | /// Key pressed to enable zoom on vertical axis | |
22 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
22 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
23 |
|
23 | |||
24 | } // namespace |
|
24 | } // namespace | |
25 |
|
25 | |||
26 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
26 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
27 |
|
27 | |||
28 | // 1 variable -> n qcpplot |
|
28 | // 1 variable -> n qcpplot | |
29 | std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap; |
|
29 | std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap; | |
30 | }; |
|
30 | }; | |
31 |
|
31 | |||
32 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
32 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
33 | : QWidget{parent}, |
|
33 | : QWidget{parent}, | |
34 | ui{new Ui::VisualizationGraphWidget}, |
|
34 | ui{new Ui::VisualizationGraphWidget}, | |
35 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} |
|
35 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} | |
36 | { |
|
36 | { | |
37 | ui->setupUi(this); |
|
37 | ui->setupUi(this); | |
38 |
|
38 | |||
39 | ui->graphNameLabel->setText(name); |
|
39 | ui->graphNameLabel->setText(name); | |
40 |
|
40 | |||
41 | // 'Close' options : widget is deleted when closed |
|
41 | // 'Close' options : widget is deleted when closed | |
42 | setAttribute(Qt::WA_DeleteOnClose); |
|
42 | setAttribute(Qt::WA_DeleteOnClose); | |
43 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close); |
|
43 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close); | |
44 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
44 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); | |
45 |
|
45 | |||
46 | // Set qcpplot properties : |
|
46 | // Set qcpplot properties : | |
47 | // - Drag (on x-axis) and zoom are enabled |
|
47 | // - Drag (on x-axis) and zoom are enabled | |
48 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
48 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
49 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
49 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); | |
50 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
50 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); | |
51 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
51 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
52 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( |
|
52 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
53 | &QCPAxis::rangeChanged), |
|
53 | &QCPAxis::rangeChanged), | |
54 | this, &VisualizationGraphWidget::onRangeChanged); |
|
54 | this, &VisualizationGraphWidget::onRangeChanged); | |
55 |
|
55 | |||
56 | // Activates menu when right clicking on the graph |
|
56 | // Activates menu when right clicking on the graph | |
57 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
57 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); | |
58 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, |
|
58 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, | |
59 | &VisualizationGraphWidget::onGraphMenuRequested); |
|
59 | &VisualizationGraphWidget::onGraphMenuRequested); | |
|
60 | ||||
|
61 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), | |||
|
62 | &VariableController::onRequestDataLoading); | |||
60 | } |
|
63 | } | |
61 |
|
64 | |||
62 |
|
65 | |||
63 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
66 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
64 | { |
|
67 | { | |
65 | delete ui; |
|
68 | delete ui; | |
66 | } |
|
69 | } | |
67 |
|
70 | |||
68 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) |
|
71 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) | |
69 | { |
|
72 | { | |
70 | // Uses delegate to create the qcpplot components according to the variable |
|
73 | // Uses delegate to create the qcpplot components according to the variable | |
71 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
74 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
72 |
|
75 | |||
73 | for (auto createdPlottable : qAsConst(createdPlottables)) { |
|
76 | for (auto createdPlottable : qAsConst(createdPlottables)) { | |
74 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); |
|
77 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); | |
75 | } |
|
78 | } | |
76 |
|
79 | |||
77 |
connect(variable.get(), SIGNAL( |
|
80 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
78 | } |
|
81 | } | |
79 |
|
82 | |||
80 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
83 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept | |
81 | { |
|
84 | { | |
82 | // Each component associated to the variable : |
|
85 | // Each component associated to the variable : | |
83 | // - is removed from qcpplot (which deletes it) |
|
86 | // - is removed from qcpplot (which deletes it) | |
84 | // - is no longer referenced in the map |
|
87 | // - is no longer referenced in the map | |
85 | auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); |
|
88 | auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); | |
86 | for (auto it = componentsIt.first; it != componentsIt.second;) { |
|
89 | for (auto it = componentsIt.first; it != componentsIt.second;) { | |
87 | ui->widget->removePlottable(it->second); |
|
90 | ui->widget->removePlottable(it->second); | |
88 | it = impl->m_VariableToPlotMultiMap.erase(it); |
|
91 | it = impl->m_VariableToPlotMultiMap.erase(it); | |
89 | } |
|
92 | } | |
90 |
|
93 | |||
91 | // Updates graph |
|
94 | // Updates graph | |
92 | ui->widget->replot(); |
|
95 | ui->widget->replot(); | |
93 | } |
|
96 | } | |
94 |
|
97 | |||
95 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
98 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
96 | { |
|
99 | { | |
97 | if (visitor) { |
|
100 | if (visitor) { | |
98 | visitor->visit(this); |
|
101 | visitor->visit(this); | |
99 | } |
|
102 | } | |
100 | else { |
|
103 | else { | |
101 | qCCritical(LOG_VisualizationGraphWidget()) |
|
104 | qCCritical(LOG_VisualizationGraphWidget()) | |
102 | << tr("Can't visit widget : the visitor is null"); |
|
105 | << tr("Can't visit widget : the visitor is null"); | |
103 | } |
|
106 | } | |
104 | } |
|
107 | } | |
105 |
|
108 | |||
106 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
109 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |
107 | { |
|
110 | { | |
108 | /// @todo : for the moment, a graph can always accomodate a variable |
|
111 | /// @todo : for the moment, a graph can always accomodate a variable | |
109 | Q_UNUSED(variable); |
|
112 | Q_UNUSED(variable); | |
110 | return true; |
|
113 | return true; | |
111 | } |
|
114 | } | |
112 |
|
115 | |||
113 | QString VisualizationGraphWidget::name() const |
|
116 | QString VisualizationGraphWidget::name() const | |
114 | { |
|
117 | { | |
115 | return ui->graphNameLabel->text(); |
|
118 | return ui->graphNameLabel->text(); | |
116 | } |
|
119 | } | |
117 |
|
120 | |||
118 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
121 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |
119 | { |
|
122 | { | |
120 | QMenu graphMenu{}; |
|
123 | QMenu graphMenu{}; | |
121 |
|
124 | |||
122 | // Iterates on variables (unique keys) |
|
125 | // Iterates on variables (unique keys) | |
123 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
126 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), | |
124 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
127 | end = impl->m_VariableToPlotMultiMap.cend(); | |
125 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
128 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
126 | // 'Remove variable' action |
|
129 | // 'Remove variable' action | |
127 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
130 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), | |
128 | [ this, var = it->first ]() { removeVariable(var); }); |
|
131 | [ this, var = it->first ]() { removeVariable(var); }); | |
129 | } |
|
132 | } | |
130 |
|
133 | |||
131 | if (!graphMenu.isEmpty()) { |
|
134 | if (!graphMenu.isEmpty()) { | |
132 | graphMenu.exec(mapToGlobal(pos)); |
|
135 | graphMenu.exec(mapToGlobal(pos)); | |
133 | } |
|
136 | } | |
134 | } |
|
137 | } | |
135 |
|
138 | |||
136 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
139 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
137 | { |
|
140 | { | |
138 |
|
141 | |||
139 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged"); |
|
142 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged"); | |
140 |
|
143 | |||
141 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
144 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); | |
142 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
145 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { | |
143 |
|
146 | |||
144 | auto variable = it->first; |
|
147 | auto variable = it->first; | |
145 | qCInfo(LOG_VisualizationGraphWidget()) |
|
|||
146 | << tr("TORM: VisualizationGraphWidget::onRangeChanged") |
|
|||
147 | << variable->dataSeries()->xAxisData()->size(); |
|
|||
148 | auto dateTime = SqpDateTime{t2.lower, t2.upper}; |
|
148 | auto dateTime = SqpDateTime{t2.lower, t2.upper}; | |
149 |
|
149 | |||
150 | if (!variable->contains(dateTime)) { |
|
150 | if (!variable->contains(dateTime)) { | |
151 |
|
151 | |||
152 | auto variableDateTimeWithTolerance = dateTime; |
|
152 | auto variableDateTimeWithTolerance = dateTime; | |
153 | if (variable->intersect(dateTime)) { |
|
153 | if (variable->intersect(dateTime)) { | |
154 | auto variableDateTime = variable->dateTime(); |
|
154 | auto variableDateTime = variable->dateTime(); | |
155 | if (variableDateTime.m_TStart < dateTime.m_TStart) { |
|
155 | if (variableDateTime.m_TStart < dateTime.m_TStart) { | |
156 |
|
156 | |||
157 | auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd; |
|
157 | auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd; | |
158 | dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta; |
|
158 | dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta; | |
159 | // Tolerance have to be added to the right |
|
159 | // Tolerance have to be added to the right | |
160 | // add 10% tolerance for right (end) side |
|
160 | // add 10% tolerance for right (end) side | |
161 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); |
|
161 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); | |
162 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
162 | variableDateTimeWithTolerance.m_TEnd += tolerance; | |
163 | } |
|
163 | } | |
164 | if (variableDateTime.m_TEnd > dateTime.m_TEnd) { |
|
164 | if (variableDateTime.m_TEnd > dateTime.m_TEnd) { | |
165 | auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart; |
|
165 | auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart; | |
166 | dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta; |
|
166 | dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta; | |
167 | // Tolerance have to be added to the left |
|
167 | // Tolerance have to be added to the left | |
168 | // add 10% tolerance for left (start) side |
|
168 | // add 10% tolerance for left (start) side | |
169 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); |
|
169 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); | |
170 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
170 | variableDateTimeWithTolerance.m_TStart -= tolerance; | |
171 | } |
|
171 | } | |
172 | } |
|
172 | } | |
173 | else { |
|
173 | else { | |
174 | // add 10% tolerance for each side |
|
174 | // add 10% tolerance for each side | |
175 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); |
|
175 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); | |
176 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
176 | variableDateTimeWithTolerance.m_TStart -= tolerance; | |
177 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
177 | variableDateTimeWithTolerance.m_TEnd += tolerance; | |
178 | } |
|
178 | } | |
179 | variable->setDateTime(dateTime); |
|
179 | variable->setDateTime(dateTime); | |
180 |
|
180 | |||
181 | // CHangement detected, we need to ask controller to request data loading |
|
181 | // CHangement detected, we need to ask controller to request data loading | |
182 | sqpApp->variableController().requestDataLoading(variable, |
|
182 | emit requestDataLoading(variable, variableDateTimeWithTolerance); | |
183 | variableDateTimeWithTolerance); |
|
|||
184 | } |
|
183 | } | |
185 | } |
|
184 | } | |
186 | } |
|
185 | } | |
187 |
|
186 | |||
188 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
187 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
189 | { |
|
188 | { | |
190 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
189 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
191 |
|
190 | |||
192 | // Lambda that enables a zoom orientation if the key modifier related to this orientation |
|
191 | // Lambda that enables a zoom orientation if the key modifier related to this orientation | |
193 | // has |
|
192 | // has | |
194 | // been pressed |
|
193 | // been pressed | |
195 | auto enableOrientation |
|
194 | auto enableOrientation | |
196 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
195 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { | |
197 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
196 | auto orientationEnabled = event->modifiers().testFlag(modifier); | |
198 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
197 | zoomOrientations.setFlag(orientation, orientationEnabled); | |
199 | }; |
|
198 | }; | |
200 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
199 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); | |
201 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
200 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); | |
202 |
|
201 | |||
203 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
202 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
204 | } |
|
203 | } | |
205 |
|
204 | |||
206 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
205 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
207 | { |
|
206 | { | |
208 | // NOTE: |
|
207 | // NOTE: | |
209 | // We don't want to call the method for each component of a variable unitarily, but for |
|
208 | // We don't want to call the method for each component of a variable unitarily, but for | |
210 | // all |
|
209 | // all | |
211 | // its components at once (eg its three components in the case of a vector). |
|
210 | // its components at once (eg its three components in the case of a vector). | |
212 |
|
211 | |||
213 | // The unordered_multimap does not do this easily, so the question is whether to: |
|
212 | // The unordered_multimap does not do this easily, so the question is whether to: | |
214 | // - use an ordered_multimap and the algos of std to group the values by key |
|
213 | // - use an ordered_multimap and the algos of std to group the values by key | |
215 | // - use a map (unique keys) and store as values directly the list of components |
|
214 | // - use a map (unique keys) and store as values directly the list of components | |
216 |
|
215 | |||
217 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
216 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); | |
218 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
217 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { | |
219 | auto variable = it->first; |
|
218 | auto variable = it->first; | |
220 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, |
|
219 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, | |
221 | variable->dataSeries(), variable->dateTime()); |
|
220 | variable->dataSeries(), variable->dateTime()); | |
222 | } |
|
221 | } | |
223 | } |
|
222 | } | |
224 |
|
223 | |||
225 | void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable) |
|
224 | void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable) | |
226 | { |
|
225 | { | |
227 | auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable); |
|
226 | auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable); | |
228 |
|
227 | |||
229 | auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{}; |
|
228 | auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{}; | |
230 |
|
229 | |||
231 | for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) { |
|
230 | for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) { | |
232 | abstractPlotableVect.push_back(it->second); |
|
231 | abstractPlotableVect.push_back(it->second); | |
233 | } |
|
232 | } | |
234 |
|
233 | |||
235 | VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(), |
|
234 | VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(), | |
236 | variable->dateTime()); |
|
235 | variable->dateTime()); | |
237 | } |
|
236 | } |
@@ -1,115 +1,129 | |||||
1 | #include "Visualization/VisualizationWidget.h" |
|
1 | #include "Visualization/VisualizationWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "Visualization/VisualizationGraphWidget.h" |
|
3 | #include "Visualization/VisualizationGraphWidget.h" | |
4 | #include "Visualization/VisualizationTabWidget.h" |
|
4 | #include "Visualization/VisualizationTabWidget.h" | |
5 | #include "Visualization/VisualizationZoneWidget.h" |
|
5 | #include "Visualization/VisualizationZoneWidget.h" | |
6 | #include "Visualization/operations/GenerateVariableMenuOperation.h" |
|
6 | #include "Visualization/operations/GenerateVariableMenuOperation.h" | |
7 | #include "Visualization/qcustomplot.h" |
|
7 | #include "Visualization/qcustomplot.h" | |
8 |
|
8 | |||
9 | #include "ui_VisualizationWidget.h" |
|
9 | #include "ui_VisualizationWidget.h" | |
10 |
|
10 | |||
11 | #include <QToolButton> |
|
11 | #include <QToolButton> | |
12 |
|
12 | |||
13 | Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") |
|
13 | Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") | |
14 |
|
14 | |||
15 | VisualizationWidget::VisualizationWidget(QWidget *parent) |
|
15 | VisualizationWidget::VisualizationWidget(QWidget *parent) | |
16 | : QWidget{parent}, ui{new Ui::VisualizationWidget} |
|
16 | : QWidget{parent}, ui{new Ui::VisualizationWidget} | |
17 | { |
|
17 | { | |
18 | ui->setupUi(this); |
|
18 | ui->setupUi(this); | |
19 |
|
19 | |||
20 | auto addTabViewButton = new QToolButton{ui->tabWidget}; |
|
20 | auto addTabViewButton = new QToolButton{ui->tabWidget}; | |
21 | addTabViewButton->setText(tr("Add View")); |
|
21 | addTabViewButton->setText(tr("Add View")); | |
22 | addTabViewButton->setCursor(Qt::ArrowCursor); |
|
22 | addTabViewButton->setCursor(Qt::ArrowCursor); | |
23 | ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); |
|
23 | ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); | |
24 |
|
24 | |||
25 | auto enableMinimumCornerWidgetSize = [this](bool enable) { |
|
25 | auto enableMinimumCornerWidgetSize = [this](bool enable) { | |
26 |
|
26 | |||
27 | auto tabViewCornerWidget = ui->tabWidget->cornerWidget(); |
|
27 | auto tabViewCornerWidget = ui->tabWidget->cornerWidget(); | |
28 | auto width = enable ? tabViewCornerWidget->width() : 0; |
|
28 | auto width = enable ? tabViewCornerWidget->width() : 0; | |
29 | auto height = enable ? tabViewCornerWidget->height() : 0; |
|
29 | auto height = enable ? tabViewCornerWidget->height() : 0; | |
30 | tabViewCornerWidget->setMinimumHeight(height); |
|
30 | tabViewCornerWidget->setMinimumHeight(height); | |
31 | tabViewCornerWidget->setMinimumWidth(width); |
|
31 | tabViewCornerWidget->setMinimumWidth(width); | |
32 | ui->tabWidget->setMinimumHeight(height); |
|
32 | ui->tabWidget->setMinimumHeight(height); | |
33 | ui->tabWidget->setMinimumWidth(width); |
|
33 | ui->tabWidget->setMinimumWidth(width); | |
34 | }; |
|
34 | }; | |
35 |
|
35 | |||
36 | auto addTabView = [this, enableMinimumCornerWidgetSize]() { |
|
36 | auto addTabView = [this, enableMinimumCornerWidgetSize]() { | |
37 | auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1), |
|
37 | auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1), | |
38 | ui->tabWidget}; |
|
38 | ui->tabWidget}; | |
39 | auto index = ui->tabWidget->addTab(widget, widget->name()); |
|
39 | auto index = ui->tabWidget->addTab(widget, widget->name()); | |
40 | if (ui->tabWidget->count() > 0) { |
|
40 | if (ui->tabWidget->count() > 0) { | |
41 | enableMinimumCornerWidgetSize(false); |
|
41 | enableMinimumCornerWidgetSize(false); | |
42 | } |
|
42 | } | |
43 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); |
|
43 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); | |
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
46 | auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) { |
|
46 | auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) { | |
47 | if (ui->tabWidget->count() == 1) { |
|
47 | if (ui->tabWidget->count() == 1) { | |
48 | enableMinimumCornerWidgetSize(true); |
|
48 | enableMinimumCornerWidgetSize(true); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | // Removes widget from tab and closes it |
|
51 | // Removes widget from tab and closes it | |
52 | auto widget = ui->tabWidget->widget(index); |
|
52 | auto widget = ui->tabWidget->widget(index); | |
53 | ui->tabWidget->removeTab(index); |
|
53 | ui->tabWidget->removeTab(index); | |
54 | if (widget) { |
|
54 | if (widget) { | |
55 | widget->close(); |
|
55 | widget->close(); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); |
|
58 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); | |
59 |
|
59 | |||
60 | }; |
|
60 | }; | |
61 |
|
61 | |||
62 | ui->tabWidget->setTabsClosable(true); |
|
62 | ui->tabWidget->setTabsClosable(true); | |
63 |
|
63 | |||
64 | connect(addTabViewButton, &QToolButton::clicked, addTabView); |
|
64 | connect(addTabViewButton, &QToolButton::clicked, addTabView); | |
65 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); |
|
65 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); | |
66 |
|
66 | |||
67 | // Adds default tab |
|
67 | // Adds default tab | |
68 | addTabView(); |
|
68 | addTabView(); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | VisualizationWidget::~VisualizationWidget() |
|
71 | VisualizationWidget::~VisualizationWidget() | |
72 | { |
|
72 | { | |
73 | delete ui; |
|
73 | delete ui; | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
76 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) | |
77 | { |
|
77 | { | |
78 | if (visitor) { |
|
78 | if (visitor) { | |
79 | visitor->visitEnter(this); |
|
79 | visitor->visitEnter(this); | |
80 |
|
80 | |||
81 | // Apply visitor for tab children |
|
81 | // Apply visitor for tab children | |
82 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { |
|
82 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { | |
83 | // Widgets different from tabs are not visited (no action) |
|
83 | // Widgets different from tabs are not visited (no action) | |
84 | if (auto visualizationTabWidget |
|
84 | if (auto visualizationTabWidget | |
85 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { |
|
85 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { | |
86 | visualizationTabWidget->accept(visitor); |
|
86 | visualizationTabWidget->accept(visitor); | |
87 | } |
|
87 | } | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | visitor->visitLeave(this); |
|
90 | visitor->visitLeave(this); | |
91 | } |
|
91 | } | |
92 | else { |
|
92 | else { | |
93 | qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null"); |
|
93 | qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null"); | |
94 | } |
|
94 | } | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | bool VisualizationWidget::canDrop(const Variable &variable) const |
|
97 | bool VisualizationWidget::canDrop(const Variable &variable) const | |
98 | { |
|
98 | { | |
99 | // The main widget can never accomodate a variable |
|
99 | // The main widget can never accomodate a variable | |
100 | Q_UNUSED(variable); |
|
100 | Q_UNUSED(variable); | |
101 | return false; |
|
101 | return false; | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | QString VisualizationWidget::name() const |
|
104 | QString VisualizationWidget::name() const | |
105 | { |
|
105 | { | |
106 | return QStringLiteral("MainView"); |
|
106 | return QStringLiteral("MainView"); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 |
void VisualizationWidget::attachVariableMenu( |
|
109 | void VisualizationWidget::attachVariableMenu( | |
110 |
|
|
110 | QMenu *menu, const QVector<std::shared_ptr<Variable> > &variables) noexcept | |
111 | { |
|
111 | { | |
112 | // Generates the actions that make it possible to visualize the variable |
|
112 | // Menu is generated only if there is a single variable | |
113 | auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable}; |
|
113 | if (variables.size() == 1) { | |
114 | accept(&generateVariableMenuOperation); |
|
114 | if (auto variable = variables.first()) { | |
|
115 | // Generates the actions that make it possible to visualize the variable | |||
|
116 | auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable}; | |||
|
117 | accept(&generateVariableMenuOperation); | |||
|
118 | } | |||
|
119 | else { | |||
|
120 | qCCritical(LOG_VisualizationWidget()) << tr( | |||
|
121 | "Can't generate the menu relative to the visualization: the variable is null"); | |||
|
122 | } | |||
|
123 | } | |||
|
124 | else { | |||
|
125 | qCDebug(LOG_VisualizationWidget()) | |||
|
126 | << tr("No generation of the menu related to the visualization: several variables are " | |||
|
127 | "selected"); | |||
|
128 | } | |||
115 | } |
|
129 | } |
@@ -1,71 +1,74 | |||||
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> | |||
|
9 | ||||
8 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") |
|
10 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") | |
9 |
|
11 | |||
10 | std::unique_ptr<IDataSeries> |
|
12 | std::unique_ptr<IDataSeries> | |
11 | CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const |
|
13 | CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const | |
12 | { |
|
14 | { | |
13 | auto dateTime = parameters.m_Time; |
|
15 | auto dateTime = parameters.m_Time; | |
14 |
|
16 | |||
15 | // Gets the timerange from the parameters |
|
17 | // Gets the timerange from the parameters | |
16 | auto start = dateTime.m_TStart; |
|
18 | auto start = dateTime.m_TStart; | |
17 | auto end = dateTime.m_TEnd; |
|
19 | auto end = dateTime.m_TEnd; | |
18 |
|
20 | |||
|
21 | ||||
19 | // We assure that timerange is valid |
|
22 | // We assure that timerange is valid | |
20 | if (end < start) { |
|
23 | if (end < start) { | |
21 | std::swap(start, end); |
|
24 | std::swap(start, end); | |
22 | } |
|
25 | } | |
23 |
|
26 | |||
24 | // Generates scalar series containing cosinus values (one value per second) |
|
27 | // Generates scalar series containing cosinus values (one value per second) | |
25 | auto scalarSeries |
|
28 | auto scalarSeries | |
26 | = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); |
|
29 | = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); | |
27 |
|
30 | |||
28 | auto dataIndex = 0; |
|
31 | auto dataIndex = 0; | |
29 | for (auto time = start; time < end; ++time, ++dataIndex) { |
|
32 | for (auto time = start; time < end; ++time, ++dataIndex) { | |
30 | scalarSeries->setData(dataIndex, time, std::cos(time)); |
|
33 | scalarSeries->setData(dataIndex, time, std::cos(time)); | |
31 | } |
|
34 | } | |
32 |
|
35 | |||
33 | return scalarSeries; |
|
36 | return scalarSeries; | |
34 | } |
|
37 | } | |
35 |
|
38 | |||
36 | void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList) |
|
39 | void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList) | |
37 | { |
|
40 | { | |
38 | // NOTE: Try to use multithread if possible |
|
41 | // NOTE: Try to use multithread if possible | |
39 | for (const auto &dateTime : dateTimeList) { |
|
42 | for (const auto &dateTime : dateTimeList) { | |
40 |
|
43 | |||
41 | auto scalarSeries = this->retrieveDataSeries(dateTime); |
|
44 | auto scalarSeries = this->retrieveDataSeries(dateTime); | |
42 |
|
45 | |||
43 | emit dataProvided(scalarSeries, dateTime); |
|
46 | emit dataProvided(scalarSeries, dateTime); | |
44 | } |
|
47 | } | |
45 | } |
|
48 | } | |
46 |
|
49 | |||
47 |
|
50 | |||
48 | std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTime &dateTime) |
|
51 | std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTime &dateTime) | |
49 | { |
|
52 | { | |
|
53 | auto dataIndex = 0; | |||
50 |
|
54 | |||
51 | // Gets the timerange from the parameters |
|
55 | // Gets the timerange from the parameters | |
52 | auto start = dateTime.m_TStart; |
|
56 | double freq = 100.0; | |
53 | auto end = dateTime.m_TEnd; |
|
57 | double start = dateTime.m_TStart * freq; // 100 htz | |
|
58 | double end = dateTime.m_TEnd * freq; // 100 htz | |||
54 |
|
59 | |||
55 | // We assure that timerange is valid |
|
60 | // We assure that timerange is valid | |
56 | if (end < start) { |
|
61 | if (end < start) { | |
57 | std::swap(start, end); |
|
62 | std::swap(start, end); | |
58 | } |
|
63 | } | |
59 |
|
64 | |||
60 | // Generates scalar series containing cosinus values (one value per second) |
|
65 | // Generates scalar series containing cosinus values (one value per second) | |
61 | auto scalarSeries |
|
66 | auto scalarSeries | |
62 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); |
|
67 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); | |
63 |
|
68 | |||
64 | auto dataIndex = 0; |
|
|||
65 | for (auto time = start; time < end; ++time, ++dataIndex) { |
|
69 | for (auto time = start; time < end; ++time, ++dataIndex) { | |
66 | scalarSeries->setData(dataIndex, time, std::cos(time)); |
|
70 | const auto timeOnFreq = time / freq; | |
|
71 | scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq)); | |||
67 | } |
|
72 | } | |
68 |
|
||||
69 |
|
||||
70 | return scalarSeries; |
|
73 | return scalarSeries; | |
71 | } |
|
74 | } |
General Comments 0
You need to be logged in to leave comments.
Login now