Skip to content

Commit

Permalink
Fix DebugBreakpointsWidget, DebugModulesWidget and ThreadFramesWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
xusheng6 committed Mar 8, 2023
1 parent 0b510f9 commit 6ea452d
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 94 deletions.
46 changes: 20 additions & 26 deletions ui/breakpointswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,37 +226,31 @@ QSize DebugBreakpointsItemDelegate::sizeHint(const QStyleOptionViewItem& option,
}


DebugBreakpointsWidget::DebugBreakpointsWidget(ViewFrame* view, BinaryViewRef data, Menu* menu) : m_view(view)
DebugBreakpointsWidget::DebugBreakpointsWidget(ViewFrame* view, BinaryViewRef data, Menu* menu):
QTableView(view), m_view(view)
{
m_controller = DebuggerController::GetController(data);

m_table = new QTableView(this);
m_model = new DebugBreakpointsListModel(m_table, view);
m_table->setModel(m_model);
m_table->setSelectionBehavior(QAbstractItemView::SelectItems);
m_table->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_model = new DebugBreakpointsListModel(this, view);
setModel(m_model);
setSelectionBehavior(QAbstractItemView::SelectItems);
setSelectionMode(QAbstractItemView::ExtendedSelection);

m_delegate = new DebugBreakpointsItemDelegate(this);
m_table->setItemDelegate(m_delegate);
setItemDelegate(m_delegate);

m_table->setSelectionBehavior(QAbstractItemView::SelectRows);
m_table->setSelectionMode(QAbstractItemView::ExtendedSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
setSelectionMode(QAbstractItemView::ExtendedSelection);

m_table->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
m_table->verticalHeader()->setVisible(false);
verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
verticalHeader()->setVisible(false);

m_table->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
m_table->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);

m_table->resizeColumnsToContents();
m_table->resizeRowsToContents();
m_table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);

QVBoxLayout* layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(m_table);
setLayout(layout);
resizeColumnsToContents();
resizeRowsToContents();
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);

m_actionHandler.setupActionHandler(this);
m_contextMenuManager = new ContextMenuManager(this);
Expand All @@ -282,7 +276,7 @@ DebugBreakpointsWidget::DebugBreakpointsWidget(ViewFrame* view, BinaryViewRef da
m_actionHandler.bindAction(
addBreakpointActionName, UIAction([&]() { add(); }));

connect(m_table, &QTableView::doubleClicked, this, &DebugBreakpointsWidget::onDoubleClicked);
connect(this, &QTableView::doubleClicked, this, &DebugBreakpointsWidget::onDoubleClicked);

updateContent();
}
Expand Down Expand Up @@ -311,14 +305,14 @@ void DebugBreakpointsWidget::contextMenuEvent(QContextMenuEvent* event)

bool DebugBreakpointsWidget::selectionNotEmpty()
{
QModelIndexList sel = m_table->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
return (!sel.empty()) && sel[0].isValid();
}


void DebugBreakpointsWidget::jump()
{
QModelIndexList sel = m_table->selectionModel()->selectedRows();
QModelIndexList sel = selectionModel()->selectedRows();
if (sel.empty())
return;

Expand Down Expand Up @@ -378,7 +372,7 @@ void DebugBreakpointsWidget::add()

void DebugBreakpointsWidget::remove()
{
QModelIndexList sel = m_table->selectionModel()->selectedRows();
QModelIndexList sel = selectionModel()->selectedRows();
std::vector<ModuleNameAndOffset> breakpointsToRemove;

for (const QModelIndex& index : sel)
Expand Down
3 changes: 1 addition & 2 deletions ui/breakpointswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,13 @@ class DebugBreakpointsItemDelegate : public QStyledItemDelegate
};


class DebugBreakpointsWidget : public QWidget
class DebugBreakpointsWidget : public QTableView
{
Q_OBJECT

ViewFrame* m_view;
DbgRef<DebuggerController> m_controller;

QTableView* m_table;
DebugBreakpointsListModel* m_model;
DebugBreakpointsItemDelegate* m_delegate;

Expand Down
59 changes: 26 additions & 33 deletions ui/moduleswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,41 +265,34 @@ QSize DebugModulesItemDelegate::sizeHint(const QStyleOptionViewItem& option, con
}


DebugModulesWidget::DebugModulesWidget(ViewFrame* view, BinaryViewRef data) : m_view(view)
DebugModulesWidget::DebugModulesWidget(ViewFrame* view, BinaryViewRef data) : QTableView(view), m_view(view)
{
m_controller = DebuggerController::GetController(data);
if (!m_controller)
return;

m_table = new QTableView(this);
m_model = new DebugModulesListModel(m_table, view);
m_model = new DebugModulesListModel(this, view);
m_filter = new DebugModulesFilterProxyModel(this);
m_filter->setSourceModel(m_model);
m_table->setModel(m_filter);
m_table->setShowGrid(false);
setModel(m_filter);
setShowGrid(false);

m_delegate = new DebugModulesItemDelegate(this);
m_table->setItemDelegate(m_delegate);
setItemDelegate(m_delegate);

m_table->setSelectionBehavior(QAbstractItemView::SelectItems);
setSelectionBehavior(QAbstractItemView::SelectItems);

m_table->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
m_table->verticalHeader()->setVisible(false);
verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
verticalHeader()->setVisible(false);

m_table->horizontalHeader()->setStretchLastSection(true);
m_table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
horizontalHeader()->setStretchLastSection(true);
horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);

m_table->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
m_table->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);

m_table->resizeColumnsToContents();
m_table->resizeRowsToContents();

QVBoxLayout* layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(m_table);
setLayout(layout);
resizeColumnsToContents();
resizeRowsToContents();

m_actionHandler.setupActionHandler(this);
m_contextMenuManager = new ContextMenuManager(this);
Expand All @@ -318,7 +311,7 @@ DebugModulesWidget::DebugModulesWidget(ViewFrame* view, BinaryViewRef data) : m_
m_menu->addAction("Copy", "Options", MENU_ORDER_NORMAL);
m_actionHandler.bindAction("Copy", UIAction([&]() { copy(); }, [&]() { return canCopy(); }));
m_actionHandler.setActionDisplayName("Copy", [&]() {
QModelIndexList sel = m_table->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty())
return "Copy";

Expand All @@ -339,7 +332,7 @@ DebugModulesWidget::DebugModulesWidget(ViewFrame* view, BinaryViewRef data) : m_
}
});

connect(m_table, &QTableView::doubleClicked, this, &DebugModulesWidget::onDoubleClicked);
connect(this, &QTableView::doubleClicked, this, &DebugModulesWidget::onDoubleClicked);

m_debuggerEventCallback = m_controller->RegisterEventCallback(
[&](const DebuggerEvent& event) {
Expand Down Expand Up @@ -372,11 +365,11 @@ DebugModulesWidget::~DebugModulesWidget()

void DebugModulesWidget::updateColumnWidths()
{
m_table->resizeColumnToContents(DebugModulesListModel::AddressColumn);
m_table->resizeColumnToContents(DebugModulesListModel::EndAddressColumn);
m_table->resizeColumnToContents(DebugModulesListModel::SizeColumn);
m_table->resizeColumnToContents(DebugModulesListModel::NameColumn);
m_table->resizeColumnToContents(DebugModulesListModel::PathColumn);
resizeColumnToContents(DebugModulesListModel::AddressColumn);
resizeColumnToContents(DebugModulesListModel::EndAddressColumn);
resizeColumnToContents(DebugModulesListModel::SizeColumn);
resizeColumnToContents(DebugModulesListModel::NameColumn);
resizeColumnToContents(DebugModulesListModel::PathColumn);
}


Expand Down Expand Up @@ -411,7 +404,7 @@ void DebugModulesWidget::showContextMenu()

void DebugModulesWidget::jumpToStart()
{
QModelIndexList sel = m_table->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty())
return;

Expand Down Expand Up @@ -439,7 +432,7 @@ void DebugModulesWidget::jumpToStart()

void DebugModulesWidget::jumpToEnd()
{
QModelIndexList sel = m_table->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty())
return;

Expand Down Expand Up @@ -467,14 +460,14 @@ void DebugModulesWidget::jumpToEnd()

bool DebugModulesWidget::canCopy()
{
QModelIndexList sel = m_table->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
return !sel.empty();
}


void DebugModulesWidget::copy()
{
QModelIndexList sel = m_table->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty())
return;

Expand Down Expand Up @@ -516,7 +509,7 @@ void DebugModulesWidget::copy()

void DebugModulesWidget::onDoubleClicked()
{
QModelIndexList sel = m_table->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty())
return;

Expand Down
3 changes: 1 addition & 2 deletions ui/moduleswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,13 @@ class DebugModulesFilterProxyModel : public QSortFilterProxyModel
};


class DebugModulesWidget : public QWidget, public FilterTarget
class DebugModulesWidget : public QTableView, public FilterTarget
{
Q_OBJECT

ViewFrame* m_view;
DbgRef<DebuggerController> m_controller;

QTableView* m_table;
DebugModulesListModel* m_model;
DebugModulesItemDelegate* m_delegate;
DebugModulesFilterProxyModel* m_filter;
Expand Down
3 changes: 2 additions & 1 deletion ui/registerswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ void DebugRegistersWidget::updateColumnWidths()
}


DebugRegistersWidget::DebugRegistersWidget(ViewFrame* view, BinaryViewRef data, Menu* menu) : m_view(view)
DebugRegistersWidget::DebugRegistersWidget(ViewFrame* view, BinaryViewRef data, Menu* menu) :
QTableView(view), m_view(view)
{
m_controller = DebuggerController::GetController(data);

Expand Down
47 changes: 19 additions & 28 deletions ui/threadframes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ void ThreadFramesWidget::contextMenuEvent(QContextMenuEvent* event)

void ThreadFramesWidget::makeItSoloThread()
{
QModelIndexList sel = m_threadFramesTree->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty())
return;

Expand Down Expand Up @@ -419,7 +419,7 @@ void ThreadFramesWidget::updateFonts()

void ThreadFramesWidget::resumeThread()
{
QModelIndexList sel = m_threadFramesTree->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty())
return;

Expand All @@ -437,7 +437,7 @@ void ThreadFramesWidget::resumeThread()

void ThreadFramesWidget::suspendThread()
{
QModelIndexList sel = m_threadFramesTree->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty())
return;

Expand All @@ -454,7 +454,7 @@ void ThreadFramesWidget::suspendThread()

bool ThreadFramesWidget::selectionNotEmpty()
{
QModelIndexList sel = m_threadFramesTree->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
return (!sel.empty()) && sel[0].isValid();
}

Expand All @@ -464,7 +464,7 @@ bool ThreadFramesWidget::canSuspendOrResume()
if (!m_debugger->IsConnected() || m_debugger->IsRunning())
return false;

QModelIndexList sel = m_threadFramesTree->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty() || !sel[0].isValid())
return false;

Expand All @@ -481,7 +481,7 @@ bool ThreadFramesWidget::canSuspendOrResume()

void ThreadFramesWidget::copy()
{
QModelIndexList sel = m_threadFramesTree->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty() || !sel[0].isValid())
return;

Expand Down Expand Up @@ -536,32 +536,23 @@ void ThreadFramesWidget::copy()


ThreadFramesWidget::ThreadFramesWidget(QWidget* parent, ViewFrame* frame, BinaryViewRef data) :
QWidget(parent), m_view(frame)
QTreeView(parent), m_view(frame)
{
m_debugger = DebuggerController::GetController(data);
if (!m_debugger)
return;

QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
setFont(getMonospaceFont(this));

m_threadFramesTree = new QTreeView(this);
m_threadFramesTree->setExpandsOnDoubleClick(false);
m_threadFramesTree->setSelectionBehavior(QAbstractItemView::SelectItems);
m_threadFramesTree->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
m_threadFramesTree->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
m_threadFramesTree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
setExpandsOnDoubleClick(false);
setSelectionBehavior(QAbstractItemView::SelectItems);
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
header()->setSectionResizeMode(QHeaderView::ResizeToContents);

m_model = new ThreadFrameModel(m_threadFramesTree, m_debugger);
m_threadFramesTree->setModel(m_model);
m_model = new ThreadFrameModel(this, m_debugger);
setModel(m_model);

m_delegate = new ThreadFramesItemDelegate(this, m_debugger);
m_threadFramesTree->setItemDelegate(m_delegate);

layout->addWidget(m_threadFramesTree);
setLayout(layout);
setItemDelegate(m_delegate);

// Set up colors
QPalette widgetPalette = this->palette();
Expand Down Expand Up @@ -590,7 +581,7 @@ ThreadFramesWidget::ThreadFramesWidget(QWidget* parent, ViewFrame* frame, Binary
m_menu->addAction("Copy", "Options", MENU_ORDER_NORMAL);
m_actionHandler.bindAction("Copy", UIAction([&]() { copy(); }, [&]() { return selectionNotEmpty(); }));
m_actionHandler.setActionDisplayName("Copy", [&]() {
QModelIndexList sel = m_threadFramesTree->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty())
return "Copy";

Expand Down Expand Up @@ -619,7 +610,7 @@ ThreadFramesWidget::ThreadFramesWidget(QWidget* parent, ViewFrame* frame, Binary

// TODO: set as active thread action?

connect(m_threadFramesTree, &QTreeView::doubleClicked, this, &ThreadFramesWidget::onDoubleClicked);
connect(this, &QTreeView::doubleClicked, this, &ThreadFramesWidget::onDoubleClicked);

m_debuggerEventCallback = m_debugger->RegisterEventCallback(
[&](const DebuggerEvent& event) {
Expand Down Expand Up @@ -663,7 +654,7 @@ void ThreadFramesWidget::expandCurrentThread()

if (m_debugger->GetActiveThread().m_tid == item->tid())
{
m_threadFramesTree->expand(index);
expand(index);
return;
}
}
Expand All @@ -682,7 +673,7 @@ void ThreadFramesWidget::updateContent()

void ThreadFramesWidget::onDoubleClicked()
{
QModelIndexList sel = m_threadFramesTree->selectionModel()->selectedIndexes();
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty())
return;

Expand Down
Loading

0 comments on commit 6ea452d

Please sign in to comment.