
Originally Posted by
Uwe
The event_filter example does this more or less - even if this example is outdated and I wouldn't recommend to copy its code. But at least CanvasPicker::select shows how to identify a curve and its point corresponding to a mouse position.
Also similar - and more up to date - is the curvetracker example in Qwt 6.1. The itemeditor example might also be of interest, showing how to select and drag plot items on the canvas.
Uwe
Hi, Uwe
I greatly appreciate your reply.
I had read the example code. I still have a small confusion:
code from CanvasPicker
const QwtPlotItemList& itmList = plot()->itemList();
for ( QwtPlotItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
{
double d;
int idx = c->closestPoint( pos, &d );
if ( d < dist )
{
curve = c;
index = idx;
dist = d;
}
}
}
const QwtPlotItemList& itmList = plot()->itemList();
for ( QwtPlotItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotCurve )
{
QwtPlotCurve *c = static_cast<QwtPlotCurve *>( *it );
double d;
int idx = c->closestPoint( pos, &d );
if ( d < dist )
{
curve = c;
index = idx;
dist = d;
}
}
}
To copy to clipboard, switch view to plain text mode
the for loop efficency is very low. In my situation, there will be as many curves as the user want (large number of curves) and meanwhile, I was told that closestPoint() is also low efficent. Any better ideas?
Considering the problem of curve crossing, this loop only can return one curve.(I think I am able to fix this problem by return a vector or sth like that)
Thank you in advance.
Bookmarks