Results 1 to 7 of 7

Thread: Convert panned() parameters to plot values

  1. #1
    Join Date
    May 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Convert panned() parameters to plot values

    Hi,

    I am using a QwtPlotPanner to pan a plot.
    I connect to the QwtPlotPanner:anned(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:
    Qt Code:
    1. double dxInv = plot->invTransform(QwtPlot::xBottom, dx);
    2. qDebug() << "dx : " << dx;
    3. qDebug() << "dxInv: " << dxInv;
    To copy to clipboard, switch view to plain text mode 
    and the output is:
    Qt Code:
    1. dx : -81
    2. dxInv: 49.768
    To copy to clipboard, switch view to plain text mode 
    If I pan 10 units I get:
    Qt Code:
    1. dx : -159
    2. dxInv: 49.8353
    To copy to clipboard, switch view to plain text mode 

    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,

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  3. #3
    Join Date
    May 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert panned() parameters to plot values

    Some more investigation:
    My code
    Qt Code:
    1. const QwtScaleMap map = d->plot->canvasMap( QwtPlot::xBottom );
    2. qDebug() << "<<<<<<<<<<<<<<<<<";
    3. qDebug() << "Left (p): " << d->plot->canvas()->rect().left();
    4. qDebug() << "Right (p): " << d->plot->canvas()->rect().width();
    5. qDebug() << "Left : " << d->plot->invTransform(QwtPlot::xBottom, 0);
    6. qDebug() << "Right: " << d->plot->invTransform(QwtPlot::xBottom, d->plot->canvas()->rect().width());
    7. qDebug() << "dx (p): " << dx;
    8. qDebug() << "dx : " << d->plot->invTransform(QwtPlot::xBottom, fabs(dx));
    To copy to clipboard, switch view to plain text mode 

    Output after moving 5 units:
    Qt Code:
    1. <<<<<<<<<<<<<<<<<
    2. Left (p): 0
    3. Right (p): 502
    4. Left : 14.6537
    5. Right: 45.3258
    6. dx (p): -81
    7. dx : 19.6028
    To copy to clipboard, switch view to plain text mode 

    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?

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  5. #5
    Join Date
    May 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:
    Qt Code:
    1. const double p1 = map.transform( d->plot->axisScaleDiv( QwtPlot::xBottom ).lowerBound() );
    2. const double p2 = map.transform( d->plot->axisScaleDiv( QwtPlot::xBottom ).upperBound() );
    3.  
    4. double d1, d2;
    5. d1 = map.invTransform( p1 - dx );
    6. d2 = map.invTransform( p2 - dx );
    7. qDebug() << "d1: " << d1;
    8. qDebug() << "d2: " << d2;
    To copy to clipboard, switch view to plain text mode 
    Moving again 5 units in 1 direction I get:
    Qt Code:
    1. d1: 19.9083
    2. d2: 49.9083
    To copy to clipboard, switch view to plain text mode 
    and in the other direction 5 units:
    Qt Code:
    1. d1: 0.214057
    2. d2: 30.2141
    To copy to clipboard, switch view to plain text mode 

    I am still not sure how those values map to my plots...

  6. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Convert panned() parameters to plot values

    In case of a linear scale, this is probably what you want:

    Qt Code:
    1. const QwtScaleMap map = plot->canvasMap( QwtPlot::xBottom );
    2. double xOff = map.invTransform( dx ) - map.invTransform( 0 );
    To copy to clipboard, switch view to plain text mode 

    Uwe

  7. #7
    Join Date
    May 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert panned() parameters to plot values

    Quote Originally Posted by Uwe View Post
    In case of a linear scale, this is probably what you want:

    Qt Code:
    1. const QwtScaleMap map = plot->canvasMap( QwtPlot::xBottom );
    2. double xOff = map.invTransform( dx ) - map.invTransform( 0 );
    To copy to clipboard, switch view to plain text mode 

    Uwe
    Well that was simple enough

    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,

Similar Threads

  1. Replies: 6
    Last Post: 1st February 2013, 08:32
  2. How to convert string hex values to its real binary values?
    By AttilaPethe in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2012, 22:47
  3. Replies: 4
    Last Post: 3rd May 2009, 18:32
  4. Replies: 1
    Last Post: 22nd May 2008, 15:10
  5. convert string to byte values
    By steg90 in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2007, 14:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.