Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QtGui>
- #include <QProcess>
- #include <qwt/qwt_plot.h>
- #include <qwt/qwt_plot_curve.h>
- #include <qwt/qwt_plot_zoomer.h>
- #include <qwt/qwt_plot_magnifier.h>
- #include <qtcagraph.hpp>
- QtCAgraph::QtCAgraph(QWidget* parent) : QWidget(parent) {
- pv_name = new QLineEdit("PV name",this);
- updateButton = new QPushButton("Start",this);
- autoscaleXButton = new QPushButton("X",this);
- autoscaleYButton = new QPushButton("Y",this);
- autoscale = new QLabel("Autoscale:",this);
- proc = new QProcess(this);
- graph = new QwtPlot();
- dataCurve = new QwtPlotCurve();
- zoomer = new QwtPlotZoomer(graph->canvas());
- mag = new QwtPlotMagnifier(graph->canvas());
- datasize = 128;
- datax = new double[datasize];
- datay = new double[datasize];
- i = 0;
- connect( autoscaleXButton,SIGNAL(clicked()),
- this,SLOT(resetAutoscaleX()) );
- connect( autoscaleYButton,SIGNAL(clicked()),
- this,SLOT(resetAutoscaleY()) );
- connect( updateButton,SIGNAL(clicked()),
- this,SLOT(updateClicked()) );
- connect( proc,SIGNAL(readyReadStandardOutput()),
- this,SLOT(readFromStdout()) );
- layout1 = new QHBoxLayout;
- layout1->addWidget(pv_name);
- layout1->addWidget(updateButton);
- layout1->addWidget(autoscale);
- layout1->addWidget(autoscaleXButton);
- layout1->addWidget(autoscaleYButton);
- layout2 = new QVBoxLayout;
- layout2->addLayout(layout1);
- layout2->addWidget(graph);
- setLayout(layout2);
- }
- QtCAgraph::~QtCAgraph() {
- delete pv_name;
- delete updateButton;
- delete proc;
- delete graph;
- // delete dataCurve;
- delete zoomer;
- delete mag;
- delete datax;
- delete datay;
- delete layout1;
- delete layout2;
- }
- void QtCAgraph::updateClicked() {
- QString pv = pv_name->text();
- QStringList args;
- args << "-f 4" << pv;
- program = "camonitor";
- if(proc->state()) {
- proc->terminate();
- updateButton->setText("Start monitor");
- }
- else {
- proc->start(program,args);
- updateButton->setText("Stop monitor");
- }
- }
- void QtCAgraph::readFromStdout() {
- QByteArray output;
- output = proc->readAllStandardOutput();
- QTextStream test(output);
- QString name;
- QString day;
- QString time;
- double value;
- QString status;
- QString severity;
- test >> name;
- test >> day;
- test >> time;
- test >> value;
- test >> status;
- test >> severity;
- if (i == datasize) expandData();
- datax[i] = i;
- datay[i] = value;
- i++;
- dataCurve->setRawSamples(datax,datay,i);
- dataCurve->attach(graph);
- graph->replot();
- }
- void QtCAgraph::expandData() {
- double* new_datax = new double[datasize*2];
- double* new_datay = new double[datasize*2];
- for(int j=0; j<datasize; j++) {
- new_datax[j] = datax[j];
- new_datay[j] = datay[j];
- }
- datasize *= 2;
- delete[] datax;
- delete[] datay;
- datax = new_datax;
- datay = new_datay;
- }
- void QtCAgraph::resetAutoscaleX() {
- graph->setAxisAutoScale(2);
- graph->replot();
- }
- void QtCAgraph::resetAutoscaleY() {
- graph->setAxisAutoScale(0);
- graph->replot();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement