Results 1 to 9 of 9

Thread: Problem with selecting qwtplotcurve and points on qwtplotcurve

  1. #1
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Problem with selecting qwtplotcurve and points on qwtplotcurve

    Greetings,

    I have several qwtplotcurve attaced on a qwtplot, and it must responds mouseEvent: single left click on the curve to pick up the closest point of the curve, and double left click on curve to select the whole curve. Whatever selected, it should be hightlighted(change the color of the selected point or curve).

    For two days, I searched on google, I got some useful information:

    1. to track a point: use QwtPlotPicker and connect the selected signal with a slot
    2. to find closest point: call QwtPlotCurve::closestPoint()

    My questions are:

    1. QwtPlotPicker is able to track all the points on canvas, but unable to track for a specific area(a rectangle, a line, a circle), only I just want to track the points on the curve, return me the object/pointer of the selected point.

    2. If there is several curve on the plot, how could I tell the point from which curve(the curves may cross each other)

    3. QwtPlotPicker can pick up a point, but how do I do to select a curve? (get the object/pointer of the curve)


    Thank you in advance.


    Tang Tao

  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: Problem with selecting qwtplotcurve and points on qwtplotcurve

    Quote Originally Posted by tangtao_xp View Post
    ... only I just want to track the points on the curve, return me the object/pointer of the selected point.
    The event_filter example does this more or less - even if this example is outdated and I wouldn't recommend to copy its code. But at least CanvasPicker::select shows how to identify a curve and its point corresponding to a mouse position.

    Also similar - and more up to date - is the curvetracker example in Qwt 6.1. The itemeditor example might also be of interest, showing how to select and drag plot items on the canvas.

    Uwe

  3. #3
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with selecting qwtplotcurve and points on qwtplotcurve

    Hi, Uwe

    Sorry for late reply.

    As your said, I will read the example of event_filter & itemeditor first, and give you the feedback soon.


    Tang Tao

  4. #4
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with selecting qwtplotcurve and points on qwtplotcurve

    Quote Originally Posted by Uwe View Post
    The event_filter example does this more or less - even if this example is outdated and I wouldn't recommend to copy its code. But at least CanvasPicker::select shows how to identify a curve and its point corresponding to a mouse position.

    Also similar - and more up to date - is the curvetracker example in Qwt 6.1. The itemeditor example might also be of interest, showing how to select and drag plot items on the canvas.

    Uwe

    Hi, Uwe

    I greatly appreciate your reply.

    I had read the example code. I still have a small confusion:

    code from CanvasPicker
    Qt Code:
    1. const QwtPlotItemList& itmList = plot()->itemList();
    2. for ( QwtPlotItemIterator it = itmList.begin();
    3. it != itmList.end(); ++it )
    4. {
    5. if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotCurve )
    6. {
    7. QwtPlotCurve *c = static_cast<QwtPlotCurve *>( *it );
    8. double d;
    9. int idx = c->closestPoint( pos, &d );
    10. if ( d < dist )
    11. {
    12. curve = c;
    13. index = idx;
    14. dist = d;
    15. }
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    the for loop efficency is very low. In my situation, there will be as many curves as the user want (large number of curves) and meanwhile, I was told that closestPoint() is also low efficent. Any better ideas?

    Considering the problem of curve crossing, this loop only can return one curve.(I think I am able to fix this problem by return a vector or sth like that)

    Thank you in advance.

  5. #5
    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: Problem with selecting qwtplotcurve and points on qwtplotcurve

    When your samples are ordered in x or y direction you can use qwtUpperSampleIndex like in the curvetracker example: the order of this algo is logarithmic instead of linear.

    But when your samples are completely random ( like in a scatter plot ) and iterating over all samples is too slow you need to introduce some spatial index - for example a quad tree.

    Uwe

  6. #6
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with selecting qwtplotcurve and points on qwtplotcurve

    Hi, Uwe

    Thank you very much. I do not think I can do the work without your kindly help.


    Tang Tao

  7. #7
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with selecting qwtplotcurve and points on qwtplotcurve

    here is my code:

    MyPicker.h
    Qt Code:
    1. class MyPicker : public QwtPlotPicker
    2. {
    3. public:
    4. MyPicker( QwtPlot *plot );
    5.  
    6. MyPicker( int xAxis = QwtPlot::xBottom,
    7. int yAxis = QwtPlot::yLeft,
    8. RubberBand rubberBand = CrossRubberBand,
    9. DisplayMode trackerMode = QwtPicker::AlwaysOn,
    10. QwtPlot *plot = NULL );
    11.  
    12. void selectPoint( const QPointF & point );
    13. void highlightPoint( bool isHightlight );
    14.  
    15. public slots:
    16. // slot for SIGNAL --> void selected( const QPointF &pos )
    17. void slotSelected( const QPointF &pos);
    18.  
    19. private:
    20. QwtPlot *m_pQwtPlot;
    21. QwtPlotCurve *m_pSelectedCurve;
    22. int m_selectedPointIndex;
    23. };
    To copy to clipboard, switch view to plain text mode 

    MyPicker.cpp
    Qt Code:
    1. #include "mypicker.h"
    2.  
    3. MyPicker::MyPicker(QwtPlot *plot) :
    4. QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, CrossRubberBand, QwtPicker::AlwaysOn, plot->canvas()),
    5. m_pSelectedCurve( NULL ),
    6. m_pQwtPlot( plot ),
    7. m_selectedPointIndex( -1 )
    8. {
    9. connect( this, SIGNAL( selected( const QPointF ) ), this, SLOT( slotSelected( const QPointF ) ) );
    10. }
    11.  
    12. ...
    To copy to clipboard, switch view to plain text mode 

    the QtCreator shows error:
    -----------------------------------------------------------------------------------------------------

    QObject::connect: No such slot QwtPlotPicker::slotSelected( const QPointF ) in ..\ttt\mypicker.cpp:9

    -----------------------------------------------------------------------------------------------------

    I think the problem caused by that: SIGANL selected() defined in parent class, and SLOT slotSelected() defined in subclass.

    So, how should fix the problem? Thank you in advance.

  8. #8
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with selecting qwtplotcurve and points on qwtplotcurve

    Quote Originally Posted by tangtao_xp View Post
    here is my code:

    MyPicker.h
    Qt Code:
    1. class MyPicker : public QwtPlotPicker
    2. {
    3. public:
    4. MyPicker( QwtPlot *plot );
    5.  
    6. MyPicker( int xAxis = QwtPlot::xBottom,
    7. int yAxis = QwtPlot::yLeft,
    8. RubberBand rubberBand = CrossRubberBand,
    9. DisplayMode trackerMode = QwtPicker::AlwaysOn,
    10. QwtPlot *plot = NULL );
    11.  
    12. void selectPoint( const QPointF & point );
    13. void highlightPoint( bool isHightlight );
    14.  
    15. public slots:
    16. // slot for SIGNAL --> void selected( const QPointF &pos )
    17. void slotSelected( const QPointF &pos);
    18.  
    19. private:
    20. QwtPlot *m_pQwtPlot;
    21. QwtPlotCurve *m_pSelectedCurve;
    22. int m_selectedPointIndex;
    23. };
    To copy to clipboard, switch view to plain text mode 

    MyPicker.cpp
    Qt Code:
    1. #include "mypicker.h"
    2.  
    3. MyPicker::MyPicker(QwtPlot *plot) :
    4. QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, CrossRubberBand, QwtPicker::AlwaysOn, plot->canvas()),
    5. m_pSelectedCurve( NULL ),
    6. m_pQwtPlot( plot ),
    7. m_selectedPointIndex( -1 )
    8. {
    9. connect( this, SIGNAL( selected( const QPointF ) ), this, SLOT( slotSelected( const QPointF ) ) );
    10. }
    11.  
    12. ...
    To copy to clipboard, switch view to plain text mode 

    the QtCreator shows error:
    -----------------------------------------------------------------------------------------------------

    QObject::connect: No such slot QwtPlotPicker::slotSelected( const QPointF ) in ..\ttt\mypicker.cpp:9

    -----------------------------------------------------------------------------------------------------

    I think the problem caused by that: SIGANL selected() defined in parent class, and SLOT slotSelected() defined in subclass.

    So, how should fix the problem? Thank you in advance.

    Done! Q_OBJECT is missing in the header file.

  9. #9
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with selecting qwtplotcurve and points on qwtplotcurve

    Hello tangtao_xp,

    I'm dealing with kind like the same situation of yours, but I confess I'm not as sucessfull like you to understand Qwt's example code regarding selecting and moving a QwtPlotCurve in a QwtPlot. Could you please post your complete code to this solution? (or someone else that happen to have a similar situation)


    Thanks,

    Momergil

Similar Threads

  1. Replies: 8
    Last Post: 18th October 2012, 07:23
  2. Replies: 4
    Last Post: 8th April 2012, 20:25
  3. Replies: 0
    Last Post: 3rd January 2012, 11:16
  4. QwtPlotCurve: maximum number of points ?
    By OverTheOCean in forum Qwt
    Replies: 2
    Last Post: 20th September 2010, 06:42
  5. Selecting a QwtPlotCurve object.
    By mah_singh1 in forum Qwt
    Replies: 1
    Last Post: 21st April 2009, 07:12

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.