Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QtPlugin>
- #include <QtGui>
- #include <QProcess>
- #include <QLineEdit>
- #include <mon_widget.hpp>
- QtCAmon::QtCAmon(QWidget* parent) : QWidget(parent) {
- pv_val = new QLabel("PV value",this);
- updateButton = new QPushButton("Start monitor",this);
- pv_name = new QLineEdit("PV name",this);
- proc = new QProcess(this);
- connect(updateButton,SIGNAL(clicked()),
- this,SLOT(updateClicked()) );
- connect(proc,SIGNAL(readyReadStandardOutput()),
- this,SLOT(readFromStdout()) );
- layout1 = new QHBoxLayout;
- layout1->addWidget(pv_name);
- layout1->addWidget(pv_val);
- layout1->addWidget(updateButton);
- setLayout(layout1);
- }
- QtCAmon::~QtCAmon() {
- delete pv_val;
- delete updateButton;
- delete pv_name;
- delete proc;
- delete layout1;
- }
- void QtCAmon::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 QtCAmon::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;
- QString out(QString::number(value,'g',6));
- if(QString::compare(severity,"MINOR",Qt::CaseInsensitive) == 0) {
- out = out.prepend("<font color=yellow>");
- out = out.append("</font>");
- }
- else if (QString::compare(severity,"MAJOR",Qt::CaseInsensitive) == 0) {
- out = out.prepend("<font color=red>");
- out = out.append("</font>");
- }
- pv_val->setText(out);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement