From 04d6ab09ee7a3f38cf735afc0378049d247ef09e Mon Sep 17 00:00:00 2001 From: jackfiled Date: Sun, 26 Jun 2022 17:21:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AF=B7=E6=B1=82=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=8A=A8=E4=BD=9C=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/queryListItem.h | 2 ++ src/centralwidget.cpp | 23 +++++++++++++++++++++-- src/form/mainwindow.ui | 2 +- src/header/centralwidget.h | 11 +++++++++-- src/header/mainwindow.h | 1 + src/mainwindow.cpp | 4 ++-- src/queryListItem.cpp | 15 ++++++++++++++- 7 files changed, 50 insertions(+), 8 deletions(-) diff --git a/include/queryListItem.h b/include/queryListItem.h index 3fea9ad..7ecf6b7 100644 --- a/include/queryListItem.h +++ b/include/queryListItem.h @@ -9,6 +9,8 @@ #include "QLabel" #include "QHBoxLayout" +#include "define.h" + class QueryListItem : public QWidget { Q_OBJECT diff --git a/src/centralwidget.cpp b/src/centralwidget.cpp index 3c35b9c..a95467e 100644 --- a/src/centralwidget.cpp +++ b/src/centralwidget.cpp @@ -35,12 +35,21 @@ void CentralWidget::SetControlConnection() // 处理轨道重新设置事件 QObject::connect(controller, &BusControllerModel::RailsCreated, this, &CentralWidget::SetRailsScene); + + // 处理添加请求事件 + QObject::connect(this, &CentralWidget::AppendQuerySignal, + controller, &BusControllerModel::AddQuerySlot); } void CentralWidget::SetWidgetConnection() { + // 处理点击创建请求按钮事件 QObject::connect(ui->create_query_button, &QPushButton::clicked, this, &CentralWidget::AddQueryButtonClicked); + + // 处理添加请求事件 + QObject::connect(this, &CentralWidget::AppendQuerySignal, + this, &CentralWidget::AppendQueryItemSlot); } void CentralWidget::SetupQueryList() @@ -66,7 +75,7 @@ void CentralWidget::DeleteQueryList() query_items.clear(); } -void CentralWidget::AppendQueryItem(int query_type, int node_id) +void CentralWidget::AppendQueryItemSlot(int query_type, int node_id) { QueryListItem *item = new QueryListItem(query_type, node_id); @@ -78,7 +87,7 @@ void CentralWidget::AppendQueryItem(int query_type, int node_id) ui->query_list->setItemWidget(widget_item, item); } -void CentralWidget::DeleteQueryItem(int query_id) +void CentralWidget::DeleteQueryItemSlot(int query_id) { // 由于表头的存在,且请求的编号从1开始,请求的编号恰好就是请求在列表中的位置 QListWidgetItem *deleted_widget = ui->query_list->takeItem(query_id); @@ -97,7 +106,17 @@ void CentralWidget::DeleteQueryItem(int query_id) void CentralWidget::AddQueryButtonClicked() { + int query_type = ui->query_type_combo->currentIndex(); + int node_id = ui->query_node_combo->currentIndex() + 1; + if(node_id == 0) + { + //此时还没有读取配置文件 + QMessageBox::warning(this, "警告", "请先读取配置文件"); + return; + } + + emit AppendQuerySignal(query_type, node_id); } void CentralWidget::SetRailsScene(int node_num) diff --git a/src/form/mainwindow.ui b/src/form/mainwindow.ui index 27bd9a3..fc8dd00 100644 --- a/src/form/mainwindow.ui +++ b/src/form/mainwindow.ui @@ -23,7 +23,7 @@ - MainWindow + Auto Bus(GUI) diff --git a/src/header/centralwidget.h b/src/header/centralwidget.h index 8ad11b6..842127f 100644 --- a/src/header/centralwidget.h +++ b/src/header/centralwidget.h @@ -9,6 +9,7 @@ #include "QListWidgetItem" #include "string" #include "list" +#include "QMessageBox" #include "mainScene.h" #include "queryListItem.h" @@ -30,19 +31,25 @@ public: ~CentralWidget() override; +signals: + /** + * 添加一个请求的信号 + */ + void AppendQuerySignal(int type, int node); + public slots: /** * 处理添加一个请求的槽函数 * @param query_type 请求的类型 * @param node_id 请求指向的站点id */ - void AppendQueryItem(int query_type, int node_id); + void AppendQueryItemSlot(int query_type, int node_id); /** * 处理删除一个请求的槽函数 * @param query_id 请求的编号 */ - void DeleteQueryItem(int query_id); + void DeleteQueryItemSlot(int query_id); /** * 处理点击添加请求按钮的槽函数 diff --git a/src/header/mainwindow.h b/src/header/mainwindow.h index effdb75..2836274 100644 --- a/src/header/mainwindow.h +++ b/src/header/mainwindow.h @@ -8,6 +8,7 @@ #include #include "QFileDialog" #include "QThread" +#include "QMessageBox" #include "centralwidget.h" #include "busModel.h" diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7c1c1f9..4fc5bbd 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -72,11 +72,11 @@ void MainWindow::ReadConfigFileButtonClicked() if(file_name.isEmpty()) { - qDebug() << "文件名为空"; + QMessageBox::warning(this, "警告", "文件名错误"); + return; } else { - qDebug() << file_name; emit OpenConfigFileSignal(file_name); } } diff --git a/src/queryListItem.cpp b/src/queryListItem.cpp index b6885ac..f8a9921 100644 --- a/src/queryListItem.cpp +++ b/src/queryListItem.cpp @@ -16,7 +16,20 @@ QueryListItem::QueryListItem(const int &type, const int &node_id) : QWidget() this->setFixedHeight(20); // 设置文本 - type_text.setText(QString::number(type)); + switch (type) + { + case BUS_CLOCK_WISE: + type_text.setText(QString("顺时针上车")); + break; + case BUS_COUNTER_CLOCK_WISE: + type_text.setText(QString("逆时针上车")); + break; + case BUS_TARGET: + type_text.setText(QString("下车")); + break; + default: + break; + } target_pos_text.setText(QString::number(node_id)); type_text.setFont(font); target_pos_text.setFont(font);