@@ -16,6 +16,11 class QCPRange; | |||
|
16 | 16 | class SqpDateTime; |
|
17 | 17 | class Variable; |
|
18 | 18 | |
|
19 | /** | |
|
20 | * Possible types of zoom operation | |
|
21 | */ | |
|
22 | enum class VisualizationGraphWidgetZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown }; | |
|
23 | ||
|
19 | 24 | namespace Ui { |
|
20 | 25 | class VisualizationGraphWidget; |
|
21 | 26 | } // namespace Ui |
@@ -27,13 +32,16 public: | |||
|
27 | 32 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
28 | 33 | virtual ~VisualizationGraphWidget(); |
|
29 | 34 | |
|
35 | void enableSynchronize(bool enable); | |
|
36 | ||
|
30 | 37 | void addVariable(std::shared_ptr<Variable> variable); |
|
31 | 38 | void addVariableUsingGraph(std::shared_ptr<Variable> variable); |
|
32 | 39 | /// Removes a variable from the graph |
|
33 | 40 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; |
|
34 | 41 | |
|
35 | /// Rescale the X axe to range parameter | |
|
36 | 42 | void setRange(std::shared_ptr<Variable> variable, const SqpDateTime &range); |
|
43 | SqpDateTime graphRange(); | |
|
44 | void setGraphRange(const SqpDateTime &range); | |
|
37 | 45 | |
|
38 | 46 | // IVisualizationWidget interface |
|
39 | 47 | void accept(IVisualizationWidgetVisitor *visitor) override; |
@@ -41,8 +49,11 public: | |||
|
41 | 49 | bool contains(const Variable &variable) const override; |
|
42 | 50 | QString name() const override; |
|
43 | 51 | |
|
52 | ||
|
44 | 53 | signals: |
|
45 | 54 | void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); |
|
55 | void synchronize(const SqpDateTime &dateTime, const SqpDateTime &oldDateTime, | |
|
56 | VisualizationGraphWidgetZoomType zoomType); | |
|
46 | 57 | |
|
47 | 58 | |
|
48 | 59 | private: |
@@ -55,7 +66,8 private slots: | |||
|
55 | 66 | /// Slot called when right clicking on the graph (displays a menu) |
|
56 | 67 | void onGraphMenuRequested(const QPoint &pos) noexcept; |
|
57 | 68 | |
|
58 | void onRangeChanged(const QCPRange &t1); | |
|
69 | /// Rescale the X axe to range parameter | |
|
70 | void onRangeChanged(const QCPRange &t1, const QCPRange &t2); | |
|
59 | 71 | |
|
60 | 72 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done |
|
61 | 73 | void onMouseWheel(QWheelEvent *event) noexcept; |
@@ -25,8 +25,12 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; | |||
|
25 | 25 | |
|
26 | 26 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
27 | 27 | |
|
28 | explicit VisualizationGraphWidgetPrivate() : m_DoSynchronize(true) {} | |
|
29 | ||
|
28 | 30 | // 1 variable -> n qcpplot |
|
29 | 31 | std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap; |
|
32 | ||
|
33 | bool m_DoSynchronize; | |
|
30 | 34 | }; |
|
31 | 35 | |
|
32 | 36 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
@@ -49,9 +53,9 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget | |||
|
49 | 53 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
50 | 54 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
51 | 55 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
52 | connect(ui->widget->xAxis, | |
|
53 | static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this, | |
|
54 | &VisualizationGraphWidget::onRangeChanged); | |
|
56 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
|
57 | &QCPAxis::rangeChanged), | |
|
58 | this, &VisualizationGraphWidget::onRangeChanged); | |
|
55 | 59 | |
|
56 | 60 | // Activates menu when right clicking on the graph |
|
57 | 61 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
@@ -68,6 +72,11 VisualizationGraphWidget::~VisualizationGraphWidget() | |||
|
68 | 72 | delete ui; |
|
69 | 73 | } |
|
70 | 74 | |
|
75 | void VisualizationGraphWidget::enableSynchronize(bool enable) | |
|
76 | { | |
|
77 | impl->m_DoSynchronize = enable; | |
|
78 | } | |
|
79 | ||
|
71 | 80 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) |
|
72 | 81 | { |
|
73 | 82 | // Uses delegate to create the qcpplot components according to the variable |
@@ -129,6 +138,22 void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable, | |||
|
129 | 138 | // for (auto it = componentsIt.first; it != componentsIt.second;) { |
|
130 | 139 | // } |
|
131 | 140 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
141 | ui->widget->replot(); | |
|
142 | } | |
|
143 | ||
|
144 | SqpDateTime VisualizationGraphWidget::graphRange() | |
|
145 | { | |
|
146 | auto grapheRange = ui->widget->xAxis->range(); | |
|
147 | return SqpDateTime{grapheRange.lower, grapheRange.upper}; | |
|
148 | } | |
|
149 | ||
|
150 | void VisualizationGraphWidget::setGraphRange(const SqpDateTime &range) | |
|
151 | { | |
|
152 | qCDebug(LOG_VisualizationGraphWidget()) | |
|
153 | << tr("VisualizationGraphWidget::setGraphRange START"); | |
|
154 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
|
155 | ui->widget->replot(); | |
|
156 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); | |
|
132 | 157 | } |
|
133 | 158 | |
|
134 | 159 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
@@ -184,78 +209,108 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |||
|
184 | 209 | } |
|
185 | 210 | } |
|
186 | 211 | |
|
187 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1) | |
|
212 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
|
188 | 213 | { |
|
189 |
qC |
|
|
190 |
|
|
|
214 | qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged") | |
|
215 | << QThread::currentThread()->objectName(); | |
|
216 | ||
|
217 | auto dateTimeRange = SqpDateTime{t1.lower, t1.upper}; | |
|
191 | 218 | |
|
219 | auto zoomType = VisualizationGraphWidgetZoomType::ZoomOut; | |
|
192 | 220 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
193 | 221 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
194 | 222 | |
|
195 | 223 | auto variable = it->first; |
|
196 |
auto |
|
|
197 | auto dateTimeRange = dateTime; | |
|
224 | auto currentDateTime = dateTimeRange; | |
|
198 | 225 | |
|
199 | 226 | auto toleranceFactor = 0.2; |
|
200 |
auto tolerance = toleranceFactor * ( |
|
|
201 |
auto variableDateTimeWithTolerance = |
|
|
227 | auto tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); | |
|
228 | auto variableDateTimeWithTolerance = currentDateTime; | |
|
202 | 229 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
203 | 230 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
204 | 231 | |
|
205 |
qCDebug(LOG_VisualizationGraphWidget()) << " |
|
|
206 |
qCDebug(LOG_VisualizationGraphWidget()) << " |
|
|
232 | qCDebug(LOG_VisualizationGraphWidget()) << "r" << currentDateTime; | |
|
233 | qCDebug(LOG_VisualizationGraphWidget()) << "t" << variableDateTimeWithTolerance; | |
|
234 | qCDebug(LOG_VisualizationGraphWidget()) << "v" << variable->dateTime(); | |
|
207 | 235 | // If new range with tol is upper than variable datetime parameters. we need to request new |
|
208 | 236 | // data |
|
209 | 237 | if (!variable->contains(variableDateTimeWithTolerance)) { |
|
210 | 238 | |
|
211 |
auto variableDateTimeWithTolerance = |
|
|
212 |
if (!variable->isInside( |
|
|
239 | auto variableDateTimeWithTolerance = currentDateTime; | |
|
240 | if (!variable->isInside(currentDateTime)) { | |
|
213 | 241 | auto variableDateTime = variable->dateTime(); |
|
214 |
if (variable |
|
|
215 |
qC |
|
|
242 | if (variable->contains(variableDateTimeWithTolerance)) { | |
|
243 | qCInfo(LOG_VisualizationGraphWidget()) | |
|
244 | << tr("TORM: Detection zoom in that need request:"); | |
|
245 | // add 10% tolerance for each side | |
|
246 | tolerance | |
|
247 | = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); | |
|
248 | variableDateTimeWithTolerance.m_TStart -= tolerance; | |
|
249 | variableDateTimeWithTolerance.m_TEnd += tolerance; | |
|
250 | zoomType = VisualizationGraphWidgetZoomType::ZoomIn; | |
|
251 | } | |
|
252 | else if (variableDateTime.m_TStart < currentDateTime.m_TStart) { | |
|
253 | qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:"); | |
|
216 | 254 | |
|
217 |
auto diffEndToKeepDelta = |
|
|
218 |
|
|
|
255 | auto diffEndToKeepDelta = currentDateTime.m_TEnd - variableDateTime.m_TEnd; | |
|
256 | currentDateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta; | |
|
219 | 257 | // Tolerance have to be added to the right |
|
220 | 258 | // add tolerance for right (end) side |
|
221 | tolerance = toleranceFactor * (dateTime.m_TEnd - dateTime.m_TStart); | |
|
259 | tolerance | |
|
260 | = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); | |
|
222 | 261 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
262 | zoomType = VisualizationGraphWidgetZoomType::PanRight; | |
|
223 | 263 | } |
|
224 |
else if (variableDateTime.m_TEnd > |
|
|
225 |
qC |
|
|
226 |
auto diffStartToKeepDelta |
|
|
227 |
|
|
|
264 | else if (variableDateTime.m_TEnd > currentDateTime.m_TEnd) { | |
|
265 | qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: "); | |
|
266 | auto diffStartToKeepDelta | |
|
267 | = variableDateTime.m_TStart - currentDateTime.m_TStart; | |
|
268 | currentDateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta; | |
|
228 | 269 | // Tolerance have to be added to the left |
|
229 | 270 | // add tolerance for left (start) side |
|
230 | tolerance = toleranceFactor * (dateTime.m_TEnd - dateTime.m_TStart); | |
|
271 | tolerance | |
|
272 | = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); | |
|
231 | 273 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
274 | zoomType = VisualizationGraphWidgetZoomType::PanLeft; | |
|
232 | 275 | } |
|
233 | 276 | else { |
|
234 |
qC |
|
|
277 | qCInfo(LOG_VisualizationGraphWidget()) | |
|
235 | 278 | << tr("Detection anormal zoom detection: "); |
|
279 | zoomType = VisualizationGraphWidgetZoomType::Unknown; | |
|
236 | 280 | } |
|
237 | 281 | } |
|
238 | 282 | else { |
|
239 |
qC |
|
|
283 | qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: "); | |
|
240 | 284 | // add 10% tolerance for each side |
|
241 |
tolerance = |
|
|
285 | tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart); | |
|
242 | 286 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
243 | 287 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
288 | zoomType = VisualizationGraphWidgetZoomType::ZoomOut; | |
|
244 | 289 | } |
|
245 | 290 | if (!variable->contains(dateTimeRange)) { |
|
246 |
qC |
|
|
247 |
<< "TORM: Modif on variable datetime detected" << |
|
|
248 |
variable->setDateTime( |
|
|
291 | qCInfo(LOG_VisualizationGraphWidget()) | |
|
292 | << "TORM: Modif on variable datetime detected" << currentDateTime; | |
|
293 | variable->setDateTime(currentDateTime); | |
|
249 | 294 | } |
|
250 | 295 | |
|
251 |
qC |
|
|
296 | qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Request data detection: "); | |
|
252 | 297 | // CHangement detected, we need to ask controller to request data loading |
|
253 | 298 | emit requestDataLoading(variable, variableDateTimeWithTolerance); |
|
254 | 299 | } |
|
255 | 300 | else { |
|
256 |
qC |
|
|
301 | qCInfo(LOG_VisualizationGraphWidget()) | |
|
302 | << tr("TORM: Detection zoom in that doesn't need request: "); | |
|
303 | zoomType = VisualizationGraphWidgetZoomType::ZoomIn; | |
|
257 | 304 | } |
|
258 | 305 | } |
|
306 | ||
|
307 | if (impl->m_DoSynchronize) { | |
|
308 | auto oldDateTime = SqpDateTime{t2.lower, t2.upper}; | |
|
309 | qCDebug(LOG_VisualizationGraphWidget()) | |
|
310 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") | |
|
311 | << QThread::currentThread()->objectName(); | |
|
312 | emit synchronize(dateTimeRange, oldDateTime, zoomType); | |
|
313 | } | |
|
259 | 314 | } |
|
260 | 315 | |
|
261 | 316 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
@@ -1,8 +1,11 | |||
|
1 | 1 | #include "Visualization/VisualizationZoneWidget.h" |
|
2 | ||
|
3 | #include "Data/SqpDateTime.h" | |
|
4 | ||
|
2 | 5 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
6 | #include "Visualization/VisualizationGraphWidget.h" | |
|
3 | 7 | #include "ui_VisualizationZoneWidget.h" |
|
4 | 8 | |
|
5 | #include "Visualization/VisualizationGraphWidget.h" | |
|
6 | 9 | |
|
7 | 10 | #include <SqpApplication.h> |
|
8 | 11 | |
@@ -57,6 +60,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||
|
57 | 60 | auto graphWidget = new VisualizationGraphWidget{ |
|
58 | 61 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; |
|
59 | 62 | |
|
63 | ||
|
60 | 64 | // Set graph properties |
|
61 | 65 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); |
|
62 | 66 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); |
@@ -65,6 +69,71 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||
|
65 | 69 | |
|
66 | 70 | graphWidget->addVariable(variable); |
|
67 | 71 | |
|
72 | // Lambda to synchronize zone widget | |
|
73 | auto synchronizeZoneWidget = [this, graphWidget](const SqpDateTime &dateTime, | |
|
74 | const SqpDateTime &oldDateTime, | |
|
75 | VisualizationGraphWidgetZoomType zoomType) { | |
|
76 | auto frameLayout = ui->visualizationZoneFrame->layout(); | |
|
77 | for (auto i = 0; i < frameLayout->count(); ++i) { | |
|
78 | auto graphChild | |
|
79 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); | |
|
80 | if (graphChild && (graphChild != graphWidget)) { | |
|
81 | ||
|
82 | auto dateTimeThatKeepDelta = dateTime; | |
|
83 | auto graphChildRange = graphChild->graphRange(); | |
|
84 | switch (zoomType) { | |
|
85 | case VisualizationGraphWidgetZoomType::ZoomIn: { | |
|
86 | auto deltaLeft = dateTime.m_TStart - oldDateTime.m_TStart; | |
|
87 | auto deltaRight = oldDateTime.m_TEnd - dateTime.m_TEnd; | |
|
88 | graphChildRange.m_TStart += deltaLeft; | |
|
89 | graphChildRange.m_TEnd -= deltaRight; | |
|
90 | dateTimeThatKeepDelta = graphChildRange; | |
|
91 | break; | |
|
92 | } | |
|
93 | ||
|
94 | case VisualizationGraphWidgetZoomType::ZoomOut: { | |
|
95 | auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart; | |
|
96 | auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd; | |
|
97 | graphChildRange.m_TStart -= deltaLeft; | |
|
98 | graphChildRange.m_TEnd += deltaRight; | |
|
99 | dateTimeThatKeepDelta = graphChildRange; | |
|
100 | break; | |
|
101 | } | |
|
102 | case VisualizationGraphWidgetZoomType::PanRight: { | |
|
103 | auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd; | |
|
104 | graphChildRange.m_TStart += deltaRight; | |
|
105 | graphChildRange.m_TEnd += deltaRight; | |
|
106 | dateTimeThatKeepDelta = graphChildRange; | |
|
107 | break; | |
|
108 | } | |
|
109 | case VisualizationGraphWidgetZoomType::PanLeft: { | |
|
110 | auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart; | |
|
111 | graphChildRange.m_TStart -= deltaLeft; | |
|
112 | graphChildRange.m_TEnd -= deltaLeft; | |
|
113 | dateTimeThatKeepDelta = graphChildRange; | |
|
114 | break; | |
|
115 | } | |
|
116 | case VisualizationGraphWidgetZoomType::Unknown: { | |
|
117 | qCCritical(LOG_VisualizationZoneWidget()) | |
|
118 | << tr("Impossible to synchronize: zoom type unknown"); | |
|
119 | break; | |
|
120 | } | |
|
121 | default: | |
|
122 | qCCritical(LOG_VisualizationZoneWidget()) | |
|
123 | << tr("Impossible to synchronize: zoom type not take into account"); | |
|
124 | // No action | |
|
125 | break; | |
|
126 | } | |
|
127 | graphChild->enableSynchronize(false); | |
|
128 | graphChild->setGraphRange(dateTimeThatKeepDelta); | |
|
129 | graphChild->enableSynchronize(true); | |
|
130 | } | |
|
131 | } | |
|
132 | }; | |
|
133 | ||
|
134 | // connection for synchronization | |
|
135 | connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); | |
|
136 | ||
|
68 | 137 | return graphWidget; |
|
69 | 138 | } |
|
70 | 139 |
General Comments 0
You need to be logged in to leave comments.
Login now