From a692d9a826d864e91b668415aea266228c2ae323 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Fri, 11 Oct 2019 09:18:12 +0300 Subject: Draw points that lie inside the chart rect only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only drawback of this approach is that if the pen has a transparent color, the overlap between a point and the graph line below it is clear. But it wasn't perfect anyway before this patch. The impact of this approach on performance is minimal. Task-number: QTBUG-62839 Change-Id: I4478d9136fe7ca1a1c6bf5dd5a3f459af63b953c Reviewed-by: Tomi Korpipää Reviewed-by: Miikka Heikkinen --- src/charts/linechart/linechartitem.cpp | 40 ++++++++++++++-------------------- 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/charts/linechart/linechartitem.cpp b/src/charts/linechart/linechartitem.cpp index 99e16d29..c6eb2d07 100644 --- a/src/charts/linechart/linechartitem.cpp +++ b/src/charts/linechart/linechartitem.cpp @@ -291,19 +291,8 @@ void LineChartItem::updateGeometry() // because shape doesn't get clipped. It doesn't seem possible to do sensibly. } else { // not polar linePath.moveTo(points.at(0)); - if (m_pointsVisible) { - int size = m_linePen.width(); - linePath.addEllipse(points.at(0), size, size); - linePath.moveTo(points.at(0)); - for (int i = 1; i < points.size(); i++) { - linePath.lineTo(points.at(i)); - linePath.addEllipse(points.at(i), size, size); - linePath.moveTo(points.at(i)); - } - } else { - for (int i = 1; i < points.size(); i++) - linePath.lineTo(points.at(i)); - } + for (int i = 1; i < points.size(); i++) + linePath.lineTo(points.at(i)); fullPath = linePath; } @@ -407,19 +396,12 @@ void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt painter->setClipRect(clipRect); } - if (m_pointsVisible) { - painter->setBrush(m_linePen.color()); + if (m_linePen.style() != Qt::SolidLine || alwaysUsePath) { + // If pen style is not solid line, use path painting to ensure proper pattern continuity painter->drawPath(m_linePath); } else { - painter->setBrush(QBrush(Qt::NoBrush)); - if (m_linePen.style() != Qt::SolidLine || alwaysUsePath) { - // If pen style is not solid line, always fall back to path painting - // to ensure proper continuity of the pattern - painter->drawPath(m_linePath); - } else { - for (int i(1); i < m_linePoints.size(); i++) - painter->drawLine(m_linePoints.at(i - 1), m_linePoints.at(i)); - } + for (int i = 1; i < m_linePoints.size(); ++i) + painter->drawLine(m_linePoints.at(i - 1), m_linePoints.at(i)); } if (m_pointLabelsVisible) { @@ -432,6 +414,16 @@ void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt painter->restore(); + if (m_pointsVisible) { + // draw points that lie inside clipRect only + qreal ptSize = m_linePen.width() * 1.5; + painter->setPen(Qt::NoPen); + painter->setBrush(m_linePen.color()); + for (int i = 0; i < m_linePoints.size(); ++i) { + if (clipRect.contains(m_linePoints.at(i))) + painter->drawEllipse(m_linePoints.at(i), ptSize, ptSize); + } + } } void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) -- cgit v1.2.3