forked from qt-creator/qt-creator
PeripheralRegisterHandler: Avoid using sender()
Change-Id: I3d8c6a22f03afcb589a9c35ff610c60ffbb881c9 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -799,24 +799,25 @@ bool PeripheralRegisterHandler::contextMenuEvent(const ItemViewEvent &ev)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMenu *PeripheralRegisterHandler::createRegisterGroupsMenu(DebuggerState state) const
|
QMenu *PeripheralRegisterHandler::createRegisterGroupsMenu(DebuggerState state)
|
||||||
{
|
{
|
||||||
const auto groupMenu = new QMenu(Tr::tr("View Groups"));
|
const auto groupMenu = new QMenu(Tr::tr("View Groups"));
|
||||||
const auto actionGroup = new QActionGroup(groupMenu);
|
const auto actionGroup = new QActionGroup(groupMenu);
|
||||||
bool hasActions = false;
|
bool hasActions = false;
|
||||||
for (const PeripheralRegisterGroup &group : qAsConst(m_peripheralRegisterGroups)) {
|
for (const PeripheralRegisterGroup &group : qAsConst(m_peripheralRegisterGroups)) {
|
||||||
const QString actName = QStringLiteral("%1: %2")
|
const QString groupName = group.name;
|
||||||
.arg(group.name, group.description);
|
const QString actName = QStringLiteral("%1: %2").arg(groupName, group.description);
|
||||||
QAction *act = groupMenu->addAction(actName);
|
QAction *act = groupMenu->addAction(actName);
|
||||||
const bool on = m_engine->hasCapability(RegisterCapability)
|
const bool on = m_engine->hasCapability(RegisterCapability)
|
||||||
&& (state == InferiorStopOk || state == InferiorUnrunnable);
|
&& (state == InferiorStopOk || state == InferiorUnrunnable);
|
||||||
act->setEnabled(on);
|
act->setEnabled(on);
|
||||||
act->setData(group.name);
|
|
||||||
act->setCheckable(true);
|
act->setCheckable(true);
|
||||||
act->setChecked(group.active);
|
act->setChecked(group.active);
|
||||||
actionGroup->addAction(act);
|
actionGroup->addAction(act);
|
||||||
QObject::connect(act, &QAction::triggered,
|
QObject::connect(act, &QAction::triggered, this, [this, groupName](bool checked) {
|
||||||
this, &PeripheralRegisterHandler::setActiveGroup);
|
if (checked)
|
||||||
|
setActiveGroup(groupName);
|
||||||
|
});
|
||||||
hasActions = true;
|
hasActions = true;
|
||||||
}
|
}
|
||||||
groupMenu->setEnabled(hasActions);
|
groupMenu->setEnabled(hasActions);
|
||||||
@@ -932,13 +933,10 @@ QMenu *PeripheralRegisterHandler::createRegisterFieldFormatMenu(
|
|||||||
return fmtMenu;
|
return fmtMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeripheralRegisterHandler::setActiveGroup(bool checked)
|
void PeripheralRegisterHandler::setActiveGroup(const QString &groupName)
|
||||||
{
|
{
|
||||||
if (!checked)
|
|
||||||
return;
|
|
||||||
deactivateGroups();
|
deactivateGroups();
|
||||||
if (const auto act = qobject_cast<QAction *>(sender())) {
|
if (const auto act = qobject_cast<QAction *>(sender())) {
|
||||||
const QString groupName = act->data().toString();
|
|
||||||
const auto groupEnd = m_peripheralRegisterGroups.end();
|
const auto groupEnd = m_peripheralRegisterGroups.end();
|
||||||
const auto groupIt = std::find_if(
|
const auto groupIt = std::find_if(
|
||||||
m_peripheralRegisterGroups.begin(), groupEnd,
|
m_peripheralRegisterGroups.begin(), groupEnd,
|
||||||
|
@@ -166,12 +166,12 @@ private:
|
|||||||
bool setData(const QModelIndex &idx, const QVariant &data, int role) final;
|
bool setData(const QModelIndex &idx, const QVariant &data, int role) final;
|
||||||
|
|
||||||
bool contextMenuEvent(const Utils::ItemViewEvent &ev);
|
bool contextMenuEvent(const Utils::ItemViewEvent &ev);
|
||||||
QMenu *createRegisterGroupsMenu(DebuggerState state) const;
|
QMenu *createRegisterGroupsMenu(DebuggerState state);
|
||||||
QMenu *createRegisterFormatMenu(DebuggerState state,
|
QMenu *createRegisterFormatMenu(DebuggerState state,
|
||||||
PeripheralRegisterItem *item) const;
|
PeripheralRegisterItem *item) const;
|
||||||
QMenu *createRegisterFieldFormatMenu(DebuggerState state,
|
QMenu *createRegisterFieldFormatMenu(DebuggerState state,
|
||||||
PeripheralRegisterFieldItem *item) const;
|
PeripheralRegisterFieldItem *item) const;
|
||||||
void setActiveGroup(bool checked);
|
void setActiveGroup(const QString &groupName);
|
||||||
void deactivateGroups();
|
void deactivateGroups();
|
||||||
|
|
||||||
PeripheralRegisterGroups m_peripheralRegisterGroups;
|
PeripheralRegisterGroups m_peripheralRegisterGroups;
|
||||||
|
Reference in New Issue
Block a user