Skip to content

Commit 4e11fdb

Browse files
Copilotxusheng6
andcommitted
Add UI support for enabling/disabling breakpoints
Co-authored-by: xusheng6 <94503187+xusheng6@users.noreply.github.com>
1 parent 1c53ee1 commit 4e11fdb

2 files changed

Lines changed: 67 additions & 10 deletions

File tree

ui/breakpointswidget.cpp

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ QVariant DebugBreakpointsListModel::data(const QModelIndex& index, int role) con
104104

105105
switch (index.column())
106106
{
107-
// case DebugBreakpointsListModel::EnabledColumn:
108-
// {
109-
// QString text = item->enabled() ? "true" : "false";
110-
// return QVariant(text);
111-
// }
107+
case DebugBreakpointsListModel::EnabledColumn:
108+
{
109+
QString text = item->enabled() ? "" : "";
110+
return QVariant(text);
111+
}
112112
case DebugBreakpointsListModel::LocationColumn:
113113
{
114114
QString text;
@@ -152,8 +152,8 @@ QVariant DebugBreakpointsListModel::headerData(int column, Qt::Orientation orien
152152

153153
switch (column)
154154
{
155-
// case DebugBreakpointsListModel::EnabledColumn:
156-
// return "Enabled";
155+
case DebugBreakpointsListModel::EnabledColumn:
156+
return "Enabled";
157157
case DebugBreakpointsListModel::LocationColumn:
158158
return "Location";
159159
case DebugBreakpointsListModel::AddressColumn:
@@ -197,7 +197,7 @@ void DebugBreakpointsItemDelegate::paint(
197197
auto data = idx.data(Qt::DisplayRole);
198198
switch (idx.column())
199199
{
200-
// case DebugBreakpointsListModel::EnabledColumn:
200+
case DebugBreakpointsListModel::EnabledColumn:
201201
case DebugBreakpointsListModel::LocationColumn:
202202
case DebugBreakpointsListModel::AddressColumn:
203203
{
@@ -291,6 +291,24 @@ DebugBreakpointsWidget::DebugBreakpointsWidget(ViewFrame* view, BinaryViewRef da
291291
m_actionHandler.bindAction(
292292
addBreakpointActionName, UIAction([&]() { add(); }));
293293

294+
QString enableBreakpointActionName = QString::fromStdString("Enable Breakpoint");
295+
UIAction::registerAction(enableBreakpointActionName);
296+
m_menu->addAction(enableBreakpointActionName, "Options", MENU_ORDER_NORMAL);
297+
m_actionHandler.bindAction(
298+
enableBreakpointActionName, UIAction([&]() { enableSelected(); }, [&]() { return selectionNotEmpty(); }));
299+
300+
QString disableBreakpointActionName = QString::fromStdString("Disable Breakpoint");
301+
UIAction::registerAction(disableBreakpointActionName);
302+
m_menu->addAction(disableBreakpointActionName, "Options", MENU_ORDER_NORMAL);
303+
m_actionHandler.bindAction(
304+
disableBreakpointActionName, UIAction([&]() { disableSelected(); }, [&]() { return selectionNotEmpty(); }));
305+
306+
QString toggleBreakpointActionName = QString::fromStdString("Toggle Breakpoint Enable/Disable");
307+
UIAction::registerAction(toggleBreakpointActionName, QKeySequence("Ctrl+Shift+B"));
308+
m_menu->addAction(toggleBreakpointActionName, "Options", MENU_ORDER_NORMAL);
309+
m_actionHandler.bindAction(
310+
toggleBreakpointActionName, UIAction([&]() { toggleSelected(); }, [&]() { return selectionNotEmpty(); }));
311+
294312
connect(this, &QTableView::doubleClicked, this, &DebugBreakpointsWidget::onDoubleClicked);
295313

296314
updateContent();
@@ -418,6 +436,42 @@ void DebugBreakpointsWidget::add()
418436
}
419437

420438

439+
void DebugBreakpointsWidget::enableSelected()
440+
{
441+
QModelIndexList sel = selectionModel()->selectedRows();
442+
for (const QModelIndex& index : sel)
443+
{
444+
BreakpointItem bp = m_model->getRow(index.row());
445+
m_controller->EnableBreakpoint(bp.location());
446+
}
447+
}
448+
449+
450+
void DebugBreakpointsWidget::disableSelected()
451+
{
452+
QModelIndexList sel = selectionModel()->selectedRows();
453+
for (const QModelIndex& index : sel)
454+
{
455+
BreakpointItem bp = m_model->getRow(index.row());
456+
m_controller->DisableBreakpoint(bp.location());
457+
}
458+
}
459+
460+
461+
void DebugBreakpointsWidget::toggleSelected()
462+
{
463+
QModelIndexList sel = selectionModel()->selectedRows();
464+
for (const QModelIndex& index : sel)
465+
{
466+
BreakpointItem bp = m_model->getRow(index.row());
467+
if (bp.enabled())
468+
m_controller->DisableBreakpoint(bp.location());
469+
else
470+
m_controller->EnableBreakpoint(bp.location());
471+
}
472+
}
473+
474+
421475
void DebugBreakpointsWidget::remove()
422476
{
423477
QModelIndexList sel = selectionModel()->selectedRows();

ui/breakpointswidget.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class DebugBreakpointsListModel : public QAbstractTableModel
6565
public:
6666
enum ColumnHeaders
6767
{
68-
//EnabledColumn,
68+
EnabledColumn,
6969
LocationColumn,
7070
AddressColumn,
7171
};
@@ -83,7 +83,7 @@ class DebugBreakpointsListModel : public QAbstractTableModel
8383
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override
8484
{
8585
(void)parent;
86-
return 2;
86+
return 3;
8787
}
8888
BreakpointItem getRow(int row) const;
8989
virtual QVariant data(const QModelIndex& i, int role) const override;
@@ -148,6 +148,9 @@ private slots:
148148
void remove();
149149
void onDoubleClicked();
150150
void add();
151+
void enableSelected();
152+
void disableSelected();
153+
void toggleSelected();
151154

152155
public slots:
153156
void updateContent();

0 commit comments

Comments
 (0)