|
|
@ -1,13 +1,41 @@ |
|
|
|
#include "mainwidget.h" |
|
|
|
#include "ui_mainwidget.h" |
|
|
|
#include <QtCore> |
|
|
|
#include "httpservice.h" |
|
|
|
#include "mainconfig.h" |
|
|
|
|
|
|
|
MainWidget::MainWidget(QWidget *parent) : |
|
|
|
QWidget(parent), |
|
|
|
ui(new Ui::MainWidget) |
|
|
|
{ |
|
|
|
ui->setupUi(this); |
|
|
|
m_patientIndex = 0; |
|
|
|
m_wsConnectedStatus = 0; |
|
|
|
m_maxPatientNum = MainConfig::maxPatientNum.toInt(); |
|
|
|
m_switchPatientInterval = MainConfig::switchPatientInterval.toInt(); |
|
|
|
|
|
|
|
//1s倒计时
|
|
|
|
m_countDownTimer.setInterval(1000); |
|
|
|
m_countDownTimer.start(); |
|
|
|
connect(&m_countDownTimer, &QTimer::timeout,[=](){ |
|
|
|
for(PatientEmergencyInfo *info : m_patientEmergencyInfos){ |
|
|
|
if(info->realCountDownInSeconds > 0){ |
|
|
|
info->realCountDownInSeconds--; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
//切换病人
|
|
|
|
m_switchPatientTimer.setInterval(5000); |
|
|
|
m_switchPatientTimer.start(); |
|
|
|
connect(&m_switchPatientTimer, &QTimer::timeout,[=](){ |
|
|
|
if(++m_patientIndex >= m_patientEmergencyInfos.length()){ |
|
|
|
m_patientIndex = 0; |
|
|
|
} |
|
|
|
updateUi(); |
|
|
|
}); |
|
|
|
|
|
|
|
//显示连接状态
|
|
|
|
ui->statusLabel->setText("Not Connected"); |
|
|
|
} |
|
|
|
|
|
|
|
MainWidget::~MainWidget() |
|
|
@ -15,13 +43,50 @@ MainWidget::~MainWidget() |
|
|
|
delete ui; |
|
|
|
} |
|
|
|
|
|
|
|
void MainWidget::updateUi() |
|
|
|
{ |
|
|
|
ui->statusLabel->setText(QString("%1 | %2") |
|
|
|
.arg(m_wsConnectedStatus == 0 ? "未连接" : "已经连") |
|
|
|
.arg(m_patientEmergencyInfos.length()) |
|
|
|
); |
|
|
|
|
|
|
|
if(m_patientEmergencyInfos.length() == 0){ |
|
|
|
//不显示
|
|
|
|
ui->textLabel->setText(""); |
|
|
|
ui->countdownLabel->setText(""); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//获取当前病人
|
|
|
|
if(m_patientIndex >= m_patientEmergencyInfos.length()){ |
|
|
|
m_patientIndex = 0; |
|
|
|
} |
|
|
|
PatientEmergencyInfo *pInfo = m_patientEmergencyInfos[m_patientIndex]; |
|
|
|
|
|
|
|
//显示文本
|
|
|
|
ui->textLabel->setText(pInfo->text); |
|
|
|
|
|
|
|
//显示倒计时
|
|
|
|
int hour,min,sec,nTotalSecs; |
|
|
|
nTotalSecs = pInfo->realCountDownInSeconds; |
|
|
|
sec = nTotalSecs % 60; |
|
|
|
min = nTotalSecs / 60 % 60; |
|
|
|
hour = nTotalSecs / 3600; |
|
|
|
QString str = QString("%1:%2").arg(min,2,10,QLatin1Char('0')).arg(sec,2,10,QLatin1Char('0')); |
|
|
|
ui->countdownLabel->setText(str); |
|
|
|
} |
|
|
|
|
|
|
|
void MainWidget::onWsConnectedStatusChanged(int status) |
|
|
|
{ |
|
|
|
qDebug() << "MainWidget::onWsConnectedStatusChanged " << status; |
|
|
|
updateUi(); |
|
|
|
} |
|
|
|
|
|
|
|
void MainWidget::onNewPatientMergencyInfo(QString firstAidId, QString name, QString content, quint64 realCountDownInSeconds) |
|
|
|
{ |
|
|
|
//TODO 此处是否需要加锁处理
|
|
|
|
PatientEmergencyInfo *pInfo = new PatientEmergencyInfo(firstAidId,name,content,realCountDownInSeconds); |
|
|
|
addPatientToList(pInfo); |
|
|
|
qDebug() << "MainWidget::onNewPatientMergencyInfo " << firstAidId << name << content << realCountDownInSeconds; |
|
|
|
} |
|
|
|
|
|
|
@ -42,6 +107,32 @@ void MainWidget::onPatientMergencyStatusChanged(QString firstAidId,QString time, |
|
|
|
if(status == 1){ //进行中(拍了一下按键)
|
|
|
|
|
|
|
|
}else if(status == 2){//服务环节结束
|
|
|
|
deletePatientFromList(firstAidId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void MainWidget::addPatientToList(PatientEmergencyInfo *info) |
|
|
|
{ |
|
|
|
//1.如果有就删除,以保证同一个病人按两次应该重新开始计时
|
|
|
|
deletePatientFromList(info->id); |
|
|
|
|
|
|
|
//2.如果超过长度,就删除第一个,取后来的
|
|
|
|
if(m_patientEmergencyInfos.length() >= m_maxPatientNum){ |
|
|
|
delete m_patientEmergencyInfos[0]; |
|
|
|
m_patientEmergencyInfos.pop_front(); |
|
|
|
} |
|
|
|
|
|
|
|
//3.加入链表
|
|
|
|
m_patientEmergencyInfos.push_back(info); |
|
|
|
} |
|
|
|
|
|
|
|
void MainWidget::deletePatientFromList(QString firstAidId) |
|
|
|
{ |
|
|
|
for(int i=0;i<m_patientEmergencyInfos.length();i++){ |
|
|
|
if(m_patientEmergencyInfos[i]->id == firstAidId){ |
|
|
|
delete m_patientEmergencyInfos[i]; |
|
|
|
m_patientEmergencyInfos.removeAt(i); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|