283 lines
10 KiB
C++
283 lines
10 KiB
C++
#include "SystemSelfcheck.h"
|
|
#include "ui_SystemSelfcheck.h"
|
|
#include "NetMgr.h"
|
|
#include <QNetworkRequest>
|
|
#include "global.h"
|
|
|
|
CSystemSelfcheck::CSystemSelfcheck(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::CSystemSelfcheck)
|
|
{
|
|
ui->setupUi(this);
|
|
ui->widget_6->setProperty("flag", "Title");
|
|
ui->widget->setProperty("flag", "normal");
|
|
|
|
m_centerLabel = new QLabel(ui->chartView);
|
|
m_centerLabel->setStyleSheet(QString("background:transparent;font-family:\"微软雅黑\";"
|
|
"font-size:20px; color:#409CE1; font-weight:900;"));
|
|
m_centerLabel->hide();
|
|
|
|
|
|
|
|
initPieChart();
|
|
bulidPieChart(0);
|
|
|
|
}
|
|
|
|
CSystemSelfcheck::~CSystemSelfcheck()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
|
|
void CSystemSelfcheck::resizeEvent(QResizeEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
|
|
m_centerLabel->move((ui->chartView->width()-m_centerLabel->width())/2,
|
|
(ui->chartView->height()-m_centerLabel->height())/2);
|
|
|
|
// m_bottomLabel->move((ui->chartView->width()-m_bottomLabel->width())/2,
|
|
// ui->chartView->height() - m_bottomLabel->height() - 15);
|
|
}
|
|
|
|
void CSystemSelfcheck::slotNetMgr(QString sAddr,const QVariant& msg)
|
|
{
|
|
QJsonObject objec = msg.value<QJsonObject>();
|
|
if(!objec["success"].toBool()){
|
|
QString strMessage = objec["message"].toString();
|
|
if(strMessage.isEmpty())
|
|
QMessageBox::information(this, QStringLiteral("提示"), "连接失败!");
|
|
else
|
|
QMessageBox::information(this, QStringLiteral("提示"), strMessage);
|
|
return;
|
|
}
|
|
if(objec.contains("cmd")){
|
|
bulidPieChart(100);
|
|
ui->label_CPU->setText("正常");
|
|
ui->label_Power->setText("正常");
|
|
ui->label_CPU->setStyleSheet("color:green");
|
|
ui->label_Power->setStyleSheet("color:green");
|
|
QJsonValue arrays_value = objec.take("cmd");
|
|
qDebug()<<"cmd ="<<arrays_value.toString();
|
|
if(arrays_value.toString() == "42"){
|
|
QJsonArray contentArray = objec["content"].toArray();
|
|
if(contentArray.at(0)["state"] == 0){
|
|
ui->label_Board1->setText("待检");
|
|
}
|
|
if(contentArray.at(0)["state"] == 1){
|
|
ui->label_Board1->setText("检验失败");
|
|
ui->label_Board1->setStyleSheet("color:#ff0000");
|
|
}
|
|
if(contentArray.at(0)["state"] == 2){
|
|
ui->label_Board1->setText("无板卡");
|
|
ui->label_Board1->setStyleSheet("color:#ff9900");
|
|
}
|
|
if(contentArray.at(0)["state"] == 3){
|
|
ui->label_Board1->setText("板卡正常");
|
|
ui->label_Board1->setStyleSheet("color:green");
|
|
|
|
}
|
|
|
|
if(contentArray.at(1)["state"] == 0){
|
|
ui->label_Board2->setText("待检");
|
|
}
|
|
if(contentArray.at(1)["state"] == 1){
|
|
ui->label_Board2->setText("检验失败");
|
|
ui->label_Board2->setStyleSheet("color:#ff0000");
|
|
}
|
|
if(contentArray.at(1)["state"] == 2){
|
|
ui->label_Board2->setText("无板卡");
|
|
ui->label_Board2->setStyleSheet("color:#ff9900");
|
|
}
|
|
if(contentArray.at(1)["state"] == 3){
|
|
ui->label_Board2->setText("板卡正常");
|
|
ui->label_Board2->setStyleSheet("color:green");
|
|
}
|
|
|
|
if(contentArray.at(2)["state"] == 0){
|
|
ui->label_Board3->setText("待检");
|
|
}
|
|
if(contentArray.at(2)["state"] == 1){
|
|
ui->label_Board3->setText("检验失败");
|
|
ui->label_Board3->setStyleSheet("color:#ff0000");
|
|
}
|
|
if(contentArray.at(2)["state"] == 2){
|
|
ui->label_Board3->setText("无板卡");
|
|
ui->label_Board3->setStyleSheet("color:#ff9900");
|
|
}
|
|
if(contentArray.at(2)["state"] == 3){
|
|
ui->label_Board3->setText("板卡正常");
|
|
ui->label_Board3->setStyleSheet("color:green");
|
|
}
|
|
|
|
if(contentArray.at(3)["state"] == 0){
|
|
ui->label_Board4->setText("待检");
|
|
}
|
|
if(contentArray.at(3)["state"] == 1){
|
|
ui->label_Board4->setText("检验失败");
|
|
ui->label_Board4->setStyleSheet("color:#ff0000");
|
|
}
|
|
if(contentArray.at(3)["state"] == 2){
|
|
ui->label_Board4->setText("无板卡");
|
|
ui->label_Board4->setStyleSheet("color:#ff9900");
|
|
}
|
|
if(contentArray.at(3)["state"] == 3){
|
|
ui->label_Board4->setText("板卡正常");
|
|
ui->label_Board4->setStyleSheet("color:green");
|
|
}
|
|
|
|
if(contentArray.at(4)["state"] == 0){
|
|
ui->label_Board5->setText("待检");
|
|
}
|
|
if(contentArray.at(4)["state"] == 1){
|
|
ui->label_Board5->setText("检验失败");
|
|
ui->label_Board5->setStyleSheet("color:#ff0000");
|
|
}
|
|
if(contentArray.at(4)["state"] == 2){
|
|
ui->label_Board5->setText("无板卡");
|
|
ui->label_Board5->setStyleSheet("color:#ff9900");
|
|
}
|
|
if(contentArray.at(4)["state"] == 3){
|
|
ui->label_Board5->setText("板卡正常");
|
|
ui->label_Board5->setStyleSheet("color:green");
|
|
}
|
|
|
|
if(contentArray.at(5)["state"] == 0){
|
|
ui->label_Board6->setText("待检");
|
|
}
|
|
if(contentArray.at(5)["state"] == 1){
|
|
ui->label_Board6->setText("检验失败");
|
|
ui->label_Board6->setStyleSheet("color:#ff0000");
|
|
}
|
|
if(contentArray.at(5)["state"] == 2){
|
|
ui->label_Board6->setText("无板卡");
|
|
ui->label_Board6->setStyleSheet("color:#ff9900");
|
|
}
|
|
if(contentArray.at(5)["state"] == 3){
|
|
ui->label_Board6->setText("板卡正常");
|
|
ui->label_Board6->setStyleSheet("color:green");
|
|
}
|
|
|
|
if(contentArray.at(6)["state"] == 0){
|
|
ui->label_Board7->setText("待检");
|
|
}
|
|
if(contentArray.at(6)["state"] == 1){
|
|
ui->label_Board7->setText("检验失败");
|
|
ui->label_Board7->setStyleSheet("color:#ff0000");
|
|
}
|
|
if(contentArray.at(6)["state"] == 2){
|
|
ui->label_Board7->setText("无板卡");
|
|
ui->label_Board7->setStyleSheet("color:#ff9900");
|
|
}
|
|
if(contentArray.at(6)["state"] == 3){
|
|
ui->label_Board7->setText("板卡正常");
|
|
ui->label_Board7->setStyleSheet("color:green");
|
|
}
|
|
|
|
if(contentArray.at(7)["state"] == 0){
|
|
ui->label_Board8->setText("待检");
|
|
}
|
|
if(contentArray.at(7)["state"] == 1){
|
|
ui->label_Board8->setText("检验失败");
|
|
ui->label_Board8->setStyleSheet("color:#ff0000");
|
|
}
|
|
if(contentArray.at(7)["state"] == 2){
|
|
ui->label_Board8->setText("无板卡");
|
|
ui->label_Board8->setStyleSheet("color:#ff9900");
|
|
}
|
|
if(contentArray.at(7)["state"] == 3){
|
|
ui->label_Board8->setText("板卡正常");
|
|
ui->label_Board8->setStyleSheet("color:green");
|
|
}
|
|
|
|
if(contentArray.at(8)["state"] == 0){
|
|
ui->label_Board9->setText("待检");
|
|
}
|
|
if(contentArray.at(8)["state"] == 1){
|
|
ui->label_Board9->setText("检验失败");
|
|
ui->label_Board9->setStyleSheet("color:#ff0000");
|
|
}
|
|
if(contentArray.at(8)["state"] == 2){
|
|
ui->label_Board9->setText("无板卡");
|
|
ui->label_Board9->setStyleSheet("color:#ff9900");
|
|
}
|
|
if(contentArray.at(8)["state"] == 3){
|
|
ui->label_Board9->setText("板卡正常");
|
|
ui->label_Board9->setStyleSheet("color:green");
|
|
}
|
|
|
|
if(contentArray.at(9)["state"] == 0){
|
|
ui->label_Board10->setText("待检");
|
|
}
|
|
if(contentArray.at(9)["state"] == 1){
|
|
ui->label_Board10->setText("检验失败");
|
|
ui->label_Board10->setStyleSheet("color:#ff0000");
|
|
}
|
|
if(contentArray.at(9)["state"] == 2){
|
|
ui->label_Board10->setText("无板卡");
|
|
ui->label_Board10->setStyleSheet("color:#ff9900");
|
|
}
|
|
if(contentArray.at(9)["state"] == 3){
|
|
ui->label_Board10->setText("板卡正常");
|
|
ui->label_Board10->setStyleSheet("color:green");
|
|
}
|
|
|
|
}
|
|
}
|
|
disconnect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&)));
|
|
}
|
|
void CSystemSelfcheck::initPieChart()
|
|
{
|
|
QChart *chart = new QChart();
|
|
|
|
chart->setAnimationOptions(QChart::SeriesAnimations);
|
|
|
|
m_ChartView = ui->chartView;
|
|
ui->chartView->setChart(chart);
|
|
ui->chartView->setRenderHint(QPainter::Antialiasing);
|
|
}
|
|
|
|
|
|
void CSystemSelfcheck::bulidPieChart(int percent)
|
|
{
|
|
m_centerLabel->setText(QString(" %1%\n%2").arg(percent).arg("自检进度"));
|
|
QChart *chart = ui->chartView->chart();
|
|
chart->removeAllSeries();
|
|
|
|
ui->chartView->setRenderHint(QPainter::NonCosmeticDefaultPen);
|
|
QPieSeries *series = new QPieSeries();//创建饼图序列
|
|
series->setHoleSize(0.66);//饼图中间空心的大小
|
|
series->setPieSize(0.8);//饼图的大小
|
|
|
|
QPieSlice *slice0 = new QPieSlice();
|
|
slice0->setValue(percent);
|
|
slice0->setColor(QColor(64, 156, 225));
|
|
|
|
QPieSlice *slice1 = new QPieSlice();
|
|
slice1->setValue(100 - percent);
|
|
slice1->setColor(QColor(231, 238, 251));
|
|
|
|
series->append(slice0);
|
|
series->append(slice1);
|
|
|
|
chart->addSeries(series);
|
|
chart->legend()->setVisible(false);
|
|
|
|
m_centerLabel->show();
|
|
resizeEvent(NULL);
|
|
}
|
|
|
|
void CSystemSelfcheck::on_pushButton_check_clicked()
|
|
{
|
|
//绑定HTTP消息响应
|
|
connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&)));
|
|
QJsonObject allObj,cmdBody;
|
|
allObj.insert("cmd", "42");
|
|
QNetworkRequest req;
|
|
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
|
|
req.setUrl(sUrl);
|
|
g_NetMgr->PostJson(req,allObj);
|
|
}
|
|
|