#include <QWidget>
class QwtPlotRescaler;
{
Q_OBJECT
public:
private:
QwtPlotRescaler* rescaler;
private slots:
void switchData();
};
#include <QWidget>
class QPushButton;
class QHBoxLayout;
class QwtPlot;
class QwtPlotCurve;
class QwtPlotRescaler;
class Window : public QWidget
{
Q_OBJECT
public:
Window( QWidget* parent = 0 );
private:
QwtPlot* plot;
QwtPlotCurve* curve;
QwtPlotRescaler* rescaler;
QPushButton* switchDataButton;
QHBoxLayout* layout;
private slots:
void switchData();
};
To copy to clipboard, switch view to plain text mode
main.cpp:
#include "main.h"
#include "qwt_plot.h"
#include "qwt_plot_curve.h"
#include "qwt_plot_rescaler.h"
#include <QtGui>
const double HI = 20.0;
const double LO = 10.0;
const int N = 5;
const double DATA_HI[] = { 0.0, 0.25*HI, 0.5*HI, 0.75*HI, HI };
const double DATA_LO[] = { 0.0, 0.25*LO, 0.5*LO, 0.75*LO, LO };
{
resize( 400, 500 );
curve->setData( DATA_HI, DATA_HI, N );
curve->attach( plot );
rescaler = new QwtPlotRescaler( plot->canvas() );
rescaler->setRescalePolicy( QwtPlotRescaler::Fitting );
switchDataButton
= new QPushButton( "Switch data",
this );
connect( switchDataButton, SIGNAL( clicked() ),
this, SLOT( switchData() ) );
layout->addWidget( plot );
layout->addWidget( switchDataButton );
setLayout( layout );
plot->replot();
}
void Window::switchData()
{
if ( curve->maxYValue() > LO ) curve->setData( DATA_LO, DATA_LO, N );
else curve->setData( DATA_HI, DATA_HI, N );
plot->updateAxes(); // This doesn't make a difference that I can tell
plot->replot();
rescaler->rescale();
}
int main( int argc, char* argv[] )
{
Window window;
window.show();
return app.exec();
}
#include "main.h"
#include "qwt_plot.h"
#include "qwt_plot_curve.h"
#include "qwt_plot_rescaler.h"
#include <QtGui>
const double HI = 20.0;
const double LO = 10.0;
const int N = 5;
const double DATA_HI[] = { 0.0, 0.25*HI, 0.5*HI, 0.75*HI, HI };
const double DATA_LO[] = { 0.0, 0.25*LO, 0.5*LO, 0.75*LO, LO };
Window::Window( QWidget* parent ) : QWidget( parent )
{
resize( 400, 500 );
plot = new QwtPlot( this );
curve = new QwtPlotCurve;
curve->setData( DATA_HI, DATA_HI, N );
curve->attach( plot );
rescaler = new QwtPlotRescaler( plot->canvas() );
rescaler->setRescalePolicy( QwtPlotRescaler::Fitting );
switchDataButton = new QPushButton( "Switch data", this );
connect( switchDataButton, SIGNAL( clicked() ),
this, SLOT( switchData() ) );
layout = new QHBoxLayout;
layout->addWidget( plot );
layout->addWidget( switchDataButton );
setLayout( layout );
plot->replot();
}
void Window::switchData()
{
if ( curve->maxYValue() > LO ) curve->setData( DATA_LO, DATA_LO, N );
else curve->setData( DATA_HI, DATA_HI, N );
plot->updateAxes(); // This doesn't make a difference that I can tell
plot->replot();
rescaler->rescale();
}
int main( int argc, char* argv[] )
{
QApplication app( argc, argv );
Window window;
window.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks