From 8c23335be340428c0ab92a1e564d28b14e6b72ba Mon Sep 17 00:00:00 2001 From: aldelaro5 Date: Fri, 4 May 2018 23:38:13 -0400 Subject: [PATCH] Qt/RegisterView: fix the context menu not working correctly It seemed impossible to SELECT an item, however, when right clicking, the CURRENT item is set to the appropriate cell, this commit makes the view use thta cell instead of the first selected one. --- .../DolphinQt2/Debugger/RegisterWidget.cpp | 193 +++++++++--------- 1 file changed, 95 insertions(+), 98 deletions(-) diff --git a/Source/Core/DolphinQt2/Debugger/RegisterWidget.cpp b/Source/Core/DolphinQt2/Debugger/RegisterWidget.cpp index 57d0487c07..c028e9626c 100644 --- a/Source/Core/DolphinQt2/Debugger/RegisterWidget.cpp +++ b/Source/Core/DolphinQt2/Debugger/RegisterWidget.cpp @@ -108,108 +108,105 @@ void RegisterWidget::ShowContextMenu() { QMenu* menu = new QMenu(this); - if (m_table->selectedItems().size()) + auto variant = m_table->currentItem()->data(DATA_TYPE); + + if (!variant.isNull()) { - auto variant = m_table->selectedItems()[0]->data(DATA_TYPE); + auto* item = static_cast(m_table->currentItem()); + auto type = static_cast(item->data(DATA_TYPE).toInt()); + auto display = item->GetDisplay(); - if (!variant.isNull()) + AddAction(menu, tr("Add to &watch"), this, + [this, item] { emit RequestMemoryBreakpoint(item->GetValue()); }); + menu->addAction(tr("View &memory")); + menu->addAction(tr("View &code")); + + menu->addSeparator(); + + QActionGroup* group = new QActionGroup(menu); + group->setExclusive(true); + + auto* view_hex = menu->addAction(tr("Hexadecimal")); + auto* view_int = menu->addAction(tr("Signed Integer")); + auto* view_uint = menu->addAction(tr("Unsigned Integer")); + // i18n: A floating point number + auto* view_float = menu->addAction(tr("Float")); + // i18n: A double precision floating point number + auto* view_double = menu->addAction(tr("Double")); + + for (auto* action : {view_hex, view_int, view_uint, view_float, view_double}) { - auto* item = reinterpret_cast(m_table->selectedItems()[0]); - auto type = static_cast(item->data(DATA_TYPE).toInt()); - auto display = item->GetDisplay(); - - AddAction(menu, tr("Add to &watch"), this, - [this, item] { emit RequestMemoryBreakpoint(item->GetValue()); }); - menu->addAction(tr("View &memory")); - menu->addAction(tr("View &code")); - - menu->addSeparator(); - - QActionGroup* group = new QActionGroup(menu); - group->setExclusive(true); - - auto* view_hex = menu->addAction(tr("Hexadecimal")); - auto* view_int = menu->addAction(tr("Signed Integer")); - auto* view_uint = menu->addAction(tr("Unsigned Integer")); - // i18n: A floating point number - auto* view_float = menu->addAction(tr("Float")); - // i18n: A double precision floating point number - auto* view_double = menu->addAction(tr("Double")); - - for (auto* action : {view_hex, view_int, view_uint, view_float, view_double}) - { - action->setCheckable(true); - action->setVisible(false); - action->setActionGroup(group); - } - - switch (display) - { - case RegisterDisplay::Hex: - view_hex->setChecked(true); - break; - case RegisterDisplay::SInt32: - view_int->setChecked(true); - break; - case RegisterDisplay::UInt32: - view_uint->setChecked(true); - break; - case RegisterDisplay::Float: - view_float->setChecked(true); - break; - case RegisterDisplay::Double: - view_double->setChecked(true); - break; - } - - switch (type) - { - case RegisterType::gpr: - view_hex->setVisible(true); - view_int->setVisible(true); - view_uint->setVisible(true); - view_float->setVisible(true); - break; - case RegisterType::fpr: - view_hex->setVisible(true); - view_double->setVisible(true); - break; - default: - break; - } - - connect(view_hex, &QAction::triggered, [this, item] { - m_updating = true; - item->SetDisplay(RegisterDisplay::Hex); - m_updating = false; - }); - - connect(view_int, &QAction::triggered, [this, item] { - m_updating = true; - item->SetDisplay(RegisterDisplay::SInt32); - m_updating = false; - }); - - connect(view_uint, &QAction::triggered, [this, item] { - m_updating = true; - item->SetDisplay(RegisterDisplay::UInt32); - m_updating = false; - }); - - connect(view_float, &QAction::triggered, [this, item] { - m_updating = true; - item->SetDisplay(RegisterDisplay::Float); - m_updating = false; - }); - - connect(view_double, &QAction::triggered, [this, item] { - m_updating = true; - item->SetDisplay(RegisterDisplay::Double); - m_updating = false; - }); - - menu->addSeparator(); + action->setCheckable(true); + action->setVisible(false); + action->setActionGroup(group); } + + switch (display) + { + case RegisterDisplay::Hex: + view_hex->setChecked(true); + break; + case RegisterDisplay::SInt32: + view_int->setChecked(true); + break; + case RegisterDisplay::UInt32: + view_uint->setChecked(true); + break; + case RegisterDisplay::Float: + view_float->setChecked(true); + break; + case RegisterDisplay::Double: + view_double->setChecked(true); + break; + } + + switch (type) + { + case RegisterType::gpr: + view_hex->setVisible(true); + view_int->setVisible(true); + view_uint->setVisible(true); + view_float->setVisible(true); + break; + case RegisterType::fpr: + view_hex->setVisible(true); + view_double->setVisible(true); + break; + default: + break; + } + + connect(view_hex, &QAction::triggered, [this, item] { + m_updating = true; + item->SetDisplay(RegisterDisplay::Hex); + m_updating = false; + }); + + connect(view_int, &QAction::triggered, [this, item] { + m_updating = true; + item->SetDisplay(RegisterDisplay::SInt32); + m_updating = false; + }); + + connect(view_uint, &QAction::triggered, [this, item] { + m_updating = true; + item->SetDisplay(RegisterDisplay::UInt32); + m_updating = false; + }); + + connect(view_float, &QAction::triggered, [this, item] { + m_updating = true; + item->SetDisplay(RegisterDisplay::Float); + m_updating = false; + }); + + connect(view_double, &QAction::triggered, [this, item] { + m_updating = true; + item->SetDisplay(RegisterDisplay::Double); + m_updating = false; + }); + + menu->addSeparator(); } AddAction(menu, tr("Update"), this, [this] { emit RequestTableUpdate(); });