优化了部分代码
This commit is contained in:
parent
ef07325a82
commit
c4015a4589
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 12.0.2, 2024-03-05T11:27:57. -->
|
||||
<!-- Written by QtCreator 12.0.2, 2024-03-05T18:00:21. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
|
|
@ -102,6 +102,15 @@ void DataManager::find_code()
|
|||
qDebug() << "发送更新code请求" << data;
|
||||
}
|
||||
|
||||
void DataManager::update_count()
|
||||
{
|
||||
QByteArray data, data_encrypt;
|
||||
data = protocol->data_maker(Protocol::MESSAGE, QString("count"), "unused");
|
||||
data_encrypt = protocol->data_encrypt(data);
|
||||
tcpclient->sendToserver(data_encrypt);
|
||||
qDebug() << "发送获取人数请求" << data;
|
||||
}
|
||||
|
||||
void DataManager::recv_from_server(QByteArray data)
|
||||
{
|
||||
QByteArray data_decrypt;
|
||||
|
@ -112,8 +121,14 @@ void DataManager::recv_from_server(QByteArray data)
|
|||
QJsonDocument json_data = QJsonDocument::fromJson(list[i]);
|
||||
if (json_data["type"] == "message")
|
||||
{
|
||||
emit new_message();
|
||||
//暂时没用
|
||||
QString data, action;
|
||||
action = json_data["action"].toString();
|
||||
if(action == "count")
|
||||
{
|
||||
data = json_data["data"].toString();
|
||||
emit handle_count(data);
|
||||
}
|
||||
|
||||
}
|
||||
if(json_data["type"] == "code")
|
||||
{
|
||||
|
@ -134,6 +149,7 @@ void DataManager::recv_from_server(QByteArray data)
|
|||
data = json_data["data"].toString();
|
||||
emit update_code(data);
|
||||
|
||||
|
||||
}
|
||||
else if(action == "update")
|
||||
{
|
||||
|
|
|
@ -36,6 +36,7 @@ signals:
|
|||
void update_file(QString sendname,QString filename,QString file_data);
|
||||
void update_file_private(QString sendname,QString filename,QString file_data);
|
||||
void update_users(int count,QList<QString>online_users);
|
||||
void handle_count(QString count);
|
||||
|
||||
|
||||
public slots:
|
||||
|
@ -53,6 +54,7 @@ public slots:
|
|||
void pick_up(QString code);
|
||||
void parking();
|
||||
void find_code();
|
||||
void update_count();
|
||||
|
||||
/******TCPClient******/
|
||||
void TCPClientConnected();
|
||||
|
|
|
@ -15,6 +15,7 @@ Login::Login(QWidget *parent) :
|
|||
|
||||
/********datamanager********/
|
||||
datamanager = DataManager::getInstance();
|
||||
|
||||
connect(datamanager,&DataManager::signin_response,this,&Login::signin_response);
|
||||
connect(datamanager,&DataManager::signup_response,this,&Login::signup_response);
|
||||
connect(datamanager,&DataManager::connect_to_server,this,&Login::connected);
|
||||
|
@ -22,7 +23,6 @@ Login::Login(QWidget *parent) :
|
|||
connect(this,&Login::signin_request,datamanager,&DataManager::signin_request);
|
||||
connect(this,&Login::Register,datamanager,&DataManager::Register);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Login::~Login()
|
||||
|
@ -85,9 +85,12 @@ void Login::signin_response(bool result)
|
|||
connect(mainwidget,&Widget::exit_client,this,&Login::exit_client);
|
||||
connect(datamanager,&DataManager::update_code,mainwidget,&Widget::update_code);
|
||||
connect(datamanager,&DataManager::update_line,mainwidget,&Widget::update_line);
|
||||
connect(datamanager,&DataManager::handle_count,mainwidget,&Widget::handle_count);
|
||||
|
||||
connect(mainwidget, &Widget::parking, datamanager, &DataManager::parking);
|
||||
connect(mainwidget, &Widget::pick_up, datamanager, &DataManager::pick_up);
|
||||
connect(mainwidget, &Widget::find_code, datamanager, &DataManager::find_code);
|
||||
connect(mainwidget, &Widget::update_count, datamanager, &DataManager::update_count);
|
||||
|
||||
this->hide();
|
||||
mainwidget->show();
|
||||
|
@ -145,7 +148,6 @@ void Login::exit_client()
|
|||
this->close();
|
||||
}
|
||||
|
||||
|
||||
/*****************************Others******************************/
|
||||
void Login::zoom_down(QPushButton* btn)
|
||||
{
|
||||
|
|
1
login.h
1
login.h
|
@ -47,6 +47,7 @@ private slots:
|
|||
void disconnected();
|
||||
void exit_client();
|
||||
|
||||
|
||||
private:
|
||||
Ui::Login *ui;
|
||||
QPoint point;
|
||||
|
|
24
login.ui
24
login.ui
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>438</width>
|
||||
<height>609</height>
|
||||
<width>399</width>
|
||||
<height>682</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -16,8 +16,8 @@
|
|||
<widget class="QPushButton" name="btn_signup">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>250</x>
|
||||
<y>370</y>
|
||||
<x>230</x>
|
||||
<y>360</y>
|
||||
<width>79</width>
|
||||
<height>40</height>
|
||||
</rect>
|
||||
|
@ -49,8 +49,8 @@ QPushButton:pressed
|
|||
<widget class="QLineEdit" name="lineEdit_username">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>70</x>
|
||||
<y>230</y>
|
||||
<x>50</x>
|
||||
<y>220</y>
|
||||
<width>289</width>
|
||||
<height>45</height>
|
||||
</rect>
|
||||
|
@ -74,8 +74,8 @@ font: 12pt "Candara";</string>
|
|||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>120</x>
|
||||
<y>160</y>
|
||||
<x>100</x>
|
||||
<y>150</y>
|
||||
<width>191</width>
|
||||
<height>51</height>
|
||||
</rect>
|
||||
|
@ -91,8 +91,8 @@ background:transparent;</string>
|
|||
<widget class="QPushButton" name="btn_signin">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>100</x>
|
||||
<y>370</y>
|
||||
<x>80</x>
|
||||
<y>360</y>
|
||||
<width>71</width>
|
||||
<height>40</height>
|
||||
</rect>
|
||||
|
@ -124,8 +124,8 @@ QPushButton:pressed
|
|||
<widget class="QLineEdit" name="lineEdit_password">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>70</x>
|
||||
<y>290</y>
|
||||
<x>50</x>
|
||||
<y>280</y>
|
||||
<width>289</width>
|
||||
<height>45</height>
|
||||
</rect>
|
||||
|
|
|
@ -27,7 +27,7 @@ QByteArray Protocol::data_builder(QList<any_types> &args)
|
|||
case MESSAGE:
|
||||
{
|
||||
data.insert("type","message");
|
||||
data.insert("sendname",args[1].get_string());
|
||||
data.insert("action",args[1].get_string());
|
||||
data.insert("data",args[2].get_string());
|
||||
break;
|
||||
}
|
||||
|
|
14
signup.ui
14
signup.ui
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>438</width>
|
||||
<height>609</height>
|
||||
<width>399</width>
|
||||
<height>682</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -16,7 +16,7 @@
|
|||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<x>50</x>
|
||||
<y>90</y>
|
||||
<width>161</width>
|
||||
<height>31</height>
|
||||
|
@ -32,10 +32,10 @@
|
|||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<x>50</x>
|
||||
<y>190</y>
|
||||
<width>271</width>
|
||||
<height>344</height>
|
||||
<width>301</width>
|
||||
<height>391</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
|
@ -179,7 +179,7 @@ font: 26 10pt "Bahnschrift Light";</string>
|
|||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<x>50</x>
|
||||
<y>120</y>
|
||||
<width>301</width>
|
||||
<height>51</height>
|
||||
|
|
52
widget.cpp
52
widget.cpp
|
@ -8,7 +8,7 @@ Widget::Widget(QWidget *parent)
|
|||
{
|
||||
ui->setupUi(this);
|
||||
ui->log->setEnabled(false);
|
||||
ui->pushButton_3->setEnabled(false);
|
||||
|
||||
|
||||
//连接mqtt服务器,端口1883
|
||||
mqtt_client = new QMqttClient(this);
|
||||
|
@ -52,6 +52,10 @@ void Widget::on_pushButton_3_clicked()
|
|||
//点击取车按钮
|
||||
void Widget::on_pushButton_4_clicked()
|
||||
{
|
||||
if(ui->code->toPlainText().isEmpty())
|
||||
{
|
||||
QMessageBox::information(this,"取车错误","请先放置正确的取车码!");
|
||||
}
|
||||
emit pick_up(ui->code->toPlainText());
|
||||
ui->code->clear();
|
||||
ui->pushButton_3->setEnabled(true);
|
||||
|
@ -142,13 +146,27 @@ void Widget::update_line(QString data)
|
|||
{
|
||||
//向mqtt服务器发送路径消息
|
||||
qDebug() << "向mqtt服务器发送的路径消息" << data;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Widget::update_code(QString code)
|
||||
{
|
||||
if(code == "000")
|
||||
{
|
||||
ui->pushButton_3->setEnabled(true);
|
||||
QMessageBox::information(this,"消息","当前用户并无存车信息");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -157,8 +175,38 @@ void Widget::update_code(QString code)
|
|||
}
|
||||
}
|
||||
|
||||
void Widget::handle_count(QString count)
|
||||
{
|
||||
QString data = QString("当前剩余空位'%1'").arg(count);
|
||||
ui->label_4->setText(data);
|
||||
if(count.toInt() == 0)
|
||||
{
|
||||
ui->pushButton_3->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->pushButton_3->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::on_pushButton_5_clicked()
|
||||
{
|
||||
emit find_code();
|
||||
if(!ui->code->document()->isEmpty())
|
||||
{
|
||||
QMessageBox::information(this,"消息","已显示当前车位信息!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_pushButton_6_clicked()
|
||||
{
|
||||
emit update_count();
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_pushButton_7_clicked()
|
||||
{
|
||||
ui->stackedWidget->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
|
|
7
widget.h
7
widget.h
|
@ -33,6 +33,7 @@ signals:
|
|||
void parking();
|
||||
void pick_up(QString code);
|
||||
void find_code();
|
||||
void update_count();
|
||||
|
||||
public slots:
|
||||
void on_pushButton_3_clicked();
|
||||
|
@ -45,9 +46,15 @@ public slots:
|
|||
|
||||
void update_code(QString code);
|
||||
|
||||
void handle_count(QString count);
|
||||
|
||||
private slots:
|
||||
void on_pushButton_5_clicked();
|
||||
|
||||
void on_pushButton_6_clicked();
|
||||
|
||||
void on_pushButton_7_clicked();
|
||||
|
||||
private:
|
||||
Ui::Widget *ui;
|
||||
QMqttClient *mqtt_client;
|
||||
|
|
238
widget.ui
238
widget.ui
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>489</width>
|
||||
<height>718</height>
|
||||
<width>399</width>
|
||||
<height>682</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -18,8 +18,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>501</width>
|
||||
<height>661</height>
|
||||
<width>399</width>
|
||||
<height>682</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QWidget" name="page">
|
||||
|
@ -27,8 +27,8 @@
|
|||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
<y>50</y>
|
||||
<width>251</width>
|
||||
<y>40</y>
|
||||
<width>371</width>
|
||||
<height>71</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -41,80 +41,147 @@
|
|||
<string>欢迎来到停车场</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>150</y>
|
||||
<width>171</width>
|
||||
<height>71</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>放置取车码</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>390</y>
|
||||
<width>93</width>
|
||||
<height>28</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>存车</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_4">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>280</x>
|
||||
<y>390</y>
|
||||
<width>93</width>
|
||||
<height>28</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>取车</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="code">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>266</y>
|
||||
<width>281</width>
|
||||
<height>51</height>
|
||||
<x>40</x>
|
||||
<y>360</y>
|
||||
<width>321</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
hr { height: 1px; border-width: 0; }
|
||||
li.unchecked::marker { content: "\2610"; }
|
||||
li.checked::marker { content: "\2612"; }
|
||||
</style></head><body style=" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<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:15pt;"><br /></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_5">
|
||||
<widget class="QWidget" name="horizontalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>170</y>
|
||||
<width>93</width>
|
||||
<height>28</height>
|
||||
<x>40</x>
|
||||
<y>130</y>
|
||||
<width>321</width>
|
||||
<height>111</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>查看取车码</string>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>当前车位数量</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_6">
|
||||
<property name="text">
|
||||
<string>获取车位数量</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="horizontalLayoutWidget_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
<y>240</y>
|
||||
<width>321</width>
|
||||
<height>101</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>放置取车码</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_5">
|
||||
<property name="text">
|
||||
<string>查看取车码</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="horizontalLayoutWidget_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
<y>400</y>
|
||||
<width>321</width>
|
||||
<height>80</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_4">
|
||||
<property name="text">
|
||||
<string>取车</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<property name="text">
|
||||
<string>存车</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="horizontalLayoutWidget_4">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
<y>490</y>
|
||||
<width>321</width>
|
||||
<height>91</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
<string>用户</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>主页</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_2">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>60</y>
|
||||
<x>40</x>
|
||||
<y>70</y>
|
||||
<width>241</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
|
@ -131,41 +198,28 @@
|
|||
<widget class="QTextBrowser" name="log">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<x>50</x>
|
||||
<y>140</y>
|
||||
<width>341</width>
|
||||
<height>381</height>
|
||||
<width>301</width>
|
||||
<height>431</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_7">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>70</x>
|
||||
<y>590</y>
|
||||
<width>251</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>返回</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>70</x>
|
||||
<y>660</y>
|
||||
<width>93</width>
|
||||
<height>28</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>主页</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>310</x>
|
||||
<y>660</y>
|
||||
<width>93</width>
|
||||
<height>28</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>用户</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
Loading…
Reference in New Issue