Convert panned() parameters to plot values
Hi,
I am using a QwtPlotPanner to pan a plot.
I connect to the QwtPlotPanner::panned(int,int) signal and in the slot I want to convert the dx value to the corresponding value on the plot.
What I am doing:
I click the plot and pan it by 5 units (by checking the axis values)
Then in my slot I debug a few values as follow:
Code:
double dxInv
= plot
->invTransform
(QwtPlot::xBottom, dx
);
qDebug() << "dx : " << dx;
qDebug() << "dxInv: " << dxInv;
and the output is:
Code:
dx : -81
dxInv: 49.768
If I pan 10 units I get:
Code:
dx : -159
dxInv: 49.8353
What should I do to actually get the panned amount in the coordinates of the axis (5 in the first example and 10 in the second)?
Regards,
Re: Convert panned() parameters to plot values
You could have a look at the implementation of QwtPlotPanner::moveCanvas ( the slot, that is connected to the panned signal ).
Uwe
Re: Convert panned() parameters to plot values
Some more investigation:
My code
Code:
qDebug() << "<<<<<<<<<<<<<<<<<";
qDebug() << "Left (p): " << d->plot->canvas()->rect().left();
qDebug() << "Right (p): " << d->plot->canvas()->rect().width();
qDebug
() <<
"Left : " << d
->plot
->invTransform
(QwtPlot::xBottom,
0);
qDebug
() <<
"Right: " << d
->plot
->invTransform
(QwtPlot::xBottom, d
->plot
->canvas
()->rect
().
width());
qDebug() << "dx (p): " << dx;
qDebug
() <<
"dx : " << d
->plot
->invTransform
(QwtPlot::xBottom,
fabs(dx
));
Output after moving 5 units:
Code:
<<<<<<<<<<<<<<<<<
Left (p): 0
Right (p): 502
Left : 14.6537
Right: 45.3258
dx (p): -81
dx : 19.6028
So my question is, what is dx?
The (limited) documentation says "Offset in horizontal direction", my question is offset from what?
My deductions:
- If left is 0 and right is 502 in pixels(?)
- In my plot axis, left is 14 and right is 45
- So moving 5 units in the units of my plot should be about (+/-)17 pixels(?) in either direction
- Why is the dx then -81, where does that value come from?
Re: Convert panned() parameters to plot values
The panned signal is derived from QwtPanner, that doesn't know about plots and plot coordinates at all. So dx, dy are obviously widget ( = canvas ) coordinates: the offset between the mouse press/release positions ( see QMouseEvent ).
Note that Qwt is open source, meaning, that you always have the option to look into the implementation.
Uwe
Re: Convert panned() parameters to plot values
Thanks Uwe, I have looked at the implementation but could not learn anything.
I use the code from there as follow:
Code:
const double p1
= map.
transform( d
->plot
->axisScaleDiv
( QwtPlot::xBottom ).
lowerBound() );
const double p2
= map.
transform( d
->plot
->axisScaleDiv
( QwtPlot::xBottom ).
upperBound() );
double d1, d2;
d1 = map.invTransform( p1 - dx );
d2 = map.invTransform( p2 - dx );
qDebug() << "d1: " << d1;
qDebug() << "d2: " << d2;
Moving again 5 units in 1 direction I get:
Code:
d1: 19.9083
d2: 49.9083
and in the other direction 5 units:
Code:
d1: 0.214057
d2: 30.2141
I am still not sure how those values map to my plots...
Re: Convert panned() parameters to plot values
In case of a linear scale, this is probably what you want:
Code:
double xOff = map.invTransform( dx ) - map.invTransform( 0 );
Uwe
Re: Convert panned() parameters to plot values
Quote:
Originally Posted by
Uwe
In case of a linear scale, this is probably what you want:
Code:
double xOff = map.invTransform( dx ) - map.invTransform( 0 );
Uwe
Well that was simple enough :D
Thank you very much for the help, it is what I was looking for.
My problem was that I should have used the map to do the transform, and not the plot.
Apart from the struggles now and again, I have to say very well done on this library.
Regards,