| 382 | } |
| 383 | |
| 384 | void PlotWidget::showPointValues(QPoint paint_point) { |
| 385 | if (!show_points_ || show_point_marker_ == nullptr || show_point_text_ == nullptr) { |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | auto paint_to_plot = [this](QPoint p) { |
| 390 | return QPointF(qwtPlot()->invTransform(QwtPlot::xBottom, p.x()), qwtPlot()->invTransform(QwtPlot::yLeft, p.y())); |
| 391 | }; |
| 392 | auto plot_to_paint = [this](QPointF p) { |
| 393 | return QPoint(qwtPlot()->transform(QwtPlot::xBottom, p.x()), qwtPlot()->transform(QwtPlot::yLeft, p.y())); |
| 394 | }; |
| 395 | |
| 396 | const QPointF mouse_in_plot = paint_to_plot(paint_point); |
| 397 | const int precision = QSettings().value(QStringLiteral("Preferences::precision"), 3).toInt(); |
| 398 | |
| 399 | QString text; |
| 400 | int min_distance_sqr = kHoverHitRadiusPx * kHoverHitRadiusPx; |
| 401 | bool updated = false; |
| 402 | QPointF marker_point; |
| 403 | const QwtPlotItemList curves = qwtPlot()->itemList(QwtPlotItem::Rtti_PlotCurve); |
| 404 | for (auto* item : curves) { |
| 405 | auto* curve = dynamic_cast<QwtPlotCurve*>(item); |
| 406 | if (curve == nullptr || !curve->isVisible()) { |
| 407 | continue; |
| 408 | } |
| 409 | const auto maybe_point = curvePointAt(curve, mouse_in_plot.x()); |
| 410 | if (!maybe_point) { |
| 411 | continue; |
| 412 | } |
| 413 | const QPoint sample_paint = plot_to_paint(*maybe_point); |
| 414 | const QPoint diff = sample_paint - paint_point; |
| 415 | const int dist_sqr = diff.x() * diff.x() + diff.y() * diff.y(); |
| 416 | if (dist_sqr < min_distance_sqr) { |
| 417 | updated = true; |
| 418 | min_distance_sqr = dist_sqr; |
| 419 | marker_point = *maybe_point; |
| 420 | text = |
| 421 | QString("<font color=%1>%2<br>x: %3<br>y: %4</font>") |
| 422 | .arg( |
| 423 | curve->pen().color().name(), curve->title().text(), QString::number(maybe_point->x(), 'f', precision), |
| 424 | QString::number(maybe_point->y(), 'f', precision)); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | const bool was_visible = show_point_marker_->isVisible(); |
| 429 | show_point_marker_->setVisible(updated); |
| 430 | show_point_text_->setVisible(updated); |
| 431 | |
| 432 | if (updated) { |
| 433 | show_point_marker_->setValue(marker_point); |
| 434 | |
| 435 | QwtText label; |
| 436 | label.setText(text); |
| 437 | label.setBorderPen(QColor(Qt::transparent)); |
| 438 | QColor background = qwtPlot()->palette().color(QPalette::Window); |
| 439 | background.setAlpha(220); |
| 440 | label.setBackgroundBrush(background); |
| 441 | QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); |
nothing calls this directly
no test coverage detected