daily pastebin goal
44%
SHARE
TWEET

mon_widget.cpp

a guest Jun 24th, 2011 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <QtPlugin>
  2.  
  3. #include <QtGui>
  4. #include <QProcess>
  5. #include <QLineEdit>
  6.  
  7. #include <mon_widget.hpp>
  8.  
  9. QtCAmon::QtCAmon(QWidget* parent) : QWidget(parent) {
  10.     pv_val = new QLabel("PV value",this);
  11.     updateButton = new QPushButton("Start monitor",this);
  12.     pv_name = new QLineEdit("PV name",this);
  13.     proc = new QProcess(this);
  14.  
  15.     connect(updateButton,SIGNAL(clicked()),
  16.             this,SLOT(updateClicked()) );
  17.     connect(proc,SIGNAL(readyReadStandardOutput()),
  18.             this,SLOT(readFromStdout()) );
  19.  
  20.     layout1 = new QHBoxLayout;
  21.     layout1->addWidget(pv_name);
  22.     layout1->addWidget(pv_val);
  23.     layout1->addWidget(updateButton);
  24.  
  25.     setLayout(layout1);
  26. }
  27.  
  28. QtCAmon::~QtCAmon() {
  29.     delete pv_val;
  30.     delete updateButton;
  31.     delete pv_name;
  32.     delete proc;
  33.  
  34.     delete layout1;
  35. }
  36.  
  37. void QtCAmon::updateClicked() {
  38.     QString pv = pv_name->text();
  39.     QStringList args;
  40.     args << "-f 4" << pv;
  41.  
  42.     program = "camonitor";
  43.  
  44.     if(proc->state()) {
  45.         proc->terminate();
  46.         updateButton->setText("Start monitor");
  47.     }
  48.     else {
  49.         proc->start(program,args);
  50.         updateButton->setText("Stop monitor");
  51.     }
  52.  
  53. }
  54.  
  55. void QtCAmon::readFromStdout() {
  56.     QByteArray output;
  57.     output = proc->readAllStandardOutput();
  58.  
  59.     QTextStream test(output);
  60.     QString name;
  61.     QString day;
  62.     QString time;
  63.     double value;
  64.     QString status;
  65.     QString severity;
  66.  
  67.     test >> name;
  68.     test >> day;
  69.     test >> time;
  70.     test >> value;
  71.     test >> status;
  72.     test >> severity;
  73.  
  74.     QString out(QString::number(value,'g',6));
  75.  
  76.     if(QString::compare(severity,"MINOR",Qt::CaseInsensitive) == 0) {
  77.         out = out.prepend("<font color=yellow>");
  78.         out = out.append("</font>");
  79.     }
  80.  
  81.     else if (QString::compare(severity,"MAJOR",Qt::CaseInsensitive) == 0) {
  82.         out = out.prepend("<font color=red>");
  83.         out = out.append("</font>");
  84.     }
  85.  
  86.     pv_val->setText(out);
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top