summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMahmoud Badri <mahmoud.badri@qt.io>2019-10-11 09:18:12 +0300
committerMahmoud Badri <mahmoud.badri@qt.io>2019-10-11 10:20:03 +0300
commita692d9a826d864e91b668415aea266228c2ae323 (patch)
treef52aa1d5762e1c6974bfc407c96c96174818d1f8 /src
parent289b9904a7c9ce241896f65509a19d0213def35c (diff)
Draw points that lie inside the chart rect only
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ää <tomi.korpipaa@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/charts/linechart/linechartitem.cpp40
1 files changed, 16 insertions, 24 deletions
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)