Merge pull request #9527 from sepalani/watch-items

WatchWidget: Add new/delete/clear toolbar items
This commit is contained in:
JMC47 2021-05-18 04:08:58 -04:00 committed by GitHub
commit 736de8abf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 2 deletions

View File

@ -5,6 +5,7 @@
#include "DolphinQt/Debugger/WatchWidget.h" #include "DolphinQt/Debugger/WatchWidget.h"
#include <QHeaderView> #include <QHeaderView>
#include <QInputDialog>
#include <QMenu> #include <QMenu>
#include <QTableWidget> #include <QTableWidget>
#include <QToolBar> #include <QToolBar>
@ -85,9 +86,15 @@ void WatchWidget::CreateWidgets()
m_table->setContextMenuPolicy(Qt::CustomContextMenu); m_table->setContextMenuPolicy(Qt::CustomContextMenu);
m_table->setSelectionMode(QAbstractItemView::SingleSelection); m_table->setSelectionMode(QAbstractItemView::SingleSelection);
m_new = m_toolbar->addAction(tr("New"), this, &WatchWidget::OnNewWatch);
m_delete = m_toolbar->addAction(tr("Delete"), this, &WatchWidget::OnDelete);
m_clear = m_toolbar->addAction(tr("Clear"), this, &WatchWidget::OnClear);
m_load = m_toolbar->addAction(tr("Load"), this, &WatchWidget::OnLoad); m_load = m_toolbar->addAction(tr("Load"), this, &WatchWidget::OnLoad);
m_save = m_toolbar->addAction(tr("Save"), this, &WatchWidget::OnSave); m_save = m_toolbar->addAction(tr("Save"), this, &WatchWidget::OnSave);
m_new->setEnabled(false);
m_delete->setEnabled(false);
m_clear->setEnabled(false);
m_load->setEnabled(false); m_load->setEnabled(false);
m_save->setEnabled(false); m_save->setEnabled(false);
@ -111,6 +118,10 @@ void WatchWidget::ConnectWidgets()
void WatchWidget::UpdateIcons() void WatchWidget::UpdateIcons()
{ {
// TODO: Create a "debugger_add_watch" icon
m_new->setIcon(Resources::GetScaledThemeIcon("debugger_add_breakpoint"));
m_delete->setIcon(Resources::GetScaledThemeIcon("debugger_delete"));
m_clear->setIcon(Resources::GetScaledThemeIcon("debugger_clear"));
m_load->setIcon(Resources::GetScaledThemeIcon("debugger_load")); m_load->setIcon(Resources::GetScaledThemeIcon("debugger_load"));
m_save->setIcon(Resources::GetScaledThemeIcon("debugger_save")); m_save->setIcon(Resources::GetScaledThemeIcon("debugger_save"));
} }
@ -120,8 +131,12 @@ void WatchWidget::UpdateButtonsEnabled()
if (!isVisible()) if (!isVisible())
return; return;
m_load->setEnabled(Core::IsRunning()); const bool is_enabled = Core::IsRunning();
m_save->setEnabled(Core::IsRunning()); m_new->setEnabled(is_enabled);
m_delete->setEnabled(is_enabled);
m_clear->setEnabled(is_enabled);
m_load->setEnabled(is_enabled);
m_save->setEnabled(is_enabled);
} }
void WatchWidget::Update() void WatchWidget::Update()
@ -216,6 +231,40 @@ void WatchWidget::showEvent(QShowEvent* event)
Update(); Update();
} }
void WatchWidget::OnDelete()
{
if (m_table->selectedItems().empty())
return;
auto row_variant = m_table->selectedItems()[0]->data(Qt::UserRole);
if (row_variant.isNull())
return;
DeleteWatch(row_variant.toInt());
}
void WatchWidget::OnClear()
{
PowerPC::debug_interface.ClearWatches();
Update();
}
void WatchWidget::OnNewWatch()
{
QString text = QInputDialog::getText(this, tr("Input"), tr("Enter address to watch:"));
bool good;
uint address = text.toUInt(&good, 16);
if (!good)
{
ModalMessageBox::warning(this, tr("Error"), tr("Invalid watch address: %1").arg(text));
return;
}
const QString name = QStringLiteral("mem_%1").arg(address, 8, 16, QLatin1Char('0'));
AddWatch(name, address);
}
void WatchWidget::OnLoad() void WatchWidget::OnLoad()
{ {
IniFile ini; IniFile ini;

View File

@ -34,6 +34,10 @@ private:
void CreateWidgets(); void CreateWidgets();
void ConnectWidgets(); void ConnectWidgets();
void OnDelete();
void OnClear();
void OnNewWatch();
void OnLoad(); void OnLoad();
void OnSave(); void OnSave();
@ -47,6 +51,9 @@ private:
void UpdateIcons(); void UpdateIcons();
QAction* m_new;
QAction* m_delete;
QAction* m_clear;
QAction* m_load; QAction* m_load;
QAction* m_save; QAction* m_save;
QToolBar* m_toolbar; QToolBar* m_toolbar;