23 |
24 | QT_BEGIN_NAMESPACE
25 |
26 | class Ui_rumor_info
27 | {
28 | public:
29 | QVBoxLayout *verticalLayout;
30 | QTextBrowser *tb_rumor_info;
31 | QHBoxLayout *horizontalLayout;
32 | QSpacerItem *horizontalSpacer;
33 | QPushButton *btn_back;
34 | QSpacerItem *horizontalSpacer_2;
35 |
36 | void setupUi(QDialog *rumor_info)
37 | {
38 | if (rumor_info->objectName().isEmpty())
39 | rumor_info->setObjectName(QStringLiteral("rumor_info"));
40 | rumor_info->resize(634, 345);
41 | verticalLayout = new QVBoxLayout(rumor_info);
42 | verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
43 | tb_rumor_info = new QTextBrowser(rumor_info);
44 | tb_rumor_info->setObjectName(QStringLiteral("tb_rumor_info"));
45 |
46 | verticalLayout->addWidget(tb_rumor_info);
47 |
48 | horizontalLayout = new QHBoxLayout();
49 | horizontalLayout->setObjectName(QStringLiteral("horizontalLayout"));
50 | horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
51 |
52 | horizontalLayout->addItem(horizontalSpacer);
53 |
54 | btn_back = new QPushButton(rumor_info);
55 | btn_back->setObjectName(QStringLiteral("btn_back"));
56 | QFont font;
57 | font.setFamily(QString::fromUtf8("\351\273\221\344\275\223"));
58 | font.setPointSize(12);
59 | btn_back->setFont(font);
60 |
61 | horizontalLayout->addWidget(btn_back);
62 |
63 | horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
64 |
65 | horizontalLayout->addItem(horizontalSpacer_2);
66 |
67 |
68 | verticalLayout->addLayout(horizontalLayout);
69 |
70 |
71 | retranslateUi(rumor_info);
72 |
73 | QMetaObject::connectSlotsByName(rumor_info);
74 | } // setupUi
75 |
76 | void retranslateUi(QDialog *rumor_info)
77 | {
78 | rumor_info->setWindowTitle(QApplication::translate("rumor_info", "Dialog", Q_NULLPTR));
79 | tb_rumor_info->setHtml(QApplication::translate("rumor_info", "\n"
80 | "\n"
83 | "\345\244\251\346\260\224\346\232\226\345\222\214\344\273\216\345\215\227\346\226\271\345\233\236\345\275\222\345\214\227\346\226\271\347\232\204\351\270\237\344\274\232\345\270\246\345\233\236\347\227\205\346\257\222\357\274\214\346\204\237\346\237\223\344\272\272\347\261\273
\n"
84 | "
\n"
86 | ""\346\265\201\344\274\240\350\257\264\346\263\225\357\274\232\345\244\251\346\260\224\345\233\236\346\232\226\357\274\214\344\273\216\345\215\227\346\226\271\351\243\236\345\233\236\345\214\227\346\226\271\347\232\204\351\270\237\347\273\217\350\277\207\347\226\253\345\214\272\344\274\232\345\270\246\345\233\236\347\227\205\346\257\222\357\274\214\346\204\237\346\237\223\344\272\272\347\261\273\343\200\202"
\n"
87 | "
\n"
88 | "\350\276\203\347\234\237"
89 | "\351\211\264\345\256\232\357\274\232 [\347\226\221]\346\234\211\345\244\261\345\256\236
\n"
90 | "
\n"
91 | "\346\237\245\350\257\201\350\246\201\347\202\271\357\274\232
\n"
92 | " 1 \345\206\240\347\212\266\347\227\205\346\257\222\346\230\257\344\270\200\347\261\273\344\270\273\350\246\201\345\274\225\350\265\267\345\221\274\345\220\270\351\201\223\343\200\201\350\202\240\351\201\223\347\226\276\347\227\205\347\232\204\347\227\205\345\216\237\344\275\223\343\200\202\351\231\244\344\272\206\345\217\257\346\204\237\346\237\223\344\272\272\347\261\273\357\274\214\350\277\230\345\217\257\346\204\237\346\237\223\347\214\252\343\200\201\347\211\233\343\200\201\347\214\253\343\200\201\347\212\254\343\200\201\351\252\206\351\251\274\343\200\201\350\235\231\350\235\240\343\200\201\350\200\201\351\274\240\343\200\201\345\210\272\347\214\254\347\255\211\345\244\232\347\247\215\345\223\272\344\271\263\345\212\250\347\211\251\344\273\245\345\217\212\345\244\232\347\247\215\351\270\237\347\261\273\343\200\202\351\270\237\347\261\273\344\275\234\344\270\272\345\256\277\344\270\273\344\271\213\344\270\200"
94 | "\357\274\214\345\205\266\344\274\232\346\204\237\346\237\223SARS\347\227\205\346\257\222\346\210\226MERS\347\227\205\346\257\222\345\267\262\350\242\253\350\257\201\345\256\236\343\200\202\346\234\254\346\254\241\346\226\260\345\236\213\345\206\240\347\212\266\347\227\205\346\257\222\350\267\237SARS\345\261\236\344\272\216\344\270\200\344\270\252\346\227\217\357\274\214\351\270\237\347\261\273\346\204\237\346\237\223\345\217\257\350\203\275\344\270\215\350\241\250\347\216\260\347\227\207\347\212\266\357\274\214\344\275\206\345\246\202\346\236\234\344\272\272\346\216\245\350\247\246\346\210\226\351\243\237\347\224\250\346\220\272\345\270\246\347\227\205\346\257\222\351\270\237\347\261\273\357\274\214\344\274\232\350\242\253\346\204\237\346\237\223\345\271\266\345\274\225\350\265\267\347\227\207\347\212\266\343\200\202
\n"
95 | " 2 \346\211\200\344\273\245\345\244\251\346\260\224\345\233\236\346\232\226\357\274\214\345\214\227\351\243\236\347\232\204\351\270\237\345\217\257\350\203\275\346\220\272\345\270\246\347\227\205\346\257\222\357\274\214\344\275\206\350\277\231\345\271\266\344\270\215\346\204\217\345\221\263\347\235\200\344\273\200\344\271\210\343\200\202\345\233\240\344\270\272\350\213\245\346\262\241\346\234\211\346\234\254\346\254\241\347\226\253\346\203\205\357\274\214\351\270\237\347\261\273\344\271\237\344\274\232\346\220\272\345\270\246\347\227\205\346\257\222\357\274\214\344\272\272\347\261\273\344\270\216\350\277\231\344\272\233\351\207\216\347\224\237\345\212\250\347\211\251\347\233\270\345\256\211\346\227\240\344\272\213\357\274\214\350\242\253\346\204\237\346\237\223\347\232\204\346\246\202\347\216\207\345\276\210\344\275"
97 | "\216\357\274\233\345\217\246\345\244\226\357\274\214\345\214\227\346\226\271\345\237\216\345\270\202\346\257\224\345\246\202\351\273\221\351\276\231\346\261\237\343\200\201\345\214\227\344\272\254\347\255\211\345\235\207\346\234\211\346\225\260\347\231\276\347\241\256\350\257\212\347\227\205\344\276\213\357\274\214\347\227\205\346\257\222\345\234\250\345\205\250\345\233\275\346\211\251\346\225\243\346\230\257\346\227\242\345\256\232\344\272\213\345\256\236\357\274\214\345\217\252\350\246\201\346\210\221\344\273\254\345\201\232\345\245\275\345\237\272\347\241\200\351\230\262\346\212\244\357\274\214\344\270\215\345\220\203\351\207\216\347\224\237\345\212\250\347\211\251\357\274\214\347\226\253\346\203\205\344\270\215\344\274\232\345\233\240\344\270\272\351\270\237\347\261\273\345\210\260\346\235\245\350\200\214\345\212\240\351\207\215\343\200\202
\n"
98 | "
\n"
100 | "\346\237\245\350\257\201\350\200\205\357\274\232\350\260\242\346\234\233\346\227\266 \350\215\257\347\220\206\345\255\246\347\241\225\345\243\253\357\274\214\347\237\245\350\264\235\345\204\277\347\247\221\350\215\257\345\270\210
\n"
101 | "
\n"
102 | "\346\227\266\351\227\264\357\274\2322020-02-13\343\200\200\346\235\245\346\272\220\357\274\232\350\205\276\350\256\257\350\276\203\347\234\237
\n"
104 | "
", Q_NULLPTR));
105 | btn_back->setText(QApplication::translate("rumor_info", "\350\277\224\345\233\236", Q_NULLPTR));
106 | } // retranslateUi
107 |
108 | };
109 |
110 | namespace Ui {
111 | class rumor_info: public Ui_rumor_info {};
112 | } // namespace Ui
113 |
114 | QT_END_NAMESPACE
115 |
116 | #endif // UI_RUMOR_INFO_H
117 |
--------------------------------------------------------------------------------
/Export/备用OSS下载链接.txt:
--------------------------------------------------------------------------------
1 | v1.2
2 | 安装版:
3 | https://wcc-blog.oss-cn-beijing.aliyuncs.com/QtUpdate/qt_2019_ncov/v1.2_20200222_qt_2019_ncov_install.exe
4 | 免安装版:
5 | https://wcc-blog.oss-cn-beijing.aliyuncs.com/QtUpdate/qt_2019_ncov/v1.2_20200222_qt_2019_ncov_portable.exe
6 |
7 | v1.1
8 | 安装版:
9 | https://wcc-blog.oss-cn-beijing.aliyuncs.com/QtUpdate/qt_2019_ncov/v1.1_20200214_qt_2019_ncov_install.exe
10 | 免安装版:
11 | https://wcc-blog.oss-cn-beijing.aliyuncs.com/QtUpdate/qt_2019_ncov/v1.1_20200214_qt_2019_ncov_portable.exe
12 |
13 | v1.0
14 | 安装版:
15 | https://wcc-blog.oss-cn-beijing.aliyuncs.com/QtUpdate/qt_2019_ncov/20200212_qt_2019_ncov_install.exe
16 | 免安装版:
17 | https://wcc-blog.oss-cn-beijing.aliyuncs.com/QtUpdate/qt_2019_ncov/20200212_qt_2019_ncov_portable.exe
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # qt_2019_ncov
2 |
3 | 基于Qt/C++框架实现的新冠肺炎疫情数据可视化显示。主要包括新型冠状病毒肺炎疫情数据实时查看,确诊/疑似/治愈/死亡数据趋势折线图,各省市和海外数据树形显示,实时新闻动态显示等,数据源来自腾讯新闻接口,数据格式为JSON。
4 |
5 | ### 如何实现
6 |
7 | 我的博客文章:
8 | - [基于Qt的新冠肺炎疫情数据实时监控平台(开源小项目)](https://www.qtexe.com/post/2020-02-14-qt-ncov/)
9 | - [基于Qt的新冠肺炎疫情数据实时监控平台1.1版本](https://www.qtexe.com/post/2020-02-15-qt-ncov-2/)
10 | ### 版本历史
11 |
12 | [v1.0](https://github.com/qtexe/qt_2019_ncov/releases/tag/v1.0)
13 |
14 | - 全国疫情数据实时显示
15 | - 历史疫情数据趋势折线图显示
16 | - 各省市和海外疫情数据树形显示
17 | - 最新疫情新闻动态显示
18 | - 最新辟谣信息展示
19 | - 手动和自动更新(每5分钟)
20 |
21 | [v1.1](https://github.com/qtexe/qt_2019_ncov/releases/tag/v1.1)
22 |
23 | - 添加一个API和窗口,用于显示辟谣信息详情
24 | - 辟谣信息详情界面设计
25 | - 打开超链接改为QtDesktop,不使用widows.h(linux不支持)
26 |
27 |
--------------------------------------------------------------------------------
/Release/.qmake.stash:
--------------------------------------------------------------------------------
1 | QMAKE_DEFAULT_INCDIRS = \
2 | D:/Qt/Qt5.8.0/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0/include \
3 | D:/Qt/Qt5.8.0/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0/include-fixed \
4 | D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include \
5 | D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/c++ \
6 | D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/c++/i686-w64-mingw32 \
7 | D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/c++/backward
8 | QMAKE_DEFAULT_LIBDIRS = \
9 | D:/Qt/Qt5.8.0/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0 \
10 | D:/Qt/Qt5.8.0/Tools/mingw530_32/lib/gcc \
11 | D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/lib \
12 | D:/Qt/Qt5.8.0/Tools/mingw530_32/lib
13 | QMAKE_CXX.INCDIRS = \
14 | D:/Qt/Qt5.8.0/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0/include \
15 | D:/Qt/Qt5.8.0/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0/include-fixed \
16 | D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include \
17 | D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/c++ \
18 | D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/c++/i686-w64-mingw32 \
19 | D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/c++/backward \
20 | F:/Qt/Qt5.9.0/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0/include \
21 | F:/Qt/Qt5.9.0/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0/include-fixed \
22 | F:/Qt/Qt5.9.0/Tools/mingw530_32/i686-w64-mingw32/include \
23 | F:/Qt/Qt5.9.0/Tools/mingw530_32/i686-w64-mingw32/include/c++ \
24 | F:/Qt/Qt5.9.0/Tools/mingw530_32/i686-w64-mingw32/include/c++/i686-w64-mingw32 \
25 | F:/Qt/Qt5.9.0/Tools/mingw530_32/i686-w64-mingw32/include/c++/backward
26 | QMAKE_CXX.LIBDIRS = \
27 | D:/Qt/Qt5.8.0/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0 \
28 | D:/Qt/Qt5.8.0/Tools/mingw530_32/lib/gcc \
29 | D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/lib \
30 | D:/Qt/Qt5.8.0/Tools/mingw530_32/lib \
31 | F:/Qt/Qt5.9.0/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0 \
32 | F:/Qt/Qt5.9.0/Tools/mingw530_32/lib/gcc \
33 | F:/Qt/Qt5.9.0/Tools/mingw530_32/i686-w64-mingw32/lib \
34 | F:/Qt/Qt5.9.0/Tools/mingw530_32/lib
35 | QMAKE_CXX.QT_COMPILER_STDCXX = 199711L
36 | QMAKE_CXX.QT_GCC_MAJOR_VERSION = 5
37 | QMAKE_CXX.QT_GCC_MINOR_VERSION = 3
38 | QMAKE_CXX.QT_GCC_PATCH_VERSION = 0
39 | QMAKE_CXX.COMPILER_MACROS = \
40 | QT_COMPILER_STDCXX \
41 | QT_GCC_MAJOR_VERSION \
42 | QT_GCC_MINOR_VERSION \
43 | QT_GCC_PATCH_VERSION
44 |
--------------------------------------------------------------------------------
/Release/html_news.txt:
--------------------------------------------------------------------------------
1 |
2 |
5 | · *
6 | *
7 | 来源:* 发布于:*
8 |
*
9 |
10 |
13 | 查看更多报道 央视新闻直播
--------------------------------------------------------------------------------
/Release/html_rumor.txt:
--------------------------------------------------------------------------------
1 |
4 | *: *
5 | *
6 |
*
7 |
10 | 查看更多辟谣信息
--------------------------------------------------------------------------------
/Release/html_rumor_info.txt:
--------------------------------------------------------------------------------
1 |
2 |
5 | *
6 |
7 | "流传说法:*"
8 |
9 | 较真鉴定: [*]*
10 |
11 | 查证要点:
12 |
13 | *
14 | * *
*
15 |
16 |
17 |
18 | 查证者:* *
19 |
20 | 时间:* 来源:*
21 |
--------------------------------------------------------------------------------
/Release/object_script.qt_2019_ncov.Debug:
--------------------------------------------------------------------------------
1 | INPUT(
2 | ./debug\main.o
3 | ./debug\dialog.o
4 | ./debug\qcustomplot.o
5 | ./debug\parse.o
6 | ./debug\network.o
7 | ./debug\plot.o
8 | ./debug\slots.o
9 | ./debug\about.o
10 | ./debug\rumor.o
11 | ./debug\rumor_info.o
12 | ./debug\news_info.o
13 | ./debug\qrc_img.o
14 | ./debug\moc_dialog.o
15 | ./debug\moc_qcustomplot.o
16 | ./debug\moc_about.o
17 | ./debug\moc_rumor.o
18 | ./debug\moc_rumor_info.o
19 | ./debug\moc_news_info.o
20 | );
21 |
--------------------------------------------------------------------------------
/Release/object_script.qt_2019_ncov.Release:
--------------------------------------------------------------------------------
1 | INPUT(
2 | ./release\main.o
3 | ./release\dialog.o
4 | ./release\qcustomplot.o
5 | ./release\parse.o
6 | ./release\network.o
7 | ./release\plot.o
8 | ./release\slots.o
9 | ./release\about.o
10 | ./release\rumor.o
11 | ./release\rumor_info.o
12 | ./release\news_info.o
13 | ./release\qrc_img.o
14 | ./release\moc_dialog.o
15 | ./release\moc_qcustomplot.o
16 | ./release\moc_about.o
17 | ./release\moc_rumor.o
18 | ./release\moc_rumor_info.o
19 | ./release\moc_news_info.o
20 | );
21 |
--------------------------------------------------------------------------------
/Release/qt_2019_ncov:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whik/qt_2019_ncov/9474e808ee5095955daf12b981141b676b35805b/Release/qt_2019_ncov
--------------------------------------------------------------------------------
/Release/qt_2019_ncov_resource.rc:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | IDI_ICON1 ICON DISCARDABLE "E:\\qt_2019_ncov\\bitbug_favicon.ico"
4 |
5 | VS_VERSION_INFO VERSIONINFO
6 | FILEVERSION 0,0,0,0
7 | PRODUCTVERSION 0,0,0,0
8 | FILEFLAGSMASK 0x3fL
9 | #ifdef _DEBUG
10 | FILEFLAGS VS_FF_DEBUG
11 | #else
12 | FILEFLAGS 0x0L
13 | #endif
14 | FILEOS VOS__WINDOWS32
15 | FILETYPE VFT_DLL
16 | FILESUBTYPE 0x0L
17 | BEGIN
18 | BLOCK "StringFileInfo"
19 | BEGIN
20 | BLOCK "040904b0"
21 | BEGIN
22 | VALUE "CompanyName", "\0"
23 | VALUE "FileDescription", "\0"
24 | VALUE "FileVersion", "0.0.0.0\0"
25 | VALUE "LegalCopyright", "\0"
26 | VALUE "OriginalFilename", "qt_2019_ncov.exe\0"
27 | VALUE "ProductName", "qt_2019_ncov\0"
28 | VALUE "ProductVersion", "0.0.0.0\0"
29 | END
30 | END
31 | BLOCK "VarFileInfo"
32 | BEGIN
33 | VALUE "Translation", 0x0409, 1200
34 | END
35 | END
36 | /* End of Version info */
37 |
38 |
--------------------------------------------------------------------------------
/Release/release/html_news.txt:
--------------------------------------------------------------------------------
1 |
2 |
5 | · *
6 | *
7 | 来源:* 发布于:*
8 |
*
9 |
10 |
13 | 查看更多报道 央视新闻直播
--------------------------------------------------------------------------------
/Release/release/html_rumor.txt:
--------------------------------------------------------------------------------
1 |
4 | *: *
5 | *
6 |
*
7 |
10 | 查看更多辟谣信息
--------------------------------------------------------------------------------
/Release/release/html_rumor_info.txt:
--------------------------------------------------------------------------------
1 |
2 |
5 | *
6 |
7 | "流传说法:*"
8 |
9 | 较真鉴定: [*]*
10 |
11 | 查证要点:
12 |
13 | *
14 | * *
*
15 |
16 |
17 |
18 | 查证者:* *
19 |
20 | 时间:* 来源:*
21 |
--------------------------------------------------------------------------------
/Release/release/libeay32.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whik/qt_2019_ncov/9474e808ee5095955daf12b981141b676b35805b/Release/release/libeay32.dll
--------------------------------------------------------------------------------
/Release/release/qt_2019_ncov.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whik/qt_2019_ncov/9474e808ee5095955daf12b981141b676b35805b/Release/release/qt_2019_ncov.exe
--------------------------------------------------------------------------------
/Release/release/ssleay32.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whik/qt_2019_ncov/9474e808ee5095955daf12b981141b676b35805b/Release/release/ssleay32.dll
--------------------------------------------------------------------------------
/about.cpp:
--------------------------------------------------------------------------------
1 | #include "about.h"
2 | #include "ui_about.h"
3 | //#include "windows.h"
4 | #include
5 | //#include
6 |
7 | about::about(QWidget *parent) :
8 | QDialog(parent),
9 | ui(new Ui::about)
10 | {
11 | ui->setupUi(this);
12 |
13 | this->setWindowTitle("关于");
14 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
15 |
16 | ui->tb_about->setOpenLinks(false);
17 | connect(ui->tb_about, SIGNAL(anchorClicked(const QUrl&)), this, SLOT(anchorClickedSlot(const QUrl&)));
18 | }
19 |
20 | about::~about()
21 | {
22 | delete ui;
23 | }
24 | void about::anchorClickedSlot(const QUrl& url)
25 | {
26 | QDesktopServices::openUrl(url);
27 | // ShellExecuteA(NULL, "open", url.toString().toStdString().c_str(), "", "", SW_SHOW);
28 | }
29 |
--------------------------------------------------------------------------------
/about.h:
--------------------------------------------------------------------------------
1 | #ifndef ABOUT_H
2 | #define ABOUT_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class about;
9 | }
10 |
11 | class about : public QDialog
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit about(QWidget *parent = 0);
17 | ~about();
18 |
19 | private slots:
20 | void anchorClickedSlot(const QUrl& url);
21 |
22 |
23 | private:
24 | Ui::about *ui;
25 | };
26 |
27 | #endif // ABOUT_H
28 |
--------------------------------------------------------------------------------
/about.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | about
4 |
5 |
6 |
7 | 0
8 | 0
9 | 570
10 | 696
11 |
12 |
13 |
14 |
15 | 0
16 | 0
17 |
18 |
19 |
20 |
21 | 570
22 | 470
23 |
24 |
25 |
26 | Dialog
27 |
28 |
29 | background-color: rgb(255, 255, 255);
30 |
31 |
32 | -
33 |
34 |
35 |
36 | 黑体
37 | 7
38 |
39 |
40 |
41 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
42 | <html><head><meta name="qrichtext" content="1" /><style type="text/css">
43 | p, li { white-space: pre-wrap; }
44 | </style></head><body style=" font-family:'黑体'; font-size:7pt; font-weight:400; font-style:normal;">
45 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:600;">·数据来源</span></p>
46 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt; font-weight:600;"><br /></p>
47 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;"> </span><a href="https://news.qq.com/zt2020/page/feiyan.htm"><span style=" font-size:14pt; text-decoration: underline; color:#000000;">腾讯新闻:新冠肺炎疫情最新动态</span></a></p>
48 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;"><br /></p>
49 | <hr />
50 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:600;">·如何实现</span></p>
51 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;"><br /></p>
52 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;"> </span><a href="http://www.wangchaochao.top/2020/02/14/qt-ncov/"><span style=" font-size:14pt; text-decoration: underline; color:#000000;">基于Qt的新冠肺炎疫情数据实时监控平台</span></a></p>
53 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt; text-decoration: underline; color:#0000ff;"><br /></p>
54 | <hr />
55 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:600;">·关于作者</span></p>
56 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;"><br /></p>
57 | <p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://www.wangchaochao.top/2020/02/14/qt-ncov/"><span style=" font-size:14pt; text-decoration: underline; color:#000000;">Home</span></a><span style=" font-size:14pt; color:#000000;"> · </span><a href="https://github.com/qtexe/qt_2019_ncov"><span style=" font-size:14pt; text-decoration: underline; color:#000000;">Github</span></a><span style=" font-size:14pt; color:#000000;"> · </span><a href="https://wcc-blog.oss-cn-beijing.aliyuncs.com/payQR.jpg"><span style=" font-size:14pt; text-decoration: underline; color:#000000;">Support</span></a></p>
58 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;"><br /></p>
59 | <hr />
60 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:600;">·公众号</span></p>
61 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;"><br /></p>
62 | <p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><img src=":/my_sub.jpg" /></p></body></html>
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/api.txt:
--------------------------------------------------------------------------------
1 | 新浪新闻:
2 | 城市名为unicode
3 | https://interface.sina.cn/news/wap/fymap2020_data.d.json?1580868609265&&callback=sinajp_15808686092969432005074395626
4 |
5 | 腾讯api地址
6 | https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&_=1580872265054
7 |
8 | 丁香园疫情新闻:
9 | http://api.tianapi.com/txapi/ncov/index?key=964dc226dd5b57e892e6199735b6c55f
10 |
11 | 各平台肺炎疫情实时动态
12 |
13 | 梅斯:http://m.medsci.cn/wh.asp
14 |
15 | 新浪:https://news.sina.cn/zt_d/yiqing0121
16 |
17 | 网易:https://news.163.com/special/epidemic/
18 |
19 | 知乎:https://www.zhihu.com/special/19681091
20 |
21 | 一财:https://m.yicai.com/news/100476965.html
22 |
23 | 丁香:https://3g.dxy.cn/newh5/view/pneumonia
24 |
25 | 腾讯:https://news.qq.com/zt2020/page/feiyan.htm
26 |
27 | 夸克:https://broccoli.uc.cn/apps/pneumonia/routes/index
28 |
29 | 百度:https://voice.baidu.com/act/newpneumonia/newpneumonia
30 |
31 | >>> import time, json, requests
32 | >>> url = 'https://view.inews.qq.com/g2/getOnsInfo?name=wuwei_ww_area_counts&callback=&_=%d'%int(time.time()*1000)
33 | >>> data = json.loads(requests.get(url=url).json()['data'])
34 | >>> print(len(data))
35 | 301
36 |
37 |
38 | 全国累计
39 | https://ncov-api.werty.cn:2021/latest/tx/
40 |
41 | 按钮边框
42 |
43 | 未选中
44 | border:3px groove rgb(255, 0, 0); //边框线条粗线,线型,颜色
45 | border-radius:8px; //圆角弧度
46 | padding:2px 4px; //文字离边框的距离,H/L
47 | background-color: rgb(243, 246, 248); //背景颜色
48 | color: rgb(255, 255, 255);
49 |
50 |
51 | 选中:
52 | border:3px groove rgb(255, 0, 0); //边框线条粗线,线型,颜色
53 | border-radius:8px; //圆角弧度
54 | padding:2px 4px; //文字离边框的距离,H/L
55 | background-color: rgb(243, 246, 248); //背景颜色
56 | color: rgb(243, 246, 248);
57 |
58 | 字体颜色:color: rgb(243, 246, 248);
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/bitbug_favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whik/qt_2019_ncov/9474e808ee5095955daf12b981141b676b35805b/bitbug_favicon.ico
--------------------------------------------------------------------------------
/del_obj.bat:
--------------------------------------------------------------------------------
1 | del *.o /s
2 | del *.json /s
3 | del *.user /s
--------------------------------------------------------------------------------
/dialog.cpp:
--------------------------------------------------------------------------------
1 | #include "dialog.h"
2 | #include "ui_dialog.h"
3 | //#include
4 | //#include
5 |
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 |
20 | #include
21 | #include
22 | #include
23 | #include "qjsonvalue.h"
24 |
25 | #include
26 |
27 | #include
28 | #include
29 |
30 | Dialog::Dialog(QWidget *parent) :
31 | QDialog(parent),
32 | ui(new Ui::Dialog)
33 | {
34 | ui->setupUi(this);
35 |
36 | //右上角不显示帮助按钮
37 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
38 |
39 | //属性的用法
40 | /*
41 | ui->lbe_add_confirm->setProperty("number", 1933); //不可见,仅为一个属性
42 | QVariant number = ui->lbe_add_confirm->property("number");
43 | qDebug() << number; //QVariant(int, 1933)
44 | */
45 | this->setWindowTitle("2019_nCoV冠状病毒感染疫情实时监控_" + verison);
46 | manager = new QNetworkAccessManager(this); //新建网络请求对象
47 |
48 | wigetAddGraph(ui->widget_chart);
49 |
50 | QTimer *timer = new QTimer(this);
51 |
52 | connect(timer, SIGNAL(timeout()), this, SLOT(update()));
53 | timer->start(1000); //ms = 1s
54 | // treeAddData();
55 |
56 | ui->tb_news->setOpenLinks(false);
57 | connect(ui->tb_news, SIGNAL(anchorClicked(const QUrl&)), this, SLOT(anchorClickedSlot(const QUrl&)));
58 |
59 | ui->btn_group->setId(ui->btn_line_0, 0);
60 | ui->btn_group->setId(ui->btn_line_1, 1);
61 | ui->btn_group->setId(ui->btn_line_2, 2);
62 | ui->btn_group->setId(ui->btn_line_3, 3);
63 |
64 | emit on_btn_update_clicked();
65 | }
66 |
67 |
68 | Dialog::~Dialog()
69 | {
70 | delete ui;
71 | }
72 |
73 |
74 | void Dialog::on_btn_update_clicked()
75 | {
76 | // qDebug() << isNetWorkOnline();
77 | if(isNetWorkOnline() == true)
78 | {
79 | // ui->btn_update->setEnabled(false);
80 | /*
81 | QList list;
82 | list.clear();
83 | list << "2020-01-15_09_00_00_000";
84 | list << "2020-01-20_09_00_00_000";
85 | list << "2020-01-25_09_00_00_000";
86 | list << "2020-02-05_09_00_00_000";
87 | list << "2020-02-10_09_00_00_000";
88 | list << "2020-02-15_09_00_00_000";
89 | list << "2020-02-20_09_00_00_000";
90 | list << "2020-02-23_09_00_00_000";
91 | static int i = 0;
92 | QDateTime dateTime = QDateTime::fromString(list[i], "yyyy-MM-dd_hh_mm_ss_zzz");
93 | qint64 timestamp = dateTime.toMSecsSinceEpoch(); //毫秒级时间戳
94 | QString current_time = list[i];
95 | qDebug() << list[i] << timestamp;
96 | i++;
97 | */
98 | qint64 timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch(); //毫秒级
99 | QString current_time = QDateTime::currentDateTime().toString("yyyyMMdd_hh_mm_ss_zzz");
100 |
101 | QString timestamp_str;
102 | timestamp_str.setNum(timestamp, 10);
103 |
104 | if(selAPI == 1)
105 | selAPI = 2;
106 | else if(selAPI == 2)
107 | selAPI = 1;
108 |
109 | if(selAPI == 1)
110 | url = QUrl(data1_Api + timestamp_str);
111 | else if(selAPI == 2)
112 | url = QUrl(data2_Api + timestamp_str);
113 |
114 | // url = QUrl("https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5");
115 | //只包含全国累计数据
116 | // url = QUrl("https://ncov-api.werty.cn:2021/latest/tx/");
117 | // qDebug() << url.toString();
118 | qDebug() << "网络正常,开始更新疫情数据" + url.toString();
119 | filename = "data_" +current_time + ".json";
120 | file = new QFile(filename);
121 |
122 | if(!file->open(QIODevice::WriteOnly))
123 | {
124 | // qDebug() << "文件打开失败";
125 | delete file;
126 | file = 0;
127 | return;
128 | }
129 |
130 | // qDebug() << "网络正常";
131 | reply = manager->get(QNetworkRequest(url)); //发送get请求数据
132 | //下载完成执行槽函数
133 | connect(reply,SIGNAL(finished()),this,SLOT(httpFinished()));
134 | //有可用的数据
135 | connect(reply,SIGNAL(readyRead()),this,SLOT(httpReadyRead()));
136 | }
137 | else
138 | {
139 | qDebug() << "网络错误,请检查网络";
140 | QMessageBox::warning(NULL, "错误", "无网络连接,请检查网络", QMessageBox::Yes);
141 | }
142 | }
143 |
144 | //获取两个日期的间隔天数
145 | int Dialog::getDay(QString date)
146 | {
147 | QDate date1 = QDate::fromString(date, "yyyyMMdd");
148 | QString current_time = QDateTime::currentDateTime().toString("yyyyMMdd"); //当前日期QString类型
149 | QDate date2 = QDate::fromString(current_time, "yyyyMMdd");
150 | qint16 day = date1.daysTo(date2);
151 | // qDebug() << date1 << date2 << day;
152 | return day;
153 | }
154 |
155 | void Dialog::disInfo(QString info)
156 | {
157 | // ui->tb_info->append(info);
158 | }
159 |
160 | //获取两个double容器类的最大值
161 | double Dialog::getMaxVaule(QVector dub1, QVector dub2)
162 | {
163 | double max = 0;
164 | for(int i = 0; i < dub1.size(); i++)
165 | {
166 | if(max < dub1[i])
167 | max = dub1[i];
168 | }
169 | for(int i = 0; i < dub2.size(); i++)
170 | {
171 | if(max < dub2[i])
172 | max = dub2[i];
173 | }
174 |
175 | return max;
176 | }
177 |
178 | void Dialog::on_btn_about_clicked()
179 | {
180 | this->ab_win.exec();
181 | }
182 |
183 | void Dialog::on_btn_rumor_clicked()
184 | {
185 | // this->rm_win.show();
186 | // qDebug() << isNetWorkOnline();
187 | if(isNetWorkOnline() == true)
188 | {
189 | this->rm_win.getRumorNews(0); //当天
190 | // this->rm_win.getRumorNews(1); //昨天
191 | // this->rm_win.getRumorNews(2); //前天
192 | this->rm_win.exec();
193 | }
194 | else
195 | {
196 | QMessageBox::warning(NULL, "错误", "无网络连接,请检查网络", QMessageBox::Yes);
197 | }
198 | }
199 |
200 | void Dialog::on_btn_chkUpdate_clicked()
201 | {
202 | QString refUrl = "http://www.wangchaochao.top/2019/03/31/Qt-Update/";
203 | QString refTitle = "Qt实现软件自动更新的一种简单方法";
204 | int ret = QMessageBox::information(this, "检查更新", "更新功能暂未添加,可参考以下文章:\n" + refTitle, "去看看", "不去了");
205 |
206 | if(ret == 0)
207 | {
208 | QDesktopServices::openUrl(QUrl(refUrl));
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/dialog.h:
--------------------------------------------------------------------------------
1 | #ifndef DIALOG_H
2 | #define DIALOG_H
3 |
4 | #include
5 |
6 | #include
7 |
8 | //网络相关头文件
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | #include
17 |
18 | //JSON相关头文件
19 | #include
20 | #include
21 | #include
22 |
23 | #include
24 | #include "qjsonvalue.h"
25 |
26 | #include "qcustomplot.h"
27 | #include "about.h"
28 | #include "rumor.h"
29 | #include "news_info.h"
30 |
31 | namespace Ui {
32 | class Dialog;
33 | }
34 |
35 | class Dialog : public QDialog
36 | {
37 | Q_OBJECT
38 |
39 | public:
40 | explicit Dialog(QWidget *parent = 0);
41 | ~Dialog();
42 | bool isNetWorkOnline();
43 | int dataParse(QByteArray str);
44 | int readFromFile(QString filename);
45 |
46 | int getNum(QJsonObject obj, int *num_confirm, int *num_suspect, int *num_dead, int *num_heal);
47 | int getDay(QString date);
48 | int getTotalAddData(QJsonObject chinaTotal, QJsonObject chinaAdd);
49 |
50 | void chinaDayListParse(QJsonArray chinaDayListObj);
51 | void chinaDayAddListParse(QJsonArray chinaDayAddListObj);
52 | void disInfo(QString info);
53 |
54 | QVector QStringToDouble(QVector str, uint16_t len);
55 | double getMaxVaule(QVector dub1, QVector dub2);
56 | //参数是double
57 | void widgetDrawLine(QCustomPlot *widget, QVector date,
58 | QVector data1Dub, QVector data2Dub);
59 | void widgetDrawLine(QCustomPlot *widget, QString chartName, QString name1, QString name2,
60 | QColor clr1, QColor clr2, QVector date,
61 | QVector data1, QVector data2);
62 |
63 | void dataAddTree(QJsonObject province_obj);
64 | void countryTreeParse(QJsonArray areaTree_obj);
65 |
66 | void disTip(QMouseEvent *event, QCustomPlot *widget, QVector date);
67 | void chinaTreeParse(QJsonObject chinaTree);
68 | void articleParse(QJsonArray arr);
69 |
70 | void wigetAddGraph(QCustomPlot *widget);
71 | void wigetSetColor(QCustomPlot *widget, QColor clr1, QColor clr2);
72 | QString rgbToStyle(QColor rbg);
73 | void setSelectStyle(int id);
74 | void parseAddSwitch(QJsonObject sw_obj);
75 | void showAddData(QString key, int num, QLabel *lbe);
76 |
77 | private slots:
78 | void on_btn_update_clicked();
79 | void httpReadyRead(); //有可用数据
80 | void httpFinished(); //完成下载
81 | // void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes);
82 | void widget_chart_event(QMouseEvent*);
83 | void update();
84 | void anchorClickedSlot(const QUrl& url);
85 | void drawCharts(int id);
86 |
87 | void on_btn_about_clicked();
88 | void closeEvent(QCloseEvent *win);
89 | void on_btn_rumor_clicked();
90 |
91 | void on_btn_chkUpdate_clicked();
92 |
93 | private:
94 | Ui::Dialog *ui;
95 |
96 | QNetworkAccessManager *manager;
97 | QNetworkReply *reply;
98 | QUrl url;
99 | QFile *file;
100 | QString filename;
101 | QString verison = "v1.2";
102 | //腾讯,最新接口有新闻,添加了病死率和治愈率
103 | QString data1_Api = "http://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&_="; //时间戳可以不添加
104 | QString data2_Api = "https://view.inews.qq.com/g2/getOnsInfo?name=disease_other&_="; //时间戳可以不添加
105 | //2020_02_10:添加最新动态新闻键值,大小116KB
106 |
107 | //网易api,目前还没新闻,和腾讯非常相似
108 | // QString dataApi = "https://c.m.163.com/ug/api/wuhan/app/data/list-total?t=";
109 | // QString newsApi = "http://api.tianapi.com/txapi/ncov/index?key=964dc226dd5b57e892e6199735b6c55f";
110 | uint8_t selAPI = 1;
111 | bool dat1_parse_ok = true;
112 |
113 | int clickId = 0;
114 | uint8_t updateTime = 5; //默认5分钟更新一次
115 | QString newsHtmlFileName = "html_news.txt";
116 |
117 | QColor clr1_1 = QColor(0, 93, 255);
118 | QColor clr1_2 = QColor(237, 160, 70);
119 |
120 | QColor clr2_1 = QColor(245, 60, 60);
121 | QColor clr2_2 = QColor(36, 200, 200);
122 |
123 | QColor clr3_1 = QColor(33, 144, 5);
124 | QColor clr3_2 = QColor(135, 135, 139);
125 |
126 | QColor clr4_1 = QColor(33, 144, 5);
127 | QColor clr4_2 = QColor(245, 60, 60);
128 |
129 | QVector AddDate; //新增从1.20
130 | QVector AddConfirmDub; //新增确诊
131 | QVector AddSuspectDub; //新增疑似
132 | QVector AddDeadDub; //新增死亡
133 | QVector AddHealDub; //新增治愈
134 |
135 | QVector TotalDate; //累计从1.13
136 | QVector TotalConfirmDub; //累计确诊
137 | QVector TotalSuspectDub; //累计疑似
138 | QVector TotalDeadDub; //累计死亡
139 | QVector TotalHealDub; //累计治愈
140 |
141 | QVector chinaDayListHealRate; //累计治愈率,从1.20开始
142 | QVector chinaDayListDeadRate; //累计死亡率,从1.20开始
143 | QVector RateDate; //从1.20日开始
144 |
145 | QMap AddSwitchMap; //保存键值对
146 |
147 | /*
148 |
149 |
150 |
151 | */
152 |
153 | about ab_win;
154 | rumor rm_win;
155 | news_info newsInfo_win;
156 | };
157 |
158 | class ncovPerson
159 | {
160 | public:
161 | int confirm; //确诊
162 | int suspect; //疑似
163 | int heal; //治愈
164 | int dead; //死亡
165 | QString deadRate; //死亡率
166 | QString healRate; //治愈率
167 | bool isUpdated; //国家数据中, 是否更新
168 | QString date; //历史数据中包含日期
169 | };
170 |
171 |
172 | #endif // DIALOG_H
173 |
--------------------------------------------------------------------------------
/img.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | my_sub.jpg
4 | new_top.jpg
5 |
6 |
7 |
--------------------------------------------------------------------------------
/lib/README.txt:
--------------------------------------------------------------------------------
1 |
2 | Qt 应用程序中如果使用了https网络访问,使用windeployqt打包工具是不会添加网络支持相关的库,则需要手动添加两个库文件。
3 |
4 | 1.使用Qt 5.12.4之前的版本开发的网络应用,需要添加以下两个文件:
5 |
6 | libeay32.dll
7 | ssleay32.dll
8 |
9 | 2.使用Qt 5.12.4及之后的版本开发的网络应用,需要添加以下两个文件:
10 |
11 | libssl-1_1-x64.dll
12 | libcrypto-1_1-x64.dll
13 |
14 | 查看当前openSSL版本:
15 |
16 | qDebug()<
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | Dialog w;
8 | w.show();
9 |
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/my_sub.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whik/qt_2019_ncov/9474e808ee5095955daf12b981141b676b35805b/my_sub.jpg
--------------------------------------------------------------------------------
/network.cpp:
--------------------------------------------------------------------------------
1 | #include "dialog.h"
2 |
3 | void Dialog::update()
4 | {
5 | static uint16_t cnt = 0;
6 | cnt++;
7 | if(cnt == 60 * updateTime) //60s = 1min
8 | {
9 | qDebug() << "开始更新";
10 | emit on_btn_update_clicked();//触发更新
11 | cnt = 0;
12 | }
13 | }
14 | bool Dialog::isNetWorkOnline()
15 | {
16 | QNetworkConfigurationManager mgr;
17 | return mgr.isOnline();
18 | }
19 | int Dialog::readFromFile(QString filename)
20 | {
21 | // qDebug() << "开始解析数据";
22 | // qDebug() << filename;
23 | QFile file(filename);
24 | // QFile file("20200205_12_29_53_290.json"); //string
25 | // QFile file("20200207_13_01_38_931.json"); //double
26 | if(!file.open(QIODevice::ReadOnly))
27 | {
28 | qDebug() << "文件打开失败";
29 | return -1;
30 | }
31 | QByteArray allData = file.readAll();
32 | file.close();
33 | dataParse(allData);
34 | file.remove(); //删除文件
35 | return 0;
36 | }
37 | void Dialog::httpReadyRead() //有可用数据
38 | {
39 | /*
40 | QTextStream streamFileOut(file);
41 | streamFileOut.setCodec("GBK");
42 | streamFileOut << reply->readAll();
43 | streamFileOut.flush();
44 | streamFileOut.setGenerateByteOrderMark(false);
45 | */
46 | if(file)
47 | file->write(reply->readAll()); //如果文件存在,则写入文件
48 | }
49 | void Dialog::httpFinished() //完成下载
50 | {
51 | file->flush();
52 | file->close();
53 | disInfo("数据下载成功");
54 | reply->deleteLater();
55 | reply = 0;
56 | delete file;
57 | file = 0;
58 | // QMessageBox::information(this, "提示", "下载完成");
59 | readFromFile(filename);
60 | }
61 |
--------------------------------------------------------------------------------
/new_top.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whik/qt_2019_ncov/9474e808ee5095955daf12b981141b676b35805b/new_top.jpg
--------------------------------------------------------------------------------
/news_info.cpp:
--------------------------------------------------------------------------------
1 | #include "news_info.h"
2 | #include "ui_news_info.h"
3 | #include
4 | #include
5 | #include
6 | news_info::news_info(QWidget *parent) :
7 | QDialog(parent),
8 | ui(new Ui::news_info)
9 | {
10 | ui->setupUi(this);
11 | // QAxWidget *flash = new QAxWidget(0, 0); //QAxWidget使用的是ActiveX插件
12 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
13 |
14 | this->setWindowTitle("新闻详情_IE");
15 |
16 | ui->flash_newsInfo->resize(690, 570); //设置该控件的初始大小
17 | ui->flash_newsInfo->setControl(QString::fromUtf8("{8856F961-340A-11D0-A96B-00C04FD705A2}"));//注册组件ID
18 | ui->flash_newsInfo->setProperty("DisplayAlerts", false);//不显示警告信息
19 | ui->flash_newsInfo->setProperty("DisplayScrollBars", false);//显示滚动条
20 | // ui->flash_newsInfo->set
21 |
22 | // qDebug() << "ActiveX Initial";
23 | }
24 |
25 | news_info::~news_info()
26 | {
27 | delete ui;
28 | }
29 |
30 | void news_info::openURL(QUrl url)
31 | {
32 | ui->le_url->setText(url.toString());
33 | link = url;
34 | ui->flash_newsInfo->resize(690, 520);
35 | this->resize(690,520+80);
36 | ui->flash_newsInfo->dynamicCall("Navigate(const QString&)", link.toString());//显示网页
37 | ui->flash_newsInfo->show();
38 | }
39 |
40 |
41 | void news_info::on_btn_refresh_clicked()
42 | {
43 | openURL(link);
44 | }
45 |
46 | void news_info::on_btn_close_clicked()
47 | {
48 | this->close();
49 | }
50 |
--------------------------------------------------------------------------------
/news_info.h:
--------------------------------------------------------------------------------
1 | #ifndef NEWS_INFO_H
2 | #define NEWS_INFO_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class news_info;
9 | }
10 |
11 | class news_info : public QDialog
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit news_info(QWidget *parent = 0);
17 | ~news_info();
18 | void openURL(QUrl url);
19 |
20 | private slots:
21 | void on_btn_refresh_clicked();
22 |
23 | void on_btn_close_clicked();
24 |
25 | private:
26 | Ui::news_info *ui;
27 | QUrl link;
28 | };
29 |
30 | #endif // NEWS_INFO_H
31 |
--------------------------------------------------------------------------------
/news_info.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | news_info
4 |
5 |
6 |
7 | 0
8 | 0
9 | 545
10 | 657
11 |
12 |
13 |
14 | Dialog
15 |
16 |
17 | false
18 |
19 |
20 | false
21 |
22 |
23 | -
24 |
25 |
-
26 |
27 |
28 |
29 | 黑体
30 | 12
31 |
32 |
33 |
34 | 地址:
35 |
36 |
37 |
38 | -
39 |
40 |
41 |
42 | 黑体
43 | 12
44 |
45 |
46 |
47 | true
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 | 黑体
56 | 12
57 |
58 |
59 |
60 | 刷新
61 |
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 | -
70 |
71 |
-
72 |
73 |
74 | Qt::Horizontal
75 |
76 |
77 |
78 | 40
79 | 20
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 | 黑体
89 | 12
90 |
91 |
92 |
93 | 返回
94 |
95 |
96 |
97 | -
98 |
99 |
100 | Qt::Horizontal
101 |
102 |
103 |
104 | 40
105 | 20
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 | QAxWidget
117 | QWidget
118 |
119 |
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/parse.cpp:
--------------------------------------------------------------------------------
1 | #include "dialog.h"
2 | #include "ui_dialog.h"
3 |
4 | //JSON数据解析
5 | int Dialog::dataParse(QByteArray str)
6 | {
7 | QJsonParseError err_rpt;
8 | QJsonDocument root_Doc = QJsonDocument::fromJson(str, &err_rpt);
9 | // qDebug() << "ok ";
10 | if(err_rpt.error != QJsonParseError::NoError)
11 | {
12 | file->remove();
13 | emit on_btn_update_clicked();
14 | qDebug() << "JSON格式错误";
15 | // return -1;
16 | }
17 | // qDebug() << "JSON格式正确";
18 | if(root_Doc.isObject())
19 | {
20 | QJsonObject root_obj = root_Doc.object(); //创建JSON对象,不是字符串
21 | if(root_obj.contains("data"))
22 | {
23 | // qDebug() << root_obj.value("ret").toString();
24 |
25 | QString data_str = root_obj.value("data").toString();
26 | QJsonObject data_obj = QJsonDocument::fromJson(data_str.toUtf8(),&err_rpt).object();
27 | if(selAPI == 1)
28 | {
29 | //获取显示开关
30 | QJsonObject AddSwitch = data_obj.value("showAddSwitch").toObject();
31 | parseAddSwitch(AddSwitch);
32 |
33 | QJsonObject chinaTotal = data_obj.value("chinaTotal").toObject();
34 | QJsonObject chinaAdd = data_obj.value("chinaAdd").toObject();
35 | //获取累计数据和新增数据,并显示
36 | getTotalAddData(chinaTotal, chinaAdd); //全国累计和新增数据显示
37 | QString lastUpdateTime = data_obj.value("lastUpdateTime").toString();
38 | ui->lbe_update_time->setText(lastUpdateTime);
39 |
40 | QJsonArray areaTree_obj = data_obj.value("areaTree").toArray();
41 | QJsonObject chinaTree_obj = areaTree_obj.at(0).toObject(); //第0个是中国
42 | chinaTreeParse(chinaTree_obj);
43 | countryTreeParse(areaTree_obj);
44 | }
45 | /*以下数据在api2*/
46 | else if(selAPI == 2)
47 | {
48 | QJsonArray chinaDayListObj = data_obj.value("chinaDayList").toArray();
49 | chinaDayListParse(chinaDayListObj);
50 |
51 | QJsonArray chinaDayAddListObj = data_obj.value("chinaDayAddList").toArray();
52 | chinaDayAddListParse(chinaDayAddListObj);
53 |
54 | QJsonArray articleArr = data_obj.value("articleList").toArray();
55 | articleParse(articleArr);
56 | connect(ui->widget_chart, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(widget_chart_event(QMouseEvent*)));
57 | connect(ui->btn_group, SIGNAL(buttonClicked(int)), this, SLOT(drawCharts(int)));
58 | //默认绘制
59 | setSelectStyle(0);
60 | clickId = 0; //修复当点击死亡率按钮之后,再更新按钮,此时tip单位还是%的BUG
61 | widgetDrawLine(ui->widget_chart, "新增疑似/确诊趋势", "新增确诊", "新增疑似",
62 | clr1_1, clr1_2, AddDate, AddConfirmDub, AddSuspectDub);
63 | }
64 | }
65 | qDebug() << "疫情数据更新成功";
66 | // ui->btn_update->setEnabled(true);
67 | if(selAPI == 2)
68 | emit on_btn_update_clicked();
69 | }
70 | else
71 | qDebug() << "更新失败";
72 | return 0;
73 | }
74 |
75 | //累计确诊/疑似/死亡/治愈
76 | void Dialog::chinaDayListParse(QJsonArray chinaDayListObj)
77 | {
78 | //累计数量从1.13开始统计
79 | // size = getDay("20200113");
80 |
81 | uint16_t arraySize = chinaDayListObj.size();
82 | // qDebug() << arraySize;
83 | //size设置必须放在clear之前,可省略
84 | TotalDate.clear();
85 | TotalConfirmDub.clear();
86 | TotalSuspectDub.clear();
87 | TotalDeadDub.clear();
88 | TotalHealDub.clear();
89 |
90 | RateDate.clear();
91 | chinaDayListHealRate.clear(); //累计治愈率,从1.20开始
92 | chinaDayListDeadRate.clear(); //累计死亡率,从1.20开始
93 | for(int i = 0; i < arraySize; i++)
94 | {
95 | QJsonObject chinaDay = chinaDayListObj.at(i).toObject();
96 |
97 | QString date = chinaDay.value("date").toString();
98 | double deadRate = chinaDay.value("deadRate").toString().toDouble();
99 | double healRate = chinaDay.value("healRate").toString().toDouble();
100 |
101 | TotalDate << date;
102 |
103 | if(i >= 7) //从1.20开始输出
104 | {
105 | chinaDayListHealRate << healRate;
106 | chinaDayListDeadRate << deadRate;
107 | RateDate << date;
108 | // qDebug() << deadRate << healRate;
109 | }
110 |
111 | double confirm = chinaDay.value("confirm").toDouble();
112 | double suspect = chinaDay.value("suspect").toDouble();
113 | double dead = chinaDay.value("dead").toDouble();
114 | double heal = chinaDay.value("heal").toDouble();
115 |
116 | TotalConfirmDub << confirm;
117 | TotalSuspectDub << suspect;
118 | TotalDeadDub << dead;
119 | TotalHealDub << heal;
120 | }
121 | }
122 |
123 | //新增确诊/疑似/死亡/治愈
124 | void Dialog::chinaDayAddListParse(QJsonArray chinaDayAddListObj)
125 | {
126 | uint16_t arraySize = chinaDayAddListObj.size();
127 | // qDebug() << arraySize;
128 | //size设置必须放在clear之前,可省略
129 | AddDate.clear();
130 | AddConfirmDub.clear();
131 | AddSuspectDub.clear();
132 | AddDeadDub.clear();
133 | AddHealDub.clear();
134 |
135 | for(int i = 0; i < arraySize; i++)
136 | {
137 | QJsonObject chinaDay = chinaDayAddListObj.at(i).toObject();
138 | QString date = chinaDay.value("date").toString();
139 | AddDate << date;
140 |
141 | double confirm = chinaDay.value("confirm").toDouble();
142 | double suspect = chinaDay.value("suspect").toDouble();
143 | double dead = chinaDay.value("dead").toDouble();
144 | double heal = chinaDay.value("heal").toDouble();
145 |
146 | AddConfirmDub << confirm;
147 | AddSuspectDub << suspect;
148 | AddDeadDub << dead;
149 | AddHealDub << heal;
150 |
151 | if(i == arraySize - 1) //新增疑似取最新的历史数据
152 | ui->lbe_add_suspect->setText("+" + QString::number(AddSuspectDub[arraySize-1]));
153 | }
154 | }
155 | //中国疫情数据解析
156 | void Dialog::chinaTreeParse(QJsonObject chinaTree)
157 | {
158 | QJsonObject chinaTotal_obj = chinaTree.value("total").toObject();
159 | // QString chinaName = chinaTree.value("name").toString();
160 | // QString chinaTotalConfirm = QString::number(chinaTotal_obj.value("confirm").toInt()); //28130;
161 | // QString chinaTotalSuspect = QString::number(chinaTotal_obj.value("suspect").toInt()); //0;
162 | // QString chinaTotalDead = QString::number(chinaTotal_obj.value("dead").toInt()); //564
163 | // QString chinaTotalHeal = QString::number(chinaTotal_obj.value("heal").toInt()); //1301
164 |
165 | QJsonArray provinces_obj = chinaTree.value("children").toArray(); //包含所有的省份
166 |
167 | uint16_t provinceSize = provinces_obj.size();
168 | // qDebug() << provinceSize; //省份个数34
169 | ui->tree->clear();
170 | ui->tree->sortByColumn(2, Qt::DescendingOrder); //累计确诊排序
171 |
172 | for(int i = 0; i < provinceSize; i++) //0-33
173 | {
174 | QJsonObject province_obj = provinces_obj.at(i).toObject(); //0:湖北省
175 | dataAddTree(province_obj);
176 | // 0 1 2 3 4
177 | //省市 新增确诊 累计确诊 累计治愈 累计死亡
178 | }
179 | }
180 | //中国疫情数据树状显示
181 | void Dialog::dataAddTree(QJsonObject province_obj)
182 | {
183 | QString provinceName = province_obj.value("name").toString(); //"湖北"
184 | //省份新增
185 | uint16_t provinceAddConfirm = province_obj.value("today").toObject().value("confirm").toDouble();
186 | QJsonObject provinceTotal_obj = province_obj.value("total").toObject();
187 | //省份累计
188 | uint16_t provinceTotalConfirm = provinceTotal_obj.value("confirm").toDouble();
189 | uint16_t provinceTotalHeal = provinceTotal_obj.value("heal").toDouble();
190 | uint16_t provinceTotalDead = provinceTotal_obj.value("dead").toDouble();
191 |
192 | // qDebug() << provinceName << provinceAddConfirm << provinceTotalConfirm << provinceTotalHeal << provinceTotalDead << citySize; //省份下面多少个市
193 | // 0 1 2 3 4
194 | //省市 新增确诊 累计确诊 累计治愈 累计死亡
195 | QTreeWidgetItem *province = new QTreeWidgetItem(ui->tree);
196 |
197 | province->setData(0, Qt::DisplayRole, provinceName);
198 | province->setData(1, Qt::DisplayRole, provinceAddConfirm);
199 | province->setData(2, Qt::DisplayRole, provinceTotalConfirm);
200 | province->setData(3, Qt::DisplayRole, provinceTotalHeal);
201 | province->setData(4, Qt::DisplayRole, provinceTotalDead);
202 |
203 | QJsonArray citys_obj = province_obj.value("children").toArray(); //包含当前省的所有市
204 | uint16_t citySize = citys_obj.size(); //城市的个数
205 |
206 | for(int j = 0; j < citySize; j++)
207 | {
208 | QJsonObject city_obj = citys_obj.at(j).toObject();
209 |
210 | QString cityName = city_obj.value("name").toString();
211 | uint16_t cityAddConfirm = city_obj.value("today").toObject().value("confirm").toInt();
212 |
213 | QJsonObject cityTotal_obj = city_obj.value("total").toObject();
214 | uint16_t cityTotalConfirm = cityTotal_obj.value("confirm").toInt();
215 | uint16_t cityTotalHeal = cityTotal_obj.value("heal").toInt();
216 | uint16_t cityTotalDead = cityTotal_obj.value("dead").toInt();
217 |
218 | QTreeWidgetItem *citys = new QTreeWidgetItem(province);
219 |
220 | citys->setData(0, Qt::DisplayRole, cityName);
221 | citys->setData(1, Qt::DisplayRole, cityAddConfirm);
222 | citys->setData(2, Qt::DisplayRole, cityTotalConfirm);
223 | citys->setData(3, Qt::DisplayRole, cityTotalHeal);
224 | citys->setData(4, Qt::DisplayRole, cityTotalDead);
225 | }
226 | }
227 | //海外疫情数据解析并显示
228 | void Dialog::countryTreeParse(QJsonArray areaTree_obj)
229 | {
230 | ui->tree_2->clear();
231 | ui->tree_2->sortByColumn(1, Qt::DescendingOrder); //累计确诊排序
232 | uint16_t TotalConfirm = 0;
233 | uint16_t TotalDead = 0;
234 | for(int i = 1; i < areaTree_obj.size(); i++)
235 | {
236 | QJsonObject obj = areaTree_obj.at(i).toObject();
237 | QString countryName = obj.value("name").toString(); //日本
238 | QJsonObject countryTotal_obj = obj.value("total").toObject();
239 | uint16_t countryTotalConfirm = countryTotal_obj.value("confirm").toDouble();
240 | uint16_t countryTotalHeal = countryTotal_obj.value("heal").toDouble();
241 | uint16_t countryTotalDead = countryTotal_obj.value("dead").toDouble();
242 | //0 3 2 0
243 | //国家 确诊 治愈 死亡
244 | QTreeWidgetItem *country = new QTreeWidgetItem(ui->tree_2);
245 | country->setData(0, Qt::DisplayRole, countryName);
246 | country->setData(1, Qt::DisplayRole, countryTotalConfirm);
247 | country->setData(2, Qt::DisplayRole, countryTotalHeal);
248 | country->setData(3, Qt::DisplayRole, countryTotalDead);
249 |
250 | TotalConfirm += countryTotalConfirm;
251 | TotalDead += countryTotalDead;
252 | // qDebug() << countryName << countryTotalConfirm << countryTotalHeal <lbe_countryTotal->setText(text);
256 | }
257 |
258 | int Dialog::getTotalAddData(QJsonObject chinaTotal, QJsonObject chinaAdd)
259 | {
260 | if(!chinaTotal.isEmpty() && !chinaAdd.isEmpty())
261 | {
262 | int chinaTotal_confirm, chinaTotal_suspect, chinaTotal_dead, chinaTotal_heal;
263 | int chinaAdd_confirm, chinaAdd_suspect, chinaAdd_dead, chinaAdd_heal;
264 |
265 | getNum(chinaAdd, &chinaAdd_confirm, &chinaAdd_suspect, &chinaAdd_dead, &chinaAdd_heal);
266 | getNum(chinaTotal, &chinaTotal_confirm, &chinaTotal_suspect, &chinaTotal_dead, &chinaTotal_heal);
267 | //显示累计数据
268 | ui->lbe_total_confirm->setText(QString::number(chinaTotal_confirm));
269 | ui->lbe_total_suspect->setText(QString::number(chinaTotal_suspect));
270 | ui->lbe_total_dead->setText(QString::number(chinaTotal_dead));
271 | ui->lbe_total_heal->setText(QString::number(chinaTotal_heal));
272 |
273 | int total_nowConfirm = chinaTotal.value("nowConfirm").toDouble(); //现有确诊
274 | int total_nowSevere = chinaTotal.value("nowSevere").toDouble(); //现有重症
275 |
276 | ui->lbe_total_nowConfirm->setText(QString::number(total_nowConfirm));
277 | ui->lbe_total_nowSevere->setText(QString::number(total_nowSevere));
278 |
279 | //显示新增
280 | int chinaAdd_nowConfirm = chinaAdd.value("nowConfirm").toDouble();
281 | int chinaAdd_nowServere = chinaAdd.value("nowSevere").toDouble();
282 |
283 | showAddData("confirm", chinaAdd_confirm, ui->lbe_add_confirm);
284 | // showAddData("suspect", chinaAdd_suspect, ui->lbe_add_suspect);
285 | showAddData("dead", chinaAdd_dead, ui->lbe_add_dead);
286 | showAddData("heal", chinaAdd_heal, ui->lbe_add_heal);
287 | showAddData("nowConfirm", chinaAdd_nowConfirm, ui->lbe_add_nowConfirm);
288 | showAddData("nowServere", chinaAdd_nowServere, ui->lbe_add_nowSevere);
289 |
290 | QString tip = "较上日国家卫健委公布的现有疑似病例数" + QString::number(chinaAdd_suspect);
291 |
292 | ui->lbe_suspect->setToolTip(tip);
293 |
294 | return 0;
295 | }
296 | else
297 | return -1;
298 | }
299 |
300 | void Dialog::articleParse(QJsonArray arr)
301 | {
302 | uint16_t arrSize = arr.size();
303 | // qDebug() << "共 " << arrSize << " 条新闻";
304 | // qDebug() << QCoreApplication::applicationDirPath();
305 | // qDebug() << QCoreApplication::applicationFilePath();
306 | // qDebug() << QCoreApplication::applicationName();
307 |
308 | // QString tmp = newsHtmlFileName;
309 | QString tmp = QCoreApplication::applicationDirPath() + "/" + newsHtmlFileName;
310 | QFile file(tmp);
311 |
312 | if(!file.open(QIODevice::ReadOnly))
313 | {
314 | qDebug() << "文件打开失败";
315 | }
316 | // qDebug() << "file open ok";
317 | QByteArray allData = file.readAll();
318 | file.close();
319 | QList ba;
320 |
321 | // ba = allData.split("");
322 | ba = allData.split('*');
323 | // qDebug() << ba.size();
324 | QString html;
325 | for(int i = 0; i < arrSize; i++)
326 | {
327 | QJsonObject article_obj = arr.at(i).toObject();//每一篇文件信息
328 | // QString cmsId = article_obj.value("cmsId").toString();
329 | QString media = article_obj.value("media").toString();
330 | QString publish_time = article_obj.value("publish_time").toString();
331 | QString desc = article_obj.value("desc").toString();
332 | QString url = article_obj.value("url").toString();
333 | QString title = article_obj.value("title").toString();
334 | QString str = ba[0] + title + ba[1] + desc + ba[2] + url + ba[3] + media + ba[4] + publish_time + ba[5];
335 | html.append(str);
336 | // if(i == 0)
337 | // qDebug() << html;
338 |
339 | // qDebug() << publish_time << media << title << url;
340 | }
341 | html.append(ba[6]);
342 | // qDebug() << html;
343 | ui->tb_news->clear();
344 | ui->tb_news->setHtml(html);
345 | // qDebug() << "set Html ok";
346 | }
347 | //获取人数
348 | int Dialog::getNum(QJsonObject obj, int *num_confirm, int *num_suspect, int *num_dead, int *num_heal)
349 | {
350 | if(!obj.isEmpty())
351 | {
352 | *num_confirm = obj.value("confirm").toDouble();
353 | *num_suspect = obj.value("suspect").toDouble();
354 | *num_dead = obj.value("dead").toDouble();
355 | *num_heal = obj.value("heal").toDouble();
356 |
357 | return 0;
358 | }
359 | else
360 | return -1;
361 | }
362 | //容器类转换:QString转换为double
363 | QVector Dialog::QStringToDouble(QVector str, uint16_t len)
364 | {
365 | QVector dub(len);
366 |
367 | for(int i = 0; i < str.size(); i++)
368 | {
369 | dub[i] = str[i].toDouble();
370 | }
371 | return dub;
372 | }
373 |
374 | //显示新增数据
375 | void Dialog::showAddData(QString key, int num, QLabel *lbe)
376 | {
377 | QString str_num;
378 | if(num > 0)
379 | str_num = "+" + QString::number(num);
380 | else
381 | str_num = QString::number(num);
382 |
383 | bool sw = AddSwitchMap.value(key);
384 |
385 | QString str = (sw) ? str_num : "待公布";
386 |
387 | lbe->setText(str);
388 | }
389 |
390 | void Dialog::parseAddSwitch(QJsonObject sw_obj)
391 | {
392 | bool sw_all = sw_obj.value("all").toBool();
393 | bool sw_confirm = sw_obj.value("confirm").toBool();
394 | bool sw_suspect = sw_obj.value("suspect").toBool();
395 | bool sw_dead = sw_obj.value("dead").toBool();
396 | bool sw_heal = sw_obj.value("heal").toBool();
397 | bool sw_nowConfirm = sw_obj.value("nowConfirm").toBool();
398 | bool sw_nowSevere = sw_obj.value("nowSevere").toBool();
399 |
400 | AddSwitchMap.clear();
401 | AddSwitchMap.insert("all", sw_all);
402 | AddSwitchMap.insert("confirm", sw_confirm);
403 | AddSwitchMap.insert("suspect", sw_suspect);
404 | AddSwitchMap.insert("dead", sw_dead);
405 | AddSwitchMap.insert("heal", sw_heal);
406 | AddSwitchMap.insert("nowConfirm", sw_nowConfirm);
407 | AddSwitchMap.insert("nowServere", sw_nowSevere);
408 |
409 | // AddSwitchMap["all"] = false; //用于赋值
410 | // if(AddSwitchMap.contains("all")); //用于查询,是否包含
411 | // bool val = AddSwitchMap.value("all"); //用于获取值
412 |
413 | }
414 |
--------------------------------------------------------------------------------
/plot.cpp:
--------------------------------------------------------------------------------
1 | #include "dialog.h"
2 | #include "ui_dialog.h"
3 |
4 | //添加2条曲线
5 | void Dialog::wigetAddGraph(QCustomPlot *widget)
6 | {
7 | widget->addGraph();
8 | widget->graph(0)->setLineStyle(QCPGraph::lsLine);
9 | widget->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5));
10 |
11 | widget->addGraph();
12 | widget->graph(1)->setLineStyle(QCPGraph::lsLine);
13 | widget->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5));
14 |
15 | widget->xAxis->setSubTicks(false); //小格刻度不显示
16 | widget->xAxis->setTickPen(QPen(Qt::white));
17 | widget->xAxis->setTickLabelFont(QFont(QFont().family(), 8)); //字体和大小
18 | widget->xAxis->setTickLabelRotation(150); //标签旋转角度
19 |
20 | // widget->xAxis->rescale(true); //刻度自适应,默认省略
21 | }
22 |
23 | //设置曲线颜色
24 | void Dialog::wigetSetColor(QCustomPlot *widget, QColor clr1, QColor clr2)
25 | {
26 | widget->yAxis->setTickPen(QPen(Qt::white));
27 | widget->yAxis->setSubTickPen(QPen(Qt::white));
28 | widget->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
29 | // widget->yAxis->rescale(true); //刻度自适应,默认省略
30 |
31 | widget->graph(0)->setPen(QPen(clr1)); //QColor(255, 100, 0)
32 | widget->graph(1)->setPen(QPen(clr2)); //QColor(50, 200, 0)
33 | }
34 |
35 | //用于在一个画布上绘制
36 | void Dialog::widgetDrawLine(QCustomPlot *widget, QString chartName, QString name1, QString name2,
37 | QColor clr1, QColor clr2, QVector date,
38 | QVector data1, QVector data2)
39 | {
40 | ui->lbe_chart_name->setText(chartName);
41 | //图例名字
42 | ui->lbe_chart_line1_name->setText(name1);
43 | ui->lbe_chart_line2_name->setText(name2);
44 | //图例颜色设置
45 | QString style1 = ui->lbe_chart_line1_clr->styleSheet();
46 | QString style2 = ui->lbe_chart_line2_clr->styleSheet();
47 |
48 | style1.append(rgbToStyle(clr1));
49 | style2.append(rgbToStyle(clr2));
50 |
51 | ui->lbe_chart_line1_clr->setStyleSheet(style1);
52 | ui->lbe_chart_line2_clr->setStyleSheet(style2);
53 |
54 | widget->graph(0)->setName(name1); //设置曲线名字
55 | widget->graph(1)->setName(name2); //设置曲线名字
56 |
57 | widget->graph(0)->setPen(QPen(clr1)); //QColor(255, 100, 0)
58 | widget->graph(1)->setPen(QPen(clr2)); //QColor(50, 200, 0)
59 |
60 | double maxValue = getMaxVaule(data1, data2);
61 | uint16_t dataSize = data1.size();
62 |
63 | QVector ticks;
64 | for(int i = 0; i < dataSize; i++)
65 | ticks << i; //tick:0 1 2 3 4 5 6
66 |
67 | QSharedPointer textTicker(new QCPAxisTickerText);
68 |
69 | for(int i = 0; i < dataSize; i++)
70 | {
71 | if(i % 2 == 0) //偶数
72 | textTicker->addTick(i, date.at(i)); //tick和标签对应
73 | else
74 | textTicker->addTick(i, " ");
75 | }
76 |
77 | // textTicker->addTicks(ticks, date); //每一个都显示
78 |
79 | widget->xAxis->setTicker(textTicker); //x轴为文本标签
80 | widget->xAxis->setTickLabelRotation(60); //标签旋转角度
81 |
82 | widget->xAxis->setRange(0, dataSize);
83 | if(clickId == 3)
84 | {
85 | widget->yAxis->setRange(0, maxValue + 2);
86 | }
87 | else
88 | widget->yAxis->setRange(0, maxValue + maxValue/20);
89 |
90 | widget->graph(0)->setData(ticks, data1);//曲线0添加数据新增确诊人数
91 | widget->graph(1)->setData(ticks, data2);//曲线1添加数据新增疑似人数
92 |
93 | widget->replot();
94 | }
95 |
96 | QString Dialog::rgbToStyle(QColor rbg)
97 | {
98 | QString r_str = QString::number(rbg.red()) + ", ";
99 | QString g_str = QString::number(rbg.green()) + ", ";
100 | QString b_str = QString::number(rbg.blue()) + "); ";
101 |
102 | QString style = "background-color: rgb(" + r_str + g_str + b_str;
103 | // qDebug() << style;
104 | return style;
105 | }
106 |
107 | //画折线图,数据类型是double
108 | void Dialog::widgetDrawLine(QCustomPlot *widget, QVector date,
109 | QVector data1Dub, QVector data2Dub)
110 | {
111 | uint16_t dataSize = date.size();
112 | // qDebug() << dataSize;
113 | double maxValue = getMaxVaule(data1Dub, data2Dub);;
114 |
115 | QVector ticks;
116 | for(int i = 0; i < dataSize; i++)
117 | ticks << i; //tick:0 1 2 3 4 5 6
118 |
119 | QSharedPointer textTicker(new QCPAxisTickerText);
120 |
121 | for(int i = 0; i < dataSize; i++)
122 | {
123 | if(i % 2 == 0) //偶数
124 | textTicker->addTick(i, date.at(i)); //tick和标签对应
125 | else
126 | textTicker->addTick(i, " ");
127 | }
128 |
129 | // textTicker->addTicks(ticks, date); //每一个都显示
130 |
131 | widget->xAxis->setTicker(textTicker); //x轴为文本标签
132 | widget->xAxis->setTickLabelRotation(60); //标签旋转角度
133 |
134 | widget->xAxis->setRange(0, dataSize);
135 | widget->yAxis->setRange(0, maxValue + maxValue/20);
136 |
137 | widget->graph(0)->setData(ticks, data1Dub);//曲线0添加数据新增确诊人数
138 | widget->graph(1)->setData(ticks, data2Dub);//曲线1添加数据新增疑似人数
139 | widget->replot();
140 | }
141 |
--------------------------------------------------------------------------------
/qt_2019_ncov.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2020-02-05T11:16:34
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui
8 |
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10 |
11 | TARGET = qt_2019_ncov
12 | TEMPLATE = app
13 |
14 | # The following define makes your compiler emit warnings if you use
15 | # any feature of Qt which as been marked as deprecated (the exact warnings
16 | # depend on your compiler). Please consult the documentation of the
17 | # deprecated API in order to know how to port your code away from it.
18 | DEFINES += QT_DEPRECATED_WARNINGS
19 |
20 | # You can also make your code fail to compile if you use deprecated APIs.
21 | # In order to do so, uncomment the following line.
22 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
24 |
25 |
26 | SOURCES += main.cpp\
27 | dialog.cpp \
28 | qcustomplot.cpp \
29 | parse.cpp \
30 | network.cpp \
31 | plot.cpp \
32 | slots.cpp \
33 | about.cpp \
34 | rumor.cpp \
35 | rumor_info.cpp \
36 | news_info.cpp
37 |
38 | HEADERS += dialog.h \
39 | qcustomplot.h \
40 | about.h \
41 | rumor.h \
42 | rumor_info.h \
43 | news_info.h
44 |
45 | FORMS += dialog.ui \
46 | about.ui \
47 | rumor.ui \
48 | rumor_info.ui \
49 | news_info.ui
50 |
51 |
52 | QT += network
53 | QT += printsupport
54 | QT += axcontainer
55 |
56 | RESOURCES += \
57 | img.qrc
58 |
59 | #运行文件附带调试输出窗口
60 | #CONFIG += console pro
61 |
62 | # 程序版本
63 | #VERSION = 2018.7.25
64 |
65 | # 添加图标
66 | RC_ICONS = bitbug_favicon.ico
67 | #VERSION = 1.0.0.0 //设置程序版本号,可省略
68 |
69 | #CONFIG -= debug_and_release
70 |
--------------------------------------------------------------------------------
/rumor.cpp:
--------------------------------------------------------------------------------
1 | #include "rumor.h"
2 | #include "ui_rumor.h"
3 | //#include "windows.h"
4 | #include
5 |
6 | rumor::rumor(QWidget *parent) :
7 | QDialog(parent),
8 | ui(new Ui::rumor)
9 | {
10 | ui->setupUi(this);
11 |
12 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
13 | this->setWindowTitle("辟谣信息");
14 | ui->tb_rumor->setOpenLinks(false);
15 | // ui->tb_rumor->setOpenLinks(true);
16 | connect(ui->tb_rumor, SIGNAL(anchorClicked(const QUrl&)), this, SLOT(anchorClickedSlot(const QUrl&)));
17 | manager = new QNetworkAccessManager(this); //新建网络请求对象
18 | }
19 |
20 | rumor::~rumor()
21 | {
22 | delete ui;
23 | }
24 |
25 | void rumor::anchorClickedSlot(const QUrl& url)
26 | {
27 | // qDebug() << url;
28 | QString url_str = url.toString();
29 |
30 | if(url_str == "https://vp.fact.qq.com/home")
31 | {
32 | QDesktopServices::openUrl(url);
33 | }
34 | else
35 | {
36 | QNetworkConfigurationManager mgr;
37 | if(mgr.isOnline() == true)
38 | {
39 | QList list = url_str.split('=');
40 | info.getRumorInfo(list[1]);
41 | info.exec();
42 | }
43 | else
44 | QMessageBox::warning(NULL, "错误", "无网络连接,请检查网络", QMessageBox::Yes);
45 | }
46 | }
47 | void rumor::httpReadyRead() //有可用数据
48 | {
49 | if(file)
50 | file->write(reply->readAll()); //如果文件存在,则写入文件
51 | }
52 | void rumor::httpFinished() //完成下载
53 | {
54 | file->flush();
55 | file->close();
56 | // qDebug() << "rumor数据下载成功";
57 | reply->deleteLater();
58 | reply = 0;
59 | delete file;
60 | file = 0;
61 | // QMessageBox::information(this, "提示", "下载完成");
62 | parseRumor(filename);
63 | }
64 |
65 | void rumor::parseRumor(QString filename)
66 | {
67 | // qDebug() << "开始解析rumor数据:" << filename;
68 | QFile file(filename);
69 | if(!file.open(QIODevice::ReadOnly))
70 | {
71 | qDebug() << "rumor文件打开失败";
72 | }
73 | QByteArray allData = file.readAll();
74 | file.close();
75 | file.remove(); //删除文件
76 |
77 | QJsonParseError err_rpt;
78 | QJsonDocument root_Doc = QJsonDocument::fromJson(allData, &err_rpt);
79 |
80 | if(err_rpt.error != QJsonParseError::NoError)
81 | {
82 | file.remove();
83 | qDebug() << "JSON格式错误";
84 | // return -1;
85 | }
86 | // qDebug() << "JSON格式正确";
87 | if(root_Doc.isObject())
88 | {
89 | QJsonObject root_obj = root_Doc.object();
90 | // QString code = root_obj.value("code").toString(); //0
91 | QJsonArray content_arr = root_obj.value("content").toArray();
92 | disRumorNews(content_arr);
93 | }
94 | }
95 |
96 | void rumor::getRumorNews(uint8_t page) //获取几页
97 | {
98 | // uint8_t page = 0;
99 |
100 | // ui->tb_rumor->clear();
101 | // html.clear();
102 |
103 | // for(int i = 0; i < num; i++)
104 | // {
105 | QNetworkConfigurationManager mgr;
106 | if(mgr.isOnline() == true)
107 | {
108 | qint64 timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch(); //毫秒级
109 | QString timestamp_str;
110 | timestamp_str.setNum(timestamp, 10); //十进制时间戳15555550001
111 | QString current_time = QDateTime::currentDateTime().toString("yyyyMMdd_hh_mm_ss_zzz");
112 | QString pageStr = QString::number(page);
113 | url = QUrl(rumorApi + pageStr);
114 | // qDebug() << url.toString();
115 | qDebug() << "网络正常,开始更新辟谣信息" + url.toString();
116 |
117 | filename = "rumorNews_" + pageStr + "_" + current_time + ".json";
118 | file = new QFile(filename);
119 |
120 | if(!file->open(QIODevice::WriteOnly))
121 | {
122 | qDebug() << "rumor文件打开失败";
123 | delete file;
124 | file = 0;
125 | return;
126 | }
127 |
128 | // qDebug() << "rumorApi网络正常";
129 | reply = manager->get(QNetworkRequest(url)); //发送get请求数据
130 | //下载完成执行槽函数
131 | connect(reply,SIGNAL(finished()),this,SLOT(httpFinished()));
132 | //有可用的数据
133 | connect(reply,SIGNAL(readyRead()),this,SLOT(httpReadyRead()));
134 | }
135 | else
136 | {
137 | qDebug() << "rumorApi网络错误,请检查网络";
138 | QMessageBox::warning(NULL, "错误", "无网络连接,请检查网络", QMessageBox::Yes);
139 | }
140 | }
141 |
142 | //假,谣言,url,"谣言标题", 腾讯医典, id
143 |
144 | void rumor::disRumorNews(QJsonArray content_arr)
145 | {
146 | QString tmp = QCoreApplication::applicationDirPath() + "/" + rumorHtmlFileName;
147 |
148 | QFile file(tmp);
149 |
150 | if(!file.open(QIODevice::ReadOnly))
151 | {
152 | qDebug() << "rumor文件打开失败";
153 | }
154 | QByteArray allData = file.readAll();
155 | QList ba;
156 |
157 | file.close();
158 | ba = allData.split('*');
159 |
160 | // qDebug() << ba.size();
161 |
162 | QString html;
163 | uint8_t arrSize = content_arr.size();
164 | for(int i = 0; i < arrSize; i++)
165 | {
166 | QJsonObject rumor_obj = content_arr.at(i).toObject();
167 | QString date = rumor_obj.value("date").toString(); //"2020-02-12"
168 | QString result = rumor_obj.value("result").toString(); //"假"
169 | // QString markstyle = rumor_obj.value("markstyle").toString(); //"fake"
170 | QString explain = rumor_obj.value("explain").toString(); //"谣言"
171 | QString title = rumor_obj.value("title").toString(); //"拔头两侧的白发可以防治新型冠状病毒肺炎"
172 | QString author = rumor_obj.value("author").toString(); //"腾讯旗下专业医学科普平台"
173 | QString id = rumor_obj.value("id").toString(); //"fdfb9439ecf2a5113791a46252764ece"
174 | QString bgmClr;
175 | if(result == "假") //假
176 | bgmClr = bgmClr_fake;
177 | else if(result == "真") //真
178 | bgmClr = bgmClr_true;
179 | else //疑
180 | bgmClr = bgmClr_doubt;
181 | // QString url = rumorUrl + id;
182 | QString head = "[" + result + "]" + explain;
183 | QString from = date + " " + author;
184 | QString str = ba[0] + bgmClr + ba[1] + head+ ba[2] + id + ba[3] + title + ba[4] + from + ba[5];
185 | html.append(str);
186 |
187 | // qDebug() << date << result << markstyle << explain << title;
188 | }
189 | html.append(ba[6]);
190 | // qDebug() << html;
191 | ui->tb_rumor->clear();
192 | ui->tb_rumor->setHtml(html);
193 | qDebug() << "辟谣信息更新成功";
194 | }
195 |
--------------------------------------------------------------------------------
/rumor.h:
--------------------------------------------------------------------------------
1 | #ifndef RUMOR_H
2 | #define RUMOR_H
3 |
4 | #include
5 |
6 | #include
7 | //网络相关头文件
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 |
15 | //JSON相关头文件
16 | #include
17 | #include
18 | #include
19 |
20 | #include "rumor_info.h"
21 | #include "news_info.h"
22 |
23 | namespace Ui {
24 | class rumor;
25 | }
26 |
27 | class rumor : public QDialog
28 | {
29 | Q_OBJECT
30 |
31 | public:
32 | explicit rumor(QWidget *parent = 0);
33 | ~rumor();
34 | void getRumorNews(uint8_t page);
35 | void parseRumor(QString filename);
36 | void disRumorNews(QJsonArray content_arr);
37 |
38 | private slots:
39 | void anchorClickedSlot(const QUrl& url);
40 | void httpReadyRead(); //有可用数据
41 | void httpFinished(); //完成下载
42 |
43 | private:
44 | Ui::rumor *ui;
45 | // QString rumorApi = "https://vp.fact.qq.com/loadmore?page=0&_=1581341095686";
46 | QString rumorApi = "https://vp.fact.qq.com/loadmore?page=";
47 | QString rumorUrl = "https://vp.fact.qq.com/article?id=";
48 | uint8_t rumorPage = 0;
49 |
50 | QString bgmClr_true = "42a163";
51 | QString bgmClr_fake = "c41f20";
52 | QString bgmClr_doubt = "484848";
53 |
54 | QString rumorHtmlFileName = "html_rumor.txt";
55 |
56 | QNetworkAccessManager *manager;
57 | QNetworkReply *reply;
58 | QUrl url;
59 | QFile *file;
60 | QString filename;
61 | // QString html;
62 | rumor_info info;
63 | news_info moreRumor;
64 | };
65 |
66 | #endif // RUMOR_H
67 |
--------------------------------------------------------------------------------
/rumor.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | rumor
4 |
5 |
6 |
7 | 0
8 | 0
9 | 664
10 | 433
11 |
12 |
13 |
14 |
15 | Ubuntu
16 |
17 |
18 |
19 | Dialog
20 |
21 |
22 | -
23 |
24 |
25 |
26 | 微软雅黑
27 |
28 |
29 |
30 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
31 | <html><head><meta name="qrichtext" content="1" /><title>CanvasLayer</title><style type="text/css">
32 | p, li { white-space: pre-wrap; }
33 | </style></head><body style=" font-family:'微软雅黑'; font-size:9pt; font-weight:400; font-style:normal;">
34 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html>
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/rumor_info.cpp:
--------------------------------------------------------------------------------
1 | #include "rumor_info.h"
2 | #include "ui_rumor_info.h"
3 | #include
4 |
5 | rumor_info::rumor_info(QWidget *parent) :
6 | QDialog(parent),
7 | ui(new Ui::rumor_info)
8 | {
9 | ui->setupUi(this);
10 | manager = new QNetworkAccessManager(this); //新建网络请求对象
11 |
12 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
13 | this->setWindowTitle("较真查证");
14 | }
15 |
16 | rumor_info::~rumor_info()
17 | {
18 | delete ui;
19 | }
20 |
21 | void rumor_info::httpReadyRead() //有可用数据
22 | {
23 | if(file)
24 | file->write(reply->readAll()); //如果文件存在,则写入文件
25 | }
26 | void rumor_info::httpFinished() //完成下载
27 | {
28 | file->flush();
29 | file->close();
30 | // qDebug() << "rumor数据下载成功";
31 | reply->deleteLater();
32 | reply = 0;
33 | delete file;
34 | file = 0;
35 | // QMessageBox::information(this, "提示", "下载完成");
36 | paraseRumorInfo(filename);
37 |
38 | }
39 |
40 | void rumor_info::paraseRumorInfo(QString filename)
41 | {
42 | // qDebug() << "开始解析rumorInfo数据:" << filename;
43 | QFile file(filename);
44 | if(!file.open(QIODevice::ReadOnly))
45 | {
46 | qDebug() << "rumorInfo文件打开失败";
47 | }
48 | QByteArray allData = file.readAll();
49 | file.close();
50 | file.remove(); //删除文件
51 |
52 | QJsonParseError err_rpt;
53 | QJsonDocument root_Doc = QJsonDocument::fromJson(allData, &err_rpt);
54 |
55 | if(err_rpt.error != QJsonParseError::NoError)
56 | {
57 | // file.remove();
58 | qDebug() << "JSON格式错误";
59 | // return -1;
60 | }
61 | // qDebug() << "JSON格式正确";
62 | if(root_Doc.isObject())
63 | {
64 | QJsonObject root_obj = root_Doc.object();
65 | // QString code = root_obj.value("code").toString(); //0
66 | QJsonObject content_obj = root_obj.value("content").toObject();
67 | disRumorInfo(content_obj);
68 | }
69 | }
70 |
71 | void rumor_info::disRumorInfo(QJsonObject content_obj)
72 | {
73 | ui->tb_rumor_info->clear();
74 | QString tmp = QCoreApplication::applicationDirPath() + "/" + rumorInfoHtmlFileName;
75 |
76 | QFile file(tmp);
77 | if(!file.open(QIODevice::ReadOnly))
78 | {
79 | qDebug() << "rumor文件打开失败";
80 | }
81 | QByteArray allData = file.readAll();
82 | QList ba;
83 | file.close();
84 |
85 | ba = allData.split('*');
86 | // qDebug() << ba.size();
87 |
88 | QString bgmClr;
89 | QString html;
90 |
91 | QString title = content_obj.value("title").toString();
92 | html.append(ba[0]);
93 | html.append(title);
94 |
95 | QString rumor = content_obj.value("rumor").toString(); //说法
96 | html.append(ba[1]);
97 | html.append(rumor);
98 |
99 | QString result = content_obj.value("result").toString(); //疑
100 | if(result == "假") //假
101 | bgmClr = bgmClr_fake;
102 | else if(result == "真") //真
103 | bgmClr = bgmClr_true;
104 | else //疑
105 | bgmClr = bgmClr_doubt;
106 |
107 | html.append(ba[2]);
108 | html.append(bgmClr);
109 |
110 | html.append(ba[3]);
111 | html.append(result);
112 |
113 | QString explain = content_obj.value("explain").toString(); //有失实
114 | html.append(ba[4]);
115 | html.append(explain);
116 |
117 | QJsonArray abstract_arr = content_obj.value("abstract").toArray();
118 | uint8_t arrSize = abstract_arr.size();
119 | for(int i = 0; i < arrSize; i++)
120 | {
121 | QString index = QString::number(abstract_arr.at(i).toObject().value("index").toInt());
122 | QString content = abstract_arr.at(i).toObject().value("content").toString();
123 | html.append(ba[6]);
124 | html.append(index);
125 | html.append(ba[7]);
126 | html.append(content);
127 | html.append(ba[8]);
128 | }
129 |
130 | QJsonObject Author = content_obj.value("Author").toObject();
131 | QString name = Author.value("name").toString(); //谢望时
132 | QString desc = Author.value("desc").toString();
133 | html.append(ba[9]);
134 | html.append(name);
135 | html.append(ba[10]);
136 | html.append(desc);
137 |
138 | // QString markstyle = content_obj.value("doubt").toString();
139 |
140 | QString date = content_obj.value("date").toString(); //2020-02-13
141 | html.append(ba[11]);
142 | html.append(date);
143 | QString source = content_obj.value("source").toString();
144 | html.append(ba[12]);
145 | html.append(source);
146 | html.append(ba[13]);
147 |
148 | // QString head = "[" + result + "]" + explain;
149 |
150 | ui->tb_rumor_info->setHtml(html);
151 | qDebug() << "辟谣详细信息解析成功";
152 | }
153 |
154 | void rumor_info::getRumorInfo(QString rumor_id)
155 | {
156 | QNetworkConfigurationManager mgr;
157 | if(mgr.isOnline() == true)
158 | {
159 | qint64 timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch(); //毫秒级
160 | QString timestamp_str;
161 | timestamp_str.setNum(timestamp, 10); //十进制时间戳15555550001
162 | QString current_time = QDateTime::currentDateTime().toString("yyyyMMdd_hh_mm_ss_zzz");
163 |
164 | url = QUrl(rumor_infoApi + rumor_id);
165 | qDebug() << "网络正常,开始获取辟谣详细信息" + url.toString();
166 | // qDebug() << url.toString();
167 |
168 | filename = "rumorInfo_" + current_time + ".json";
169 | file = new QFile(filename);
170 |
171 | if(!file->open(QIODevice::WriteOnly))
172 | {
173 | qDebug() << "rumorInfo文件打开失败";
174 | delete file;
175 | file = 0;
176 | return;
177 | }
178 |
179 | // qDebug() << "rumorInfoApi网络正常";
180 | reply = manager->get(QNetworkRequest(url)); //发送get请求数据
181 | //下载完成执行槽函数
182 | connect(reply,SIGNAL(readyRead()),this,SLOT(httpReadyRead()));
183 | //有可用的数据
184 | connect(reply,SIGNAL(finished()),this,SLOT(httpFinished()));
185 | }
186 | else
187 | {
188 | qDebug() << "rumorInfoApi网络错误,请检查网络";
189 | QMessageBox::warning(NULL, "错误", "无网络连接,请检查网络", QMessageBox::Yes);
190 | }
191 | }
192 |
193 |
194 | void rumor_info::on_btn_back_clicked()
195 | {
196 | this->close();
197 | }
198 |
--------------------------------------------------------------------------------
/rumor_info.h:
--------------------------------------------------------------------------------
1 | #ifndef RUMOR_INFO_H
2 | #define RUMOR_INFO_H
3 |
4 | #include
5 | //网络相关头文件
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | //JSON相关头文件
12 | #include
13 | #include
14 | #include
15 |
16 | #include
17 |
18 | namespace Ui {
19 | class rumor_info;
20 | }
21 |
22 | class rumor_info : public QDialog
23 | {
24 | Q_OBJECT
25 |
26 | public:
27 | explicit rumor_info(QWidget *parent = 0);
28 | ~rumor_info();
29 | void paraseRumorInfo(QString filename);
30 | void getRumorInfo(QString rumor_id);
31 | QString bgmClr_true = "42a163";
32 | QString bgmClr_fake = "c41f20";
33 | QString bgmClr_doubt = "484848";
34 | void disRumorInfo(QJsonObject content_obj);
35 |
36 | private slots:
37 | void httpReadyRead(); //有可用数据
38 | void httpFinished(); //完成下载
39 |
40 | void on_btn_back_clicked();
41 |
42 | private:
43 | Ui::rumor_info *ui;
44 |
45 | QNetworkAccessManager *manager;
46 | QNetworkReply *reply;
47 | QUrl url;
48 | QFile *file;
49 | QString filename;
50 | QString rumor_infoApi = "https://vp.fact.qq.com/miniArtData?id=";
51 | QString rumorInfoHtmlFileName = "html_rumor_info.txt";
52 |
53 | };
54 |
55 | #endif // RUMOR_INFO_H
56 |
--------------------------------------------------------------------------------
/rumor_info.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | rumor_info
4 |
5 |
6 |
7 | 0
8 | 0
9 | 634
10 | 345
11 |
12 |
13 |
14 | Dialog
15 |
16 |
17 | -
18 |
19 |
20 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
21 | <html><head><meta name="qrichtext" content="1" /><style type="text/css">
22 | p, li { white-space: pre-wrap; }
23 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;">
24 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'微软雅黑'; font-size:16pt; font-weight:600;">天气暖和从南方回归北方的鸟会带回病毒,感染人类</span></p>
25 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'微软雅黑'; font-size:6pt; font-weight:600;"> </span></p>
26 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'微软雅黑'; font-size:14pt; color:#555753;">"流传说法:天气回暖,从南方飞回北方的鸟经过疫区会带回病毒,感染人类。"</span></p>
27 | <hr />
28 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'微软雅黑'; font-size:14pt; font-weight:600;">较真鉴定:</span><span style=" font-family:'微软雅黑'; font-size:14pt; color:#ffffff; background-color:#484848;"> [疑]有失实 </span></p>
29 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:7pt;"> </span></p>
30 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'微软雅黑'; font-size:14pt; font-weight:600; color:#000000;">查证要点:</span></p>
31 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'微软雅黑'; font-size:15pt; color:#ffffff; background-color:#333333;"> 1 </span><span style=" font-family:'微软雅黑'; font-size:14pt; color:#000000;"> 冠状病毒是一类主要引起呼吸道、肠道疾病的病原体。除了可感染人类,还可感染猪、牛、猫、犬、骆驼、蝙蝠、老鼠、刺猬等多种哺乳动物以及多种鸟类。鸟类作为宿主之一,其会感染SARS病毒或MERS病毒已被证实。本次新型冠状病毒跟SARS属于一个族,鸟类感染可能不表现症状,但如果人接触或食用携带病毒鸟类,会被感染并引起症状。</span></p>
32 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'微软雅黑'; font-size:15pt; color:#ffffff; background-color:#333333;"> 2 </span><span style=" font-family:'微软雅黑'; font-size:14pt; color:#000000;"> 所以天气回暖,北飞的鸟可能携带病毒,但这并不意味着什么。因为若没有本次疫情,鸟类也会携带病毒,人类与这些野生动物相安无事,被感染的概率很低;另外,北方城市比如黑龙江、北京等均有数百确诊病例,病毒在全国扩散是既定事实,只要我们做好基础防护,不吃野生动物,疫情不会因为鸟类到来而加重。</span></p>
33 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'微软雅黑'; font-size:7pt; color:#000000;"> </span></p>
34 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'微软雅黑'; font-size:14pt; font-weight:600; color:#000000;">查证者:</span><span style=" font-family:'微软雅黑'; font-size:14pt; color:#000000;">谢望时 </span><span style=" font-family:'微软雅黑'; font-size:14pt; color:#8d8d8d;">药理学硕士,知贝儿科药师</span></p>
35 | <hr />
36 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'微软雅黑'; font-size:12pt; font-weight:600; color:#000000;">时间</span><span style=" font-family:'微软雅黑'; font-size:12pt; color:#000000;">:2020-02-13 </span><span style=" font-family:'微软雅黑'; font-size:12pt; font-weight:600; color:#000000;">来源</span><span style=" font-family:'微软雅黑'; font-size:12pt; color:#000000;">:腾讯较真</span></p>
37 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html>
38 |
39 |
40 |
41 | -
42 |
43 |
-
44 |
45 |
46 | Qt::Horizontal
47 |
48 |
49 |
50 | 40
51 | 20
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 | 黑体
61 | 12
62 |
63 |
64 |
65 | 返回
66 |
67 |
68 |
69 | -
70 |
71 |
72 | Qt::Horizontal
73 |
74 |
75 |
76 | 40
77 | 20
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/slots.cpp:
--------------------------------------------------------------------------------
1 | #include "dialog.h"
2 | #include "ui_dialog.h"
3 |
4 | void Dialog::anchorClickedSlot(const QUrl& url)
5 | {
6 | //更多报道:840*520
7 | QString moreUrl = "https://new.qq.com/ch/antip/";
8 | //视频直播:1230*520
9 | QString cctvUrl = "http://tv.cctv.com/live/cctv13/";
10 | QString urlStr = url.toString();
11 |
12 | QNetworkConfigurationManager mgr;
13 | if(mgr.isOnline() == true)
14 | {
15 | if(urlStr != moreUrl && urlStr != cctvUrl)
16 | {
17 | qDebug() << urlStr;
18 | // this->setWindowModality(Qt::WindowModal); //不阻塞当前窗口的进程
19 | newsInfo_win.openURL(url);
20 | newsInfo_win.exec();
21 | }
22 | else
23 | QDesktopServices::openUrl(url);
24 | }
25 | else
26 | QMessageBox::warning(NULL, "错误", "无网络连接,请检查网络", QMessageBox::Yes);
27 | }
28 | void Dialog::closeEvent(QCloseEvent *win)
29 | {
30 | int ret = QMessageBox::information(this, "提示", "是否关闭?", "是/Yes", "否/No");
31 | if(ret == 0)
32 | {
33 | win->accept();//不会将事件传递给组件的父组件
34 | qDebug()<<"已关闭";
35 | }
36 | else
37 | win->ignore();
38 | }
39 | //鼠标悬停,显示曲线值
40 | void Dialog::disTip(QMouseEvent *event, QCustomPlot *widget, QVector date)
41 | {
42 | //获取鼠标坐标,相对父窗体坐标
43 | float x_pos = event->pos().x();
44 | // int y_pos = event->pos().y();
45 | //鼠标坐标转化为CustomPlot内部坐标
46 | uint16_t x_val = widget->xAxis->pixelToCoord(x_pos) + 0.5;
47 | // int y_val = ui->widget_1->yAxis->pixelToCoord(y_pos);
48 | QString str, strToolTip;
49 | // int a = x_val + 0.5;
50 | // qDebug() << x_val << a;
51 | if(x_val < date.size())
52 | {
53 | // qDebug() << x_val;
54 | str = date[x_val];
55 | // str = QString::number(x_val, 10, 3);
56 | strToolTip += "日期: ";
57 | strToolTip += str;
58 | strToolTip += "\n";
59 |
60 | uint8_t lineNum = widget->xAxis->graphs().count(); //当前窗口的曲线个数
61 |
62 | for (int i = 0; i < lineNum; i++)
63 | {
64 | QString lineName = widget->graph(i)->name();
65 | //获得x轴坐标位置对应的曲线上y的值
66 | if(clickId < 3)
67 | {
68 | int y = widget->graph(i)->data()->at(x_val)->value;
69 | str = QString::number(y);
70 | }
71 | else
72 | {
73 | double y= widget->graph(i)->data()->at(x_val)->value;
74 | str = QString::number(y, 10, 1);
75 | }
76 | strToolTip += lineName + ":";
77 | strToolTip += str;
78 | if(clickId == 3)
79 | strToolTip += "%";
80 | if(i != lineNum - 1)
81 | strToolTip += "\n";
82 | }
83 | QToolTip::showText(cursor().pos(), strToolTip, widget);
84 | }
85 | }
86 |
87 | void Dialog::widget_chart_event(QMouseEvent *event)
88 | {
89 | if(clickId == 1 | clickId == 2)
90 | {
91 | disTip(event, ui->widget_chart, TotalDate);
92 | }
93 | else if(clickId == 0)
94 | disTip(event, ui->widget_chart, AddDate);
95 | // else if(ui->rb3_rate->isChecked())
96 | else
97 | disTip(event, ui->widget_chart, RateDate);
98 | }
99 |
100 | //点击不同的按钮绘制不同的曲线
101 | void Dialog::drawCharts(int id)
102 | {
103 | // qDebug() << id;
104 | setSelectStyle(id);
105 | clickId = id;
106 | switch(id)
107 | {
108 | case 0:
109 | widgetDrawLine(ui->widget_chart, "新增疑似/确诊趋势", "新增确诊", "新增疑似",
110 | clr1_1, clr1_2, AddDate, AddConfirmDub, AddSuspectDub);
111 | break;
112 | case 1:
113 | widgetDrawLine(ui->widget_chart, "累计疑似/确诊趋势", "累计确诊", "累计疑似",
114 | clr2_1, clr2_2, TotalDate, TotalConfirmDub, TotalSuspectDub);
115 | break;
116 | case 2:
117 | widgetDrawLine(ui->widget_chart, "累计治愈/死亡趋势", "累计治愈", "累计死亡",
118 | clr3_1, clr3_2, TotalDate, TotalHealDub, TotalDeadDub);
119 | break;
120 | case 3:
121 | widgetDrawLine(ui->widget_chart, "治愈率/病死率", "治愈率", "病死率",
122 | clr4_1, clr4_2, RateDate, chinaDayListHealRate, chinaDayListDeadRate);
123 | break;
124 | default:break;
125 | }
126 | }
127 |
128 | void Dialog::setSelectStyle(int id)
129 | {
130 | QString style1 =
131 | "border:3px groove rgb(126, 126, 126);" //边框线条粗线,线型,颜色
132 | "border-radius:8px;" //圆角弧度
133 | "padding:2px 4px;" //文字离边框的距离,H/L
134 | "background-color: rgb(243, 246, 248);" //背景颜色
135 | "color: rgb(0, 0, 0);"; //字体黑色; //未选中
136 |
137 | QString style2 =
138 | "border:3px groove rgb(126, 126, 226);" //边框线条粗线,线型,颜色
139 | "border-radius:8px;" //圆角弧度
140 | "padding:2px 4px;" //文字离边框的距离,H/L
141 | "background-color: rgb(238,244,255);" //背景颜色
142 | "color: rgb(22,107,241);" ; //字体蓝色;
143 |
144 | ui->btn_group->button(id)->setStyleSheet(style2);
145 |
146 | QList btnList = ui->btn_group->buttons();
147 | btnList.removeAt(id); //移除当前,其余设置未选中状态
148 | for(int i = 0; i < btnList.size(); i++)
149 | {
150 | btnList.at(i)->setStyleSheet(style1);
151 | }
152 |
153 | }
154 |
155 |
--------------------------------------------------------------------------------