#ifndef PLOT_H
#define PLOT_H
#include <qvaluelist.h>
#include <qwt_plot.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_scale_engine.h>
#include <qwt_data.h>
#include <qwt_text.h>
#include <math.h>
{
public:
Plot()
{
curves.setAutoDelete(true);
X.setAutoDelete(true);
Y.setAutoDelete(true);
setTitle("A Simple QwtPlot Demonstration");
// Set axis titles
setAxisTitle(xBottom, "x -->");
setAxisTitle(yLeft, "y -->");
/*
setAxisAutoScale(xBottom);
setAxisAutoScale(xTop);
setAxisAutoScale(yLeft);
setAxisAutoScale(yRight);
*/
minX = 0.0;
maxX = 0.0;
minY = 0.0;
maxY = 0.0;
// 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 = 2 * pi
/*
QwtPlotMarker *mX = new QwtPlotMarker();
mX->setLabel(QString::fromLatin1("x = 2 pi"));
mX->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mX->setLineStyle(QwtPlotMarker::VLine);
mX->setXValue(1000.0);
mX->attach(this);
*/
}
~Plot()
{
curves.clear();
X.clear();
Y.clear();
}
void addCurve(QValueList<double> & list)
{
double * x = new double[list.count()];
double * y = new double[list.count()];
for (unsigned int i = 0 ; i < list.count() ; i++)
{
x[i] = i;
y[i] = list[i];
}
X.append(x);
Y.append(y);
c->setRawData(x, y, list.count());
c->attach(this);
if (c->minXValue() < minX)
minX = c->minXValue();
if (c->maxXValue() > maxX)
maxX = c->maxXValue();
if (c->minYValue() < minY)
minY = c->minYValue();
if (c->maxYValue() > maxY)
maxY = c->maxYValue();
setAxisScale(xBottom, minX, maxX);
setAxisScale(yLeft, minY, maxY);
curves.append(c);
}
private:
QPtrList<QwtPlotCurve> curves;
QPtrList<double> X;
QPtrList<double> Y;
double minX;
double maxX;
double minY;
double maxY;
};
#endif
#ifndef PLOT_H
#define PLOT_H
#include <qvaluelist.h>
#include <qwt_plot.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_scale_engine.h>
#include <qwt_data.h>
#include <qwt_text.h>
#include <math.h>
class Plot : public QwtPlot
{
public:
Plot()
{
curves.setAutoDelete(true);
X.setAutoDelete(true);
Y.setAutoDelete(true);
setTitle("A Simple QwtPlot Demonstration");
insertLegend(new QwtLegend(), QwtPlot::RightLegend);
// Set axis titles
setAxisTitle(xBottom, "x -->");
setAxisTitle(yLeft, "y -->");
/*
setAxisAutoScale(xBottom);
setAxisAutoScale(xTop);
setAxisAutoScale(yLeft);
setAxisAutoScale(yRight);
*/
minX = 0.0;
maxX = 0.0;
minY = 0.0;
maxY = 0.0;
setAxisScaleEngine(xBottom, new QwtLinearScaleEngine());
setAxisScaleEngine(yLeft, new QwtLinearScaleEngine());
// 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 = 2 * pi
/*
QwtPlotMarker *mX = new QwtPlotMarker();
mX->setLabel(QString::fromLatin1("x = 2 pi"));
mX->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mX->setLineStyle(QwtPlotMarker::VLine);
mX->setXValue(1000.0);
mX->attach(this);
*/
}
~Plot()
{
curves.clear();
X.clear();
Y.clear();
}
void addCurve(QValueList<double> & list)
{
double * x = new double[list.count()];
double * y = new double[list.count()];
for (unsigned int i = 0 ; i < list.count() ; i++)
{
x[i] = i;
y[i] = list[i];
}
X.append(x);
Y.append(y);
QwtPlotCurve * c = new QwtPlotCurve();
c->setRawData(x, y, list.count());
c->attach(this);
if (c->minXValue() < minX)
minX = c->minXValue();
if (c->maxXValue() > maxX)
maxX = c->maxXValue();
if (c->minYValue() < minY)
minY = c->minYValue();
if (c->maxYValue() > maxY)
maxY = c->maxYValue();
setAxisScale(xBottom, minX, maxX);
setAxisScale(yLeft, minY, maxY);
curves.append(c);
}
private:
QPtrList<QwtPlotCurve> curves;
QPtrList<double> X;
QPtrList<double> Y;
double minX;
double maxX;
double minY;
double maxY;
};
#endif
To copy to clipboard, switch view to plain text mode
Bookmarks