VisualizationGraphRenderingDelegate.cpp
46 lines
| 1.3 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r480 | #include "Visualization/VisualizationGraphRenderingDelegate.h" | ||
#include "Visualization/qcustomplot.h" | ||||
Alexandre Leroux
|
r482 | namespace { | ||
/// Timeout after which a tracer is displayed | ||||
const auto TRACER_TIMEOUT = 500; | ||||
} // namespace | ||||
Alexandre Leroux
|
r480 | struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegatePrivate { | ||
Alexandre Leroux
|
r482 | explicit VisualizationGraphRenderingDelegatePrivate(QCustomPlot &plot) | ||
: m_Plot{plot}, | ||||
m_PointTracer{new QCPItemTracer{&plot}}, | ||||
m_TextTracer{new QCPItemText{&plot}}, | ||||
m_TracerTimer{} | ||||
{ | ||||
m_TracerTimer.setInterval(TRACER_TIMEOUT); | ||||
m_TracerTimer.setSingleShot(true); | ||||
} | ||||
Alexandre Leroux
|
r480 | |||
QCustomPlot &m_Plot; | ||||
Alexandre Leroux
|
r482 | QCPItemTracer *m_PointTracer; | ||
QCPItemText *m_TextTracer; | ||||
QTimer m_TracerTimer; | ||||
Alexandre Leroux
|
r480 | }; | ||
VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegate(QCustomPlot &plot) | ||||
: impl{spimpl::make_unique_impl<VisualizationGraphRenderingDelegatePrivate>(plot)} | ||||
{ | ||||
} | ||||
Alexandre Leroux
|
r481 | |||
void VisualizationGraphRenderingDelegate::onMouseMove(QMouseEvent *event) noexcept | ||||
{ | ||||
Alexandre Leroux
|
r482 | // Cancels pending refresh | ||
impl->m_TracerTimer.disconnect(); | ||||
auto showTracers = [ eventPos = event->pos(), this ]() | ||||
{ | ||||
}; | ||||
// Starts the timer to display tracers at timeout | ||||
QObject::connect(&impl->m_TracerTimer, &QTimer::timeout, showTracers); | ||||
impl->m_TracerTimer.start(); | ||||
Alexandre Leroux
|
r481 | } | ||