-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
134 lines (118 loc) · 3.84 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* @file mainwindows.cpp
* @author Myth
* @version 1.0
* @date 2021.10.23
*/
#include "ui_mainwindow.h"
#include "notificationclient.h"
#include "syncdata.h"
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
syncdata = new SyncData(this);
connect(syncdata, SIGNAL(timeUpdated(QString)),
this, SLOT(dispUpdateTime(QString)));
connect(syncdata, SIGNAL(nodeDataUpdated(int, float, float, float)),
this, SLOT(dispNodeData(int, float, float, float)));
connect(syncdata, SIGNAL(nodeDataUpdated(int, float, float, float)),
this, SLOT(sendNodeWarn(int, float, float, float)));
temp_max = 27.0;
connect(this->ui->doubleSpinBox, SIGNAL(valueChanged(double)),
this, SLOT(updateTempMax(double)));
}
/**
* @brief 槽函数:更新高温报警温度
*/
void MainWindow::updateTempMax(double temp_value)
{
temp_max = temp_value;
}
/**
* @brief 槽函数:显示节点数据
*/
void MainWindow::dispNodeData(int seq, float humi, float temp, float light)
{
QString line_str;
if (temp >= temp_max)
{
line_str = "节点<font color=\"#FF00FF\">" +
QString::number(seq) +
"</font> 湿度:<font color=\"#0000FF\">" +
QString::number((double)humi) +
"%</font> 温度:<font color=\"#FF0000\">" +
QString::number((double)temp) +
"°C</font><br> 光照度:<font color=\"#0000FF\">" +
QString::number((double)light) +
"lx</font>";
}
else
{
line_str = "节点<font color=\"#FF00FF\">" +
QString::number(seq) +
"</font> 湿度:<font color=\"#0000FF\">" +
QString::number((double)humi) +
"%</font> 温度:<font color=\"#0000FF\">" +
QString::number((double)temp) +
"°C</font><br> 光照度:<font color=\"#0000FF\">" +
QString::number((double)light) +
"lx</font>";
}
switch (seq)
{
case 2:
ui->textBrowser_node2->setHtml("<b><font size=\"60\">" + line_str + "</font></b>");
break;
case 3:
ui->textBrowser_node3->setHtml("<b><font size=\"60\">" + line_str + "</font></b>");
break;
case 4:
ui->textBrowser_node4->setHtml("<b><font size=\"60\">" + line_str + "</font></b>");
break;
case 5:
ui->textBrowser_node5->setHtml("<b><font size=\"60\">" + line_str + "</font></b>");
}
}
/**
* @brief 槽函数:显示更新时间
*/
void MainWindow::dispUpdateTime(QString time)
{
QString line_str;
line_str = "更新时间:" + time;
ui->label_time->setText(line_str);
}
/**
* @brief 槽函数:发送系统通知
*/
void MainWindow::sendNodeWarn(int seq, float humi, float temp, float light)
{
static bool is_first_run = true;
static QString last_warn_str;
if (is_first_run)
{
NotificationClient().setNotification("成功获取数据!");
is_first_run = false;
}
if (temp >= temp_max)
{
QString warn_str = "节点" +
QString::number(seq) +
"温度过高:" +
QString::number((double)temp) +
"°C";
if (QString::compare(warn_str, last_warn_str) != 0)
{
NotificationClient().setNotification(warn_str);
last_warn_str.clear();
last_warn_str.append(warn_str);
}
}
}
MainWindow::~MainWindow()
{
delete ui;
delete syncdata;
}