{
Q_OBJECT
static int const NPOINTS = 150;
double x[NPOINTS], ysin[NPOINTS], ycos[NPOINTS];
public:
explicit vtPlot
(QObject *parent
= 0);
void *myData();
QwtPointArrayData *myArray[2];
};
{
}
void *vtPlot::myData()
{
for(int i = 0; i < NPOINTS; i++)
{
x[i] = 0.1*i;
ysin[i] = sin(x[i]);
ycos[i] = cos(x[i]);
}
myArray[0] = new QwtPointArrayData(x,ysin,(sizeof(x)+sizeof(ysin))); // actually not sure if the third argument is correct
myArray[1] = new QwtPointArrayData(x,ycos,(sizeof(x)+sizeof(ycos)));
}
int main(int argc, char *argv[])
{
MainWindow w;
vtPlot *myPlot = new vtPlot(&w);
myPlot->myData();
curve1->setData(myPlot->myArray[0]);
curve1->attach(myPlot);
curve2->setData(myPlot->myArray[1]);
curve2->attach(myPlot);
myPlot->setTitle("Voltage [mV] - Time [s]");
myPlot->setAxisTitle(myPlot->yLeft,"Voltage [mV]");
myPlot->setAxisTitle(myPlot->xBottom,"Time [s]");
w.setCentralWidget(myPlot);
w.show();
return a.exec();
}
class vtPlot : public QwtPlot
{
Q_OBJECT
static int const NPOINTS = 150;
double x[NPOINTS], ysin[NPOINTS], ycos[NPOINTS];
public:
explicit vtPlot(QObject *parent = 0);
void *myData();
QwtPointArrayData *myArray[2];
};
vtPlot::vtPlot(QObject *parent)
{
}
void *vtPlot::myData()
{
for(int i = 0; i < NPOINTS; i++)
{
x[i] = 0.1*i;
ysin[i] = sin(x[i]);
ycos[i] = cos(x[i]);
}
myArray[0] = new QwtPointArrayData(x,ysin,(sizeof(x)+sizeof(ysin))); // actually not sure if the third argument is correct
myArray[1] = new QwtPointArrayData(x,ycos,(sizeof(x)+sizeof(ycos)));
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
vtPlot *myPlot = new vtPlot(&w);
QwtPlotCurve *curve1 = new QwtPlotCurve("sinus");
QwtPlotCurve *curve2 = new QwtPlotCurve("cosinus");
myPlot->myData();
curve1->setData(myPlot->myArray[0]);
curve1->attach(myPlot);
curve2->setData(myPlot->myArray[1]);
curve2->attach(myPlot);
myPlot->setTitle("Voltage [mV] - Time [s]");
myPlot->setAxisTitle(myPlot->yLeft,"Voltage [mV]");
myPlot->setAxisTitle(myPlot->xBottom,"Time [s]");
w.setCentralWidget(myPlot);
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks