代码拉取完成,页面将自动刷新
#include "healthy.h"
#include "ui_healthy.h"
#include "myapp.h"
#include "mydata.h"
#include "widget.h"
healthy::healthy(QWidget *parent) :
QWidget(parent),
ui(new Ui::healthy)
{
ui->setupUi(this);
QPalette palette;
palette.setBrush(QPalette::Background, QBrush(QPixmap(":/Rescoure_File/13.jpg").scaled(this->size())));
this->setPalette(palette);
this->ui->pushButton->setStyleSheet("border-image:url(:/Rescoure_File/25.png); ");
QLabel *background = new QLabel(this);
background->setPixmap(QPixmap(":/Rescoure_File/Main_BK.png"));
background->setGeometry(0, 0, this->width(), this->height());
background->lower();
background->show();
setupSleepList();
setupHeartOxyList();
}
healthy::~healthy()
{
delete ui;
}
void healthy::on_pushButton_clicked()
{
this->close();
myapp::getapp()->widget->show();
}
void healthy::onSignalReceived()
{
qDebug() << "接受到了信号";
this->ui->HeartOxy_list->clear();
this->ui->Sleep_List->clear();
setupSleepList();
setupHeartOxyList();
}
void healthy::setupSleepList()
{
// Title setup
QListWidgetItem *item_sevenDays_title = new QListWidgetItem("入 睡--起 床 打 鼾 次 数 翻 身 次 数 睡 眠 时 长");
font_sleep = item_sevenDays_title->font();
font_sleep.setPointSize(12);
item_sevenDays_title->setFont(font_sleep);
item_sevenDays_title->setIcon(QIcon(":/Rescoure_File/sleep_icon.png"));
ui->Sleep_List->addItem(item_sevenDays_title);
// Fetch and display sleep data
QString query = "SELECT get_sleep_time, wakeup_time, snore_time, filp_time, sleep_time_length "
"FROM user_sleep_info ORDER BY get_sleep_time DESC LIMIT 7";
displaySleepData(query);
}
void healthy::setupHeartOxyList()
{
// Title setup
QListWidgetItem *item_HeartOxy_title = new QListWidgetItem(" 测量时间 心率值 血氧值");
QFont font_Oxy = item_HeartOxy_title->font();
font_Oxy.setPointSize(12);
item_HeartOxy_title->setFont(font_Oxy);
item_HeartOxy_title->setIcon(QIcon(":/Rescoure_File/heart_icon.png"));
ui->HeartOxy_list->addItem(item_HeartOxy_title);
// Fetch and display heart rate and blood oxygen data
QString query = "SELECT current_timetemp, Heart_rate, blood_oxygen "
"FROM User_HeartRate_Info "
"ORDER BY current_time DESC LIMIT 10";
displayHeartOxyData(query);
}
void healthy::displaySleepData(const QString &query)
{
MyDate* data = MyDate::getdata();
char** qres_sleep_info = nullptr;
int row_sleep_info = 0;
int col_sleep_info = 0;
data->getData_exec(query.toStdString().c_str(), qres_sleep_info, row_sleep_info, col_sleep_info);
if (row_sleep_info == 0) {
qDebug() << "表中无数据!";
} else {
for (int i = 1; i <= row_sleep_info; ++i) {
QString str_time = QString(qres_sleep_info[i * col_sleep_info + 0]) + "--" + QString(qres_sleep_info[i * col_sleep_info + 1]);
str_time = str_time.left(18);
QString str_snore_time = QString(qres_sleep_info[i * col_sleep_info + 2]);
QString str_filp_time = QString(qres_sleep_info[i * col_sleep_info + 3]);
QString str_time_length = QString(qres_sleep_info[i * col_sleep_info + 4]);
QListWidgetItem *item_sleep_info = new QListWidgetItem(str_time + " " + str_snore_time + " " + str_filp_time + " " + str_time_length);
item_sleep_info->setIcon(QIcon(":/Rescoure_File/sleep_icon.png"));
item_sleep_info->setFont(font_sleep);
ui->Sleep_List->addItem(item_sleep_info);
}
}
sqlite3_free_table(qres_sleep_info);
}
void healthy::displayHeartOxyData(const QString &query)
{
MyDate* data = MyDate::getdata();
char** qres_heartOxy_info = nullptr;
int row_heartOxy_info = 0;
int col_heartOxy_info = 0;
data->getData_exec(query.toStdString().c_str(), qres_heartOxy_info, row_heartOxy_info, col_heartOxy_info);
if (row_heartOxy_info == 0) {
qDebug() << "表中无数据!";
} else {
for (int i = 1; i <= row_heartOxy_info; ++i) {
QString time_in_bloodoxygon = QString(qres_heartOxy_info[i * col_heartOxy_info + 0]);
QString heartRate =QString(qres_heartOxy_info[i * col_heartOxy_info + 1]);
QString bloodOxygen =QString(qres_heartOxy_info[i * col_heartOxy_info + 2]);
QListWidgetItem *item_HeartOxy_info = new QListWidgetItem(time_in_bloodoxygon + " " + heartRate + " " + bloodOxygen);
item_HeartOxy_info->setIcon(QIcon(":/Rescoure_File/heart_icon.png"));
item_HeartOxy_info->setFont(font_Oxy);
ui->HeartOxy_list->addItem(item_HeartOxy_info);
}
}
sqlite3_free_table(qres_heartOxy_info);
}
void healthy::readData()
{
QByteArray data = this->client->readAll();
// Read data and process it
}
void healthy::on_server_clicked()
{
this->server = new QTcpServer(this);
this->server->listen(QHostAddress("192.168.110.161"), 9999);
connect(this->server, &QTcpServer::newConnection, this, [=]()
{
this->client = this->server->nextPendingConnection();
connect(this->client, &QTcpSocket::readyRead, this, &healthy::readData);
});
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。