Improved. Melhorado
Use the comments from the previous example. Uso comentarios do exemplo anterior
It can be used for one or more curves in the graph. Este método pode ser usado quando voce possuir em seu gráfico uma ou mais curvas.
I return the clicked curve. Agora retorno a curva clicada.
QwtPlotCurve* CLASS::clickedCurve( const QPoint& _pos ) const
{
const QwtPlot *plot = this->plot();
if ( plot == NULL )
return NULL;
// translate pos into the plot coordinates
const QPointF &curvePosF = transformWindowToCanvas(_pos);
const QwtPlotItemList &curves = plot->itemList( QwtPlotItem::Rtti_PlotCurve );
for ( int i = curves.size() - 1; i >= 0; --i )
{
const QLineF line = curveLineAt( static_cast<const QwtPlotCurve *>( curves[i] ), curvePosF.x()); //Returns the two points that created the line
if ( !line.isNull() )
{
const double xP1 = plot->canvasMap(QwtPlot::xBottom).transform(line.p1().x ());
const double yP1 = line.p1().y();
const double xP2 = plot->canvasMap(QwtPlot::xBottom).transform(line.p2().x ());
const double yP2 = line.p2().y();
const double xP3 = plot->canvasMap(QwtPlot::xBottom).transform(curvePosF.x ());
const double yP3 = curvePosF.y();
if ((xP2 - xP1) == 0 || ( xP3 - xP1 ) == 0)
return NULL;
qreal RazaoT1 = (yP2 - yP1)/(xP2 - xP1);
qreal RazaoT2 = ( yP3 - yP1 )/( xP3 - xP1 );
if (RazaoT2 > 0 && RazaoT1 - TOLERANCIA < RazaoT2 && RazaoT1 + TOLERANCIA > RazaoT2)
return static_cast<QwtPlotCurve *>( curves[i] );
}
}
return NULL;
}
const QPointF CLASS::transformWindowToCanvas( const QPoint& _pos ) const
{
const QwtPlot* pPlot = this->plot();
const double dX = pPlot->canvasMap( QwtPlot::xBottom ).invTransform( _pos.x() );
const double dY = pPlot->canvasMap( QwtPlot::yLeft ).invTransform( _pos.y() );
return QPointF(dX, dY);
}
I hope I have helped
Bookmarks