#include <QtGui>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <cstdlib>
#include <ctime>
{
Q_OBJECT
public:
public slots:
void getData();
void drawCurves();
private:
};
{
srand(time(0));
redCurveCheckBox
= new QCheckBox("Red Curve");
redCurveCheckBox->setChecked(true);
greenCurveCheckBox
= new QCheckBox("Green Curve");
redCurve.
setRenderHint(QwtPlotItem::RenderAntialiased);
greenCurve.
setRenderHint(QwtPlotItem::RenderAntialiased);
getData();
rightLayout->addWidget(redCurveCheckBox);
rightLayout->addWidget(greenCurveCheckBox);
rightLayout->addWidget(drawButton);
rightLayout->addStretch();
mainLayout->addWidget(plot);
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);
resize(640,480);
connect(redCurveCheckBox, SIGNAL(clicked()), this, SLOT(drawCurves()));
connect(greenCurveCheckBox, SIGNAL(clicked()), this, SLOT(drawCurves()));
connect(drawButton, SIGNAL(clicked()), this, SLOT(getData()));
}
void Dialog::getData()
{
int size = 1+rand()%10 + 10;
double redCurveData[size];
double greenCurveData[size];
double xval[size];
for(int i = 0; i < size; i++)
{
redCurveData[i] = 0+rand()%10;
greenCurveData[i] = 0+rand()%10;
xval[i] = i + 1;
}
redCurve.setRawData(xval,redCurveData,size);
greenCurve.setRawData(xval,greenCurveData,size);
plot
->setAxisScale
(QwtPlot::xBottom,
1, size
);
plot
->setAxisScale
(QwtPlot::yLeft,
0,
10);
drawCurves();
}
void Dialog::drawCurves()
{
if(redCurveCheckBox->isChecked())
redCurve.attach(plot);
else
redCurve.detach();
if(greenCurveCheckBox->isChecked())
greenCurve.attach(plot);
else
greenCurve.detach();
plot->replot();
}
int main(int argc, char *argv[])
{
Dialog *dialog = new Dialog;
dialog->show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <cstdlib>
#include <ctime>
class Dialog: public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
public slots:
void getData();
void drawCurves();
private:
QwtPlot *plot;
QwtPlotCurve redCurve;
QwtPlotCurve greenCurve;
QCheckBox *redCurveCheckBox;
QCheckBox *greenCurveCheckBox;
};
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
srand(time(0));
redCurveCheckBox = new QCheckBox("Red Curve");
redCurveCheckBox->setChecked(true);
greenCurveCheckBox = new QCheckBox("Green Curve");
QPushButton *drawButton = new QPushButton("Draw");
plot = new QwtPlot;
redCurve.setPen(QPen(QColor(Qt::red),2));
redCurve.setStyle(QwtPlotCurve::Lines);
redCurve.setRenderHint(QwtPlotItem::RenderAntialiased);
greenCurve.setPen(QPen(QColor(Qt::green),2));
greenCurve.setStyle(QwtPlotCurve::Lines);
greenCurve.setRenderHint(QwtPlotItem::RenderAntialiased);
getData();
QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(redCurveCheckBox);
rightLayout->addWidget(greenCurveCheckBox);
rightLayout->addWidget(drawButton);
rightLayout->addStretch();
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(plot);
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);
resize(640,480);
connect(redCurveCheckBox, SIGNAL(clicked()), this, SLOT(drawCurves()));
connect(greenCurveCheckBox, SIGNAL(clicked()), this, SLOT(drawCurves()));
connect(drawButton, SIGNAL(clicked()), this, SLOT(getData()));
}
void Dialog::getData()
{
int size = 1+rand()%10 + 10;
double redCurveData[size];
double greenCurveData[size];
double xval[size];
for(int i = 0; i < size; i++)
{
redCurveData[i] = 0+rand()%10;
greenCurveData[i] = 0+rand()%10;
xval[i] = i + 1;
}
redCurve.setRawData(xval,redCurveData,size);
greenCurve.setRawData(xval,greenCurveData,size);
plot->setAxisScale(QwtPlot::xBottom, 1, size);
plot->setAxisScale(QwtPlot::yLeft, 0, 10);
drawCurves();
}
void Dialog::drawCurves()
{
if(redCurveCheckBox->isChecked())
redCurve.attach(plot);
else
redCurve.detach();
if(greenCurveCheckBox->isChecked())
greenCurve.attach(plot);
else
greenCurve.detach();
plot->replot();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Dialog *dialog = new Dialog;
dialog->show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
for(int i = 0; i < 9; i++)
std::cout << redCurve.y(i) << " ";
std::cout << std::endl;
for(int i = 0; i < 9; i++)
std::cout << redCurve.y(i) << " ";
std::cout << std::endl;
To copy to clipboard, switch view to plain text mode
Bookmarks