Hallo Leute
Ich versuche vorerst einige Testkurven in Qt4 mit der Library qwtplot anzuzeigen. Beim Aufruf der Funktion populate() im Konstruktor Plot::Plot..., werden die Testkurven angezeigt.
Wenn ich aber die Fkt. populate() im module modbusadapter.cpp (nach einer modbus response) aufrufe, dann wird leider nichts geplottet. Im Debug Mode kann ich sehen, dass der Spung in populate() stattfindet, wird aber eben nichts angezeigt.
Ich verwende zwei separate Fenster, einer für die Modbus Kommunikation und das andere Fenster für die Plots. Ich hoffe nicht, dass diese zwei "Instanzen" das Problem ist.
Hier einige Code Ausschnitte:
plot.h
plot.cpp
Ich versuche vorerst einige Testkurven in Qt4 mit der Library qwtplot anzuzeigen. Beim Aufruf der Funktion populate() im Konstruktor Plot::Plot..., werden die Testkurven angezeigt.
Wenn ich aber die Fkt. populate() im module modbusadapter.cpp (nach einer modbus response) aufrufe, dann wird leider nichts geplottet. Im Debug Mode kann ich sehen, dass der Spung in populate() stattfindet, wird aber eben nichts angezeigt.
Ich verwende zwei separate Fenster, einer für die Modbus Kommunikation und das andere Fenster für die Plots. Ich hoffe nicht, dass diese zwei "Instanzen" das Problem ist.
Hier einige Code Ausschnitte:
plot.h
Code:
#ifndef PLOT_H
#define PLOT_H
#include <qapplication.h>
#include <qlayout.h>
#include <qwt_plot.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_series_data.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
#include <qwt_text.h>
#include <qwt_math.h>
#include <math.h>
#define SIZE 15
class Plot : public QwtPlot
{
Q_OBJECT
public:
Plot(QWidget * = NULL);
virtual ~Plot();
void setPlotValue(double value);
void populate();
protected:
virtual void resizeEvent( QResizeEvent * );
private:
void updateGradient();
double cntX;
QwtPlotCurve *density;
double xData[SIZE];
double yData[SIZE];
public slots:
void addNewValue(double value);
signals:
};
#endif // PLOT_H
plot.cpp
Code:
#include "plot.h"
Plot::Plot(QWidget *parent):
QwtPlot( parent )
{
xData[0] = 0;
yData[0] = 0;
// Insert new density curve
density = new QwtPlotCurve("y = density");
//density->setRenderHint(QwtPlotItem::RenderAntialiased);
density->setStyle(QwtPlotCurve::Lines);
density->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
density->setPen(QPen(Qt::red));
density->attach(this);
// Draw grid
QwtPlotGrid *grid = new QwtPlotGrid();
grid->setPen(QPen(Qt::gray, 0.0, Qt::DotLine));
grid->enableX(true);
grid->enableXMin(true);
grid->enableY(true);
grid->enableYMin(false);
grid->attach(this);
// Insert markers
// ...a horizontal line at y = 0...
QwtPlotMarker *mY = new QwtPlotMarker();
mY->setLabel(QString::fromLatin1("y = 0"));
mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mY->setLineStyle(QwtPlotMarker::HLine);
mY->setYValue(0.0);
mY->attach(this);
// ...a vertical line at x = 0...
QwtPlotMarker *mX = new QwtPlotMarker();
mX->setLabel(QString::fromLatin1("x = 0"));
mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
mX->setLabelOrientation(Qt::Vertical);
mX->setLineStyle(QwtPlotMarker::VLine);
mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine));
mX->setXValue(0.0);
mX->attach(this);
// panning with the left mouse button
(void) new QwtPlotPanner( canvas() );
// zoom in/out with the wheel
(void) new QwtPlotMagnifier( canvas() );
setAutoFillBackground( true );
setPalette( QPalette( QColor( 165, 193, 228 ) ) );
updateGradient();
setTitle("A Simple QwtPlot Demonstration");
insertLegend(new QwtLegend(), QwtPlot::RightLegend);
// axes
setAxisTitle(xBottom, "x -->" );
setAxisScale(xBottom, 0.0, 10.0);
setAxisTitle(yLeft, "y -->");
setAxisScale(yLeft, -1.0, 1.0);
// canvas
canvas()->setLineWidth( 1 );
canvas()->setFrameStyle( QFrame::Box | QFrame::Plain );
canvas()->setBorderRadius( 15 );
QPalette canvasPalette( Qt::white );
canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );
canvas()->setPalette( canvasPalette );
//populate(); // beim Aufruf von hier aus, funktionieren die Plots...
}
Plot::~Plot()
{
}
void Plot::populate()
{
qWarning()<< "Plot : populate()";
double maxD = 0;
double minD = 1;
double maxS = 0;
double minS = 1;
double dens = 2.0;
unsigned int sample = 0;
unsigned int x = 0;
unsigned int y = 0;
while(sample < 5)
{
xData[x++]= sample;
yData[y++]= dens;
maxS = sample;
minS = sample++;
maxD = dens;
minD = dens++;
setAxisScale(xBottom, (int)minS-1, (int)maxS+1);
setAxisScale(yLeft, (int)minD-1, (int)maxD+1);
density->setSamples(xData, yData, sample);
}
setAutoReplot(true);
// Call "replot()" to refresh plot displaying
replot();
}
Zuletzt bearbeitet: