项目主进程接收报警后,将alarm msg 发送给代理, 并将其分发:
else if (msg.name == "MesLCUalarmRep") {
QString errorText;
QXmlTools tool;
int status;
int code;
int severity;
if ( tool.setData(msg.body, errorText) ) {
QDomElement root = tool.getDocument()->documentElement();
QString tag = root.tagName();
if ( tag == "Body" ) {
QDomNode child = root.firstChild();
while ( !child.isNull() ) {
tag = child.toElement().tagName();
if ( tag == "STAT" ) {
QString text_status = child.toElement().text();
if( text_status == "MesInfo" ){
//return;
}
status = ( text_status.toUpper() == "MESON" ) ? : ;
}
else if ( tag == "ErrorType" ) {
severity = ( child.toElement().text().toUpper() == "HEAVY" ) ? : ;
}
else if ( tag == "ErrorMessage" ) {
errorText = child.toElement().text();
}
else if ( tag == "ErrorCode" ) {
code = atoi( child.toElement().text().toLatin1().data() );
}
child = child.nextSibling();
}
if(code == COMMONDEFECTALARMCODE || code == GLASSBROKENCALLCODE)
{
debug("enter common defect judge insertAlarm [%d] waitAlarmList.size:[%d]",code, waitAlarmList.size());
switchAlarmCode(code); }
sendAlarmDetail2GUI(errorText);
/**
*@projectName BoeB9Project
*@author Hasan
**/
void BoeB9QtmCellInlineMain::sendAlarmDetail2GUI(QString errorMsg)
{
mgrGlassMapCellInlineBoeB9Lst& GlassMapLst = mgrGlassMapCellInlineBoeB9Lst::GetInstance(); QString diffMsg = "4H"; QString errorTIme = QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss");
QString errorGls = GlassMapLst.GetJobGlassFromkey("GlsID"); if(errorGls == "") errorGls = "9AAB85001702a1";
else if(errorGls.size()< && errorGls != "") errorGls.append(" "); errorMsg = diffMsg + errorTIme + errorGls + errorMsg; sendMesGUIOperatorCallMsg(errorMsg);
}
代理将其分发后GUI接收此alarm, 并且将其在独立窗口显示:
void BoeB9InlineMainForm::showOperatorCallMsg(QString msg)
{
if(msg.startsWith("4H"))
showAlarmList(msg);
else
{
opCallDialog->insertMassge(msg);
opCallDialog->show();
}
}
void BoeB9InlineMainForm::showAlarmList(QString alarmMsg)
{
alarmListForm->addAlarmItem2List(alarmMsg.mid(, alarmMsg.size()-));
alarmListForm->show();
}
独立窗口代码如此,并且点击窗口上的confirm按钮,可以将其输出文件保存:
#include "alarmlistform.h"
#include "ui_alarmlistform.h"
#include <QMessageBox> AlarmListForm::AlarmListForm(QWidget *parent, Qt::WindowFlags) :
QWidget(parent),
ui(new Ui::AlarmListForm),
currentRow(-)
{
ui->setupUi(this);
setWindowTitle("Alarm List"); QString currentDay = QDateTime::currentDateTime().toString("yyyy-MM-dd");
QString filePath = SMCU_WORK_PATH "/";
filePath += currentDay;
filePath += "-alarmList.dat";
file = new QFile(filePath); } AlarmListForm::~AlarmListForm()
{
delete ui;
} void AlarmListForm::addAlarmItem2List(QString alarmMsg)
{
QListWidgetItem *item = new QListWidgetItem;
item->setText(alarmMsg);
ui->listWidget->addItem(item);
} void AlarmListForm::on_pushButton_clicked()
{
if(currentRow < )
return; showDetailAlarm(currentRow); currentRow = -;
} void AlarmListForm::on_listWidget_clicked(const QModelIndex &index)
{
currentRow = ui->listWidget->currentRow();
} void AlarmListForm::on_pushButton_2_clicked()
{
int count = ui->listWidget->count();
for(int index = count; index >= ; index --)
{
QListWidgetItem *item = ui->listWidget->takeItem(index);
delete item;
}
this->close();
} void AlarmListForm::on_listWidget_doubleClicked(const QModelIndex &index)
{
showDetailAlarm(ui->listWidget->currentRow());
} void AlarmListForm::showDetailAlarm(int row)
{
QListWidgetItem *item = ui->listWidget->item(row);
QString alarmDetail = item->text();
int ans = QMessageBox::question(this,
tr("Alarm Detail"),
tr(alarmDetail.toLatin1().data()),
QMessageBox::Save | QMessageBox::Cancel);
if(ans == QMessageBox::Save)
{
saveAlarm2File(alarmDetail);
delete item;
} } void AlarmListForm::saveAlarm2File(QString alarmMsg)
{
if(!file->isOpen())
{
if(file->open(QIODevice::Append | QIODevice::Text))
{
}
else
{
return;
} }
if(alarmMsg.size() <= )
{
QTextStream buff(file);
buff<<"<Time>" << "alarmMsg.left(10)" << "</Time>";
return;
}
QTextStream buff(file);
buff<<"<Time>" << alarmMsg.mid(, ) << "</Time>";
buff<<"<GlsID>" << alarmMsg.mid(, ) << "</GlsID>";
buff<<"<AlarmMsg>" << alarmMsg.mid(, alarmMsg.size()-) << "</AlarmMsg>";
buff<<endl; buff.flush();
file->close();
}