Changeset View
Changeset View
Standalone View
Standalone View
plugins/debuggercommon/registers/registersview.cpp
Show All 20 Lines | |||||
21 | #include "registersview.h" | 21 | #include "registersview.h" | ||
22 | 22 | | |||
23 | #include "converters.h" | 23 | #include "converters.h" | ||
24 | #include "debuglog.h" | 24 | #include "debuglog.h" | ||
25 | #include "modelsmanager.h" | 25 | #include "modelsmanager.h" | ||
26 | 26 | | |||
27 | #include <QMenu> | 27 | #include <QMenu> | ||
28 | #include <QContextMenuEvent> | 28 | #include <QContextMenuEvent> | ||
29 | #include <QSignalMapper> | | |||
30 | 29 | | |||
31 | #include <KLocalizedString> | 30 | #include <KLocalizedString> | ||
32 | 31 | | |||
33 | using namespace KDevMI; | 32 | using namespace KDevMI; | ||
34 | 33 | | |||
35 | namespace | 34 | namespace | ||
36 | { | 35 | { | ||
37 | const int TABLES_COUNT = 5; | 36 | const int TABLES_COUNT = 5; | ||
38 | } | 37 | } | ||
39 | 38 | | |||
40 | RegistersView::RegistersView(QWidget* p) | 39 | RegistersView::RegistersView(QWidget* p) | ||
41 | : QWidget(p), m_menu(new QMenu(this)), m_mapper(new QSignalMapper(this)), m_modelsManager(nullptr) | 40 | : QWidget(p), m_menu(new QMenu(this)), m_modelsManager(nullptr) | ||
42 | { | 41 | { | ||
43 | setupUi(this); | 42 | setupUi(this); | ||
44 | 43 | | |||
45 | setupActions(); | 44 | setupActions(); | ||
46 | 45 | | |||
47 | connect(m_mapper, static_cast<void(QSignalMapper::*)(const QString&)>(&QSignalMapper::mapped), this, &RegistersView::menuTriggered); | | |||
48 | | ||||
49 | connect(tabWidget, &QTabWidget::currentChanged, this, &RegistersView::updateRegisters); | 46 | connect(tabWidget, &QTabWidget::currentChanged, this, &RegistersView::updateRegisters); | ||
50 | } | 47 | } | ||
51 | 48 | | |||
52 | void RegistersView::contextMenuEvent(QContextMenuEvent* e) | 49 | void RegistersView::contextMenuEvent(QContextMenuEvent* e) | ||
53 | { | 50 | { | ||
54 | //Don't remove update action. | 51 | //Don't remove update action. | ||
55 | const QList<QAction*> actions = m_menu->actions(); | 52 | const QList<QAction*> actions = m_menu->actions(); | ||
56 | for (int i = 1; i < actions.count(); i++) { | 53 | for (int i = 1; i < actions.count(); i++) { | ||
▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Line(s) | 234 | { | |||
238 | QAction* a = new QAction(this); | 235 | QAction* a = new QAction(this); | ||
239 | a->setCheckable(true); | 236 | a->setCheckable(true); | ||
240 | a->setShortcut(k); | 237 | a->setShortcut(k); | ||
241 | a->setText(name); | 238 | a->setText(name); | ||
242 | a->setShortcutContext(Qt::WidgetWithChildrenShortcut); | 239 | a->setShortcutContext(Qt::WidgetWithChildrenShortcut); | ||
243 | m_actions.append(a); | 240 | m_actions.append(a); | ||
244 | addAction(a); | 241 | addAction(a); | ||
245 | 242 | | |||
246 | m_mapper->setMapping(a, a->text()); | 243 | const QString atext = a->text(); | ||
247 | connect(a, &QAction::triggered, m_mapper, static_cast<void(QSignalMapper::*)()>(&QSignalMapper::map)); | 244 | connect(a, &QAction::triggered, this, [this, atext](){ menuTriggered(atext); }); | ||
mwolff: why not capture a and then call `a->text()` in the lambda? | |||||
croick: Sure, if there is no `a`, there is no connection. Thanks. | |||||
248 | } | 245 | } |
why not capture a and then call a->text() in the lambda?