PDA

View Full Version : AxisAutoScale is not working



P@u1
5th July 2011, 16:29
Hi,

I wrote a very simple example to test qwt and recognized that the axisautoscale feature does not work for me so far...
Here is the code:


class QwtTest : public QMainWindow
{
Q_OBJECT

public:
QwtTest(QWidget *parent = 0, Qt::WFlags flags = 0);
~QwtTest();

protected:
void timerEvent(QTimerEvent * event);

private:
Ui::QwtTestClass ui;
double * xData_;
double * yData_;
int dataSize_;
int currXPos_;
int sinPos_;
int scaleFac;
QwtPlotCurve curve_;
static const double pi;
};
const double QwtTest::pi = 3.14159265358979323846264338327950;

QwtTest::QwtTest(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags),
currXPos_(0),
sinPos_(0),
scaleFac(1)
{
ui.setupUi(this);
ui.qwtPlot->setAxisAutoScale(QwtPlot::yLeft);
dataSize_ = 200;

xData_ = new double[dataSize_];
yData_ = new double[dataSize_];
for(int i = 0; i < dataSize_; ++i)
{
xData_[i] = double(i);
yData_[i] = sin(2*pi*i/dataSize_);
}
curve_.setRawSamples(xData_, yData_, dataSize_);
curve_.attach(ui.qwtPlot);
ui.qwtPlot->replot();
QObject::startTimer(1000/60);
}

QwtTest::~QwtTest()
{
delete[] xData_;
delete[] yData_;
}

void QwtTest::timerEvent(QTimerEvent * event)
{
for(int i = 0; i < 5; ++i)
{
yData_[currXPos_] = scaleFac*sin(2*pi*sinPos_/(0.169*dataSize_));
++sinPos_;
currXPos_ = (currXPos_ + 1) % dataSize_;
}
++scaleFac;
//ui.qwtPlot->setAxisScale(QwtPlot::yLeft, -1000, 1000);
ui.qwtPlot->replot();
}


I draws a sinus, which is getting bigger and bigger, but unfortunately the autoscale is not working, so after short time most parts of the sinus leave the visible area...
Is the problem maybe, that autoscale does not work together with rawSamples?

When I uncomment the line
//ui.qwtPlot->setAxisScale(QwtPlot::yLeft, -1000, 1000);
I can see how the scale changes, but that should be done automaticully...

Thanks for help in advance!

Uwe
5th July 2011, 17:19
When I uncomment the line
//ui.qwtPlot->setAxisScale(QwtPlot::yLeft, -1000, 1000);
I can see how the scale changes ...
Sure, setting an scale range explicitly disables autoscaling - you can't have both.

Simply read the docs,
Uwe

P@u1
5th July 2011, 18:24
I only added the line after I recognized that autoscale did not work to test if it works if i do it manually.
With "uncomment" i meant removing the "//" :D
With the line commented out it does no autoscale for me.

My suggestion that autoscale just doesent work with setRawSamples was wrong?

Please help :-)

P@u1
6th July 2011, 09:12
I added the line


curve_.setRawSamples(xData_, yData_, dataSize_);

in the timerEvent and now its working.
I didn't know that I need to set the samples again each time I apply changes to the data...

Uwe
6th July 2011, 11:13
Autoscaling uses the coordinates of the bounding rectangle. The bounding rectangle of the data is internally cached and when you update the samples behind the back of the data object the cached bounding rectangle gets wrong.

Uwe