##// END OF EJS Templates
Implementation of the calibration for the synchronization...
perrinel -
r445:a75bae0e8d4d
parent child
Show More
@@ -1,78 +1,82
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 SqpDateTime;
17 class Variable;
17 class Variable;
18
18
19 /**
19 /**
20 * Possible types of zoom operation
20 * Possible types of zoom operation
21 */
21 */
22 enum class VisualizationGraphWidgetZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown };
22 enum class VisualizationGraphWidgetZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown };
23
23
24 namespace Ui {
24 namespace Ui {
25 class VisualizationGraphWidget;
25 class VisualizationGraphWidget;
26 } // namespace Ui
26 } // namespace Ui
27
27
28 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
28 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
29 Q_OBJECT
29 Q_OBJECT
30
30
31 public:
31 public:
32 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
32 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
33 virtual ~VisualizationGraphWidget();
33 virtual ~VisualizationGraphWidget();
34
34
35 void enableSynchronize(bool enable);
35 void enableSynchronize(bool enable);
36
36
37 void addVariable(std::shared_ptr<Variable> variable);
37 void addVariable(std::shared_ptr<Variable> variable);
38 void addVariableUsingGraph(std::shared_ptr<Variable> variable);
38 void addVariableUsingGraph(std::shared_ptr<Variable> variable);
39 /// Removes a variable from the graph
39 /// Removes a variable from the graph
40 void removeVariable(std::shared_ptr<Variable> variable) noexcept;
40 void removeVariable(std::shared_ptr<Variable> variable) noexcept;
41
41
42 void setRange(std::shared_ptr<Variable> variable, const SqpDateTime &range);
42 void setRange(std::shared_ptr<Variable> variable, const SqpDateTime &range);
43 SqpDateTime graphRange();
43 SqpDateTime graphRange();
44 void setGraphRange(const SqpDateTime &range);
44 void setGraphRange(const SqpDateTime &range);
45
45
46 // IVisualizationWidget interface
46 // IVisualizationWidget interface
47 void accept(IVisualizationWidgetVisitor *visitor) override;
47 void accept(IVisualizationWidgetVisitor *visitor) override;
48 bool canDrop(const Variable &variable) const override;
48 bool canDrop(const Variable &variable) const override;
49 bool contains(const Variable &variable) const override;
49 bool contains(const Variable &variable) const override;
50 QString name() const override;
50 QString name() const override;
51
51
52
52
53 signals:
53 signals:
54 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
54 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
55 void synchronize(const SqpDateTime &dateTime, const SqpDateTime &oldDateTime,
55 void synchronize(const SqpDateTime &dateTime, const SqpDateTime &oldDateTime,
56 VisualizationGraphWidgetZoomType zoomType);
56 VisualizationGraphWidgetZoomType zoomType);
57
57
58
58
59 private:
59 private:
60 Ui::VisualizationGraphWidget *ui;
60 Ui::VisualizationGraphWidget *ui;
61
61
62 class VisualizationGraphWidgetPrivate;
62 class VisualizationGraphWidgetPrivate;
63 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
63 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
64
64
65 private slots:
65 private slots:
66 /// Slot called when right clicking on the graph (displays a menu)
66 /// Slot called when right clicking on the graph (displays a menu)
67 void onGraphMenuRequested(const QPoint &pos) noexcept;
67 void onGraphMenuRequested(const QPoint &pos) noexcept;
68
68
69 /// Rescale the X axe to range parameter
69 /// Rescale the X axe to range parameter
70 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
70 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
71
71
72 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
72 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
73 void onMouseWheel(QWheelEvent *event) noexcept;
73 void onMouseWheel(QWheelEvent *event) noexcept;
74 /// Slot called when a mouse press was made, to activate the calibration of a graph
75 void onMousePress(QMouseEvent *event) noexcept;
76 /// Slot called when a mouse release was made, to deactivate the calibration of a graph
77 void onMouseRelease(QMouseEvent *event) noexcept;
74
78
75 void onDataCacheVariableUpdated();
79 void onDataCacheVariableUpdated();
76 };
80 };
77
81
78 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
82 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
@@ -1,362 +1,399
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 explicit VisualizationGraphWidgetPrivate() : m_DoSynchronize(true) {}
28 explicit VisualizationGraphWidgetPrivate() : m_DoSynchronize(true), m_IsCalibration(false) {}
29
30
31 // Return the operation when range changed
32 VisualizationGraphWidgetZoomType getZoomType(const QCPRange &t1, const QCPRange &t2);
29
33
30 // 1 variable -> n qcpplot
34 // 1 variable -> n qcpplot
31 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
35 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
32
36
33 bool m_DoSynchronize;
37 bool m_DoSynchronize;
38 bool m_IsCalibration;
34 };
39 };
35
40
36 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
41 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
37 : QWidget{parent},
42 : QWidget{parent},
38 ui{new Ui::VisualizationGraphWidget},
43 ui{new Ui::VisualizationGraphWidget},
39 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
44 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
40 {
45 {
41 ui->setupUi(this);
46 ui->setupUi(this);
42
47
43 ui->graphNameLabel->setText(name);
48 ui->graphNameLabel->setText(name);
44
49
45 // 'Close' options : widget is deleted when closed
50 // 'Close' options : widget is deleted when closed
46 setAttribute(Qt::WA_DeleteOnClose);
51 setAttribute(Qt::WA_DeleteOnClose);
47 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close);
52 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close);
48 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
53 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
49
54
50 // Set qcpplot properties :
55 // Set qcpplot properties :
51 // - Drag (on x-axis) and zoom are enabled
56 // - Drag (on x-axis) and zoom are enabled
52 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
57 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
53 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
58 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
54 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
59 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
60 connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress);
61 connect(ui->widget, &QCustomPlot::mouseRelease, this,
62 &VisualizationGraphWidget::onMouseRelease);
55 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
63 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
56 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
64 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
57 &QCPAxis::rangeChanged),
65 &QCPAxis::rangeChanged),
58 this, &VisualizationGraphWidget::onRangeChanged);
66 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
59
67
60 // Activates menu when right clicking on the graph
68 // Activates menu when right clicking on the graph
61 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
69 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
62 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
70 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
63 &VisualizationGraphWidget::onGraphMenuRequested);
71 &VisualizationGraphWidget::onGraphMenuRequested);
64
72
65 connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
73 connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
66 &VariableController::onRequestDataLoading);
74 &VariableController::onRequestDataLoading);
67 }
75 }
68
76
69
77
70 VisualizationGraphWidget::~VisualizationGraphWidget()
78 VisualizationGraphWidget::~VisualizationGraphWidget()
71 {
79 {
72 delete ui;
80 delete ui;
73 }
81 }
74
82
75 void VisualizationGraphWidget::enableSynchronize(bool enable)
83 void VisualizationGraphWidget::enableSynchronize(bool enable)
76 {
84 {
77 impl->m_DoSynchronize = enable;
85 impl->m_DoSynchronize = enable;
78 }
86 }
79
87
80 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
88 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
81 {
89 {
82 // Uses delegate to create the qcpplot components according to the variable
90 // Uses delegate to create the qcpplot components according to the variable
83 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
91 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
84
92
85 for (auto createdPlottable : qAsConst(createdPlottables)) {
93 for (auto createdPlottable : qAsConst(createdPlottables)) {
86 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
94 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
87 }
95 }
88
96
89 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
97 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
90 }
98 }
91 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
99 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
92 {
100 {
93
101
94 // when adding a variable, we need to set its time range to the current graph range
102 // when adding a variable, we need to set its time range to the current graph range
95 auto grapheRange = ui->widget->xAxis->range();
103 auto grapheRange = ui->widget->xAxis->range();
96 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
104 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
97 variable->setDateTime(dateTime);
105 variable->setDateTime(dateTime);
98
106
99 auto variableDateTimeWithTolerance = dateTime;
107 auto variableDateTimeWithTolerance = dateTime;
100
108
101 // add 10% tolerance for each side
109 // add 10% tolerance for each side
102 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
110 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
103 variableDateTimeWithTolerance.m_TStart -= tolerance;
111 variableDateTimeWithTolerance.m_TStart -= tolerance;
104 variableDateTimeWithTolerance.m_TEnd += tolerance;
112 variableDateTimeWithTolerance.m_TEnd += tolerance;
105
113
106 // Uses delegate to create the qcpplot components according to the variable
114 // Uses delegate to create the qcpplot components according to the variable
107 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
115 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
108
116
109 for (auto createdPlottable : qAsConst(createdPlottables)) {
117 for (auto createdPlottable : qAsConst(createdPlottables)) {
110 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
118 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
111 }
119 }
112
120
113 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
121 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
114
122
115 // CHangement detected, we need to ask controller to request data loading
123 // CHangement detected, we need to ask controller to request data loading
116 emit requestDataLoading(variable, variableDateTimeWithTolerance);
124 emit requestDataLoading(variable, variableDateTimeWithTolerance);
117 }
125 }
118
126
119 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
127 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
120 {
128 {
121 // Each component associated to the variable :
129 // Each component associated to the variable :
122 // - is removed from qcpplot (which deletes it)
130 // - is removed from qcpplot (which deletes it)
123 // - is no longer referenced in the map
131 // - is no longer referenced in the map
124 auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
132 auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
125 for (auto it = componentsIt.first; it != componentsIt.second;) {
133 for (auto it = componentsIt.first; it != componentsIt.second;) {
126 ui->widget->removePlottable(it->second);
134 ui->widget->removePlottable(it->second);
127 it = impl->m_VariableToPlotMultiMap.erase(it);
135 it = impl->m_VariableToPlotMultiMap.erase(it);
128 }
136 }
129
137
130 // Updates graph
138 // Updates graph
131 ui->widget->replot();
139 ui->widget->replot();
132 }
140 }
133
141
134 void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable,
142 void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable,
135 const SqpDateTime &range)
143 const SqpDateTime &range)
136 {
144 {
137 // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
145 // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
138 // for (auto it = componentsIt.first; it != componentsIt.second;) {
146 // for (auto it = componentsIt.first; it != componentsIt.second;) {
139 // }
147 // }
140 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
148 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
141 ui->widget->replot();
149 ui->widget->replot();
142 }
150 }
143
151
144 SqpDateTime VisualizationGraphWidget::graphRange()
152 SqpDateTime VisualizationGraphWidget::graphRange()
145 {
153 {
146 auto grapheRange = ui->widget->xAxis->range();
154 auto grapheRange = ui->widget->xAxis->range();
147 return SqpDateTime{grapheRange.lower, grapheRange.upper};
155 return SqpDateTime{grapheRange.lower, grapheRange.upper};
148 }
156 }
149
157
150 void VisualizationGraphWidget::setGraphRange(const SqpDateTime &range)
158 void VisualizationGraphWidget::setGraphRange(const SqpDateTime &range)
151 {
159 {
152 qCDebug(LOG_VisualizationGraphWidget())
160 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START");
153 << tr("VisualizationGraphWidget::setGraphRange START");
154 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
161 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
155 ui->widget->replot();
162 ui->widget->replot();
156 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END");
163 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END");
157 }
164 }
158
165
159 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
166 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
160 {
167 {
161 if (visitor) {
168 if (visitor) {
162 visitor->visit(this);
169 visitor->visit(this);
163 }
170 }
164 else {
171 else {
165 qCCritical(LOG_VisualizationGraphWidget())
172 qCCritical(LOG_VisualizationGraphWidget())
166 << tr("Can't visit widget : the visitor is null");
173 << tr("Can't visit widget : the visitor is null");
167 }
174 }
168 }
175 }
169
176
170 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
177 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
171 {
178 {
172 /// @todo : for the moment, a graph can always accomodate a variable
179 /// @todo : for the moment, a graph can always accomodate a variable
173 Q_UNUSED(variable);
180 Q_UNUSED(variable);
174 return true;
181 return true;
175 }
182 }
176
183
177 bool VisualizationGraphWidget::contains(const Variable &variable) const
184 bool VisualizationGraphWidget::contains(const Variable &variable) const
178 {
185 {
179 // Finds the variable among the keys of the map
186 // Finds the variable among the keys of the map
180 auto variablePtr = &variable;
187 auto variablePtr = &variable;
181 auto findVariable
188 auto findVariable
182 = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); };
189 = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); };
183
190
184 auto end = impl->m_VariableToPlotMultiMap.cend();
191 auto end = impl->m_VariableToPlotMultiMap.cend();
185 auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable);
192 auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable);
186 return it != end;
193 return it != end;
187 }
194 }
188
195
189 QString VisualizationGraphWidget::name() const
196 QString VisualizationGraphWidget::name() const
190 {
197 {
191 return ui->graphNameLabel->text();
198 return ui->graphNameLabel->text();
192 }
199 }
193
200
194 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
201 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
195 {
202 {
196 QMenu graphMenu{};
203 QMenu graphMenu{};
197
204
198 // Iterates on variables (unique keys)
205 // Iterates on variables (unique keys)
199 for (auto it = impl->m_VariableToPlotMultiMap.cbegin(),
206 for (auto it = impl->m_VariableToPlotMultiMap.cbegin(),
200 end = impl->m_VariableToPlotMultiMap.cend();
207 end = impl->m_VariableToPlotMultiMap.cend();
201 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
208 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
202 // 'Remove variable' action
209 // 'Remove variable' action
203 graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()),
210 graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()),
204 [ this, var = it->first ]() { removeVariable(var); });
211 [ this, var = it->first ]() { removeVariable(var); });
205 }
212 }
206
213
207 if (!graphMenu.isEmpty()) {
214 if (!graphMenu.isEmpty()) {
208 graphMenu.exec(mapToGlobal(pos));
215 graphMenu.exec(mapToGlobal(pos));
209 }
216 }
210 }
217 }
211
218
212 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
219 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
213 {
220 {
214 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
221 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
215 << QThread::currentThread()->objectName();
222 << QThread::currentThread()->objectName();
216
223
217 auto dateTimeRange = SqpDateTime{t1.lower, t1.upper};
224 auto dateTimeRange = SqpDateTime{t1.lower, t1.upper};
218
225
219 auto zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
226 auto zoomType = impl->getZoomType(t1, t2);
220 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
227 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
221 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
228 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
222
229
223 auto variable = it->first;
230 auto variable = it->first;
224 auto currentDateTime = dateTimeRange;
231 auto currentDateTime = dateTimeRange;
225
232
226 auto toleranceFactor = 0.2;
233 auto toleranceFactor = 0.2;
227 auto tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
234 auto tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
228 auto variableDateTimeWithTolerance = currentDateTime;
235 auto variableDateTimeWithTolerance = currentDateTime;
229 variableDateTimeWithTolerance.m_TStart -= tolerance;
236 variableDateTimeWithTolerance.m_TStart -= tolerance;
230 variableDateTimeWithTolerance.m_TEnd += tolerance;
237 variableDateTimeWithTolerance.m_TEnd += tolerance;
231
238
232 qCDebug(LOG_VisualizationGraphWidget()) << "r" << currentDateTime;
239 qCDebug(LOG_VisualizationGraphWidget()) << "r" << currentDateTime;
233 qCDebug(LOG_VisualizationGraphWidget()) << "t" << variableDateTimeWithTolerance;
240 qCDebug(LOG_VisualizationGraphWidget()) << "t" << variableDateTimeWithTolerance;
234 qCDebug(LOG_VisualizationGraphWidget()) << "v" << variable->dateTime();
241 qCDebug(LOG_VisualizationGraphWidget()) << "v" << variable->dateTime();
235 // If new range with tol is upper than variable datetime parameters. we need to request new
242 // If new range with tol is upper than variable datetime parameters. we need to request new
236 // data
243 // data
237 if (!variable->contains(variableDateTimeWithTolerance)) {
244 if (!variable->contains(variableDateTimeWithTolerance)) {
238
245
239 auto variableDateTimeWithTolerance = currentDateTime;
246 auto variableDateTimeWithTolerance = currentDateTime;
240 if (!variable->isInside(currentDateTime)) {
247 if (!variable->isInside(currentDateTime)) {
241 auto variableDateTime = variable->dateTime();
248 auto variableDateTime = variable->dateTime();
242 if (variable->contains(variableDateTimeWithTolerance)) {
249 if (variable->contains(variableDateTimeWithTolerance)) {
243 qCInfo(LOG_VisualizationGraphWidget())
250 qCDebug(LOG_VisualizationGraphWidget())
244 << tr("TORM: Detection zoom in that need request:");
251 << tr("TORM: Detection zoom in that need request:");
245 // add 10% tolerance for each side
252 // add 10% tolerance for each side
246 tolerance
253 tolerance
247 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
254 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
248 variableDateTimeWithTolerance.m_TStart -= tolerance;
255 variableDateTimeWithTolerance.m_TStart -= tolerance;
249 variableDateTimeWithTolerance.m_TEnd += tolerance;
256 variableDateTimeWithTolerance.m_TEnd += tolerance;
250 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
251 }
257 }
252 else if (variableDateTime.m_TStart < currentDateTime.m_TStart) {
258 else if (variableDateTime.m_TStart < currentDateTime.m_TStart) {
253 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:");
259 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:");
254
260
255 auto diffEndToKeepDelta = currentDateTime.m_TEnd - variableDateTime.m_TEnd;
261 auto diffEndToKeepDelta = currentDateTime.m_TEnd - variableDateTime.m_TEnd;
256 currentDateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
262 currentDateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
257 // Tolerance have to be added to the right
263 // Tolerance have to be added to the right
258 // add tolerance for right (end) side
264 // add tolerance for right (end) side
259 tolerance
265 tolerance
260 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
266 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
261 variableDateTimeWithTolerance.m_TEnd += tolerance;
267 variableDateTimeWithTolerance.m_TEnd += tolerance;
262 zoomType = VisualizationGraphWidgetZoomType::PanRight;
263 }
268 }
264 else if (variableDateTime.m_TEnd > currentDateTime.m_TEnd) {
269 else if (variableDateTime.m_TEnd > currentDateTime.m_TEnd) {
265 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: ");
270 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: ");
266 auto diffStartToKeepDelta
271 auto diffStartToKeepDelta
267 = variableDateTime.m_TStart - currentDateTime.m_TStart;
272 = variableDateTime.m_TStart - currentDateTime.m_TStart;
268 currentDateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
273 currentDateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
269 // Tolerance have to be added to the left
274 // Tolerance have to be added to the left
270 // add tolerance for left (start) side
275 // add tolerance for left (start) side
271 tolerance
276 tolerance
272 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
277 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
273 variableDateTimeWithTolerance.m_TStart -= tolerance;
278 variableDateTimeWithTolerance.m_TStart -= tolerance;
274 zoomType = VisualizationGraphWidgetZoomType::PanLeft;
275 }
279 }
276 else {
280 else {
277 qCInfo(LOG_VisualizationGraphWidget())
281 qCCritical(LOG_VisualizationGraphWidget())
278 << tr("Detection anormal zoom detection: ");
282 << tr("Detection anormal zoom detection: ");
279 zoomType = VisualizationGraphWidgetZoomType::Unknown;
280 }
283 }
281 }
284 }
282 else {
285 else {
283 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: ");
286 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: ");
284 // add 10% tolerance for each side
287 // add 10% tolerance for each side
285 tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
288 tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
286 variableDateTimeWithTolerance.m_TStart -= tolerance;
289 variableDateTimeWithTolerance.m_TStart -= tolerance;
287 variableDateTimeWithTolerance.m_TEnd += tolerance;
290 variableDateTimeWithTolerance.m_TEnd += tolerance;
288 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
291 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
289 }
292 }
290 if (!variable->contains(dateTimeRange)) {
293 if (!variable->contains(dateTimeRange)) {
291 qCInfo(LOG_VisualizationGraphWidget())
294 qCDebug(LOG_VisualizationGraphWidget())
292 << "TORM: Modif on variable datetime detected" << currentDateTime;
295 << "TORM: Modif on variable datetime detected" << currentDateTime;
293 variable->setDateTime(currentDateTime);
296 variable->setDateTime(currentDateTime);
294 }
297 }
295
298
296 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Request data detection: ");
299 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Request data detection: ");
297 // CHangement detected, we need to ask controller to request data loading
300 // CHangement detected, we need to ask controller to request data loading
298 emit requestDataLoading(variable, variableDateTimeWithTolerance);
301 emit requestDataLoading(variable, variableDateTimeWithTolerance);
299 }
302 }
300 else {
303 else {
301 qCInfo(LOG_VisualizationGraphWidget())
304 qCInfo(LOG_VisualizationGraphWidget())
302 << tr("TORM: Detection zoom in that doesn't need request: ");
305 << tr("TORM: Detection zoom in that doesn't need request: ");
303 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
306 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
304 }
307 }
305 }
308 }
306
309
307 if (impl->m_DoSynchronize) {
310 if (impl->m_DoSynchronize && !impl->m_IsCalibration) {
308 auto oldDateTime = SqpDateTime{t2.lower, t2.upper};
311 auto oldDateTime = SqpDateTime{t2.lower, t2.upper};
309 qCDebug(LOG_VisualizationGraphWidget())
312 qCDebug(LOG_VisualizationGraphWidget())
310 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
313 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
311 << QThread::currentThread()->objectName();
314 << QThread::currentThread()->objectName();
312 emit synchronize(dateTimeRange, oldDateTime, zoomType);
315 emit synchronize(dateTimeRange, oldDateTime, zoomType);
313 }
316 }
314 }
317 }
315
318
316 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
319 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
317 {
320 {
318 auto zoomOrientations = QFlags<Qt::Orientation>{};
321 auto zoomOrientations = QFlags<Qt::Orientation>{};
319
322
320 // Lambda that enables a zoom orientation if the key modifier related to this orientation
323 // Lambda that enables a zoom orientation if the key modifier related to this orientation
321 // has
324 // has
322 // been pressed
325 // been pressed
323 auto enableOrientation
326 auto enableOrientation
324 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
327 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
325 auto orientationEnabled = event->modifiers().testFlag(modifier);
328 auto orientationEnabled = event->modifiers().testFlag(modifier);
326 zoomOrientations.setFlag(orientation, orientationEnabled);
329 zoomOrientations.setFlag(orientation, orientationEnabled);
327 };
330 };
328 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
331 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
329 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
332 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
330
333
331 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
334 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
332 }
335 }
333
336
337 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
338 {
339 impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier);
340 }
341
342 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
343 {
344 impl->m_IsCalibration = false;
345 }
346
334 void VisualizationGraphWidget::onDataCacheVariableUpdated()
347 void VisualizationGraphWidget::onDataCacheVariableUpdated()
335 {
348 {
336 // NOTE:
349 // NOTE:
337 // We don't want to call the method for each component of a variable unitarily, but for
350 // We don't want to call the method for each component of a variable unitarily, but for
338 // all
351 // all
339 // its components at once (eg its three components in the case of a vector).
352 // its components at once (eg its three components in the case of a vector).
340
353
341 // The unordered_multimap does not do this easily, so the question is whether to:
354 // The unordered_multimap does not do this easily, so the question is whether to:
342 // - use an ordered_multimap and the algos of std to group the values by key
355 // - use an ordered_multimap and the algos of std to group the values by key
343 // - use a map (unique keys) and store as values directly the list of components
356 // - use a map (unique keys) and store as values directly the list of components
344
357
345 auto grapheRange = ui->widget->xAxis->range();
358 auto grapheRange = ui->widget->xAxis->range();
346 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
359 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
347
360
348 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
361 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
349 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
362 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
350 auto variable = it->first;
363 auto variable = it->first;
351 qCDebug(LOG_VisualizationGraphWidget())
364 qCDebug(LOG_VisualizationGraphWidget())
352 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S"
365 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S"
353 << variable->dateTime();
366 << variable->dateTime();
354 qCDebug(LOG_VisualizationGraphWidget())
367 qCDebug(LOG_VisualizationGraphWidget())
355 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime;
368 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime;
356 if (dateTime.contains(variable->dateTime()) || dateTime.intersect(variable->dateTime())) {
369 if (dateTime.contains(variable->dateTime()) || dateTime.intersect(variable->dateTime())) {
357
370
358 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
371 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
359 variable->dataSeries(), variable->dateTime());
372 variable->dataSeries(), variable->dateTime());
360 }
373 }
361 }
374 }
362 }
375 }
376
377 VisualizationGraphWidgetZoomType
378 VisualizationGraphWidget::VisualizationGraphWidgetPrivate::getZoomType(const QCPRange &t1,
379 const QCPRange &t2)
380 {
381 // t1.lower <= t2.lower && t2.upper <= t1.upper
382 auto zoomType = VisualizationGraphWidgetZoomType::Unknown;
383 if (t1.lower <= t2.lower && t2.upper <= t1.upper) {
384 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
385 }
386 else if (t1.lower > t2.lower && t1.upper > t2.upper) {
387 zoomType = VisualizationGraphWidgetZoomType::PanRight;
388 }
389 else if (t1.lower < t2.lower && t1.upper < t2.upper) {
390 zoomType = VisualizationGraphWidgetZoomType::PanLeft;
391 }
392 else if (t1.lower > t2.lower && t2.upper > t1.upper) {
393 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
394 }
395 else {
396 qCCritical(LOG_VisualizationGraphWidget()) << "getZoomType: Unknown type detected";
397 }
398 return zoomType;
399 }
@@ -1,180 +1,200
1 #include "Visualization/VisualizationZoneWidget.h"
1 #include "Visualization/VisualizationZoneWidget.h"
2
2
3 #include "Data/SqpDateTime.h"
3 #include "Data/SqpDateTime.h"
4
4
5 #include "Visualization/IVisualizationWidgetVisitor.h"
5 #include "Visualization/IVisualizationWidgetVisitor.h"
6 #include "Visualization/VisualizationGraphWidget.h"
6 #include "Visualization/VisualizationGraphWidget.h"
7 #include "ui_VisualizationZoneWidget.h"
7 #include "ui_VisualizationZoneWidget.h"
8
8
9
9
10 #include <SqpApplication.h>
10 #include <SqpApplication.h>
11
11
12 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
12 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
13
13
14 namespace {
14 namespace {
15
15
16 /// Minimum height for graph added in zones (in pixels)
16 /// Minimum height for graph added in zones (in pixels)
17 const auto GRAPH_MINIMUM_HEIGHT = 300;
17 const auto GRAPH_MINIMUM_HEIGHT = 300;
18
18
19 /// Generates a default name for a new graph, according to the number of graphs already displayed in
19 /// Generates a default name for a new graph, according to the number of graphs already displayed in
20 /// the zone
20 /// the zone
21 QString defaultGraphName(const QLayout &layout)
21 QString defaultGraphName(const QLayout &layout)
22 {
22 {
23 auto count = 0;
23 auto count = 0;
24 for (auto i = 0; i < layout.count(); ++i) {
24 for (auto i = 0; i < layout.count(); ++i) {
25 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
25 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
26 count++;
26 count++;
27 }
27 }
28 }
28 }
29
29
30 return QObject::tr("Graph %1").arg(count + 1);
30 return QObject::tr("Graph %1").arg(count + 1);
31 }
31 }
32
32
33 } // namespace
33 } // namespace
34
34
35 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
35 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
36 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
36 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
37 {
37 {
38 ui->setupUi(this);
38 ui->setupUi(this);
39
39
40 ui->zoneNameLabel->setText(name);
40 ui->zoneNameLabel->setText(name);
41
41
42 // 'Close' options : widget is deleted when closed
42 // 'Close' options : widget is deleted when closed
43 setAttribute(Qt::WA_DeleteOnClose);
43 setAttribute(Qt::WA_DeleteOnClose);
44 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
44 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
45 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
45 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
46 }
46 }
47
47
48 VisualizationZoneWidget::~VisualizationZoneWidget()
48 VisualizationZoneWidget::~VisualizationZoneWidget()
49 {
49 {
50 delete ui;
50 delete ui;
51 }
51 }
52
52
53 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
53 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
54 {
54 {
55 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
55 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
56 }
56 }
57
57
58 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
58 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
59 {
59 {
60 auto graphWidget = new VisualizationGraphWidget{
60 auto graphWidget = new VisualizationGraphWidget{
61 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
61 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
62
62
63
63
64 // Set graph properties
64 // Set graph properties
65 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
65 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
66 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
66 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
67
67
68 this->addGraph(graphWidget);
68 this->addGraph(graphWidget);
69
69
70 graphWidget->addVariable(variable);
70 graphWidget->addVariable(variable);
71
71
72 // Lambda to synchronize zone widget
72 // Lambda to synchronize zone widget
73 auto synchronizeZoneWidget = [this, graphWidget](const SqpDateTime &dateTime,
73 auto synchronizeZoneWidget = [this, graphWidget](const SqpDateTime &dateTime,
74 const SqpDateTime &oldDateTime,
74 const SqpDateTime &oldDateTime,
75 VisualizationGraphWidgetZoomType zoomType) {
75 VisualizationGraphWidgetZoomType zoomType) {
76 auto frameLayout = ui->visualizationZoneFrame->layout();
76 auto frameLayout = ui->visualizationZoneFrame->layout();
77 for (auto i = 0; i < frameLayout->count(); ++i) {
77 for (auto i = 0; i < frameLayout->count(); ++i) {
78 auto graphChild
78 auto graphChild
79 = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget());
79 = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget());
80 if (graphChild && (graphChild != graphWidget)) {
80 if (graphChild && (graphChild != graphWidget)) {
81
81
82 auto dateTimeThatKeepDelta = dateTime;
83 auto graphChildRange = graphChild->graphRange();
82 auto graphChildRange = graphChild->graphRange();
84 switch (zoomType) {
83 switch (zoomType) {
85 case VisualizationGraphWidgetZoomType::ZoomIn: {
84 case VisualizationGraphWidgetZoomType::ZoomIn: {
86 auto deltaLeft = dateTime.m_TStart - oldDateTime.m_TStart;
85 auto deltaLeft = dateTime.m_TStart - oldDateTime.m_TStart;
87 auto deltaRight = oldDateTime.m_TEnd - dateTime.m_TEnd;
86 auto deltaRight = oldDateTime.m_TEnd - dateTime.m_TEnd;
88 graphChildRange.m_TStart += deltaLeft;
87 graphChildRange.m_TStart += deltaLeft;
89 graphChildRange.m_TEnd -= deltaRight;
88 graphChildRange.m_TEnd -= deltaRight;
90 dateTimeThatKeepDelta = graphChildRange;
89 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn");
90 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
91 << deltaLeft;
92 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
93 << deltaRight;
94 qCCritical(LOG_VisualizationZoneWidget())
95 << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart;
96
91 break;
97 break;
92 }
98 }
93
99
94 case VisualizationGraphWidgetZoomType::ZoomOut: {
100 case VisualizationGraphWidgetZoomType::ZoomOut: {
101 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut");
95 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
102 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
96 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
103 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
104 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
105 << deltaLeft;
106 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
107 << deltaRight;
108 qCCritical(LOG_VisualizationZoneWidget())
109 << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart;
97 graphChildRange.m_TStart -= deltaLeft;
110 graphChildRange.m_TStart -= deltaLeft;
98 graphChildRange.m_TEnd += deltaRight;
111 graphChildRange.m_TEnd += deltaRight;
99 dateTimeThatKeepDelta = graphChildRange;
100 break;
112 break;
101 }
113 }
102 case VisualizationGraphWidgetZoomType::PanRight: {
114 case VisualizationGraphWidgetZoomType::PanRight: {
115 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight");
103 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
116 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
104 graphChildRange.m_TStart += deltaRight;
117 graphChildRange.m_TStart += deltaRight;
105 graphChildRange.m_TEnd += deltaRight;
118 graphChildRange.m_TEnd += deltaRight;
106 dateTimeThatKeepDelta = graphChildRange;
119 qCCritical(LOG_VisualizationZoneWidget())
120 << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart;
107 break;
121 break;
108 }
122 }
109 case VisualizationGraphWidgetZoomType::PanLeft: {
123 case VisualizationGraphWidgetZoomType::PanLeft: {
124 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft");
110 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
125 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
111 graphChildRange.m_TStart -= deltaLeft;
126 graphChildRange.m_TStart -= deltaLeft;
112 graphChildRange.m_TEnd -= deltaLeft;
127 graphChildRange.m_TEnd -= deltaLeft;
113 dateTimeThatKeepDelta = graphChildRange;
114 break;
128 break;
115 }
129 }
116 case VisualizationGraphWidgetZoomType::Unknown: {
130 case VisualizationGraphWidgetZoomType::Unknown: {
117 qCCritical(LOG_VisualizationZoneWidget())
131 qCCritical(LOG_VisualizationZoneWidget())
118 << tr("Impossible to synchronize: zoom type unknown");
132 << tr("Impossible to synchronize: zoom type unknown");
119 break;
133 break;
120 }
134 }
121 default:
135 default:
122 qCCritical(LOG_VisualizationZoneWidget())
136 qCCritical(LOG_VisualizationZoneWidget())
123 << tr("Impossible to synchronize: zoom type not take into account");
137 << tr("Impossible to synchronize: zoom type not take into account");
124 // No action
138 // No action
125 break;
139 break;
126 }
140 }
127 graphChild->enableSynchronize(false);
141 graphChild->enableSynchronize(false);
128 graphChild->setGraphRange(dateTimeThatKeepDelta);
142 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ")
143 << graphChild->graphRange();
144 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ")
145 << graphChildRange;
146 qCCritical(LOG_VisualizationZoneWidget())
147 << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart;
148 graphChild->setGraphRange(graphChildRange);
129 graphChild->enableSynchronize(true);
149 graphChild->enableSynchronize(true);
130 }
150 }
131 }
151 }
132 };
152 };
133
153
134 // connection for synchronization
154 // connection for synchronization
135 connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget);
155 connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget);
136
156
137 return graphWidget;
157 return graphWidget;
138 }
158 }
139
159
140 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
160 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
141 {
161 {
142 if (visitor) {
162 if (visitor) {
143 visitor->visitEnter(this);
163 visitor->visitEnter(this);
144
164
145 // Apply visitor to graph children
165 // Apply visitor to graph children
146 auto layout = ui->visualizationZoneFrame->layout();
166 auto layout = ui->visualizationZoneFrame->layout();
147 for (auto i = 0; i < layout->count(); ++i) {
167 for (auto i = 0; i < layout->count(); ++i) {
148 if (auto item = layout->itemAt(i)) {
168 if (auto item = layout->itemAt(i)) {
149 // Widgets different from graphs are not visited (no action)
169 // Widgets different from graphs are not visited (no action)
150 if (auto visualizationGraphWidget
170 if (auto visualizationGraphWidget
151 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
171 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
152 visualizationGraphWidget->accept(visitor);
172 visualizationGraphWidget->accept(visitor);
153 }
173 }
154 }
174 }
155 }
175 }
156
176
157 visitor->visitLeave(this);
177 visitor->visitLeave(this);
158 }
178 }
159 else {
179 else {
160 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
180 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
161 }
181 }
162 }
182 }
163
183
164 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
184 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
165 {
185 {
166 // A tab can always accomodate a variable
186 // A tab can always accomodate a variable
167 Q_UNUSED(variable);
187 Q_UNUSED(variable);
168 return true;
188 return true;
169 }
189 }
170
190
171 bool VisualizationZoneWidget::contains(const Variable &variable) const
191 bool VisualizationZoneWidget::contains(const Variable &variable) const
172 {
192 {
173 Q_UNUSED(variable);
193 Q_UNUSED(variable);
174 return false;
194 return false;
175 }
195 }
176
196
177 QString VisualizationZoneWidget::name() const
197 QString VisualizationZoneWidget::name() const
178 {
198 {
179 return ui->zoneNameLabel->text();
199 return ui->zoneNameLabel->text();
180 }
200 }
General Comments 0
You need to be logged in to leave comments. Login now