Results 1 to 2 of 2

Thread: How to correctly use zoomer when adding new curves?

  1. #1
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default How to correctly use zoomer when adding new curves?

    Guys,

    In my application plot can be zoomed in and out.
    User can also add/remove curves when he wants.
    Problem I see is that in certain cases zoomer doesn't update correctly it's zoom base.

    I've created sample to demostrate this problem:
    Qt Code:
    1. // .h
    2. #ifndef MAINWINDOW_H
    3. #define MAINWINDOW_H
    4.  
    5. #include <QtGui/QMainWindow>
    6.  
    7. class QwtPlot;
    8.  
    9. class MainWindow : public QMainWindow
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. MainWindow( QWidget* parent = 0 );
    15. ~MainWindow();
    16.  
    17. public slots:
    18. void curve1( void );
    19. void curve2( void );
    20.  
    21. private:
    22. QwtPlot* plot;
    23. QwtPlotZoomer* zoomer;
    24. };
    25.  
    26. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // .cpp
    2. #include "mainwindow.h"
    3.  
    4. #include <qwt_plot.h>
    5. #include <qwt_plot_curve.h>
    6. #include <qwt_plot_zoomer.h>
    7.  
    8. #include <QToolBar>
    9.  
    10. MainWindow::MainWindow( QWidget* parent )
    11. :
    12. QMainWindow( parent ),
    13. plot( new QwtPlot( this ) ),
    14. zoomer( NULL )
    15. {
    16. QToolBar* bar = this->addToolBar( "Tools" );
    17. bar->addAction( "Add Curve 1", this, SLOT( curve1() ) );
    18. bar->addAction( "Add Curve 2", this, SLOT( curve2() ) );
    19.  
    20. this->zoomer = new QwtPlotZoomer( this->plot->canvas() );
    21.  
    22. this->plot->setAxisAutoScale( QwtPlot::xBottom );
    23.  
    24. this->setCentralWidget( this->plot );
    25. }
    26.  
    27. MainWindow::~MainWindow()
    28. {
    29.  
    30. }
    31.  
    32. void MainWindow::curve1( void )
    33. {
    34. int size = 1000;
    35. QPolygonF poly;
    36. for( int i = 0; i < size; i++ )
    37. {
    38. poly << QPointF(i, 0);
    39. }
    40.  
    41. c->setSamples( poly );
    42. c->attach( this->plot );
    43.  
    44. this->zoomer->zoom( 0 );
    45. this->zoomer->setZoomBase();
    46. }
    47.  
    48. void MainWindow::curve2( void )
    49. {
    50. int size = 2000;
    51. QPolygonF poly;
    52. for( int i = 0; i < size; i++ )
    53. {
    54. poly << QPointF(i, i < size/2 ? i : size/2 - i );
    55. }
    56.  
    57. c->setSamples( poly );
    58. c->attach( this->plot );
    59.  
    60. this->zoomer->zoom( 0 );
    61. this->zoomer->setZoomBase();
    62. }
    To copy to clipboard, switch view to plain text mode 

    I've tested it using both Qwt 5.2.0 and 6.0.1 and here's what I get:
    1.
    - add curve 1
    - add curve 2
    - zoom in and out
    * everything is fine

    2.
    - add curve 1
    - zoom in
    - add curve 2
    * you're stuck at curve 1 zoom base

    What I am doing wrong?

    What I want is to be able to add smaller/larger curves to the plot and update zoomer zoom base correctly.
    It would be nice if that could be done without zooming out to the base level and losing current zoom stack.

    I appreciate any suggestions.

    Cheers!

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

    Default Re: How to correctly use zoomer when adding new curves?

    This has been answered many, many times: please check the archive of the forum.

    Uwe

Similar Threads

  1. replot in Qwt Zoomer
    By ruzik in forum Qwt
    Replies: 2
    Last Post: 22nd September 2011, 18:42
  2. Replies: 1
    Last Post: 2nd May 2010, 18:27
  3. Replies: 5
    Last Post: 18th March 2010, 09:54
  4. zoomer in spectrogram example
    By rambo83 in forum Qwt
    Replies: 0
    Last Post: 1st December 2009, 09:06
  5. how could the value in every grid after zoomer?
    By matt_atlantis in forum Qwt
    Replies: 1
    Last Post: 29th July 2009, 01:26

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.