PDA

View Full Version : QwtPlotPicker::getInvTransform does not map to correct plot coordinates



hakiim35
12th May 2011, 08:05
Hello, I am implementing a curve widget in which the user can drag the curve by mouse move operations. The problem is the returned x dimension is not accurate in plot coordinates, there is no problem in the mapped y coordinate. There is always a shift or gap in the x dimension of the selected point(I guess this gap is about the width of the y-Axis ruler), please see the problem and the gap in my image attachment. Also I attach the code below.
I am using QwtPlotPicker::getInvTransform as,


class myCurveWidget : public QwtPlot
{
/////////
}

class myCurvePicker : public QwtPlotPicker
{
//////////
}

QPointF myCurveWidget::mapMousePoint(QPoint mousePoint)
{
myCurvePicker picker(this->canvas());

QPointF mappedPt = picker.getInvTransform(mousePoint);

if(mappedPt.x() < 0)
mappedPt.setX(0);
else if(mappedPt.x() > 255)
mappedPt.setX(255);
if(mappedPt.y() < 0)
mappedPt.setY(0);
else if(mappedPt.y() > 255)
mappedPt.setY(255);

return mappedPt;
}

How can I map to exact plot coordinates?

Uwe
13th May 2011, 17:35
I am using QwtPlotPicker::getInvTransform ...
This method doesn't exist in the Qwt library.

Uwe

hakiim35
15th May 2011, 17:09
Strange. I am using the 5.2.1 version and it does exist in that version. So what would you advise me to use?

Troudhyl
15th May 2011, 17:13
The last version I think ^^.

Uwe
15th May 2011, 17:23
Strange. I am using the 5.2.1 version and it does exist in that version. So what would you advise me to use?

QwtPlotPicker has a method invTransform - if you see a method getInvTransform you are probably working with a version, that has been patched by someone. Try to find the author of this patch and ask him/her what it is about.

Uwe

hakiim35
16th May 2011, 06:47
Ok, I think I must explain where getInvTransform() comes from. As you said QwtPlotPicker has invTransform() method, but it is protected so I can't call it from my other classes, so the method getInvTransform() is a very simple public method calling invTransform() of its basic class 'QwtPlotPicker', so that other classes can use it.
So, now, do you have any idea about why invTransform() returns x-value including the width of y-axis ruler part?

FelixB
16th May 2011, 10:11
use


QPointF mappedPt = picker.getInvTransform(mousePoint) - picker.getInvTransform(0);

hakiim35
16th May 2011, 12:46
Hello, I tried but it didnt give correct result. I guess, the value you subtracted is the zero point in pixel coordinates, but I want to get the zero point in plot coordinates..

Uwe
16th May 2011, 15:55
Don't use a picker here - it's a QObject, that needs event processing - something, that is not happening the way you wrote your code.

Instead do something like this:


QPointF myCurveWidget::mapMousePoint(QPoint mousePoint)
{
const double x = canvasMap( QwtPlot::xBottom ).invTransform( mousePoint.x() );
const double y = canvasMap( QwtPlot::yLeft ).invTransform( mousePoint.y() );

...
}

I'm not 100% sure if this already solves your problem, but at least it's better than using a picker and it should be easier to find out what is going on. If the bug is still there you should check p1, p2, s1, s2 of the maps to see if there are pending updates of the scales because of a missing replot.

Uwe

hakiim35
17th May 2011, 09:04
Hello, it didnt help either..but I will try to investigate it deeper..
By the way, isnt it possible to retrieve the width of the vertical ruler on the left part of the widget?

Uwe
17th May 2011, 09:47
Hello, it didnt help either..but I will try to investigate it deeper..
Again: check p1, p2, s1, s2 !

Uwe