From 6c9328d7839fa44f854c3f896c94dbbf8e8f24fa Mon Sep 17 00:00:00 2001 From: jackfiled Date: Sun, 26 Jun 2022 19:44:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E4=BA=86=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=88=97=E8=A1=A8=E4=B8=AD=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/queryListItem.h | 4 ++++ src/centralwidget.cpp | 30 ++++++++++++++++++++++-------- src/header/centralwidget.h | 4 ++-- src/queryListItem.cpp | 3 +++ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/include/queryListItem.h b/include/queryListItem.h index 7ecf6b7..267be28 100644 --- a/include/queryListItem.h +++ b/include/queryListItem.h @@ -19,6 +19,10 @@ public: void SetColumnName(); + int query_type; + + int target_node_id; + private: /** * 请求的类型 diff --git a/src/centralwidget.cpp b/src/centralwidget.cpp index a95467e..71d1807 100644 --- a/src/centralwidget.cpp +++ b/src/centralwidget.cpp @@ -39,6 +39,9 @@ void CentralWidget::SetControlConnection() // 处理添加请求事件 QObject::connect(this, &CentralWidget::AppendQuerySignal, controller, &BusControllerModel::AddQuerySlot); + + QObject::connect(controller, &BusControllerModel::DeleteQuerySignal, + this, &CentralWidget::DeleteQueryItemSlot); } void CentralWidget::SetWidgetConnection() @@ -87,21 +90,32 @@ void CentralWidget::AppendQueryItemSlot(int query_type, int node_id) ui->query_list->setItemWidget(widget_item, item); } -void CentralWidget::DeleteQueryItemSlot(int query_id) +void CentralWidget::DeleteQueryItemSlot(bus_query_t *query) { - // 由于表头的存在,且请求的编号从1开始,请求的编号恰好就是请求在列表中的位置 - QListWidgetItem *deleted_widget = ui->query_list->takeItem(query_id); + // 由于请求列表头的存在,编号从1开始 + int query_id = 1; - auto itor = query_items.begin(); + for(auto itor = query_items.begin(); itor != query_items.end(); ++itor) + { + if((*itor)->query_type == query->type and (*itor)->target_node_id == query->node->id) + { + break; + } + query_id++; + } + + QListWidgetItem *deleted_item = ui->query_list->takeItem(query_id); + + auto pos = query_items.begin(); for(int i = 0; i < query_id; i++) { - ++itor; + ++pos; } - delete deleted_widget; - delete *itor; - query_items.erase(itor); + delete deleted_item; + query_items.erase(pos); + delete *pos; } void CentralWidget::AddQueryButtonClicked() diff --git a/src/header/centralwidget.h b/src/header/centralwidget.h index 842127f..67eb989 100644 --- a/src/header/centralwidget.h +++ b/src/header/centralwidget.h @@ -47,9 +47,9 @@ public slots: /** * 处理删除一个请求的槽函数 - * @param query_id 请求的编号 + * @param query 请求的编号 */ - void DeleteQueryItemSlot(int query_id); + void DeleteQueryItemSlot(bus_query_t *query); /** * 处理点击添加请求按钮的槽函数 diff --git a/src/queryListItem.cpp b/src/queryListItem.cpp index f8a9921..07c3ef5 100644 --- a/src/queryListItem.cpp +++ b/src/queryListItem.cpp @@ -6,6 +6,9 @@ QueryListItem::QueryListItem(const int &type, const int &node_id) : QWidget() { + query_type = type; + target_node_id = node_id; + QFont font("Microsoft YaHei", 10, 75); layout = new QHBoxLayout(this);