Results 1 to 8 of 8

Thread: QwtPlotPicker problem with QTimer

  1. #1
    Join Date
    Jun 2012
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default QwtPlotPicker problem with QTimer

    I have created my own curvetracker. My intention is to execute trackerTextF virtual function but it would be processed within time limits. So if user moves more tracer is updated max 10times/second. So timer interval is 100ms.

    For some reason i'm getting slot error:

    Object::connect: No such slot QwtPlotPicker::tracked() in \src\curvetracker.cpp:27

    I can't see any problem in my code


    CurveTracker.h

    Qt Code:
    1.  
    2. class CurveTracker: public QwtPlotPicker
    3. {
    4. public:
    5. CurveTracker( QWidget * );
    6.  
    7. protected:
    8. virtual QwtText trackerTextF( const QPointF & ) const;
    9. virtual QRect trackerRect( const QFont & ) const;
    10.  
    11. public slots:
    12. void tracked();
    13.  
    14.  
    15. protected:
    16. QTimer* timer;
    17.  
    18. private:
    19. QString curveInfoAt( const CustomQwtCurve *, const QPointF & ) const;
    20. QLineF curveLineAt( const CustomQwtCurve *, double x ) const;
    21. };
    To copy to clipboard, switch view to plain text mode 

    CurveTracker.cpp

    Qt Code:
    1. CurveTracker::CurveTracker( QWidget *canvas ):
    2. QwtPlotPicker( canvas )
    3. {
    4. setTrackerMode( QwtPlotPicker::ActiveOnly );
    5. setRubberBand( CrossRubberBand);
    6. setStateMachine( new QwtPickerDragPointMachine() );
    7.  
    8. timer=new QTimer(this);
    9. connect(timer,SIGNAL(timeout()), this, SLOT(tracked()));
    10. timer->start(100);
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QwtPlotPicker problem with QTimer

    Y ou have to add the QOBJECT macro and run moc.

    Uwe

  3. #3
    Join Date
    Jun 2012
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: QwtPlotPicker problem with QTimer

    Thanks! It works..

    but I can't resolve my problem.. I don't know how to use timer properly here. Can you help ? I want to update trackerText maximum of 10 times per second. I have so many polygons it takes too much CPU when user drags mouse over them. Since I have to return QwtText in trackerTextF it becomes a problem to use timer. Or I don't know how to do it..Thanks.

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

    Default Re: QwtPlotPicker problem with QTimer

    Quote Originally Posted by phenoboy View Post
    I have so many polygons it takes too much CPU when user drags mouse over them.
    For drawing the tracker text the number of polygons doesn't matter, so I assume the time gets lost when trying to find the information you want to display.
    Second guess: you are iterating over all points to find some information.

    Before trying to continue with your timer approach I would have a look if you can't improve the performance of finding the info. F.e. are your points ordered in x or y direction ?

    Uwe

  5. #5
    Join Date
    Jun 2012
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: QwtPlotPicker problem with QTimer

    Hello Uwe. Thanks for reply.

    I'm using code from playground\curvetracker basically which is basically unmodified. So I guess I need to look at function 'QwtText trackerTextF(const QPointF& pos) ' since it is iterating over points. Any ideas how to make it faster? Points are ordered in x direction.

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

    Default Re: QwtPlotPicker problem with QTimer

    This code iterates over all curves, but finds the points using qwtUpperSampleIndex, what is a binary search algo ( should be no performance issue: O(log n) ) using the sorted order of the points. So beside you have trillions of curves there should be no performance problem with this code. As the tracker text itself is painted as widget overlay on top of the plot ( without having to replot, as long as you didn't disable the canvas cache ) this won't also be a perfrormance issue.


    • How is the performance when you simply return QwtPlotPicker::trackerTextF() ?
    • Do you do any other updates of your user interface according to the mouse movements ?
    • Also check if you run into replots by accident, when moving the mouse.


    Uwe

  7. #7
    Join Date
    Jun 2012
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: QwtPlotPicker problem with QTimer

    Quote Originally Posted by Uwe View Post
    This code iterates over all curves, but finds the points using qwtUpperSampleIndex, what is a binary search algo ( should be no performance issue: O(log n) ) using the sorted order of the points. So beside you have trillions of curves there should be no performance problem with this code. As the tracker text itself is painted as widget overlay on top of the plot ( without having to replot, as long as you didn't disable the canvas cache ) this won't also be a perfrormance issue.


    • How is the performance when you simply return QwtPlotPicker::trackerTextF() ?
    • Do you do any other updates of your user interface according to the mouse movements ?
    • Also check if you run into replots by accident, when moving the mouse.


    Uwe

    Thanks for help. Actually I found out that my plot is drawing and adding items to curve at about 1000items (values) / second. That is the reason to slow down. I have now separated adding items (can be of rate 1000 items/sec or even higher ) and redrawing. Redrawing happens now at 50 fps and now there is no performance issues at all. tracerTextF function is very fast.

    what do you suggest is the best way to replot whot plot after dragging mouse and when tracerTextF() is called ?

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

    Default Re: QwtPlotPicker problem with QTimer

    Quote Originally Posted by phenoboy View Post
    what do you suggest is the best way to replot whot plot after dragging mouse and when tracerTextF() is called ?
    The picker draws the text to a widget overlay, not to the plot canvas, so there is no replot on mouse movements. When you didn't disable the canvas baclking store the area below the previous text rect will be restored from it.
    So there is no best way as nothing is going on, that is of relevance in terms of being performance critical.

    Uwe

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

    phenoboy (10th March 2015)

Similar Threads

  1. Replies: 3
    Last Post: 22nd October 2013, 09:57
  2. Replies: 15
    Last Post: 4th August 2012, 19:11
  3. Replies: 3
    Last Post: 5th January 2011, 07:54
  4. Replies: 14
    Last Post: 20th April 2010, 11:40
  5. Problem with QTimer under Win XP
    By wzielj in forum Qt Programming
    Replies: 9
    Last Post: 26th January 2009, 14:04

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
  •  
Qt is a trademark of The Qt Company.