From fd0439cee85631706521cd34a33d11b42f893f1e Mon Sep 17 00:00:00 2001 From: rkv Date: Fri, 13 Feb 2015 12:31:10 +0300 Subject: [PATCH] Getting closest curve has been fixed for the case of several curves in the view. --- src/Plot2d/Plot2d_ViewFrame.cxx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index c97d1770a..36e56f289 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -2209,15 +2209,28 @@ Plot2d_Curve* Plot2d_Plot2d::getClosestCurve( QPoint p, double& distance, int& i { CurveDict::Iterator it = getCurves().begin(); QwtPlotCurve* aCurve; + Plot2d_Curve* aClosestCurve = 0; + double aMinDist = -1; + int aClosestIndex = -1; for ( ; it != getCurves().end(); it++ ) { aCurve = it.key(); if ( !aCurve ) continue; index = aCurve->closestPoint( p, &distance ); if ( index > -1 ) - return it.value(); + { + if (aMinDist < 0 || aMinDist > distance) + { + aMinDist = distance; + aClosestIndex = index; + aClosestCurve = it.value(); + } + } } - return 0; + distance = aMinDist; + index = aClosestIndex; + + return aClosestCurve; } /*! -- 2.39.2