How to rescale the QwtPlotZoomer->canvas
Hey community,
I have the following problem. I am constructing a simple 2D-Plot. At the begining I construct a QwtPlot etc. . In an other thread I compute a Vector from a function or whatever. Then this Thread is calling the "preview::createCurve()" methode to draw the curve to the constructed plot. Normally the plot ist automatically rescaled (if i do not set the axisscales manually) to the plotted curve. Since I want to provide zooming in my plots, I have to tell the ZoomingClass the initial ScaleCoordinates of the plotted curve (so the coordinates to which the zoomer goes back when you press the right mouse button). => how can I do that?
Another question is: What if I plot another curve in the same Plot. Will he rescale the plot canvas automatically, when I have rescaled the ZoomingClasScale before ?
here the code and sorry for my crappy english:
Code:
#include "curve.h"
{
public:
{
setRubberBandPen
(QPen(Qt
::darkGreen,
1.5, Qt
::SolidLine));
}
{
text.
setBackgroundBrush( QBrush( bg
));
return text;
}
virtual void rescale()
{
}
};
{
QFont font
("Arial" ,
12);
plotZoom = new Zoomer(plot->canvas());
//plotTitle
plotTitle.setFont(font);
plotTitle.setText(title);
//plotGrid
plotGrid->enableXMin(true);
plotGrid->enableYMin(true);
plotGrid
->setMajPen
(QPen(Qt
::black,
1,Qt
::SolidLine));
plotGrid
->setMinPen
(QPen(Qt
::darkGray,
0,Qt
::DotLine));
plotGrid->attach(plot);
//Plot
plot->setTitle(plotTitle);
plot->setMaximumSize(800,800);
plot->setMinimumSize(400,400);
plot->setCanvasLineWidth(2);
plot
->setCanvasBackground
(QBrush(QColor(240,
240,
240), Qt
::SolidPattern));
plot->setAxisFont(0, font);
plot->setAxisFont(2, font);
plot->axisWidget(0)->setMargin(0);
plot->axisWidget(2)->setMargin(0);
plot->plotLayout()->setAlignCanvasToScales(true);
plotGridLayout->addWidget(plot);
this->setLayout(plotGridLayout);
}
//plotCurve
void curve
::createCurve(const QVector<QPointF>
&vector,
const QString &title
) {
//Std Color = blue
plotCurve
->setPen
(QPen(Qt
::blue,
1.5));
//Std_style = lines, antialiased
plotCurve
->setRenderHint
(QwtPlotItem::RenderAntialiased);
//Points = vector
plotCurve->setSamples(vector);
//Std_Plot = plot
plotCurve->attach(plot);
}
Re: How to rescale the QwtPlotZoomer->canvas
Right mouse button click is equal to QwtPlotZoomer::zoom(0).
Not sure about the second question. No idea when you want to add the second curve.
If you add two curves one after another - then just call setZoomerBase() after adding both curves and everything should work fine.
If you want to add second curve when first one is zoomed in and make sure zoomer gets updated correctly - that's a bit more complex but still possible.
Re: How to rescale the QwtPlotZoomer->canvas
Quote:
If you want to add second curve when first one is zoomed in and make sure zoomer gets updated correctly - that's a bit more complex but still possible.
I think this is, what I want. How can I solve this problem ? :D
Re: How to rescale the QwtPlotZoomer->canvas
There are only two ways how an axis scale can be set:
- explicitly by setAxisScale or setAxisScaleDiv
- implicitely by the auto scaler
Autoscaling is enabled in the default setting of QwtPlot and executed each time replot ( updateAxes ) is called. As soon as you explicitly assign a scale autoscaling gets disabled until you re-enable it with setAxisAutoScale().
The zoomer doesn't have a different API for setting the scales - all it can do is to use setAxisScale. So whenever the zoomer changes a scale autoscaling gets disabled.
When you add a new curve and want to run the autoscaler again you have to do:
Code:
plot->setAxisAutoScale( axisId, true );
plot->replot();
Usually you don't want to keep a zoom stack ( the history of the zoom rectangles ) starting with the scales from your previous
run of the autoscaler. To reinitialize the zoomer with the new scales you have to do:
Code:
doReplot = false;
zoomer->setZoomBase( doReplot );
The mystery behind the doReplot flag is, that setAxisScale/setAxisAutoScale only assign the parameters for the calculation of the new scale, but the scales are calculated later ( replot/updateAxes ). So you have to do a replot before you reinitialize the zoomer to avoid, that it gets initialized with the previous scales.
In the code snippet above doReplot is set to false. This is only done because you already did the the replot above and you don't need to do it twice.
Uwe
Re: How to rescale the QwtPlotZoomer->canvas
Thanks, now I got it.
Another little question: is it possible to change the MajorTickLabels manually ? F.e. I want the Unit to be at the next to last MajorTick .... xAxisTicks[ 0 1 2 µm 3 ] ?
Re: How to rescale the QwtPlotZoomer->canvas
Overload QwtScaleDraw::drawLabel, you can decide here what is displayed over the major ticks.
Re: How to rescale the QwtPlotZoomer->canvas
this one is too hard for me now ... too noobish :)