From c6eff0896f56bb338102bc0a30b5fc0672b69501 Mon Sep 17 00:00:00 2001 From: rkv Date: Thu, 26 Feb 2015 18:14:20 +0300 Subject: [PATCH] #2618: post - procesing - sensitive variable problem (PLEX). --- src/Plot2d/Plot2d_ToolTip.cxx | 30 ++++++++++++++----- src/Plot2d/Plot2d_ViewFrame.cxx | 53 +++++++++++++++++++++++++++++++++ src/Plot2d/Plot2d_ViewFrame.h | 1 + 3 files changed, 77 insertions(+), 7 deletions(-) diff --git a/src/Plot2d/Plot2d_ToolTip.cxx b/src/Plot2d/Plot2d_ToolTip.cxx index 043c5c487..1344edfb4 100644 --- a/src/Plot2d/Plot2d_ToolTip.cxx +++ b/src/Plot2d/Plot2d_ToolTip.cxx @@ -48,24 +48,40 @@ Plot2d_ToolTip::~Plot2d_ToolTip() void Plot2d_ToolTip::onToolTip( QPoint p, QString& str, QFont& f, QRect& txtRect, QRect& rect ) { - int pInd; - double dist; + QList< QList< int > > pInd; - Plot2d_Curve* c = myPlot->getClosestCurve( p, dist, pInd ); - if( !c || dist>maxDist ) + // Get all curves points in the vicinity. + QList aCurves = myPlot->getClosestPoints( p, maxDist, pInd ); + if( aCurves.isEmpty() ) return; + + QString aTxt; + + // Produce a tooltip containing text from all found points. + for(int i = 0; i < aCurves.length(); i++) + { + const QList< int >& aPnts = pInd[i]; + foreach(int j, aPnts) + { + aTxt = aCurves[i]->text( j ); + if (!aTxt.isEmpty()) + { + str += ("

" + aTxt + "

"); + } + } + } - str = c->text( pInd ); if( str.isEmpty() ) return; + // Compute a size according to the produced tooltip text. QFontMetrics m( f ); - QStringList lst = str.split( "\n", QString::SkipEmptyParts ); + QStringList lst = str.split( QRegExp("\n|(

)|(

)"), QString::SkipEmptyParts ); QStringList::const_iterator anIt = lst.begin(), aLast = lst.end(); int w = 0, h = 0; for( ; anIt!=aLast; anIt++ ) { - if( h>0 ) + //RKV: if( h>0 ) h+= m.lineSpacing(); QRect r = m.boundingRect( *anIt ); diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 36e56f289..29189c2fa 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -2233,6 +2233,59 @@ Plot2d_Curve* Plot2d_Plot2d::getClosestCurve( QPoint p, double& distance, int& i return aClosestCurve; } +/*! + Get list of curves located in the vicinity of the given point. + @param thePoint the point + @param theRadius the vicinity radius + @param thePntIndex the nearest points indexes of found curves + @return list of curves +*/ +QList Plot2d_Plot2d::getClosestPoints( QPoint thePoint, double theRadius, QList< QList< int > >& thePntIndex ) +{ + QList res; + thePntIndex.clear(); + // The square of the vicinity radius. + const double aMaxD = theRadius * theRadius; + const QwtScaleMap xMap = canvasMap(QwtPlot::xBottom); + const QwtScaleMap yMap = canvasMap(QwtPlot::yLeft); + + QwtPlotCurve* aCurve; + CurveDict::Iterator it = getCurves().begin(); + // Check each curve of this plot. + for ( ; it != getCurves().end(); it++ ) { + aCurve = it.key(); + if ( !aCurve ) + continue; + + // Gather points located in the vicinity of the given point for the current curve. + const pointList& aPnts = it.value()->getPointList(); + QList< int > aPntIndex; + + for (int i = 0; i < aPnts.length(); i++) + { + // Compute the square of the distance from the current curve point to the given point. + const double cx = xMap.xTransform(aCurve->x(i)) - thePoint.x(); + const double cy = yMap.xTransform(aCurve->y(i)) - thePoint.y(); + const double f = qwtSqr(cx) + qwtSqr(cy); + + // If the current curve point is in the vicinity then keep its index. + if ( f < aMaxD ) + { + aPntIndex << i; + } + } + + // Keep this curve if it has points in the vicinity. + if (!aPntIndex.isEmpty()) + { + res << it.value(); + thePntIndex << aPntIndex; + } + } + + return res; +} + /*! Sets number of markers for steps. If number of markers is equal to 1 then markers are displayed for steps only. If number of markers is equal to 3 diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 079d0d9ec..9f2b11407 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -255,6 +255,7 @@ public: QwtPlotGrid* grid() { return myGrid; }; CurveDict& getCurves() { return myCurves; } Plot2d_Curve* getClosestCurve( QPoint p, double& distance, int& index ); + QList getClosestPoints( QPoint thePoint, double theRadius, QList< QList< int > >& thePntIndex ); long insertCurve( const QString &title, int xAxis = xBottom, -- 2.39.2