@@ -26,7 +26,9 const auto OVERLAY_LAYER = QStringLiteral("overlay"); | |||
|
26 | 26 | /// Pixmap used to show x-axis properties |
|
27 | 27 | const auto SHOW_AXIS_ICON_PATH = QStringLiteral(":/icones/up.png"); |
|
28 | 28 | |
|
29 | const auto TOOLTIP_FORMAT = QStringLiteral("key: %1\nvalue: %2"); | |
|
29 | /// Tooltip format for graphs | |
|
30 | const auto GRAPH_TOOLTIP_FORMAT = QStringLiteral("key: %1\nvalue: %2"); | |
|
31 | ||
|
30 | 32 | |
|
31 | 33 | /// Offset used to shift the tooltip of the mouse |
|
32 | 34 | const auto TOOLTIP_OFFSET = QPoint{20, 20}; |
@@ -195,6 +197,8 void VisualizationGraphRenderingDelegate::onMouseMove(QMouseEvent *event) noexce | |||
|
195 | 197 | impl->m_PointTracer->setVisible(false); |
|
196 | 198 | impl->m_Plot.replot(); |
|
197 | 199 | |
|
200 | QString tooltip{}; | |
|
201 | ||
|
198 | 202 | // Gets the graph under the mouse position |
|
199 | 203 | auto eventPos = event->pos(); |
|
200 | 204 | if (auto graph = qobject_cast<QCPGraph *>(impl->m_Plot.plottableAt(eventPos))) { |
@@ -204,8 +208,10 void VisualizationGraphRenderingDelegate::onMouseMove(QMouseEvent *event) noexce | |||
|
204 | 208 | // Gets the closest data point to the mouse |
|
205 | 209 | auto graphDataIt = graphData->findBegin(mouseKey); |
|
206 | 210 | if (graphDataIt != graphData->constEnd()) { |
|
211 | // Sets tooltip | |
|
207 | 212 | auto key = formatValue(graphDataIt->key, *graph->keyAxis()); |
|
208 | 213 | auto value = formatValue(graphDataIt->value, *graph->valueAxis()); |
|
214 | tooltip = GRAPH_TOOLTIP_FORMAT.arg(key, value); | |
|
209 | 215 | |
|
210 | 216 | // Displays point tracer |
|
211 | 217 | impl->m_PointTracer->setGraph(graph); |
@@ -214,17 +220,22 void VisualizationGraphRenderingDelegate::onMouseMove(QMouseEvent *event) noexce | |||
|
214 | 220 | impl->m_Plot.layer("main")); // Tracer is set on top of the plot's main layer |
|
215 | 221 | impl->m_PointTracer->setVisible(true); |
|
216 | 222 | impl->m_Plot.replot(); |
|
223 | } | |
|
224 | } | |
|
225 | else if (auto colorMap = qobject_cast<QCPColorMap *>(impl->m_Plot.plottableAt(eventPos))) { | |
|
226 | /// @todo | |
|
227 | tooltip = "TODO"; | |
|
228 | } | |
|
217 | 229 | |
|
218 | // Starts timer to show tooltip after timeout | |
|
219 | auto showTooltip = [ tooltip = TOOLTIP_FORMAT.arg(key, value), eventPos, this ]() | |
|
220 | { | |
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
230 | if (!tooltip.isEmpty()) { | |
|
231 | // Starts timer to show tooltip after timeout | |
|
232 | auto showTooltip = [tooltip, eventPos, this]() { | |
|
233 | QToolTip::showText(impl->m_Plot.mapToGlobal(eventPos) + TOOLTIP_OFFSET, tooltip, | |
|
234 | &impl->m_Plot, TOOLTIP_RECT); | |
|
235 | }; | |
|
224 | 236 | |
|
225 |
|
|
|
226 |
|
|
|
227 | } | |
|
237 | QObject::connect(&impl->m_TracerTimer, &QTimer::timeout, showTooltip); | |
|
238 | impl->m_TracerTimer.start(); | |
|
228 | 239 | } |
|
229 | 240 | } |
|
230 | 241 |
General Comments 0
You need to be logged in to leave comments.
Login now