Results 1 to 8 of 8

Thread: Distance measuring in plot.

  1. #1

    Default Distance measuring in plot.

    Hi,

    I'm trying to create a distance measure tool, that will display the delta X and delta Y values of 2 points within the plot, and draw a line between these two points.

    I started out with some old code from (http://www.qtcentre.org/archive/index.php/t-10367.html). Some changes were needed to get it running in Qwt6.

    Qt Code:
    1. class DistancePicker : public QwtPlotPicker
    2. {
    3. public:
    4. DistancePicker( QwtPlotCanvas * canvas )
    5. :QwtPlotPicker( canvas )
    6. {
    7. setStateMachine( new QwtPickerClickRectMachine );
    8. setRubberBand( PolygonRubberBand );
    9. setTrackerMode( QwtPicker::ActiveOnly );
    10. }
    11.  
    12. protected:
    13. virtual void drawRubberBand(QPainter* painter) const
    14. {
    15. painter->drawPolygon( selection() );
    16. }
    17.  
    18. virtual QwtText trackerText (const QPoint& pos) const
    19. {
    20. const QPolygon& polygon = selection();
    21.  
    22. if ( polygon.size() != 2 )
    23. {
    24. return QwtText();
    25. }
    26.  
    27. const QLineF line(invTransform(polygon[0]), invTransform(polygon[1]));
    28.  
    29. QwtText text( QString::number(line.length()) );
    30.  
    31. QColor bg(Qt::white);
    32. bg.setAlpha(180);
    33. text.setBackgroundBrush(QBrush(bg));
    34.  
    35. return text;
    36. }
    37. };
    To copy to clipboard, switch view to plain text mode 

    While this seems to be working good, i do have a few problems with it.
    1) Depending on where you move the second selection for the measurement, the measurement picker text runs through the default picker that that always displays the current x,y position. Is there something to do about that ?
    2) When we zoom in to the plot, just after releasing the mouse for the zoom action, the plot zooms in to new selection, and then automagically a measurement is started.
    Is it possible to do measurements only when user presses space bar for instance ?

    Thanks for any help !

    TJ
    Last edited by thejester; 5th May 2011 at 07:47.

  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: Distance measuring in plot.

    Quote Originally Posted by thejester View Post
    1) Depending on where you move the second selection for the measurement, the measurement picker text runs through the default picker that that always displays the current x,y position. Is there something to do about that ?
    The implementation of DistancePicker::trackerText is your code. Do you have another picker displaying this text ( f.e. the zoomer ).
    2) When we zoom in to the plot, just after releasing the mouse for the zoom action, the plot zooms in to new selection, and then automagically a measurement is started.
    Maybe you are using the same mouse events for the zoomer and your distance picker. You can redefine them using QwtEventPattern::setMousePattern/setKeyPattern.
    Is it possible to do measurements only when user presses space bar for instance ?
    Use QwtEventPattern::setMousePattern() and redefine the input events for your distance picker.

    Uwe

  3. #3

    Default Re: Distance measuring in plot.

    Indeed the other text that is displayed, belongs to the zoomer. But when I attach the DistancePicker, i have no control over, where exactly, the text is displayed right ? DistancePicker knows nothing about zoomer ? Or am i missing something.

    The zoomer, is a default zoomer. Only changes were made to restrictions on y zoom.

    Since zooming is done with left button, i wanted to add your setMousePattern and select events ONLY when control key pressed and right mouse (instead of the left mouse button). So in constructor i added setMousePattern( QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier );
    But now, measuring is done when control is not pressed, and ignored when it is

    Must be missing something really stupid here, or I might need more coffee.

  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: Distance measuring in plot.

    More coffee !

    Uwe

  5. #5

    Default Re: Distance measuring in plot.

    Instead of more coffee i think i need joint or something.....

    when i throw : setMousePattern( QwtEventPattern::MouseSelect4, Qt::LeftButton, Qt::NoButton ); in the zoomer, and
    setMousePattern( QwtEventPattern::MouseSelect2, Qt::LeftButton, Qt::NoButton ); in the distancepicker

    i would have expected different behavior than described above... ?
    what am i doing wrong ?

  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: Distance measuring in plot.

    Quote Originally Posted by thejester View Post
    Instead of more coffee i think i need joint or something.....
    ... really boring like reading the 2 lines of documentation ?

    QwtPickerClickRectMachine implements a state machine with an input alphabet of 2 symbols:
    • QwtEventPattern::MouseSelect1
    • QwtEventPattern::KeySelect1.


    So don't be surprised, that changing the mouse/key bindings of other symbols doesn't have any effect on this state machine.

    Uwe

  7. #7

    Default Re: Distance measuring in plot.

    Uwe,

    I can understand your frustration, i assume its as big as mine

    You said : Use QwtEventPattern::setMousePattern() and redefine the input events for your distance picker.
    I looked up, where the setMousePattern could be called on, and discovered that QwtPlotPicker is derived from QwtEventPattern. Since my DistancePicker is a QwtPlotPicker i assumed calling the setMousePattern in DistancePicker's constructor would do it.

    I see now that all is handled through the statemachines.

    For me, as qwt newbie, its still confusing why QwtPlotPicker is derived from QwtEventPattern then.

    But anyway, ill create my own QwtPickerClickRectMachine for the distance picker then.

    Thanks for all help !

  8. #8
    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: Distance measuring in plot.

    Quote Originally Posted by thejester View Post
    I see now that all is handled through the statemachines.
    Not all - the picker translates real mouse/key events into something abstract like QwtEventPattern::MouseSelect1 etc. Then this abstract symbol is handled by the state machine.

    You can easily implement your own state machine - f.e, when you want to terminate your selection with a different input as you have started it. But as long as you start and terminate your measurement with the same operations there is no need to implement your own state machine: all you need to do is to redefine QwtEventPattern::MouseSelect1, so that it doesn't interfere with your zoomer.

    You can call the whole system a bit "over-engineered" - but in the end it is very flexible and powerful.

    Something you should always have in mind when you are dealing with open source software: instead of playing hours around with parameters of a method you can always try to look into the implementation of this method.

    Uwe

Similar Threads

  1. Increase the distance between two lines in QTextEdit
    By ansar in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2010, 22:08
  2. Distance Transform on a QImage
    By Franckesh in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2010, 08:58
  3. pixel distance of gaps in scaleWidget
    By KosyakOFF in forum Qwt
    Replies: 1
    Last Post: 3rd November 2008, 10:02
  4. Double click distance
    By jbd in forum Qt Programming
    Replies: 3
    Last Post: 28th December 2007, 22:13
  5. QProgress Bar-Time Measuring
    By aegis in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2007, 16:47

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.