diff --git a/src/plugins/debugger/peripheralregisterhandler.cpp b/src/plugins/debugger/peripheralregisterhandler.cpp index 726a92e92e2..8adb51d5508 100644 --- a/src/plugins/debugger/peripheralregisterhandler.cpp +++ b/src/plugins/debugger/peripheralregisterhandler.cpp @@ -799,24 +799,25 @@ bool PeripheralRegisterHandler::contextMenuEvent(const ItemViewEvent &ev) return true; } -QMenu *PeripheralRegisterHandler::createRegisterGroupsMenu(DebuggerState state) const +QMenu *PeripheralRegisterHandler::createRegisterGroupsMenu(DebuggerState state) { const auto groupMenu = new QMenu(Tr::tr("View Groups")); const auto actionGroup = new QActionGroup(groupMenu); bool hasActions = false; for (const PeripheralRegisterGroup &group : qAsConst(m_peripheralRegisterGroups)) { - const QString actName = QStringLiteral("%1: %2") - .arg(group.name, group.description); + const QString groupName = group.name; + const QString actName = QStringLiteral("%1: %2").arg(groupName, group.description); QAction *act = groupMenu->addAction(actName); const bool on = m_engine->hasCapability(RegisterCapability) && (state == InferiorStopOk || state == InferiorUnrunnable); act->setEnabled(on); - act->setData(group.name); act->setCheckable(true); act->setChecked(group.active); actionGroup->addAction(act); - QObject::connect(act, &QAction::triggered, - this, &PeripheralRegisterHandler::setActiveGroup); + QObject::connect(act, &QAction::triggered, this, [this, groupName](bool checked) { + if (checked) + setActiveGroup(groupName); + }); hasActions = true; } groupMenu->setEnabled(hasActions); @@ -932,13 +933,10 @@ QMenu *PeripheralRegisterHandler::createRegisterFieldFormatMenu( return fmtMenu; } -void PeripheralRegisterHandler::setActiveGroup(bool checked) +void PeripheralRegisterHandler::setActiveGroup(const QString &groupName) { - if (!checked) - return; deactivateGroups(); if (const auto act = qobject_cast(sender())) { - const QString groupName = act->data().toString(); const auto groupEnd = m_peripheralRegisterGroups.end(); const auto groupIt = std::find_if( m_peripheralRegisterGroups.begin(), groupEnd, diff --git a/src/plugins/debugger/peripheralregisterhandler.h b/src/plugins/debugger/peripheralregisterhandler.h index 0f8cacb080f..c5a91f07d00 100644 --- a/src/plugins/debugger/peripheralregisterhandler.h +++ b/src/plugins/debugger/peripheralregisterhandler.h @@ -166,12 +166,12 @@ private: bool setData(const QModelIndex &idx, const QVariant &data, int role) final; bool contextMenuEvent(const Utils::ItemViewEvent &ev); - QMenu *createRegisterGroupsMenu(DebuggerState state) const; + QMenu *createRegisterGroupsMenu(DebuggerState state); QMenu *createRegisterFormatMenu(DebuggerState state, PeripheralRegisterItem *item) const; QMenu *createRegisterFieldFormatMenu(DebuggerState state, PeripheralRegisterFieldItem *item) const; - void setActiveGroup(bool checked); + void setActiveGroup(const QString &groupName); void deactivateGroups(); PeripheralRegisterGroups m_peripheralRegisterGroups;