diff options
author | Antti Määttä <antti.maatta@qt.io> | 2023-08-01 10:54:18 +0300 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-08-01 10:35:13 +0000 |
commit | 183cb5a61753f5e7f7c3c5950b8109a4b175adc1 (patch) | |
tree | d8aa134672cadc44967800afbb6403d7455cff82 | |
parent | 0974849917b16011a0f0e52d027f3aa939edf199 (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.cpp | 13 | ||||
-rw-r--r-- | src/charts/scatterchart/scatterchartitem_p.h | 1 |
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;} |