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!