328 lines
14 KiB
C++
328 lines
14 KiB
C++
#include "TerminalInfo.h"
|
||
#include "ui_TerminalInfo.h"
|
||
#include "NetMgr.h"
|
||
#include <QNetworkRequest>
|
||
#include "ftpclient.h"
|
||
#include "CopyDatFile.h"
|
||
#include "Backup.h"
|
||
#include "ImportConfig.h"
|
||
|
||
CTerminalInfo::CTerminalInfo(QWidget *parent) :
|
||
QWidget(parent),
|
||
ui(new Ui::CTerminalInfo)
|
||
{
|
||
ui->setupUi(this);
|
||
ui->widget->setProperty("flag", "Title");
|
||
ui->widget_2->setProperty("flag", "normal");
|
||
// m_centerLabel1 = new QLabel(/*ui->groupBox_2*/);
|
||
// m_centerLabel1->setStyleSheet(QString("background:transparent;font-family:\"微软雅黑\";"
|
||
// "font-size:20px; color:#1564FF; font-weight:900;"));
|
||
// m_centerLabel1->hide();
|
||
|
||
//绑定HTTP消息响应
|
||
connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&)));
|
||
|
||
|
||
QJsonObject allObj,cmdBody;
|
||
allObj.insert("cmd", "07");
|
||
QNetworkRequest req;
|
||
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
|
||
req.setUrl(sUrl);
|
||
g_NetMgr->PostJson(req,allObj);
|
||
|
||
allObj.insert("cmd", "20");
|
||
cmdBody.insert("type","GET");
|
||
allObj["cmdBody"] = cmdBody;
|
||
req.setUrl(sUrl);
|
||
|
||
g_NetMgr->PostJson(req,allObj);
|
||
|
||
|
||
headerStr = QObject::tr("文件名称,创建时间,文件大小(MB),警报记录");
|
||
model = new QStandardItemModel(ui->tableView);
|
||
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); //选中行
|
||
QStringList headerList = headerStr.split(",");
|
||
model->setHorizontalHeaderLabels(headerList);
|
||
model->setColumnCount(headerList.size());
|
||
ui->tableView->setModel(model);
|
||
ui->tableView->setColumnWidth(0, 700);
|
||
ui->tableView->setColumnWidth(1, 200);
|
||
ui->tableView->setColumnWidth(2, 150);
|
||
ui->tableView->setColumnWidth(3, 150);
|
||
ui->tableView->setAlternatingRowColors(true);
|
||
model->setRowCount(10);
|
||
|
||
|
||
double cpuUserUse = 10,memoryUse = 20,hardDiskUse = 30,temperature = 60;
|
||
QString updateTime = "1583487670";
|
||
ui->label_Version_GUI->setText(g_strVersion);
|
||
//UpdateChart(cpuUserUse,memoryUse,memoryUse,temperature,updateTime);
|
||
|
||
|
||
// QString strTile = QString("CPU 占用 1%").arg(cpuUserUse);
|
||
// QChartView *chartView = new QChartView(bulidPieChart(cpuUserUse,strTile));
|
||
|
||
// chartView->setRenderHint(QPainter::Antialiasing);
|
||
// qDebug() << chartView->width() << chartView->height() << endl;
|
||
|
||
// m_centerLabel1 = new QLabel(chartView);
|
||
// m_centerLabel1->setStyleSheet(QString("background:transparent;font-family:\"微软雅黑\";"
|
||
// "font-size:20px; color:#409CE1; font-weight:900;"));
|
||
// m_centerLabel1->setText(QString(" %1%").arg(cpuUserUse));
|
||
// m_centerLabel1->move((chartView->width()-m_centerLabel1->width())/2-105,
|
||
// (chartView->height()-m_centerLabel1->height())/2-50);
|
||
// m_centerLabel1->show();
|
||
// QLabel *label = new QLabel ();
|
||
// QDateTime::fromSecsSinceEpoch(updateTime.toInt()).toString("yyyy-MM-dd hh:mm:ss");
|
||
// QString strTime = QString(" 最近更新的时间:%1 设备温度:%2℃").arg(QDateTime::fromSecsSinceEpoch(updateTime.toInt()).toString("yyyy-MM-dd hh:mm:ss")).arg(temperature);
|
||
// label->setText(strTime);
|
||
// //baseLayout->addWidget(label,0,0);
|
||
// baseLayout->addWidget(chartView,1,0);
|
||
|
||
|
||
// //baseLayout->addWidget(m_centerLabel1,0,0);
|
||
// strTile = QString("内存 占用 1%").arg(memoryUse);
|
||
// chartView=new QChartView(bulidPieChart(memoryUse,strTile));
|
||
// chartView->setRenderHint(QPainter::Antialiasing);
|
||
// m_centerLabel2 = new QLabel(chartView);
|
||
// m_centerLabel2->setStyleSheet(QString("background:transparent;font-family:\"微软雅黑\";"
|
||
// "font-size:20px; color:#409CE1; font-weight:900;"));
|
||
// m_centerLabel2->setText(QString(" %1%").arg(memoryUse));
|
||
// m_centerLabel2->move((chartView->width()-m_centerLabel2->width())/2-105,
|
||
// (chartView->height()-m_centerLabel2->height())/2-50);
|
||
// m_centerLabel2->show();
|
||
|
||
// baseLayout->addWidget(chartView,1,1);
|
||
|
||
// strTile = QString("硬盘 占用 1%").arg(hardDiskUse);
|
||
// chartView = new QChartView(bulidPieChart(hardDiskUse,strTile));
|
||
// chartView->setRenderHint(QPainter::Antialiasing);//抗锯齿
|
||
// m_centerLabel3 = new QLabel(chartView);
|
||
// m_centerLabel3->setStyleSheet(QString("background:transparent;font-family:\"微软雅黑\";"
|
||
// "font-size:20px; color:#409CE1; font-weight:900;"));
|
||
// m_centerLabel3->setText(QString(" %1%").arg(hardDiskUse));
|
||
// m_centerLabel3->move((chartView->width()-m_centerLabel3->width())/2-105,
|
||
// (chartView->height()-m_centerLabel3->height())/2-50);
|
||
// m_centerLabel3->show();
|
||
// baseLayout->addWidget(chartView,1,2);
|
||
|
||
// ui->groupBox_2->setLayout(baseLayout);
|
||
|
||
}
|
||
|
||
CTerminalInfo::~CTerminalInfo()
|
||
{
|
||
delete ui;
|
||
}
|
||
|
||
void CTerminalInfo::UpdateChart(double & cpuUserUse, double & hardDiskUse, double & memoryUse,double & temperature, QString &updateTime)
|
||
{
|
||
|
||
QGridLayout *baseLayout = new QGridLayout();//布局管理器
|
||
|
||
QGridLayout *TitlebaseLayout = new QGridLayout();//布局管理器
|
||
QString strTile = QString(" CPU占用:%1%,").arg((int)cpuUserUse);
|
||
// QChartView *chartView = new QChartView(bulidPieChart((int)cpuUserUse,strTile));
|
||
|
||
// chartView->setRenderHint(QPainter::Antialiasing);
|
||
// qDebug() << chartView->width() << chartView->height() << endl;
|
||
// chartView->setMaximumWidth(200);
|
||
// chartView->setMaximumHeight(200);
|
||
|
||
// m_centerLabel1 = new QLabel(chartView);
|
||
// m_centerLabel1->setStyleSheet(QString("background:transparent;font-family:\"微软雅黑\";"
|
||
// "font-size:20px; color:#409CE1; font-weight:900;"));
|
||
// m_centerLabel1->setText(QString(" %1%").arg((int)cpuUserUse));
|
||
// m_centerLabel1->move((chartView->width()-m_centerLabel1->width())/2+10,
|
||
// (chartView->height()-m_centerLabel1->height())/2-50);
|
||
// m_centerLabel1->show();
|
||
QLabel *label = new QLabel ();
|
||
QString strTime = QString(" 最近更新的时间:%1 \n 设备温度:%2℃").arg(QDateTime::fromSecsSinceEpoch(updateTime.toInt()).toString("yyyy-MM-dd hh:mm:ss")).arg((int)temperature);
|
||
label->setText(strTime);
|
||
TitlebaseLayout->addWidget(label,0,0);
|
||
QLabel *labelCPU = new QLabel ();
|
||
labelCPU->setText(strTile);
|
||
baseLayout->addWidget(labelCPU,0,0);
|
||
|
||
|
||
//baseLayout->addWidget(m_centerLabel1,0,0);
|
||
strTile = QString("内存占用:%1%,").arg((int)memoryUse);
|
||
QLabel *labelMemory = new QLabel ();
|
||
labelMemory->setText(strTile);
|
||
baseLayout->addWidget(labelMemory,0,1);
|
||
|
||
// chartView=new QChartView(bulidPieChart((int)memoryUse,strTile));
|
||
// chartView->setMaximumWidth(200);
|
||
// chartView->setMaximumHeight(200);
|
||
|
||
// chartView->setRenderHint(QPainter::Antialiasing);
|
||
// m_centerLabel2 = new QLabel(chartView);
|
||
// m_centerLabel2->setStyleSheet(QString("background:transparent;font-family:\"微软雅黑\";"
|
||
// "font-size:20px; color:#409CE1; font-weight:900;"));
|
||
// m_centerLabel2->setText(QString(" %1%").arg((int)memoryUse));
|
||
// m_centerLabel2->move((chartView->width()-m_centerLabel2->width())/2+10,
|
||
// (chartView->height()-m_centerLabel2->height())/2-50);
|
||
// m_centerLabel2->show();
|
||
|
||
// baseLayout->addWidget(chartView,0,1);
|
||
|
||
strTile = QString("硬盘占用:%1%").arg((int)hardDiskUse);
|
||
// chartView = new QChartView(bulidPieChart((int)hardDiskUse,strTile));
|
||
// chartView->setMaximumWidth(200);
|
||
// chartView->setMaximumHeight(200);
|
||
|
||
// chartView->setRenderHint(QPainter::Antialiasing);//抗锯齿
|
||
// m_centerLabel3 = new QLabel(chartView);
|
||
// m_centerLabel3->setStyleSheet(QString("background:transparent;font-family:\"微软雅黑\";"
|
||
// "font-size:20px; color:#409CE1; font-weight:900;"));
|
||
// m_centerLabel3->setText(QString(" %1%").arg((int)hardDiskUse));
|
||
// m_centerLabel3->move((chartView->width()-m_centerLabel3->width())/2+10,
|
||
// (chartView->height()-m_centerLabel3->height())/2-50);
|
||
// m_centerLabel3->show();
|
||
QLabel *labelDisk = new QLabel ();
|
||
labelDisk->setText(strTile);
|
||
baseLayout->addWidget(labelDisk,0,2);
|
||
|
||
ui->widget_Title->setLayout(TitlebaseLayout);
|
||
ui->widget_Chart->setLayout(baseLayout);
|
||
|
||
}
|
||
|
||
void CTerminalInfo::slotNetMgr(QString sAddr, const QVariant &msg)
|
||
{
|
||
QJsonObject objec = msg.value<QJsonObject>();
|
||
if(objec.contains("cmd"))
|
||
{
|
||
QJsonValue arrays_value = objec.take("cmd");
|
||
qDebug()<<"cmd ="<<arrays_value.toString();
|
||
if(arrays_value.toString() == "07"){
|
||
QJsonObject contentObj = objec["content"].toObject();
|
||
double cpuUserUse = contentObj["cpuUserUse"].toDouble();
|
||
double hardDiskUse = contentObj["hardDiskUse"].toString().toDouble();
|
||
double memoryUse = contentObj["memoryUse"].toDouble();
|
||
double temperature = contentObj["temperature"].toDouble();
|
||
QString updateTime = contentObj["updateTime"].toString();
|
||
UpdateChart(cpuUserUse,hardDiskUse,memoryUse,temperature,updateTime);
|
||
}
|
||
if(arrays_value.toString() == "20"){
|
||
QJsonObject contentObj = objec["content"].toObject();
|
||
QJsonObject sysObj = contentObj["SystemInfo"].toObject();
|
||
ui->label_DatawatchNo->setText(sysObj["dataWatchNo"].toString());
|
||
ui->label_DatawatchName->setText(sysObj["dataWatchName"].toString());
|
||
ui->label_Version->setText(sysObj["softVersion"].toString());
|
||
ui->label_Type->setText(sysObj["deviceType"].toString());
|
||
ui->label_SerialNo->setText(sysObj["serialNumber"].toString());
|
||
//ui->label_Address->setText(sysObj["dataWatchIpAddress"].toString());
|
||
}
|
||
}
|
||
}
|
||
|
||
void CTerminalInfo::resizeEvent(QResizeEvent *event)
|
||
{
|
||
Q_UNUSED(event)
|
||
|
||
// m_centerLabel1->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);
|
||
}
|
||
|
||
QChart * CTerminalInfo::bulidPieChart(int percent,QString& strTitle )
|
||
{
|
||
|
||
//QChart *chart = ui->chartView->chart();
|
||
QChart *chart = new QChart();
|
||
// chart->removeAllSeries();
|
||
chart->setTitle(strTitle);
|
||
QFont font;
|
||
font.setPixelSize(14);
|
||
font.setFamily(QStringLiteral("黑体"));
|
||
chart->setTitleFont(font);
|
||
// 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);
|
||
|
||
|
||
resizeEvent(NULL);
|
||
return chart;
|
||
}
|
||
|
||
void CTerminalInfo::on_pushButton_Update_clicked()
|
||
{
|
||
QStringList items;//ComboBox控件的内容
|
||
items<<QStringLiteral("系统")<<QStringLiteral("后端主程序")<<QStringLiteral("后端辅助程序");
|
||
QString dlgTitle=QStringLiteral("更新内容选择对话框");//对话框标题
|
||
QString txtLabel=QStringLiteral("请选择更新类别:");//对话框Label显示内容
|
||
int curIndex = 0;//ComboBox控件默认哪个索引的内容
|
||
bool editable = true;//ComboBox控件内容是否可被编辑
|
||
bool ok = false;
|
||
QString text = QInputDialog::getItem(this,dlgTitle,txtLabel,items,curIndex,editable,&ok);
|
||
if(!ok || text.isEmpty())
|
||
{
|
||
return;
|
||
}
|
||
|
||
QString filepath = QFileDialog::getOpenFileName(this, tr("选择文件"), tr(""), tr("*"));
|
||
qDebug() << filepath << endl;
|
||
QFileInfo fileinfo;
|
||
fileinfo = QFileInfo(filepath);
|
||
QString file_suffix = fileinfo.suffix();
|
||
QString FileName = fileinfo.fileName();
|
||
if(FileName.isEmpty())
|
||
return;
|
||
|
||
QString str = QString("ftp://%1/var/%2").arg(IP).arg(FileName);
|
||
g_FtpClient->SetServerInfo(str);
|
||
g_FtpClient->SetUserInfo("root","@#cidw!@123456");
|
||
if(text == "系统")
|
||
curIndex = 0;
|
||
else if(text == "后端主程序")
|
||
curIndex = 1;
|
||
g_FtpClient->UpLoadFile(filepath,FileName,curIndex);
|
||
}
|
||
|
||
|
||
void CTerminalInfo::on_pushButtonCopy_clicked()
|
||
{
|
||
CCopyDatFile *copyDatDialog = new CCopyDatFile();
|
||
copyDatDialog->setWindowModality(Qt::ApplicationModal);
|
||
copyDatDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||
copyDatDialog->show();
|
||
}
|
||
|
||
void CTerminalInfo::on_pushButton_export_clicked()
|
||
{
|
||
CBackup *BackupDialog = new CBackup();
|
||
BackupDialog->setWindowModality(Qt::ApplicationModal);
|
||
BackupDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||
BackupDialog->setWindowFlags(BackupDialog->windowFlags() &~ Qt::WindowMaximizeButtonHint);
|
||
BackupDialog->show();
|
||
}
|
||
|
||
|
||
void CTerminalInfo::on_pushButton_import_clicked()
|
||
{
|
||
CImportConfig *ImportConfigDialog = new CImportConfig();
|
||
ImportConfigDialog->setWindowModality(Qt::ApplicationModal);
|
||
ImportConfigDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||
ImportConfigDialog->setWindowFlags(ImportConfigDialog->windowFlags() &~ Qt::WindowMaximizeButtonHint);
|
||
ImportConfigDialog->show();
|
||
}
|
||
|