Results 1 to 2 of 2

Thread: Make a partial replot using reimplemented QwtPlot::replot()

  1. #1
    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 Make a partial replot using reimplemented QwtPlot::replot()

    Hello!

    Is there a way for doing a partial replot using a reimplemented QwtPlot::replot()? This partial replot would be essentially to tell which area of the graph I want to be reploted instead of the entire canvas.

    I noticed the code for QwtPlot::replot() in 6.1.0 is:

    Qt Code:
    1. void QwtPlot::replot()
    2. {
    3. bool doAutoReplot = autoReplot();
    4. setAutoReplot( false );
    5.  
    6. updateAxes();
    7.  
    8. /*
    9.   Maybe the layout needs to be updated, because of changed
    10.   axes labels. We need to process them here before painting
    11.   to avoid that scales and canvas get out of sync.
    12.   */
    13. QApplication::sendPostedEvents( this, QEvent::LayoutRequest );
    14.  
    15. if ( d_data->canvas )
    16. {
    17. const bool ok = QMetaObject::invokeMethod(
    18. d_data->canvas, "replot", Qt::DirectConnection );
    19. if ( !ok )
    20. {
    21. // fallback, when canvas has no a replot method
    22. d_data->canvas->update( d_data->canvas->contentsRect() );
    23. }
    24. }
    25.  
    26. setAutoReplot( doAutoReplot );
    27. }
    To copy to clipboard, switch view to plain text mode 

    When I tried, the problems arised when considering the "replot" method of the canvas:

    Qt Code:
    1. void QwtPlotCanvas::replot()
    2. {
    3. invalidateBackingStore();
    4.  
    5. if ( testPaintAttribute( QwtPlotCanvas::ImmediatePaint ) )
    6. repaint( contentsRect() );
    7. else
    8. update( contentsRect() );
    9. }
    To copy to clipboard, switch view to plain text mode 

    If I understood correctly, I'll have to create a new QwtPlotCanvas for my custom QwtPlot with a reimplemented replot() method in which instead of using contentsRect(), I'll use a QRect with customized form previously set by a new method.

    Is this all ok or did I miss something?


    Thanks,

    Momergil
    May the Lord be with you. Always.

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

    Default Re: Make a partial replot using reimplemented QwtPlot::replot()

    Assuming that you have new curve points in the area [x1,x2] ( in plot coordinates ) and the backingstore ( QwtPlotCanvas::BackingStore ) of the canvas is disabled:

    Qt Code:
    1. void updatePlot( QwtPlot* plot, double x1, double x2 )
    2. {
    3. const QwtScaleMap xMap = plot->canvasMap( QwtPlot::xBottom );
    4.  
    5. const int l = xMap.transform( x1 );
    6. const int r = xMap.transform( x2 );
    7. const QRect cr = plot->canvas()->contentsRect();
    8.  
    9. plot->canvas()->repaint( l, cr.y(), r - l, cr,height() );
    10. }
    To copy to clipboard, switch view to plain text mode 
    The rectangle you have passed to the paint event will end up as clip region of the painter and you could overload QwtPlot::drawItems():

    Qt Code:
    1. virtual void YourPlot::drawItems( QPainter *painter, const QRectF &canvasRect,
    2. const QwtScaleMap maps[axisCnt] ) const
    3. {
    4. const QRectF rect = painter->clipRegion().boundingRect();
    5.  
    6. // rect should have been filled with the background of the canvas
    7. // before. When you have other plot items ( f.e. a grid ) you have to restore
    8. // them for rect() too.
    9.  
    10. ...
    11.  
    12. double x1 = maps[curve->xAxis()].invTransform( rect.x() );
    13. double x2 = maps[curve->xAxis()].invTransform( rect.x() + rect.width() );
    14.  
    15. // find the segment of your curve for [x1, x2]
    16. // f.e. using qwtUpperSampleIndex() ?
    17.  
    18. int from = ...;
    19. int to = ...
    20.  
    21. curve->drawSeries( painter,
    22. maps[curve->xAxis()], maps[curve->yAxis()], canvasRect, from, to );
    23. }
    To copy to clipboard, switch view to plain text mode 

    You could try to use QwtPlotGLCanvas, that offers hardware acceleration and its limitations should be no big issue for your type of application. For QwtPlotCanvas ( = anything derived from QWidget ) there is only Qt4/X11 ( native graphicssystem ) where you have hardware acceleration.

    Uwe

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

    Momergil (14th May 2014)

Similar Threads

  1. QwtPlot::replot() won't clear current plot
    By Mindstormer in forum Qwt
    Replies: 6
    Last Post: 21st March 2014, 09:30
  2. the replot of a qwtPlot is too slow
    By gaia86 in forum Qwt
    Replies: 3
    Last Post: 4th April 2012, 08:33
  3. the replot of a qwtPlot is too slow
    By gaia86 in forum Qwt
    Replies: 1
    Last Post: 3rd April 2012, 16:54
  4. the replot of a qwtPlot is too slow
    By gaia86 in forum Qwt
    Replies: 0
    Last Post: 3rd April 2012, 15:19
  5. Replies: 1
    Last Post: 4th November 2009, 22:14

Tags for this Thread

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.