View Full Version : Convert panned() parameters to plot values
TheBadger
11th June 2014, 16:39
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:
double dxInv = plot->invTransform(QwtPlot::xBottom, dx);
qDebug() << "dx : " << dx;
qDebug() << "dxInv: " << dxInv;
and the output is:
dx : -81
dxInv: 49.768
If I pan 10 units I get:
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,
You could have a look at the implementation of QwtPlotPanner::moveCanvas ( the slot, that is connected to the panned signal ).
Uwe
TheBadger
13th June 2014, 08:29
Some more investigation:
My code
const QwtScaleMap map = d->plot->canvasMap( QwtPlot::xBottom );
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:
<<<<<<<<<<<<<<<<<
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 (http://qwt.sourceforge.net/class_qwt_panner.html#ae9ce78e6f9ae73317af29b2dc5d f7372) 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?
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
TheBadger
13th June 2014, 08:52
Thanks Uwe, I have looked at the implementation but could not learn anything.
I use the code from there as follow:
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:
d1: 19.9083
d2: 49.9083
and in the other direction 5 units:
d1: 0.214057
d2: 30.2141
I am still not sure how those values map to my plots...
In case of a linear scale, this is probably what you want:
const QwtScaleMap map = plot->canvasMap( QwtPlot::xBottom );
double xOff = map.invTransform( dx ) - map.invTransform( 0 );
Uwe
TheBadger
13th June 2014, 09:54
In case of a linear scale, this is probably what you want:
const QwtScaleMap map = plot->canvasMap( QwtPlot::xBottom );
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,
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.