summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2023-08-01 10:54:18 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-08-01 10:11:11 +0000
commit9b22caaadd47ff826e7f1291fcab11a07502fff6 (patch)
tree003035fc84fd052aef3241fbab816f042c8519e9
parent8ffa32f129b67b1b6317139617808189964cb1a1 (diff)
Charts: Fix crash when clicking on scatter points
There is a dependency loop in the chart marker implementation that causes a crash when clicking on the scatter points. The markers hold pointer to the parent item but when handling the mouseReleasedEvent, the markers gets deleted and the parent pointer becomes unusable. The code then returns to the marker code which uses the parent pointer and crashes. This change moves the event handling from the marker to the parent item. Fixes: QTBUG-115072 Change-Id: Ibdbbdf6b51d8a86f6bae8a9a8b7293ee3760876e Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> (cherry picked from commit 6f52849242fbfa1c6feec6591ecb837ff67dcb23) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/charts/scatterchart/scatterchartitem.cpp13
-rw-r--r--src/charts/scatterchart/scatterchartitem_p.h1
2 files changed, 10 insertions, 4 deletions
diff --git a/src/charts/scatterchart/scatterchartitem.cpp b/src/charts/scatterchart/scatterchartitem.cpp
index ec21f80b..4b5433e1 100644
--- a/src/charts/scatterchart/scatterchartitem.cpp
+++ b/src/charts/scatterchart/scatterchartitem.cpp
@@ -511,6 +511,14 @@ void ScatterChartItem::handleSeriesUpdated()
update();
}
+void ScatterChartItem::handleMarkerMouseReleaseEvent(QGraphicsItem *item)
+{
+ markerReleased(item);
+ if (mousePressed())
+ markerSelected(item);
+ setMousePressed(false);
+}
+
template<class T>
ChartMarker<T>::ChartMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent)
: T(x, y, w, h, parent)
@@ -555,10 +563,7 @@ template<class T>
void ChartMarker<T>::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
T::mouseReleaseEvent(event);
- m_parent->markerReleased(this);
- if (m_parent->mousePressed())
- m_parent->markerSelected(this);
- m_parent->setMousePressed(false);
+ m_parent->handleMarkerMouseReleaseEvent(this);
}
template<class T>
diff --git a/src/charts/scatterchart/scatterchartitem_p.h b/src/charts/scatterchart/scatterchartitem_p.h
index ce6da677..266d8e5d 100644
--- a/src/charts/scatterchart/scatterchartitem_p.h
+++ b/src/charts/scatterchart/scatterchartitem_p.h
@@ -45,6 +45,7 @@ public:
void markerPressed(QGraphicsItem *item);
void markerReleased(QGraphicsItem *item);
void markerDoubleClicked(QGraphicsItem *item);
+ void handleMarkerMouseReleaseEvent(QGraphicsItem *item);
void setMousePressed(bool pressed = true) {m_mousePressed = pressed;}
bool mousePressed() {return m_mousePressed;}