! Reimplementation of QGraphicsItem::paint(). This function does the actual painting of the legend. \sa QGraphicsItem::paint(). */
| 457 | \sa QGraphicsItem::paint(). |
| 458 | */ |
| 459 | void CartesianPlotLegendPrivate::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget*) { |
| 460 | if (!isVisible()) |
| 461 | return; |
| 462 | |
| 463 | painter->save(); |
| 464 | |
| 465 | // draw the background area |
| 466 | background->draw(painter, m_boundingRectangle, borderCornerRadius); |
| 467 | |
| 468 | // draw the border |
| 469 | if (borderLine->style() != Qt::NoPen) { |
| 470 | painter->setPen(borderLine->pen()); |
| 471 | painter->setBrush(Qt::NoBrush); |
| 472 | painter->setOpacity(borderLine->opacity()); |
| 473 | if (qFuzzyIsNull(borderCornerRadius)) |
| 474 | painter->drawRect(m_boundingRectangle); |
| 475 | else |
| 476 | painter->drawRoundedRect(m_boundingRectangle, borderCornerRadius, borderCornerRadius); |
| 477 | } |
| 478 | |
| 479 | // draw curve's line+symbol and the names |
| 480 | QFontMetrics fm(labelFont); |
| 481 | float h = fm.ascent(); |
| 482 | painter->setFont(labelFont); |
| 483 | |
| 484 | // translate to left upper corner of the bounding rect plus the layout offset and the height of the title |
| 485 | painter->translate(-m_boundingRectangle.width() / 2 + layoutLeftMargin, -m_boundingRectangle.height() / 2 + layoutTopMargin); |
| 486 | if (title->isVisible() && !title->text().text.isEmpty()) |
| 487 | painter->translate(0, title->graphicsItem()->boundingRect().height()); |
| 488 | |
| 489 | painter->save(); |
| 490 | |
| 491 | int col = 0, row = 0; |
| 492 | for (auto* plot : m_plots) { |
| 493 | // process the curves |
| 494 | // TODO: move the logic below into the plot classes |
| 495 | const auto* curve = dynamic_cast<const XYCurve*>(plot); |
| 496 | const auto* hist = dynamic_cast<const Histogram*>(plot); |
| 497 | const auto* boxPlot = dynamic_cast<const BoxPlot*>(plot); |
| 498 | const auto* barPlot = dynamic_cast<const BarPlot*>(plot); |
| 499 | const auto* lollipopPlot = dynamic_cast<const LollipopPlot*>(plot); |
| 500 | const auto* kdePlot = dynamic_cast<const KDEPlot*>(plot); |
| 501 | const auto* qqPlot = dynamic_cast<const QQPlot*>(plot); |
| 502 | |
| 503 | if (curve) { // draw the legend item for xy-curve |
| 504 | // curve's line (painted at the half of the ascent size) |
| 505 | if (curve->lineType() != XYCurve::LineType::NoLine) { |
| 506 | painter->setPen(curve->line()->pen()); |
| 507 | painter->setOpacity(curve->line()->opacity()); |
| 508 | painter->drawLine(0, h / 2, lineSymbolWidth, h / 2); |
| 509 | } |
| 510 | |
| 511 | // error bars |
| 512 | const auto xErrorType = curve->errorBar()->xErrorType(); |
| 513 | const auto yErrorType = curve->errorBar()->yErrorType(); |
| 514 | const auto* errorBarsLine = curve->errorBar()->line(); |
| 515 | if ((xErrorType != ErrorBar::ErrorType::NoError && curve->errorBar()->xPlusColumn()) |
| 516 | || (yErrorType != ErrorBar::ErrorType::NoError && curve->errorBar()->yPlusColumn())) { |
nothing calls this directly
no test coverage detected