| 65 | } |
| 66 | |
| 67 | void PlotLegend::drawLegendData( |
| 68 | QPainter* painter, const QwtPlotItem* plot_item, const QwtLegendData& data, const QRectF& rect) const { |
| 69 | const int item_margin = margin(); |
| 70 | const QRectF item_rect = rect.toRect().adjusted(item_margin, item_margin, -item_margin, -item_margin); |
| 71 | painter->setClipRect(item_rect, Qt::IntersectClip); |
| 72 | |
| 73 | int title_offset = 0; |
| 74 | constexpr qreal kDotDiameter = 8.0; |
| 75 | constexpr qreal kDotGap = 4.0; |
| 76 | if (const auto* curve = dynamic_cast<const QwtPlotCurve*>(plot_item); curve != nullptr) { |
| 77 | QColor dot_color = curve->pen().color(); |
| 78 | if (!plot_item->isVisible()) { |
| 79 | dot_color.setAlphaF(0.45); |
| 80 | } |
| 81 | const QRectF dot_rect(item_rect.left(), item_rect.center().y() - (kDotDiameter / 2.0), kDotDiameter, kDotDiameter); |
| 82 | painter->save(); |
| 83 | painter->setRenderHint(QPainter::Antialiasing, true); |
| 84 | painter->setPen(Qt::NoPen); |
| 85 | painter->setBrush(dot_color); |
| 86 | painter->drawEllipse(dot_rect); |
| 87 | painter->restore(); |
| 88 | title_offset += static_cast<int>(kDotDiameter + kDotGap); |
| 89 | } else if (const QwtGraphic graphic = data.icon(); !graphic.isEmpty()) { |
| 90 | QRectF icon_rect(item_rect.topLeft(), graphic.defaultSize()); |
| 91 | icon_rect.moveCenter(QPoint(icon_rect.center().x(), rect.center().y())); |
| 92 | if (plot_item->isVisible()) { |
| 93 | graphic.render(painter, icon_rect, Qt::KeepAspectRatio); |
| 94 | } |
| 95 | title_offset += static_cast<int>(icon_rect.width()) + spacing(); |
| 96 | } |
| 97 | |
| 98 | const QwtText text = data.title(); |
| 99 | if (text.isEmpty()) { |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | QPen pen = textPen(); |
| 104 | pen.setColor(plot_item->isVisible() ? parent_plot_->canvas()->palette().windowText().color() : QColor(122, 122, 122)); |
| 105 | painter->setPen(pen); |
| 106 | painter->setFont(font()); |
| 107 | text.draw(painter, item_rect.adjusted(title_offset, 0, 0, 0)); |
| 108 | } |
| 109 | |
| 110 | void PlotLegend::drawBackground(QPainter* painter, const QRectF& rect) const { |
| 111 | painter->save(); |
nothing calls this directly
no test coverage detected