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:
Code:
// .h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
{
Q_OBJECT
public:
~MainWindow();
public slots:
void curve1( void );
void curve2( void );
private:
};
#endif // MAINWINDOW_H
Code:
// .cpp
#include "mainwindow.h"
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_zoomer.h>
#include <QToolBar>
MainWindow
::MainWindow( QWidget* parent
) :
zoomer( NULL )
{
QToolBar* bar
= this
->addToolBar
( "Tools" );
bar->addAction( "Add Curve 1", this, SLOT( curve1() ) );
bar->addAction( "Add Curve 2", this, SLOT( curve2() ) );
this
->plot
->setAxisAutoScale
( QwtPlot::xBottom );
this->setCentralWidget( this->plot );
}
MainWindow::~MainWindow()
{
}
void MainWindow::curve1( void )
{
int size = 1000;
for( int i = 0; i < size; i++ )
{
}
c->setSamples( poly );
c->attach( this->plot );
this->zoomer->zoom( 0 );
this->zoomer->setZoomBase();
}
void MainWindow::curve2( void )
{
int size = 2000;
for( int i = 0; i < size; i++ )
{
poly <<
QPointF(i, i < size
/2 ? i
: size
/2 - i
);
}
c->setSamples( poly );
c->attach( this->plot );
this->zoomer->zoom( 0 );
this->zoomer->setZoomBase();
}
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!
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