当前位置:网站首页>Real time software source code of COVID-19
Real time software source code of COVID-19
2022-06-12 13:33:00 【You stole my name】
main function
#include "widget.h"
#include<QFile>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QFile qss(":/style/main.qss");
qss.open(QFile::ReadOnly);
a.setStyleSheet(qss.readAll());
qss.close();
Widget w;
w.show();
return a.exec();
}
//widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include<QtCharts>
#include <QWidget>
#include<QNetworkAccessManager>
#include<QNetworkReply>
#include<QTimer>
#include<QCoreApplication>
using namespace QtCharts;
QT_BEGIN_NAMESPACE
namespace Ui {
class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
void loadStyleSheet(const QString &sheetName);// Load style file
void createChart();// Create a chart
void setChartValue(QJsonArray &obj);// Set values for the chart
void httprequest();
void showData();
void showDetail(QJsonArray &array);
void chinaToday(QJsonObject &obj);
void chinaTotal(QJsonObject &obj);
public slots:
void startRequest();
void replyFinished(QNetworkReply*);
private:
Ui::Widget *ui;
QNetworkAccessManager *manager;
QNetworkReply *pReply;
QTimer *startTimer;
QNetworkRequest request;
QString path=QCoreApplication::applicationDirPath();
};
#endif // WIDGET_H
//widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include<QFile>
#include<QNetworkAccessManager>
#include<QNetworkCookie>
#include<QNetworkReply>
#include<QSslConfiguration>
#include<QJsonDocument>
#include<iostream>
#include<string>
#include<QDebug>
using namespace std;
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
setWindowTitle(" Novel coronavirus pneumonia real-time data ");
createChart();// Create a chart
manager = new QNetworkAccessManager(this);// Create a new network management class
startTimer=new QTimer(this);
connect(startTimer,SIGNAL(timeout()),this,SLOT(startRequest()));
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));// Correlating signals and slots
QSslConfiguration conf = request.sslConfiguration();
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
conf.setProtocol(QSsl::TlsV1SslV3);
request.setSslConfiguration(conf);
QString url="https://c.m.163.com/ug/api/wuhan/app/data/list-total?t=1581743590402";
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json"));
request.setUrl(QUrl(url));
startTimer->start(10000);
showData();
}
void Widget::createChart()
{
QChart *chart = new QChart();
QFont f;
f.setPointSize(12);
f.setBold(1);
chart->setTitleFont(f);
chart->setTitleBrush(QBrush(QColor(89,168,227)));
chart->setAnimationOptions(QChart::SeriesAnimations);
chart->legend()->setVisible(false);
ui->chartView->setRenderHint(QPainter::Antialiasing);
QBrush brush;
brush.setColor(QColor(1,33,56));
chart->setBackgroundBrush(brush);
brush.setColor(Qt::white);
chart->setAnimationOptions(QChart::NoAnimation);
QFont font;
font.setBold(true);
font.setFamily(" Fangzheng rough black song simplified ");
font.setPointSize(8);
QBrush brushs;
brushs.setColor(Qt::white);
QBarCategoryAxis *axisX=new QBarCategoryAxis();
QValueAxis *axisY=new QValueAxis();
axisY->setTitleText(" The number of ");
axisX->setLabelsFont(font);
axisX->setLabelsColor(Qt::white);
axisX->setGridLineColor(QColor(13,50,77));
axisX->setTitleText(" date ");
axisX->setTitleBrush(brushs);
font.setPointSize(12);
axisX->setTitleFont(font);
axisX->setGridLineVisible(false);
font.setPointSize(8);
axisY->setLabelsFont(font);
axisY->setLabelsColor(Qt::white);
axisY->setGridLineVisible(false);
axisY->setTitleText(" number ");
font.setPointSize(12);
axisY->setTitleFont(font);
axisY->setTitleBrush(brushs);
chart->addAxis(axisX,Qt::AlignBottom);
chart->addAxis(axisY,Qt::AlignLeft);
ui->chartView->setChart(chart);
}
void Widget::setChartValue(QJsonArray &obj)
{
// Parsing data
QStringList axisxList=QStringList();
QList<QPointF> confirmList,deadList,healList,suspectList;\
QList<int> yu;
int i=0;
for(auto var:obj)
{
QJsonObject subObj=var.toObject();
QString axisX=subObj["date"].toString().mid(5,5);
axisxList.append(axisX);
int confirm= subObj["today"].toObject()["confirm"].toInt();
int dead= subObj["today"].toObject()["dead"].toInt();
int heal= subObj["today"].toObject()["heal"].toInt();
int suspect= subObj["today"].toObject()["suspect"].toInt();
yu.append(confirm);
QPoint point;
point.setX(i);
point.setY(confirm);
confirmList.append(point);
point.setY(dead);
deadList.append(point);
point.setY(heal);
healList.append(point);
point.setY(suspect);
suspectList.append(point);
i++;
}
QList<QAbstractAxis *> axes=ui->chartView->chart()->axes();
QBarCategoryAxis*axisX= qobject_cast<QBarCategoryAxis*>(axes.at(0));
axisX->append(axisxList);
QValueAxis*axisY= qobject_cast<QValueAxis*>(axes.at(1));
axisY->setRange(0,15000);
ui->chartView->chart()->removeAllSeries();
QLineSeries *seriesconfirm=new QLineSeries();
seriesconfirm->setName(" Diagnosis ");
ui->chartView->chart()->addSeries(seriesconfirm);
seriesconfirm->append(confirmList);
seriesconfirm->attachAxis(axisX);
seriesconfirm->attachAxis(axisY);
QLineSeries *seriesdead=new QLineSeries();
seriesdead->setName(" Death ");
ui->chartView->chart()->addSeries(seriesdead);
seriesdead->append(deadList);
seriesdead->attachAxis(axisX);
seriesdead->attachAxis(axisY);
QLineSeries *seriesheal=new QLineSeries();
seriesheal->setName(" Cure ");
ui->chartView->chart()->addSeries(seriesheal);
seriesheal->append(healList);
seriesheal->attachAxis(axisX);
seriesheal->attachAxis(axisY);
QLineSeries *seriessuspect=new QLineSeries();
seriessuspect->setName(" Suspected ");
ui->chartView->chart()->addSeries(seriessuspect);
seriessuspect->append(suspectList);
seriessuspect->attachAxis(axisX);
seriessuspect->attachAxis(axisY);
ui->chartView->chart()->legend()->setVisible(true);
}
void Widget::startRequest()
{
/* send out get Network request */
manager->get(request);
}
void Widget::replyFinished(QNetworkReply *reply)
{
if(reply->error()== QNetworkReply::NoError)
{
qDebug("No Error");
QByteArray array= reply->readAll();
QString string =QString::fromUtf8(array);
QJsonObject l_ret;
QJsonParseError l_err;
QJsonDocument l_doc = QJsonDocument::fromJson(string.toUtf8(), &l_err);
QString filePath=path+"/Data.json";
QFile file(filePath);
file.open(QIODevice::WriteOnly);
file.write(l_doc.toJson());
file.close();
}
showData();
}
Widget::~Widget()
{
delete ui;
}
void Widget::loadStyleSheet(const QString &sheetName)
{
QFile file(sheetName);
file.open(QFile::ReadOnly);
if (file.isOpen())
{
QString styleSheet = this->styleSheet();
styleSheet += QLatin1String(file.readAll());
this->setStyleSheet(styleSheet);
}
}
void Widget::showDetail(QJsonArray &array)
{
QJsonArray chinaObj;
for( auto var:array)
{
if(var.toObject()["id"].toInt()==0)
{
chinaObj=var.toObject()["children"].toArray();
break;
}
}
QList<QTreeWidgetItem*> itemlist;
for(auto var:chinaObj)
{
QString name=var.toObject()["name"].toString();
int addNew=var.toObject()["today"].toObject()["confirm"].toInt();
int totalConfirm=var.toObject()["total"].toObject()["confirm"].toInt();
int death=var.toObject()["total"].toObject()["dead"].toInt();
int heal=var.toObject()["total"].toObject()["heal"].toInt();
QTreeWidgetItem *item=new QTreeWidgetItem;
item->setText(0,name);
item->setText(1,QString::number(addNew));
item->setText(2,QString::number(totalConfirm));
item->setText(3,QString::number(death));
item->setText(4,QString::number(heal));
QJsonArray subChildren=var.toObject()["children"].toArray();
QList<QTreeWidgetItem*> list1;
for(auto var:subChildren)
{
QString name1=var.toObject()["name"].toString();
int addNew1=var.toObject()["today"].toObject()["confirm"].toInt();
int totalConfirm1=var.toObject()["total"].toObject()["confirm"].toInt();
int death1=var.toObject()["total"].toObject()["dead"].toInt();
int heal1=var.toObject()["total"].toObject()["heal"].toInt();
QTreeWidgetItem *items=new QTreeWidgetItem;
items->setText(0,name1);
items->setText(1,QString::number(addNew1));
items->setText(2,QString::number(totalConfirm1));
items->setText(3,QString::number(death1));
items->setText(4,QString::number(heal1));
list1.append(items);
}
item->addChildren(list1);
itemlist.append(item);
}
ui->treeWidget->clear();
ui->treeWidget->addTopLevelItems(itemlist);
}
void Widget::showData()
{
QString filePath=path+"/Data.json";
QFile file(filePath);
if(!file.open(QFile::ReadOnly))
{
qDebug(" fail to open file ");
return;
}
QByteArray allData = file.readAll();
file.close();
QJsonParseError json_error;
QJsonDocument jsonDoc(QJsonDocument::fromJson(allData, &json_error));
if(json_error.error != QJsonParseError::NoError)
{
qDebug() << "json error!";
return;
}
QJsonObject rootObj = jsonDoc.object();
// Today's data
QJsonObject todayObj=rootObj["data"].toObject()["chinaTotal"].toObject()["today"].toObject();
chinaToday(todayObj);
// Cumulative data
QJsonObject totalObj=rootObj["data"].toObject()["chinaTotal"].toObject()["total"].toObject();
chinaTotal(totalObj);
// Data deadline
QString timeStr=rootObj["data"].toObject()["lastUpdateTime"].toString();
ui->timeLabel->clear();
ui->timeLabel->setText("<html><head/><body><p><span style=\" font-size:12pt; font-weight:600; color:#a1a1a1;\"> Statistics as of :</span><span style=\" font-family:'Consolas','Courier New','monospace'; font-size:12pt; font-weight:600; color:#989898;\">"+timeStr+"</span></p></body></html>");
// Set... For the chart
QJsonArray chinaDayListObj=rootObj["data"].toObject()["chinaDayList"].toArray();
setChartValue(chinaDayListObj);
// List of provinces
QJsonArray areaTree=rootObj["data"].toObject()["areaTree"].toArray();
showDetail(areaTree);
}
void Widget::chinaTotal(QJsonObject &obj)
{
int confirm=obj["confirm"].toInt();
int dead=obj["dead"].toInt();
int heal=obj["heal"].toInt();
int suspect=obj["suspect"].toInt();
ui->tconfirmLabel->clear();
ui->tdeadLabel->clear();
ui->thealLabel->clear();
ui->tsuspectLabel->clear();
ui->tdeadLabel->setText("<html><head/><body><p align=\"center\"><span style=\" font-size:12pt; font-weight:600; \">"+QString::number(dead)+"</span></p></body></html>");
ui->tconfirmLabel->setText("<html><head/><body><p align=\"center\"><span style=\" font-size:12pt; font-weight:600; color:#e32e09;\">"+QString::number(confirm)+"</span></p></body></html>");
ui->thealLabel->setText("<html><head/><body><p align=\"center\"><span style=\" font-size:12pt; font-weight:600; color:#2faa77;\">"+QString::number(heal)+"</span></p></body></html>");
ui->tsuspectLabel->setText("<html><head/><body><p align=\"center\"><span style=\" font-size:12pt; font-weight:600; color:#ffaa00;\">"+QString::number(suspect)+"</span></p></body></html>");
}
void Widget::chinaToday(QJsonObject &obj)
{
int confirm=obj["confirm"].toInt();
int dead=obj["dead"].toInt();
int heal=obj["heal"].toInt();
int suspect=obj["suspect"].toInt();
ui->confirmLabel->clear();
ui->deadLabel->clear();
ui->healLabel->clear();
ui->suspectLabel->clear();
ui->confirmLabel->setText("<html><head/><body><p align=\"center\"> Compared with yesterday <span style=\" font-size:12pt; font-weight:600; color:#ff0000;\">+"+QString::number(confirm)+"</span></p></body></html>");
ui->deadLabel->setText("<html><head/><body><p align=\"center\"> Compared with yesterday <span style=\" font-size:12pt; font-weight:600; \">+"+QString::number(dead)+"</span></p></body></html>");
ui->healLabel->setText("<html><head/><body><p align=\"center\"> Compared with yesterday <span style=\" font-size:12pt; font-weight:600; color:#0036a2;\">+"+QString::number(heal)+"</span></p></body></html>");
ui->suspectLabel->setText("<html><head/><body><p align=\"center\"> Compared with yesterday <span style=\" font-size:12pt; font-weight:600; color:#ffce6b;\">+"+QString::number(suspect)+"</span></p></body></html>");
}
//widget.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Widget</class>
<widget class="QWidget" name="Widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>886</width>
<height>640</height>
</rect>
</property>
<property name="windowTitle">
<string>Widget</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="0">
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_15">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="text">
<string> National new trend chart </string>
</property>
</widget>
</item>
<item>
<widget class="QChartView" name="chartView" native="true"/>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelPic">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="timeLabel">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<family>Calibri</family>
</font>
</property>
<property name="text">
<string><html><head/><body><p><span style=" font-size:12pt; font-weight:600; color:#a1a1a1;"> Statistics as of :</span><span style=" font-family:'Consolas','Courier New','monospace'; font-size:12pt; font-weight:600; color:#989898;">2020-02-15 15:45:35</span></p></body></html></string>
</property>
</widget>
</item>
<item row="0" column="1" rowspan="4">
<widget class="QTreeWidget" name="treeWidget">
<property name="minimumSize">
<size>
<width>450</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>450</width>
<height>16777215</height>
</size>
</property>
<column>
<property name="text">
<string> region </string>
</property>
</column>
<column>
<property name="text">
<string> New diagnosis </string>
</property>
</column>
<column>
<property name="text">
<string> Diagnosis </string>
</property>
</column>
<column>
<property name="text">
<string> Death </string>
</property>
</column>
<column>
<property name="text">
<string> Cure </string>
</property>
</column>
</widget>
</item>
<item row="2" column="0">
<widget class="QWidget" name="widget" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="confirmLabel">
<property name="text">
<string><html><head/><body><p align="center"> Compared with yesterday <span style=" font-size:12pt; font-weight:600; color:#ff0000;">+123</span></p></body></html></string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="tconfirmLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(170, 255, 0);</string>
</property>
<property name="text">
<string><html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600; color:#e32e09;">7990</span></p></body></html></string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string><html><head/><body><p align="center"><span style=" font-size:10pt; font-weight:600;"> Diagnosis </span></p></body></html></string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="suspectLabel">
<property name="text">
<string><html><head/><body><p align="center"> Compared with yesterday <span style=" font-size:12pt; font-weight:600; color:#ffce6b;">+123</span></p></body></html></string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="tsuspectLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(170, 255, 0);</string>
</property>
<property name="text">
<string><html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600; color:#ffaa00;">68799</span></p></body></html></string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string><html><head/><body><p align="center"><span style=" font-size:10pt; font-weight:600;"> Suspected </span></p></body></html></string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="deadLabel">
<property name="text">
<string><html><head/><body><p align="center"> Compared with yesterday <span style=" font-size:12pt; font-weight:600;">+123</span></p></body></html></string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="tdeadLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(170, 255, 0);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="tdeadLabels">
<property name="text">
<string><html><head/><body><p align="center"><span style=" font-size:10pt; font-weight:600;"> Death </span></p></body></html></string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="3">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="healLabel">
<property name="text">
<string><html><head/><body><p align="center"> Compared with yesterday <span style=" font-size:12pt; font-weight:600; color:#0036a2;">+123</span></p></body></html></string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="thealLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(170, 255, 0);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="thealLabelq">
<property name="text">
<string><html><head/><body><p align="center"><span style=" font-size:10pt; font-weight:600;"> Cure </span></p></body></html></string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QChartView</class>
<extends>QWidget</extends>
<header>qchartview.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
Style sheets
*{
background-color:rgba(200,200,100,100);
border-color:rgba(5,39,175,100);
}
QLabel#labelPic
{
background-color: rgb(255, 255, 0);
}
](https://img-blog.csdnimg.cn/20200216100309835.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjIwMjY3NA==,size_16,color_FFFFFF,t_70)
边栏推荐
- list和dict的应用
- Octopus network progress monthly report | may 1-May 31, 2022
- Introduction to application design scheme of intelligent garbage can voice chip, wt588f02b-8s
- Scyther工具形式化分析Woo-Lam协议
- 开发中使用的语言技巧
- Codeforces 1629 D. pecuriar movie preferences - simple thinking, palindrome strings
- C语言【23道】经典面试题【下】
- Informatics Olympiad all in one 2059: [example 3.11] buy a pen
- Getting started with NVIDIA Jetson nano Developer Kit
- Django note 21: querying databases using native SQL
猜你喜欢

LeetCode滑动窗口刷题总结

【刷题篇】超级洗衣机

上海解封背后,这群开发者“云聚会”造了个AI抗疫机器人

Qualcomm platform development series (Protocol) QMI brief introduction and usage

Stm32f1 and stm32cubeide programming examples - device driver -eeprom-at24c256 driver

list和dict的应用

Implementing pytorch style deep learning framework similartorch with numpy

镜像扫描工具预研

【刷题篇】抽牌获胜的概率

成功定级腾讯T3-2,万字解析
随机推荐
1003: align output
Codeforces 1637 D. yet another minimization problem - Mathematics, DP
多源BFS问题 模板(附题)
Codeforces 1629 F1. Game on sum (easy version) - DP, game, thinking
Informatics Olympiad all in one 1000: introductory test questions
Codeforces 1629 B. GCD arrays - simple thinking
torch_geometric mini batch 的那些事
Codeforces 1637 C. Andrew and stones - simple thinking
Does jupyternotebook have a Chinese character database. Can you recognize handwritten Chinese in deep learning
Paw 高级使用指南
基于华为云鲲鹏弹性云服务器ECS部署openGauss数据库【这次高斯不是数学家】
Pytorch framework
Wechat web developer tools tutorial, web development issues
高通平台开发系列讲解(协议篇)QMI简单介绍及使用方法
软件构造 03 正则表达式
NVIDIA Jetson Nano Developer Kit 入门
Rk3399 platform development series explanation (kernel debugging chapter) 2.50 use of systrace
Seeking magic square of order n with C language
618进入后半段,苹果占据高端市场,国产手机终于杀价竞争
C语言【23道】经典面试题【下】