PDA

View Full Version : Zoom on only one axis?



kja
5th December 2010, 14:58
Hi,

I have a plot that plots one curve on the yLeft and another on the yRight because they have different scale. I want to be able to zoom anywhere on the plot and have both y-axes be readjusted so I am looking at both the curves in the zoomer. For example, when I first load up the plot I want to be able to select a rectangle to zoom in on, and even if that rectangle has no curves passing through it, i want the new zoomed in view to show me the data of both my yLeft and yRight curves, over my x-axis scale.

What I think I need to do is make the zoomer only zoom on the x-axis then somehow have both the y axes rescale. But I can't even figure out how to make the zoom only zoom in the x-axis.

Any hints? Thanks.

FelixB
6th December 2010, 11:20
maybe it works if you enable autoscaling for the y-axis after zooming?

d_stranz
6th December 2010, 17:00
You should be able to make 2 zoomers, and assign one for xBottom/yLeft and the other for xBottom/yRight.

I do not know if both zoomers can be active at the same time. If they can, then you will get zooming on both y axes simultaneously. I have not tried this, so it is something you will have to experiment with.

kja
6th December 2010, 21:42
You should be able to make 2 zoomers, and assign one for xBottom/yLeft and the other for xBottom/yRight.

I have made two zoomers like this and it does allow me to zoom in on both y axes at the same time, but it is not quite what I want. When I zoom I want both y axes to be rescaled so that both the left and right curves will always be visible in my zoomed in area. As it is with the two zoomers made for xBottom/yLeft and xBottom/yRight the y axes do not rescale to the data



maybe it works if you enable autoscaling for the y-axis after zooming?

That seems like it might work, but I'm having a hard time actually understanding where the code goes when I use my zoomer. I'm sure this is something trivial but I can't figure it out. I've tried putting debug points at every instance of myZoomer but when I zoom on my plot it never gets to these debug points. Would I set the autoscaling in the zoomer class its self or what? I'll show some of my code so you can see how my program is working:

What happens is that MyWidget calls MyPlot who calls CurveAttrib, CurveAttrib sets up the y-right and y-left then goes back to MyPlot who sets up the zoomer for the first view, then MyPlot goes back to MyWidget who replots the whole thing.





#ifndef MYZOOMER_H
#define MYZOOMER_H
#include <qwt_plot_zoomer.h>

class MyZoomer : public QwtPlotZoomer
{
public:
MyZoomer(int xAxis, int yAxis, QwtPlotCanvas *canvas):
QwtPlotZoomer(xAxis, yAxis, canvas)
{
setTrackerMode(ActiveOnly);
}
};
#endif

//MyWidget.cpp

void MyWidget::setAxis(){
MyPlot * myPlot = new MyPlot();
myPlot->changeAxis(curveNum, y); // calls MyPlot

myPlot->replot(); // after every thing has been called and the y axes have been set, I replot.
}

//I declare myZoomer in myPlot
#include "MyZoomer.h"

class MyPlot : public QwtPlot
{
CurveAttrib ** curves;
public:
MyPlot(){
myZoomer[0] = new MyZoomer(QwtPlot::xBottom, QwtPlot::yLeft, this->canvas());
myZoomer[1] = new MyZoomer(QwtPlot::xBottom, QwtPlot::yRight, this->canvas());
enableAxis(QwtPlot::yRight);
}
MyZoomer *myZoomer[2];

....

void changeAxis(int curvNum, int axis){
curves[curvNum]->axis(axis); // the function 'axis' calls another function in
// CurveAttrib which assigns the axis
curves[curvNum]->curve->attach(this);


// here I make it so that the zoomer fits to the new data points,
// this happens before I replot so it looks right,
// the problem is that when I zoom the axis don't rescale,
// I don't know where to set auto scale for the y axes AFTER I zoom
myZoomer[0]->setZoomBase();
myZoomer[1]->setZoomBase();
this->setAxisAutoScale(yLeft);
this->setAxisAutoScale(yRight);
this->setAxisAutoScale(xBottom);
}
};
#endif

class CurveAttrib{
......
void axis(int axis){ /// sets y-left or y-right
curve->detach();
if (axis == 1){
curve->setYAxis(QwtPlot::yRight);
}else{
curve->setYAxis(QwtPlot::yLeft);
}
}



Hopefully this makes some sense. I think my problem is that I don't know where to put the setAutoScale so that it happens every time I zoom in or out. Any ideas?

Thanks!

Uwe
7th December 2010, 06:30
Hard to understand your English - so I'm not completely sure what you want. Is it that you want to zoom the x scales only ?

FelixB
7th December 2010, 08:19
That seems like it might work, but I'm having a hard time actually understanding where the code goes when I use my zoomer.

there is a signal emitted after a zoom has been performed: void QwtPlotZoomer::zoomed (const QwtDoubleRect & rect ). Connect this signal with a custom slot in your application. there you can set the y-axis of your zoomer to autoscale.

kja
7th December 2010, 15:52
so I set up the zoomed signal but I'm getting the error

Qobject::connect: No such signal QwtPlotZoomer:: zoomed(const QwtDoubleRect &) in myplot.h

I made the custom slot and added Q_OBJECT to the file. The Moc file is generated.


class MyPlot : public QwtPlot
{
Q_OBJECT
CurveAttrib ** curves;
public:
MyPlot(){
myZoomer[0] = new MyZoomer(QwtPlot::xBottom, 0, this->canvas());
myZoomer[1] = new MyZoomer(QwtPlot::xBottom, 0, this->canvas());

setAxisScaleDraw(QwtPlot::xBottom, new XaxisDates);
enableAxis(QwtPlot::yRight);

connect(myZoomer[0], SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(whenZoom(const QwtDoubleRect &)));

}
public Q_SLOTS:
void whenZoom(const QwtDoubleRect &);
public:
MyZoomer *myZoomer[2];
}

Is my syntax incorrect?

FelixB
7th December 2010, 16:04
maybe something has changed in Qwt 6.0... this is working for me:


connect(m_zoomerBL, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(updatePlots()) );

kja
7th December 2010, 18:45
hmmm that's strange. I have no idea why I can't set up the connection. All of my other slots and signals work as they should, but ever time I try to use the zoomed signal I get the error 'no such connection' any one know what might be happening?


connect (newzoom, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(newzoomer()));

kja
8th December 2010, 16:18
I mean the error is actually "no such signal QwtPlotZoomer:: zoomed(const QwtDoubleRect &) in myplot.h"

FelixB
8th December 2010, 16:22
wait... your definition of MyZoomer is in myplot.cpp, right? Maybe it must be defined in myplot.h? then the signal should be available in myplot.h...

kja
8th December 2010, 20:40
Thanks for the help FelixB,

I tried moving the MyZoomer definition into myplot.h but I still get the same problem. It is strange because, as I said before, I have different singles from push puttons and qActions that are implemented in the same way as myZoomer's connection and they all work fine.

Uwe
9th December 2010, 07:21
What about reading the documentation of Qwt 6 concerning the signature of QwtPlotZoomer::zoomed.

Uwe

PS: These type of threads are really hard to accept