From b264b1ddc4c83cf8ba8b08a6e171d6834352ef67 2012-04-23 11:20:52 From: Jani Honkonen Date: 2012-04-23 11:20:52 Subject: [PATCH] Emit hover leave signal from PieSliceItem when it gets destroyed. This fixes the problem with the drilldown demo highlight getting stuck when switching series. --- diff --git a/examples/piechartdrilldown/drilldownslice.cpp b/examples/piechartdrilldown/drilldownslice.cpp index f375f02..c0cbe05 100644 --- a/examples/piechartdrilldown/drilldownslice.cpp +++ b/examples/piechartdrilldown/drilldownslice.cpp @@ -57,6 +57,7 @@ void DrilldownSlice::updateLabel() void DrilldownSlice::showHighlight(bool show) { setLabelVisible(show); + setExploded(show); } #include "moc_drilldownslice.cpp" diff --git a/src/piechart/piesliceitem.cpp b/src/piechart/piesliceitem.cpp index f59969d..94f076b 100644 --- a/src/piechart/piesliceitem.cpp +++ b/src/piechart/piesliceitem.cpp @@ -40,7 +40,8 @@ QPointF offset(qreal angle, qreal length) } PieSliceItem::PieSliceItem(QGraphicsItem* parent) - :QGraphicsObject(parent) + :QGraphicsObject(parent), + m_hovered(false) { setAcceptHoverEvents(true); setAcceptedMouseButtons(Qt::MouseButtonMask); @@ -49,7 +50,10 @@ PieSliceItem::PieSliceItem(QGraphicsItem* parent) PieSliceItem::~PieSliceItem() { - + // If user is hovering over the slice and it gets destroyed we do + // not get a hover leave event. So we must emit the signal here. + if (m_hovered) + emit hovered(false); } QRectF PieSliceItem::boundingRect() const @@ -85,11 +89,13 @@ void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*op void PieSliceItem::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) { + m_hovered = true; emit hovered(true); } void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) { + m_hovered = false; emit hovered(false); } diff --git a/src/piechart/piesliceitem_p.h b/src/piechart/piesliceitem_p.h index 8e338d7..4a9d095 100644 --- a/src/piechart/piesliceitem_p.h +++ b/src/piechart/piesliceitem_p.h @@ -72,6 +72,7 @@ private: QPainterPath m_slicePath; QPainterPath m_labelArmPath; QRectF m_labelTextRect; + bool m_hovered; }; QTCOMMERCIALCHART_END_NAMESPACE