PDA

View Full Version : QwtPlotzoomer for more 4 -yleft axis



Abderrahim
19th January 2016, 21:33
In my app i use the qwtplotzommer, it works fine for one y-left axis. when zooming into the graph only the y-axis (first to the left) is updated.
my section code for zooming is as following:

d_zoomer[0] = new myZoomer(
QwtAxis::xBottom,QwtAxisId(QwtAxis::yLeft, 0).id, canvas() );
d_zoomer[0]->setRubberBand( QwtPicker::RectRubberBand );
d_zoomer[0]->setRubberBandPen( QColor( Qt::red ) );
d_zoomer[0]->setTrackerMode( QwtPicker::ActiveOnly );
d_zoomer[0]->setTrackerPen( QColor( Qt::white ) );
d_zoomer[0]->setZoomBase();

connect(d_zoomer[0],SIGNAL(zoomed(QRectF)),this,SLOT(ZoomedRect(QRect F)));

---------------
setAxesCount(QwtAxisId(QwtPlot::yLeft).id,nChannel +1);// set nChannel axis on y direction
d_curve->setYAxis(QwtAxisId(QwtAxis::yLeft,nChannel));
setAxisVisible(d_curve->yAxis(),true);
this->setAxisScale(QwtAxisId(QwtAxis::yLeft,nChannel), 0, 85,10 );
this->setAxisAutoScale(QwtAxisId(QwtAxis::yLeft,nChannel ),true);
_________

I have 2 problems:

1) If my plot has more than one y-left axis for example 4-y-left Axis, the zooming works but without updating y-left2 to y-left4 axis, only the y-left1 is updated, for all the graphs the zooming works fine.

2) If i add this section code to my programs and I add more curves by drag and drop to the plot, my programs works only with 4 curves and in case of more curves it crashes. And the section below is causing that problem.

d_zoomer[nChannel] = new myZoomer(
QwtAxis::xBottom, QwtAxisId(QwtAxis::yLeft, nChannel).id, canvas() );

Do you know, how zooming can work for all integrated axis?
Thanks,

Uwe
20th January 2016, 07:18
In general the idea of your implementation should work, maybe beside of one aspect: all of your zoomers are connected to the same x axis. If it is not a dummy one you will have some unexpected effects.
Assuming that xBottom is your common x-axis and you don't use xTop, I would connect only the first zoomer to xBottom all others to xTop. In case you need xTop and xBottom you could add an invisible dummy x axis.

Why things are not working in your application is hard to say from the code snippets. But as you have a crash I would start with a debugger session.

Uwe

Abderrahim
20th January 2016, 11:20
Hello Uwe,

with debugger i found that my programs crashes when the element pos gets the value 4 in this code section:

inline QwtPlotAxisData &axisData( const QwtAxisId &axisId )
{
return d[ axisId.pos ].axisData[ axisId.id ];
}



the axisId.pos must be between 0 and 3 -->{ "yLeft", "yRight", "xBottom", "xTop" };


I think that myzoomer sets the value to 4. but why?

d_zoomer[nChannel] = new myZoomer(
QwtAxis::xTop, QwtAxisId(QwtAxis::yLeft,nChannel).id, canvas() );

---------------

class myZoomer: public QwtPlotZoomer
{
public:

myZoomer( int xAxis, int yAxis, QWidget *canvas ):
QwtPlotZoomer( xAxis, yAxis, canvas )
{
setTrackerMode( QwtPicker::AlwaysOff );
setRubberBand( QwtPicker::NoRubberBand );
// RightButton: zoom out by 1
// Ctrl+RightButton: zoom out to full size
setMousePattern( QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier );
setMousePattern( QwtEventPattern::MouseSelect3,
Qt::RightButton );

}
};

Added after 5 minutes:

Problem is solved.

Sorry:
declaration was false:

myZoomer( QwtAxisId xAxis, QwtAxisId yAxis, QWidget *canvas ):
QwtPlotZoomer( xAxis, yAxis, canvas )