PDA

View Full Version : Updating and Zooming Plot, that is frequently filled with new Data



entonjackson
7th September 2011, 07:36
Hello Qt and Qwt Folks!

This is my 1st post. Sorry if this topic was already handled here in the forum, but i have found nothing.
My English is not perfect, sorry for that.

Let's get to my topic...
My problem is, that i want to plot a curve, that is updated with data from the database every 500ms. In the past i did this by doing setSamples(x_vals, y_vals); and after that replot(); inside my class that inherits QwtPlot.
That worked fine, but now I also want to zoom. Zooming in by rubberband and mousewheel, zooming out by right-clicking. So i implemented a QwtPlotZoomer and installed to my QwtPlot.
And it works fine... as long as you don't update the Plot! It zooms in for a tiny piece of a second and then immediatley zooms out again, after replot() is called.

So, my idea was to just add data to my plot and let it handle update and zooming functionality itself.
But I'm just not getting it, how to do that... i tried setAutoReplot(true); ... same problem as before.

I hope someone can help me. I'm stuck for days, trying out stuff from the qwt examples. trying out setting any scales or scaledraws or scaledivs. This cannot be that difficult, can it?


Thanks in advance!

FelixB
7th September 2011, 08:02
show the code where you add the data, please.

you probably set the axes ranges there...

entonjackson
7th September 2011, 08:17
//getting new data from database and store it on QVector<double> m_xVal and m_yVal

m_curve->setSamples(m_xVal, m_yVal);

setAxisScale(xBottom, m_xVal.first(), m_xVal.last());
setAxisScale(yLeft, yMin, yMax);

replot();

FelixB
7th September 2011, 09:09
do you know what "setAxisScale()" does?

entonjackson
7th September 2011, 09:15
No I don't. I try to understand what the great "Documentation" tries to tell me by saying the following about this method:

"Disable autoscaling and specify a fixed scale for a selected axis."

Maybe you can explain it to me in more than 1 sentence...
I understand that I'm disabling autoscaling, but I know that I'm setting the scale from update to update, so this cannot be the problem.
I'm specifying a fixed scale... ok... isn't that what i want?

Thank you

FelixB
7th September 2011, 11:18
you set the range of the scales with that method. e.g. "setAxisScales(xBottom,0,10)" makes the x-axis have the range (0-10).

When you zoomed in before, you have a different scale, e.g. (4-6). So, after "setAxisScale", "replot" makes your plot zooming out because you set the scales to a larger interval.

entonjackson
8th September 2011, 14:20
Thanks! That helped a lot!

But I have another Problem.
I made an own QwtPlotZoomer Class that inherits it. i have overriden widgetWheelEvent() signal and check if delta is > or < 0. if so, i zoom(1) or zoom(-1);
if i zoom in, it zooms to a y-scale from 0 to 1000 and won't ever zoom to another scale after that. What am I doing wrong?

FelixB
8th September 2011, 15:02
you probably have a "setAxisScale(yLeft,0,1000)" somewhere in your code... or maybe you do the zooming wrong. show some code, please...

Uwe
8th September 2011, 18:57
I made an own QwtPlotZoomer Class that inherits it. i have overriden widgetWheelEvent() signal ...
You probably want to use QwtPlotMagnifier.

Uwe

entonjackson
9th September 2011, 10:08
That seems to solve my problem...
now, inside my QwtPlot derived Class Constructur i do...


QwtPlotMagnifier magnifier(canvas());
magnifier.setAxisEnabled(xBottom, true);
magnifier.setAxisEnabled(yLeft, true);


Now it zooms automatically by scrolling... but!
I have a QwtScaleDraw class called TimeAxis... that is formatting double values into Timestamps.
And no matter if i zoom out or in, it zooms always to 01.01.1970 on the x axis. Why is that?

Any suggestions?

Edit: This must be a basic problem, because on right-clicks, i do zoom(0); after that it zooms also to 01.01.1970... so I probably must tell my zoomer and magnifier what the base rect is, or something. right?

Edit: Sorry my fault. There was an active mousewheel listener, that zoomed into 01.01.1970, that i have commented out. now it works!

Vielen Dank! Felix und Uwe

entonjackson
16th September 2011, 15:34
There's an annoying autozoom functionality implemented in the QwtPlotZoomer, that enables autozooming after right-click and moving Mouse vertically up and down.
I don't know how to disable that... can anybody please tell me?

Spitfire
16th September 2011, 16:39
Subclass Qwt<Plot>Magnifier and overwrite
virtual void QwtMagnifier::widgetMouseMoveEvent(QMouseEvent*)Th at should do the trick.

Uwe
16th September 2011, 17:17
Or:


magnifier->setMouseButton( Qt::NoButton );
Uwe

entonjackson
20th September 2011, 09:50
Thank you!

That helped, but the problem is: I don't understand it.
setMouseButton seems to be a method that sets functionality to some some mousebuttons. above you simply said setMouseButton(Qt::NoButton);
Why is it setting the right-click autozooming thing to "NoButton".
It could be any functionality of the magnifier, right?

I hope you understand my question, although it's a little confusing...
Thanks in advance