Results 1 to 8 of 8

Thread: Looking for advices to do a ruler plus other questions

  1. #1
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Looking for advices to do a ruler plus other questions

    Hi,
    It is my very first post in the Qt center I'll try to be clear.
    I have 3 questions.

    First question:
    My plot represents a sky view of a map XY. I would like to create a ruler to compute distance between to points a(x1,y1) and b(x2,y2).
    And I need also a way to draw one line from point a to point b when the ruler is activated.
    I was hesitating between 2 possibilities:
    - First way: use a QwtPlotPicker in polygon state machine. But I couldn't find a good example of how to manage the appended and selected signals. And in my case I don't really need several lines but just ONE line.
    - Second way: Create my own QwtPlotItem that use a QwtPlotPicker with click machine and manage first and second click to compute distances and draw the line.

    If their is a smarter way to do this I would like to know.
    Hoping a ruler tool could be provided by default in qwt library.


    Second question:
    Is there a way to change the mouse shape or color? I would like to make it a little bit transparent.


    Last question:
    This is a general question since I'm new in Qt.
    When we do something like:
    setStateMachine(new QwtPickerTrackerMachine());
    or
    setSymbol(ptr_symbol);
    or
    setValidator(new QDoubleValidator()); (for a QLineEdit)

    who is in charge of deleting the pointers?
    Thanks by advance.

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

    Default Re: Looking for advices to do a ruler plus other questions

    Qt Code:
    1. class PickerDragLineMachine: public QwtPickerMachine
    2. {
    3. public:
    4. PickerDragLineMachine():
    5. QwtPickerMachine( PolygonSelection )
    6. {
    7. }
    8.  
    9. virtual QList<Command> transition(
    10. const QwtEventPattern &eventPattern, const QEvent *event )
    11. {
    12. QList<QwtPickerMachine::Command> cmdList;
    13.  
    14. if ( event->type() == QEvent::MouseButtonPress )
    15. {
    16. if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
    17. static_cast<const QMouseEvent *>( event ) ) )
    18. {
    19. if ( state() == 0 )
    20. {
    21. cmdList += Begin;
    22. cmdList += Append;
    23. cmdList += Append;
    24. setState( 1 );
    25. }
    26. }
    27. }
    28. else if ( event->type() == QEvent::MouseMove )
    29. {
    30. if ( state() != 0 )
    31. cmdList += Move;
    32. }
    33. else if ( event->type() == QEvent::MouseButtonRelease )
    34. {
    35. if ( state() != 0 )
    36. {
    37. cmdList += End;
    38. setState( 0 );
    39. }
    40. }
    41.  
    42. return cmdList;
    43. }
    44. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. class DistancePicker: public QwtPlotPicker
    2. {
    3. public:
    4. DistancePicker( QWidget *canvas ):
    5. QwtPlotPicker( canvas )
    6. {
    7. setTrackerMode( QwtPicker::ActiveOnly );
    8. setStateMachine( new PickerDragLineMachine() );
    9. setMousePattern( QwtEventPattern::MouseSelect1, Qt::LeftButton );
    10. setRubberBand( QwtPlotPicker::PolygonRubberBand );
    11. }
    12.  
    13. virtual QwtText trackerTextF( const QPointF &pos ) const
    14. {
    15. QwtText text;
    16.  
    17. const QPolygon points = selection();
    18. if ( !points.isEmpty() )
    19. {
    20. QString num;
    21. num.setNum( QLineF( pos, invTransform( points[0] ) ).length() );
    22.  
    23. QColor bg( Qt::white );
    24. bg.setAlpha( 200 );
    25.  
    26. text.setBackgroundBrush( QBrush( bg ) );
    27. text.setText( num );
    28. }
    29. return text;
    30. }
    31. };
    To copy to clipboard, switch view to plain text mode 
    HTH,
    Uwe

  3. The following user says thank you to Uwe for this useful post:

    raphael.lencrerot (10th March 2013)

  4. #3
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Looking for advices to do a ruler plus other questions

    Thank you so much for this.
    Is It possible to put these lines in further examples provided by the library in such a way that users can see how we can easily implement our own pickermachine then our own pickeritem.

    Just one question, why their is 2 times append in cmdlist?

    Thanks again uwe.

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

    Default Re: Looking for advices to do a ruler plus other questions

    Quote Originally Posted by raphael.lencrerot View Post
    Is It possible to put these lines in further examples provided by the library in such a way that users can see how we can easily implement our own pickermachine then our own pickeritem.
    This example doesn't contain more information than what you have had when looking at the implementation of any picker machine. In fact I did nothing else than copying the transition method from 2 existing machines.

    Quote Originally Posted by raphael.lencrerot View Post
    Just one question, why their is 2 times append in cmdlist?
    Because a line consists of 2 points - the second one gets moved by mouse move events.

    Uwe

  6. #5
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Looking for advices to do a ruler plus other questions

    Ok,
    thanks again.

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

    Default Re: Looking for advices to do a ruler plus other questions

    I have added QwtPickerDragLineMachine to SVN trunk - the scatterplot example shows an implementation of a picker for distance measurements using it.

    Uwe

  8. #7
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Looking for advices to do a ruler plus other questions

    Nice !
    My plotting software is almost finished. I'll will then integrate this change ASAP to reduce lines code.

    Thanks again for your hard work.

  9. #8
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Looking for advices to do a ruler plus other questions

    @Uwe
    Would you please, set what are the includes we have to used to get the code posted to compile ? and would you add some expmle to show how to use??

    thanks.

    I have added these #includes:

    #include <QtCore>
    #include <qwt_picker_machine.h>
    #include <qevent.h>

    still getting this error
    PickerDragLineMachin.cpp:24: error: invalid use of incomplete type 'const struct QwtEventPattern'


    Added after 1 22 minutes:


    Thanks It was clear, I was just blinded i guess.

    add :
    #include <QtCore>
    #include <qwt_picker_machine.h>
    #include <qevent.h>
    #include <qwt_event_pattern.h>

    in PickerDragLineMachin
    and
    #include <QtCore>
    #include <qwt_text.h>
    #include <qwt_plot_picker.h>
    #include "PickerDragLineMachin.h"

    now its working great.

    Thank you so much for you code and your effort, It is a real help.
    best regards,

    Jesse.
    Last edited by jesse_mark; 6th February 2015 at 00:15.

Similar Threads

  1. Need advices for build and print document.
    By cydside in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2011, 21:29
  2. ruler in text area
    By santhosh in forum Newbie
    Replies: 1
    Last Post: 25th March 2011, 12:52
  3. QPainter and complex drawing : advices
    By toutarrive in forum Qt Programming
    Replies: 0
    Last Post: 18th November 2009, 11:51
  4. Advices for animating drawing of a QPainterPath?
    By Gnurou in forum Qt Programming
    Replies: 0
    Last Post: 4th July 2008, 16:17
  5. Help,I want to make a ruler,all the code is here
    By duduqq in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2008, 08:08

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.