##// END OF EJS Templates
Show tracers method (1)...
Alexandre Leroux -
r483:3d0f23bd071b
parent child
Show More
@@ -3,9 +3,21
3 3
4 4 namespace {
5 5
6 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz");
7
8 const auto TEXT_TRACER_FORMAT = QStringLiteral("key: %1\nvalue: %2");
9
6 10 /// Timeout after which a tracer is displayed
7 11 const auto TRACER_TIMEOUT = 500;
8 12
13 /// Formats a data value according to the axis on which it is present
14 QString formatValue(double value, const QCPAxis &axis)
15 {
16 // If the axis is a time axis, formats the value as a date
17 return qSharedPointerDynamicCast<QCPAxisTickerDateTime>(axis.ticker())
18 ? QCPAxisTickerDateTime::keyToDateTime(value).toString(DATETIME_FORMAT)
19 : QString::number(value);
20 }
9 21 } // namespace
10 22
11 23 struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegatePrivate {
@@ -38,6 +50,24 void VisualizationGraphRenderingDelegate::onMouseMove(QMouseEvent *event) noexce
38 50
39 51 auto showTracers = [ eventPos = event->pos(), this ]()
40 52 {
53 // Reinits tracers
54 impl->m_PointTracer->setGraph(nullptr);
55 impl->m_PointTracer->setVisible(false);
56 impl->m_TextTracer->setVisible(false);
57 impl->m_Plot.replot();
58
59 // Gets the graph under the mouse position
60 if (auto graph = qobject_cast<QCPGraph *>(impl->m_Plot.plottableAt(eventPos))) {
61 auto mouseKey = graph->keyAxis()->pixelToCoord(eventPos.x());
62 auto graphData = graph->data();
63
64 // Gets the closest data point to the mouse
65 auto graphDataIt = graphData->findBegin(mouseKey);
66 if (graphDataIt != graphData->constEnd()) {
67 auto key = formatValue(graphDataIt->key, *graph->keyAxis());
68 auto value = formatValue(graphDataIt->value, *graph->valueAxis());
69 impl->m_TextTracer->setText(TEXT_TRACER_FORMAT.arg(key, value));
70 }
41 71 };
42 72
43 73 // Starts the timer to display tracers at timeout
General Comments 0
You need to be logged in to leave comments. Login now