##// END OF EJS Templates
Limits requests on mouse wheels/pans
Alexandre Leroux -
r414:4b445d4313d1 feature/AltAcquis...
parent child
Show More
@@ -67,7 +67,7 private slots:
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 processRangeChange();
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;
@@ -15,6 +15,9 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
15
15
16 namespace {
16 namespace {
17
17
18 /// Timeout from which the mouse wheel is considered completed (in ms)
19 const auto MOUSE_WHEEL_TIMEOUT = 250;
20
18 /// Key pressed to enable zoom on horizontal axis
21 /// Key pressed to enable zoom on horizontal axis
19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
22 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
20
23
@@ -25,7 +28,11 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
25
28
26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
29 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
27
30
28 explicit VisualizationGraphWidgetPrivate() : m_DoSynchronize{true}, m_IsCalibration{false} {}
31 explicit VisualizationGraphWidgetPrivate()
32 : m_DoSynchronize{true}, m_IsCalibration{false}, m_RefRange{}, m_MouseWheelTimer{}
33 {
34 m_MouseWheelTimer.setSingleShot(true);
35 }
29
36
30
37
31 // Return the operation when range changed
38 // Return the operation when range changed
@@ -36,6 +43,8 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
36
43
37 bool m_DoSynchronize;
44 bool m_DoSynchronize;
38 bool m_IsCalibration;
45 bool m_IsCalibration;
46 QCPRange m_RefRange;
47 QTimer m_MouseWheelTimer;
39 };
48 };
40
49
41 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
50 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
@@ -61,9 +70,10 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
61 connect(ui->widget, &QCustomPlot::mouseRelease, this,
70 connect(ui->widget, &QCustomPlot::mouseRelease, this,
62 &VisualizationGraphWidget::onMouseRelease);
71 &VisualizationGraphWidget::onMouseRelease);
63 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
72 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
64 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
73
65 &QCPAxis::rangeChanged),
74 // Connects mouse wheel timer
66 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
75 connect(&impl->m_MouseWheelTimer, &QTimer::timeout, this,
76 &VisualizationGraphWidget::processRangeChange);
67
77
68 // Activates menu when right clicking on the graph
78 // Activates menu when right clicking on the graph
69 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
79 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -218,14 +228,17 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
218 }
228 }
219 }
229 }
220
230
221 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
231 void VisualizationGraphWidget::processRangeChange()
222 {
232 {
223 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
233 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::processRangeChange")
224 << QThread::currentThread()->objectName();
234 << QThread::currentThread()->objectName();
225
235
226 auto dateTimeRange = SqpDateTime{t1.lower, t1.upper};
236 auto oldRange = impl->m_RefRange;
237 auto newRange = ui->widget->xAxis->range();
227
238
228 auto zoomType = impl->getZoomType(t1, t2);
239 auto dateTimeRange = SqpDateTime{newRange.lower, newRange.upper};
240
241 auto zoomType = impl->getZoomType(newRange, impl->m_RefRange);
229 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
242 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
230 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
243 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
231
244
@@ -310,16 +323,20 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
310 }
323 }
311
324
312 if (impl->m_DoSynchronize && !impl->m_IsCalibration) {
325 if (impl->m_DoSynchronize && !impl->m_IsCalibration) {
313 auto oldDateTime = SqpDateTime{t2.lower, t2.upper};
326 auto oldDateTime = SqpDateTime{oldRange.lower, oldRange.upper};
314 qCDebug(LOG_VisualizationGraphWidget())
327 qCDebug(LOG_VisualizationGraphWidget())
315 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
328 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
316 << QThread::currentThread()->objectName();
329 << QThread::currentThread()->objectName();
317 emit synchronize(dateTimeRange, oldDateTime, zoomType);
330 emit synchronize(dateTimeRange, oldDateTime, zoomType);
318 }
331 }
332
333 impl->m_RefRange = newRange;
319 }
334 }
320
335
321 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
336 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
322 {
337 {
338 impl->m_MouseWheelTimer.start(MOUSE_WHEEL_TIMEOUT);
339
323 auto zoomOrientations = QFlags<Qt::Orientation>{};
340 auto zoomOrientations = QFlags<Qt::Orientation>{};
324
341
325 // Lambda that enables a zoom orientation if the key modifier related to this orientation
342 // Lambda that enables a zoom orientation if the key modifier related to this orientation
@@ -338,12 +355,14 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
338
355
339 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
356 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
340 {
357 {
358 impl->m_RefRange = ui->widget->xAxis->range();
341 impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier);
359 impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier);
342 }
360 }
343
361
344 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
362 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
345 {
363 {
346 impl->m_IsCalibration = false;
364 impl->m_IsCalibration = false;
365 processRangeChange();
347 }
366 }
348
367
349 void VisualizationGraphWidget::onDataCacheVariableUpdated()
368 void VisualizationGraphWidget::onDataCacheVariableUpdated()
General Comments 0
You need to be logged in to leave comments. Login now