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