Ich bin auf ein ziemlich komisches Verhalten der QwtPlots gestoßen.
Wenn 2 Instanzen einen QwtPlots erzeugt wurden und einer der beiden läuft, der andere gestoppt ist und man versucht hineinzuzoomen wird die laufende Kurve zum Teil angezeigt...Bilder sagen mehr als Worte(siehe unten die beiden Bilder)
Immer wenn man den zu zoomenden Ausschnitt verändert, wird Counter 2 in der Instanz von Counter 1 aktuallisiert. Es scheint, als ob der Plot der zuletzt ein replot() ausgeführt hat, die canvas beider Plots beschreibt (aber halt nur, wenn man zoomt).
Der Zoomer selbst ist aus den Examples von QWT.
Hier nun mal Code des Zoomers.
Zunächst die Header:
Code: Alles auswählen
class Zoomer: public ScrollZoomer
{
Q_OBJECT
public:
Zoomer(QwtPlotCanvas *canvas, QwtPlot *plot);
virtual void widgetMouseReleaseEvent(QMouseEvent *me)
{
if (mouseMatch(MouseSelect2, me))//right mouse-button: zoom out (complete)
{
QwtDoubleRect initialRect = zoomBase();
for (int i = 0; i < MAX_PORT_NUMBER; i++)
{
if (pCs[i] != NULL)
{
mDCs[i]->prepareZoomLoDA(initialRect.left(),
initialRect.right());
}
}
zoom(0);
plot->replot();
}
else if (mouseMatch(MouseSelect3, me))//middle mouse-button: zoom out one layer
{
int tmpIndex = zoomRectIndex();
if (tmpIndex >= 1)
tmpIndex--;
QwtDoubleRect middleRect = zoomStack()[tmpIndex];
for (int i = 0; i < MAX_PORT_NUMBER; i++)
{
if (pCs[i] != NULL)
{
mDCs[i]->prepareZoomLoDA(middleRect.left(),
middleRect.right());
}
}
zoom(-1);
plot->replot();
}
else
{
int tmpIndex = zoomRectIndex();
QwtDoubleRect lastRect = zoomStack()[tmpIndex];
for (int i = 0; i < MAX_PORT_NUMBER; i++)
{
if (pCs[i] != NULL)
{
// std::cout << "\nZOOMER: Zoom in Curve: " << i
// << " from left: " << lastRect.left()
// << " to right: " << lastRect.right() << "\n";
mDCs[i]->prepareZoomLoDA(lastRect.left(), lastRect.right());
}
}
plot->replot();
}
QwtPlotPicker::widgetMouseReleaseEvent(me);
}
void Zoomer::autoscaleY(QwtDoubleRect rect)
{
//zoomStack()[zoomRectIndex()]=rect;
}
virtual void rescale()
{
QwtScaleWidget *scaleWidget = plot->axisWidget(yAxis());
QwtScaleDraw *sd = scaleWidget->scaleDraw();
int minExtent = 0;
if (zoomRectIndex() > 0)
{
// When scrolling in vertical direction
// the plot is jumping in horizontal direction
// because of the different widths of the labels
// So we better use a fixed extent.
minExtent = sd->spacing() + sd->majTickLength() + 1;
minExtent += sd->labelSize(scaleWidget->font(), c_rangeMax).width();
}
sd->setMinimumExtent(minExtent);
ScrollZoomer::rescale();
}
void init();
void setDataContainers(QVector<DataContainer*> dc, int ports);
void setPlotCurves(QVector<QwtPlotCurve*> pc, int ports);
public slots:
void updatePlotCanvas(Qt::Orientation, double, double);
private:
DataContainer * mDCs[MAX_PORT_NUMBER];
QwtPlotCurve * pCs[MAX_PORT_NUMBER];
QwtPlotCanvas * canvas;
QwtPlot * plot;
};
Code: Alles auswählen
Zoomer::Zoomer(QwtPlotCanvas *amy_canvas, QwtPlot *amy_plot) :
ScrollZoomer(amy_canvas)
{
plot = amy_plot;
canvas = amy_canvas;
std::cout<<"Zoomer: Canvas : "<<&canvas<<"\n";
ScrollBar * scrollBar = ScrollZoomer::scrollBar(Qt::Horizontal);
connect(scrollBar, SIGNAL(sliderMoved(Qt::Orientation, double, double)),this, SLOT(updatePlotCanvas(Qt::Orientation, double, double)));
}
Der Zoomer wird in dem von QwtPlot erbenden data_plot initialisiert:
Code: Alles auswählen
//Stops the Plot
void DataPlot::stop()
{
timer->stop();
if (plotZoomer == NULL)
{
plotZoomer = new Zoomer(canvas(),this);
std::cout<<"Plot stopped => new Zoomer\n";
plotZoomer->setRubberBandPen(QPen(Qt::blue, 2, Qt::DotLine));
plotZoomer->setTrackerPen(QPen(Qt::blue));
//QVector only to pass the DataContainer
QVector <DataContainer *>dc;
QVector <QwtPlotCurve *>pc;
for (int j = 0; j<ports;j++)
{
dc.append(myDataContainers[j]);
pc.append(plotCurves[j]);
}
plotZoomer->setDataContainers(dc,ports);
plotZoomer->setPlotCurves(pc,ports);
}
for (int i = 0; i < ports; i++)
{
if (plotCurves[i] !=NULL)
{
//if the raptor is still sampling, the rt data should be stopped
myDataContainers[i]->allowSamplingToLoDA(false);
myDataContainers[i]->prepareStopLoDA();
// myDataContainers[i]->printLoDA();
//std::cout<<"S: "<<myDataContainers[i]->getSampleToLoDA()()<<"\n";
plotCurves[i]->setRawData((xLoDAs[i]),(yLoDAs[i]),myDataContainers[i]->lastLoDAIndex());
}
}
canvas()->setCursor(Qt::CrossCursor);
running = false;
setAxisScale(QwtPlot::xBottom,0,lastValue);
setAxisAutoScale(QwtPlot::yLeft);
replot();
plotZoomer->setZoomBase(); //important!Must be set after replot!!!
PlotLog::info("[Plot " + name + "]: stopped ... now you can zoom.");
}
Hoffentlich sieht einer von euch schnell einen dummen Fehler von mir, das wäre mir am liebsten...sitze schon lange an diesem Fehler.
Die Sourcen von QT und QWT sind aktuell.
Gruß,
TheMetalManiac[/code]