BranchWatchDialog: De-lambda-ize Constructor

This commit is contained in:
mitaclaw 2024-07-29 00:00:17 -07:00
parent b6c20b715a
commit 9eb79f1d28
1 changed files with 239 additions and 252 deletions

View File

@ -201,14 +201,13 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br
{ {
setWindowTitle(tr("Branch Watch Tool")); setWindowTitle(tr("Branch Watch Tool"));
setWindowFlags((windowFlags() | Qt::WindowMinMaxButtonsHint) & ~Qt::WindowContextHelpButtonHint); setWindowFlags((windowFlags() | Qt::WindowMinMaxButtonsHint) & ~Qt::WindowContextHelpButtonHint);
setLayout([this, &ppc_symbol_db]() {
auto* main_layout = new QVBoxLayout; auto* main_layout = new QVBoxLayout;
// Controls Toolbar (widgets are added later) // Controls Toolbar (widgets are added later)
main_layout->addWidget(m_control_toolbar = new QToolBar); main_layout->addWidget(m_control_toolbar = new QToolBar);
// Branch Watch Table // Branch Watch Table
main_layout->addWidget(m_table_view = [this, &ppc_symbol_db]() {
const auto& ui_settings = Settings::Instance(); const auto& ui_settings = Settings::Instance();
m_table_proxy = new BranchWatchProxyModel(m_branch_watch); m_table_proxy = new BranchWatchProxyModel(m_branch_watch);
@ -223,24 +222,24 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br
connect(Host::GetInstance(), &Host::PPCSymbolsChanged, m_table_model, connect(Host::GetInstance(), &Host::PPCSymbolsChanged, m_table_model,
&BranchWatchTableModel::UpdateSymbols); &BranchWatchTableModel::UpdateSymbols);
auto* const table_view = new QTableView; m_table_view = new QTableView;
table_view->setModel(m_table_proxy); m_table_view->setModel(m_table_proxy);
table_view->setSortingEnabled(true); m_table_view->setSortingEnabled(true);
table_view->sortByColumn(Column::Origin, Qt::AscendingOrder); m_table_view->sortByColumn(Column::Origin, Qt::AscendingOrder);
table_view->setSelectionMode(QAbstractItemView::ExtendedSelection); m_table_view->setSelectionMode(QAbstractItemView::ExtendedSelection);
table_view->setSelectionBehavior(QAbstractItemView::SelectRows); m_table_view->setSelectionBehavior(QAbstractItemView::SelectRows);
table_view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_table_view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
table_view->setContextMenuPolicy(Qt::CustomContextMenu); m_table_view->setContextMenuPolicy(Qt::CustomContextMenu);
table_view->setEditTriggers(QAbstractItemView::NoEditTriggers); m_table_view->setEditTriggers(QAbstractItemView::NoEditTriggers);
table_view->setCornerButtonEnabled(false); m_table_view->setCornerButtonEnabled(false);
table_view->verticalHeader()->hide(); m_table_view->verticalHeader()->hide();
table_view->setColumnWidth(Column::Instruction, 50); m_table_view->setColumnWidth(Column::Instruction, 50);
table_view->setColumnWidth(Column::Condition, 50); m_table_view->setColumnWidth(Column::Condition, 50);
table_view->setColumnWidth(Column::OriginSymbol, 250); m_table_view->setColumnWidth(Column::OriginSymbol, 250);
table_view->setColumnWidth(Column::DestinSymbol, 250); m_table_view->setColumnWidth(Column::DestinSymbol, 250);
// The default column width (100 units) is fine for the rest. // The default column width (100 units) is fine for the rest.
QHeaderView* const horizontal_header = table_view->horizontalHeader(); QHeaderView* const horizontal_header = m_table_view->horizontalHeader();
horizontal_header->restoreState( // Restore column visibility state. horizontal_header->restoreState( // Restore column visibility state.
Settings::GetQSettings() Settings::GetQSettings()
.value(QStringLiteral("branchwatchdialog/tableheader/state")) .value(QStringLiteral("branchwatchdialog/tableheader/state"))
@ -250,37 +249,36 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br
horizontal_header->setSectionsMovable(true); horizontal_header->setSectionsMovable(true);
horizontal_header->setFirstSectionMovable(true); horizontal_header->setFirstSectionMovable(true);
connect(table_view, &QTableView::clicked, this, &BranchWatchDialog::OnTableClicked); connect(m_table_view, &QTableView::clicked, this, &BranchWatchDialog::OnTableClicked);
connect(table_view, &QTableView::customContextMenuRequested, this, connect(m_table_view, &QTableView::customContextMenuRequested, this,
&BranchWatchDialog::OnTableContextMenu); &BranchWatchDialog::OnTableContextMenu);
connect(horizontal_header, &QHeaderView::customContextMenuRequested, this, connect(horizontal_header, &QHeaderView::customContextMenuRequested, this,
&BranchWatchDialog::OnTableHeaderContextMenu); &BranchWatchDialog::OnTableHeaderContextMenu);
connect(new QShortcut(QKeySequence(Qt::Key_Delete), this), &QShortcut::activated, this, connect(new QShortcut(QKeySequence(Qt::Key_Delete), this), &QShortcut::activated, this,
&BranchWatchDialog::OnTableDeleteKeypress); &BranchWatchDialog::OnTableDeleteKeypress);
return table_view; main_layout->addWidget(m_table_view);
}());
m_mnu_column_visibility = [this]() { {
// Column Visibility Menu
static constexpr std::array<const char*, Column::NumberOfColumns> headers = { static constexpr std::array<const char*, Column::NumberOfColumns> headers = {
QT_TR_NOOP("Instruction"), QT_TR_NOOP("Condition"), QT_TR_NOOP("Origin"), QT_TR_NOOP("Instruction"), QT_TR_NOOP("Condition"), QT_TR_NOOP("Origin"),
QT_TR_NOOP("Destination"), QT_TR_NOOP("Recent Hits"), QT_TR_NOOP("Total Hits"), QT_TR_NOOP("Destination"), QT_TR_NOOP("Recent Hits"), QT_TR_NOOP("Total Hits"),
QT_TR_NOOP("Origin Symbol"), QT_TR_NOOP("Destination Symbol")}; QT_TR_NOOP("Origin Symbol"), QT_TR_NOOP("Destination Symbol")};
auto* const menu = new QMenu(); m_mnu_column_visibility = new QMenu();
for (int column = 0; column < Column::NumberOfColumns; ++column) for (int column = 0; column < Column::NumberOfColumns; ++column)
{ {
QAction* action = menu->addAction(tr(headers[column]), [this, column](bool enabled) { QAction* const action =
m_mnu_column_visibility->addAction(tr(headers[column]), [this, column](bool enabled) {
m_table_view->setColumnHidden(column, !enabled); m_table_view->setColumnHidden(column, !enabled);
}); });
action->setChecked(!m_table_view->isColumnHidden(column)); action->setChecked(!m_table_view->isColumnHidden(column));
action->setCheckable(true); action->setCheckable(true);
} }
return menu; }
}(); {
// Menu Bar // Menu Bar
main_layout->setMenuBar([this]() {
QMenuBar* const menu_bar = new QMenuBar; QMenuBar* const menu_bar = new QMenuBar;
menu_bar->setNativeMenuBar(false); menu_bar->setNativeMenuBar(false);
@ -298,8 +296,7 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br
menu_tool->setToolTipsVisible(true); menu_tool->setToolTipsVisible(true);
menu_tool->addAction(tr("Hide &Controls"), this, &BranchWatchDialog::OnHideShowControls) menu_tool->addAction(tr("Hide &Controls"), this, &BranchWatchDialog::OnHideShowControls)
->setCheckable(true); ->setCheckable(true);
QAction* const act_ignore_apploader = QAction* const act_ignore_apploader = menu_tool->addAction(tr("Ignore &Apploader Branch Hits"));
menu_tool->addAction(tr("Ignore &Apploader Branch Hits"));
act_ignore_apploader->setToolTip( act_ignore_apploader->setToolTip(
tr("This only applies to the initial boot of the emulated software.")); tr("This only applies to the initial boot of the emulated software."));
act_ignore_apploader->setChecked(m_system.IsBranchWatchIgnoreApploader()); act_ignore_apploader->setChecked(m_system.IsBranchWatchIgnoreApploader());
@ -313,18 +310,16 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br
menu_bar->addMenu(menu_tool); menu_bar->addMenu(menu_tool);
return menu_bar; main_layout->setMenuBar(menu_bar);
}()); }
{
// Status Bar // Status Bar
main_layout->addWidget(m_status_bar = []() { m_status_bar = new QStatusBar;
auto* const status_bar = new QStatusBar; m_status_bar->setSizeGripEnabled(false);
status_bar->setSizeGripEnabled(false); main_layout->addWidget(m_status_bar);
return status_bar; }
}()); {
// Tool Controls // Tool Controls
m_control_toolbar->addWidget([this]() {
auto* const layout = new QGridLayout; auto* const layout = new QGridLayout;
layout->addWidget(m_btn_start_pause = new QPushButton(tr("Start Branch Watch")), 0, 0); layout->addWidget(m_btn_start_pause = new QPushButton(tr("Start Branch Watch")), 0, 0);
@ -333,8 +328,7 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br
m_btn_start_pause->setCheckable(true); m_btn_start_pause->setCheckable(true);
layout->addWidget(m_btn_clear_watch = new QPushButton(tr("Clear Branch Watch")), 1, 0); layout->addWidget(m_btn_clear_watch = new QPushButton(tr("Clear Branch Watch")), 1, 0);
connect(m_btn_clear_watch, &QPushButton::pressed, this, connect(m_btn_clear_watch, &QPushButton::pressed, this, &BranchWatchDialog::OnClearBranchWatch);
&BranchWatchDialog::OnClearBranchWatch);
m_btn_clear_watch->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); m_btn_clear_watch->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
layout->addWidget(m_btn_path_was_taken = new QPushButton(tr("Code Path Was Taken")), 0, 1); layout->addWidget(m_btn_path_was_taken = new QPushButton(tr("Code Path Was Taken")), 0, 1);
@ -351,18 +345,16 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br
group_box->setLayout(layout); group_box->setLayout(layout);
group_box->setAlignment(Qt::AlignHCenter); group_box->setAlignment(Qt::AlignHCenter);
return group_box; m_control_toolbar->addWidget(group_box);
}()); }
{
// Spacer // Spacer
m_control_toolbar->addWidget([]() {
auto* const widget = new QWidget; auto* const widget = new QWidget;
widget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); widget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
return widget; m_control_toolbar->addWidget(widget);
}()); }
{
// Branch Type Filter Options // Branch Type Filter Options
m_control_toolbar->addWidget([this]() {
auto* const layout = new QGridLayout; auto* const layout = new QGridLayout;
const auto routine = [this, layout](const QString& text, const QString& tooltip, int row, const auto routine = [this, layout](const QString& text, const QString& tooltip, int row,
@ -396,11 +388,10 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br
group_box->setLayout(layout); group_box->setLayout(layout);
group_box->setAlignment(Qt::AlignHCenter); group_box->setAlignment(Qt::AlignHCenter);
return group_box; m_control_toolbar->addWidget(group_box);
}()); }
{
// Origin and Destination Filter Options // Origin and Destination Filter Options
m_control_toolbar->addWidget([this]() {
auto* const layout = new QGridLayout; auto* const layout = new QGridLayout;
const auto routine = [this, layout](const QString& placeholder_text, int row, int column, const auto routine = [this, layout](const QString& placeholder_text, int row, int column,
@ -429,11 +420,10 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br
group_box->setLayout(layout); group_box->setLayout(layout);
group_box->setAlignment(Qt::AlignHCenter); group_box->setAlignment(Qt::AlignHCenter);
return group_box; m_control_toolbar->addWidget(group_box);
}()); }
{
// Condition Filter Options // Condition Filter Options
m_control_toolbar->addWidget([this]() {
auto* const layout = new QVBoxLayout; auto* const layout = new QVBoxLayout;
layout->setAlignment(Qt::AlignHCenter); layout->setAlignment(Qt::AlignHCenter);
@ -461,11 +451,10 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br
group_box->setLayout(layout); group_box->setLayout(layout);
group_box->setAlignment(Qt::AlignHCenter); group_box->setAlignment(Qt::AlignHCenter);
return group_box; m_control_toolbar->addWidget(group_box);
}()); }
{
// Misc. Controls // Misc. Controls
m_control_toolbar->addWidget([this]() {
auto* const layout = new QVBoxLayout; auto* const layout = new QVBoxLayout;
layout->addWidget(m_btn_was_overwritten = new QPushButton(tr("Branch Was Overwritten"))); layout->addWidget(m_btn_was_overwritten = new QPushButton(tr("Branch Was Overwritten")));
@ -488,21 +477,19 @@ BranchWatchDialog::BranchWatchDialog(Core::System& system, Core::BranchWatch& br
group_box->setLayout(layout); group_box->setLayout(layout);
group_box->setAlignment(Qt::AlignHCenter); group_box->setAlignment(Qt::AlignHCenter);
return group_box; m_control_toolbar->addWidget(group_box);
}()); }
UpdateIcons(); UpdateIcons();
connect(m_timer = new QTimer, &QTimer::timeout, this, &BranchWatchDialog::OnTimeout); connect(m_timer = new QTimer, &QTimer::timeout, this, &BranchWatchDialog::OnTimeout);
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
&BranchWatchDialog::OnEmulationStateChanged); &BranchWatchDialog::OnEmulationStateChanged);
connect(&Settings::Instance(), &Settings::ThemeChanged, this, connect(&Settings::Instance(), &Settings::ThemeChanged, this, &BranchWatchDialog::OnThemeChanged);
&BranchWatchDialog::OnThemeChanged);
connect(m_table_proxy, &BranchWatchProxyModel::layoutChanged, this, connect(m_table_proxy, &BranchWatchProxyModel::layoutChanged, this,
&BranchWatchDialog::UpdateStatus); &BranchWatchDialog::UpdateStatus);
return main_layout; setLayout(main_layout);
}());
const auto& settings = Settings::GetQSettings(); const auto& settings = Settings::GetQSettings();
restoreGeometry(settings.value(QStringLiteral("branchwatchdialog/geometry")).toByteArray()); restoreGeometry(settings.value(QStringLiteral("branchwatchdialog/geometry")).toByteArray());