From 8d5445398143757af4475ebf6e07c1bcc6031fbb Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 23 Mar 2021 23:23:37 +0100 Subject: [PATCH] Qt: Fix debugger breakpoint deletion --- rpcs3/rpcs3qt/breakpoint_list.cpp | 31 +++++++++++++++++++------------ rpcs3/rpcs3qt/breakpoint_list.h | 3 ++- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/rpcs3/rpcs3qt/breakpoint_list.cpp b/rpcs3/rpcs3qt/breakpoint_list.cpp index e9999dceab..ca6818d2cb 100644 --- a/rpcs3/rpcs3qt/breakpoint_list.cpp +++ b/rpcs3/rpcs3qt/breakpoint_list.cpp @@ -15,9 +15,14 @@ breakpoint_list::breakpoint_list(QWidget* parent, breakpoint_handler* handler) : setContextMenuPolicy(Qt::CustomContextMenu); setSelectionMode(QAbstractItemView::ExtendedSelection); - // connects connect(this, &QListWidget::itemDoubleClicked, this, &breakpoint_list::OnBreakpointListDoubleClicked); connect(this, &QListWidget::customContextMenuRequested, this, &breakpoint_list::OnBreakpointListRightClicked); + + m_delete_action = new QAction(tr("&Delete"), this); + m_delete_action->setShortcut(Qt::Key_Delete); + m_delete_action->setShortcutContext(Qt::WidgetShortcut); + connect(m_delete_action, &QAction::triggered, this, &breakpoint_list::OnBreakpointListDelete); + addAction(m_delete_action); } /** @@ -110,33 +115,35 @@ void breakpoint_list::OnBreakpointListRightClicked(const QPoint &pos) return; } - QMenu* menu = new QMenu(); + m_context_menu = new QMenu(); if (selectedItems().count() == 1) { - QAction* rename_action = menu->addAction(tr("&Rename")); + QAction* rename_action = m_context_menu->addAction(tr("&Rename")); connect(rename_action, &QAction::triggered, this, [this]() { QListWidgetItem* current_item = selectedItems().first(); current_item->setFlags(current_item->flags() | Qt::ItemIsEditable); editItem(current_item); }); - menu->addSeparator(); + m_context_menu->addSeparator(); } - QAction* delete_action = new QAction(tr("&Delete"), this); - delete_action->setShortcut(Qt::Key_Delete); - delete_action->setShortcutContext(Qt::WidgetShortcut); - connect(delete_action, &QAction::triggered, this, &breakpoint_list::OnBreakpointListDelete); - menu->addAction(delete_action); - - menu->exec(viewport()->mapToGlobal(pos)); + m_context_menu->addAction(m_delete_action); + m_context_menu->exec(viewport()->mapToGlobal(pos)); + m_context_menu->deleteLater(); + m_context_menu = nullptr; } void breakpoint_list::OnBreakpointListDelete() { for (int i = selectedItems().count() - 1; i >= 0; i--) { - RemoveBreakpoint(item(i)->data(Qt::UserRole).value()); + RemoveBreakpoint(selectedItems().at(i)->data(Qt::UserRole).value()); + } + + if (m_context_menu) + { + m_context_menu->close(); } } diff --git a/rpcs3/rpcs3qt/breakpoint_list.h b/rpcs3/rpcs3qt/breakpoint_list.h index 764967f0f3..fc3c6f498c 100644 --- a/rpcs3/rpcs3qt/breakpoint_list.h +++ b/rpcs3/rpcs3qt/breakpoint_list.h @@ -32,7 +32,8 @@ private Q_SLOTS: void OnBreakpointListDelete(); private: breakpoint_handler* m_breakpoint_handler; - + QMenu* m_context_menu = nullptr; + QAction* m_delete_action; cpu_thread* m_cpu; CPUDisAsm* m_disasm; };