From a98ac12d0e86cd8edb973c4f5b96c1948ac19ebc Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Wed, 4 Aug 2021 13:21:09 +0100 Subject: [PATCH] Fix clickthru SEGV for Bubble and TopN overview items .. they raised signals in paint events which was highly problematic (!) Fixes #3993 --- src/Charts/OverviewItems.cpp | 25 ++++++++++++++++++++++--- src/Charts/OverviewItems.h | 2 ++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Charts/OverviewItems.cpp b/src/Charts/OverviewItems.cpp index a457d0513..545897689 100644 --- a/src/Charts/OverviewItems.cpp +++ b/src/Charts/OverviewItems.cpp @@ -700,7 +700,7 @@ MetricOverviewItem::~MetricOverviewItem() delete sparkline; } -TopNOverviewItem::TopNOverviewItem(ChartSpace *parent, QString name, QString symbol) : ChartSpaceItem(parent, name), click(false) +TopNOverviewItem::TopNOverviewItem(ChartSpace *parent, QString name, QString symbol) : ChartSpaceItem(parent, name), click(false), clickthru(NULL) { // metric this->type = OverviewItemType::TOPN; @@ -2735,10 +2735,19 @@ TopNOverviewItem::sceneEvent(QEvent *event) if (paintarea.contains(cpos)) { event->accept(); click = true; + clickthru = NULL; update(); return true; } + } else if (event->type() == QEvent::GraphicsSceneMouseRelease) { + + if (clickthru) { + parent->context->notifyRideSelected(clickthru); + clickthru = NULL; + } + return true; + } else if (event->type() == QEvent::GraphicsSceneHoverEnter) { update(); @@ -2809,7 +2818,7 @@ TopNOverviewItem::itemPaint(QPainter *painter, const QStyleOptionGraphicsItem *, painter->setBrush(darkgray); painter->drawRect(itemarea); - if (click && ranked[i].item) parent->context->notifyRideSelected(ranked[i].item); + clickthru = ranked[i].item; } // rank @@ -3802,6 +3811,7 @@ BubbleViz::BubbleViz(IntervalOverviewItem *parent, QString name) : QGraphicsItem setZValue(11); setAcceptHoverEvents(true); + clickthru = NULL; group = new QSequentialAnimationGroup(this); QParallelAnimationGroup *par = new QParallelAnimationGroup(this); @@ -3867,6 +3877,15 @@ BubbleViz::sceneEvent(QEvent *event) if (event->type() == QEvent::GraphicsSceneMousePress) { click = true; + clickthru=NULL; + update(); + } + + if (event->type() == QEvent::GraphicsSceneMouseRelease) { + if (clickthru) { + parent->parent->context->notifyRideSelected(clickthru); + clickthru = NULL; + } } return false; } @@ -4255,7 +4274,7 @@ BubbleViz::paint(QPainter*painter, const QStyleOptionGraphicsItem *, QWidget*) } if (click && nearvalue >= 0 && nearest.item != NULL) { - parent->parent->context->notifyRideSelected(nearest.item); + clickthru = nearest.item; } click = false; diff --git a/src/Charts/OverviewItems.h b/src/Charts/OverviewItems.h index c36a9628e..47208129d 100644 --- a/src/Charts/OverviewItems.h +++ b/src/Charts/OverviewItems.h @@ -296,6 +296,7 @@ class TopNOverviewItem : public ChartSpaceItem // interaction bool click; + RideItem *clickthru; OverviewItemConfig *configwidget; }; @@ -563,6 +564,7 @@ class BubbleViz : public QObject, public QGraphicsItem // where is the cursor? bool hover; bool click; + RideItem *clickthru; QPointF plotpos; // for animated transition