citra-qt: Edit and copy register values

This commit is contained in:
Kingcom 2015-01-13 11:23:48 +01:00
parent 868e6f2d82
commit 15afa4aefb
5 changed files with 69 additions and 4 deletions

View file

@ -5,6 +5,9 @@
#include <QPainter> #include <QPainter>
#include <QMouseEvent> #include <QMouseEvent>
#include <QShortcut> #include <QShortcut>
#include <QApplication>
#include <QClipboard>
#include <QInputDialog>
#include "core/debugger/debug_interface.h" #include "core/debugger/debug_interface.h"
@ -29,13 +32,17 @@ RegisterView::RegisterView(QWidget* parent) : QFrame(parent) {
last_pc = 0; last_pc = 0;
selection = 0; selection = 0;
QShortcut* up_shortcut = new QShortcut(QKeySequence(Qt::Key_Up), this); QShortcut* up_shortcut = new QShortcut(QKeySequence("Up"), this);
up_shortcut->setContext(Qt::WidgetShortcut); up_shortcut->setContext(Qt::WidgetShortcut);
connect(up_shortcut, SIGNAL(activated()), this, SLOT(previousRegister())); connect(up_shortcut, SIGNAL(activated()), this, SLOT(moveSelectionUp()));
QShortcut* down_shortcut = new QShortcut(QKeySequence(Qt::Key_Down), this); QShortcut* down_shortcut = new QShortcut(QKeySequence("Down"), this);
down_shortcut->setContext(Qt::WidgetShortcut); down_shortcut->setContext(Qt::WidgetShortcut);
connect(down_shortcut, SIGNAL(activated()), this, SLOT(nextRegister())); connect(down_shortcut, SIGNAL(activated()), this, SLOT(moveSelectionDown()));
QShortcut* copy_shortcut = new QShortcut(QKeySequence("Ctrl+C"), this);
down_shortcut->setContext(Qt::WidgetShortcut);
connect(copy_shortcut, SIGNAL(activated()), this, SLOT(copyRegisterValue()));
setFocusPolicy(Qt::FocusPolicy::ClickFocus); setFocusPolicy(Qt::FocusPolicy::ClickFocus);
} }
@ -157,6 +164,11 @@ void RegisterView::mouseMoveEvent(QMouseEvent* event) {
} }
} }
void RegisterView::mouseDoubleClickEvent(QMouseEvent* event) {
if (event->button() == Qt::MouseButton::LeftButton)
editRegisterValue();
}
void RegisterView::moveSelectionUp() { void RegisterView::moveSelectionUp() {
selection = qMax<int>(0, selection - 1); selection = qMax<int>(0, selection - 1);
update(); update();
@ -166,3 +178,27 @@ void RegisterView::moveSelectionDown() {
selection = qMin<int>(registers.size() - 1, selection + 1); selection = qMin<int>(registers.size() - 1, selection + 1);
update(); update();
} }
void RegisterView::copyRegisterValue() {
QString value;
Register& reg = registers[selection];
value.sprintf("0x%08X", g_debug->GetRegValue(reg.category, reg.index));
QApplication::clipboard()->setText(value);
}
void RegisterView::editRegisterValue() {
QString value;
Register& reg = registers[selection];
value.sprintf("0x%08X", g_debug->GetRegValue(reg.category, reg.index));
QString result = QInputDialog::getText(this,"Input value","Input new value",QLineEdit::EchoMode::Normal,value);
u32 newValue;
if (!result.isEmpty() && parseExpression(result,newValue)) {
g_debug->SetRegValue(reg.category,reg.index,newValue);
emit registerValueChanged();
update();
}
}

View file

@ -16,6 +16,7 @@ protected:
void paintEvent(QPaintEvent* event) override; void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent* event) override; void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override;
void mouseDoubleClickEvent(QMouseEvent* event) override;
private slots: private slots:
// Select previous register // Select previous register
@ -24,6 +25,16 @@ private slots:
// Select next register // Select next register
void moveSelectionDown(); void moveSelectionDown();
// Copies a string representation of the selected
// register's value to the clipboard
void copyRegisterValue();
void editRegisterValue();
signals:
// Emitted when the value of a register was changed by the user
void registerValueChanged();
private: private:
// Reloads register values if necessary // Reloads register values if necessary
void refreshChangedRegs(); void refreshChangedRegs();

View file

@ -24,6 +24,9 @@ RegistersWidget::RegistersWidget(QWidget* parent) : QDockWidget(parent)
} }
cpu_regs_ui.flags->addItem(new QSpacerItem(0,0,QSizePolicy::Minimum,QSizePolicy::Expanding)); cpu_regs_ui.flags->addItem(new QSpacerItem(0,0,QSizePolicy::Minimum,QSizePolicy::Expanding));
// reload cpsr flags when register values have been changed
connect(cpu_regs_ui.registerView,SIGNAL(registerValueChanged()),this,SLOT(OnDebugModeEntered()));
} }
void RegistersWidget::OnFlagToggled(int state) void RegistersWidget::OnFlagToggled(int state)

View file

@ -4,6 +4,8 @@
#include <QFontMetrics> #include <QFontMetrics>
#include "core/debugger/debug_interface.h"
#include "util.h" #include "util.h"
DebuggerFont::DebuggerFont() { DebuggerFont::DebuggerFont() {
@ -27,3 +29,12 @@ void DebuggerFont::updateMetrics() {
height = metrics.height(); height = metrics.height();
descent = metrics.descent(); descent = metrics.descent();
} }
bool parseExpression(QString& exp, u32& dest) {
PostfixExpression postfix;
if (!g_debug->InitExpression(exp.toLatin1().data(),postfix))
return false;
return g_debug->ParseExpression(postfix,dest);
}

View file

@ -6,6 +6,8 @@
#include <QFont> #include <QFont>
#include <QPoint> #include <QPoint>
#include "common/common_types.h"
// Abstracts font calculations used by some // Abstracts font calculations used by some
// debugger widgets // debugger widgets
class DebuggerFont { class DebuggerFont {
@ -31,3 +33,5 @@ private:
int height; int height;
int descent; int descent;
}; };
bool parseExpression(QString& exp, u32& dest);