summaryrefslogtreecommitdiffstats
path: root/src/charts/xychart/xychart.cpp
diff options
context:
space:
mode:
authorLukas Kosinski <lukasz@scythe-studio.com>2021-04-15 18:00:53 +0200
committerLukas Kosinski <lukasz@scythe-studio.com>2021-05-07 15:42:44 +0200
commit8ce2fd52e0d5ea8189c193db0138488bafedbd10 (patch)
treeb65dd85c09ee226f8826f5bf8e6c6d21be41b0be /src/charts/xychart/xychart.cpp
parent512078eea7e96c0a2cc25db46078fc1dc66f3d8f (diff)
QXYSeries: Add light marker
Now you can setLightMarker(QImage) on any QXYSeries. Which will result in that image being painted on all points of the series. Setting to a null/empty-image (also default value) will disable this again. Mouse events supported added as well. Task-number: QTBUG-92884 Change-Id: Ic28e67e74b190fdb249cdc3ac48af59d0cc29bd6 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/charts/xychart/xychart.cpp')
-rw-r--r--src/charts/xychart/xychart.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/charts/xychart/xychart.cpp b/src/charts/xychart/xychart.cpp
index 2348e848..79c8c40c 100644
--- a/src/charts/xychart/xychart.cpp
+++ b/src/charts/xychart/xychart.cpp
@@ -251,6 +251,35 @@ bool XYChart::isEmpty()
return domain()->isEmpty() || m_series->points().isEmpty();
}
+QPointF XYChart::matchForLightMarker(const QPointF &eventPos)
+{
+ if (m_series->lightMarker().isNull())
+ return QPointF(qQNaN(), qQNaN()); // 0,0 could actually be in points()
+
+ int markerWidth = m_series->lightMarker().width();
+ int markerHeight = m_series->lightMarker().height();
+
+ for (const QPointF &dp : m_series->points()) {
+ bool ok;
+ const QPointF gp = domain()->calculateGeometryPoint(dp, ok);
+ if (ok) {
+ // '+2' and '+4': There is an addRect for the (mouse-)shape
+ // in LineChartItem::updateGeometry()
+ // This has a margin of 1 to make sure a press in the icon will always be detected,
+ // but as there is a bunch of 'translations' and therefore inaccuracies,
+ // so it is necessary to increase that margin to 2
+ // (otherwise you can click next to an icon, get a click event but not match it)
+ QRectF r(gp.x() - (markerWidth / 2 + 2),
+ gp.y() - (markerHeight / 2 + 2),
+ markerWidth + 4, markerHeight + 4);
+
+ if (r.contains(eventPos))
+ return dp;
+ }
+ }
+ return QPointF(qQNaN(), qQNaN()); // 0,0 could actually be in points()
+}
+
QT_END_NAMESPACE
#include "moc_xychart_p.cpp"