Qt: Link memory scanner address double-click to editor

This commit is contained in:
Stenzek
2025-09-26 22:44:22 +10:00
parent ecf13ded23
commit da471120c4
2 changed files with 45 additions and 5 deletions

View File

@@ -2,6 +2,8 @@
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
#include "memoryscannerwindow.h"
#include "mainwindow.h"
#include "memoryeditorwindow.h"
#include "qthost.h"
#include "qtutils.h"
@@ -169,9 +171,11 @@ void MemoryScannerWindow::connectUi()
connect(m_ui.scanFreezeWatch, &QPushButton::clicked, this, &MemoryScannerWindow::freezeWatchClicked);
connect(m_ui.scanRemoveWatch, &QPushButton::clicked, this, &MemoryScannerWindow::removeWatchClicked);
connect(m_ui.scanTable, &QTableWidget::currentItemChanged, this, &MemoryScannerWindow::scanCurrentItemChanged);
connect(m_ui.watchTable, &QTableWidget::currentItemChanged, this, &MemoryScannerWindow::watchCurrentItemChanged);
connect(m_ui.scanTable, &QTableWidget::itemChanged, this, &MemoryScannerWindow::scanItemChanged);
connect(m_ui.scanTable, &QTableWidget::itemDoubleClicked, this, &MemoryScannerWindow::scanItemDoubleClicked);
connect(m_ui.watchTable, &QTableWidget::currentItemChanged, this, &MemoryScannerWindow::watchCurrentItemChanged);
connect(m_ui.watchTable, &QTableWidget::itemChanged, this, &MemoryScannerWindow::watchItemChanged);
connect(m_ui.watchTable, &QTableWidget::itemDoubleClicked, this, &MemoryScannerWindow::watchItemDoubleClicked);
m_update_timer = new QTimer(this);
connect(m_update_timer, &QTimer::timeout, this, &MemoryScannerWindow::updateScanUi);
@@ -384,10 +388,25 @@ void MemoryScannerWindow::scanCurrentItemChanged(QTableWidgetItem* current, QTab
m_ui.scanAddWatch->setEnabled((current != nullptr));
}
void MemoryScannerWindow::watchCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous)
void MemoryScannerWindow::scanItemDoubleClicked(QTableWidgetItem* item)
{
m_ui.scanFreezeWatch->setEnabled((current != nullptr));
m_ui.scanRemoveWatch->setEnabled((current != nullptr));
const QModelIndex index = m_ui.scanTable->indexFromItem(item);
if (!index.isValid() || index.column() != 0)
return;
tryOpenAddressInMemoryEditor(item->data(Qt::UserRole).toUInt());
}
void MemoryScannerWindow::tryOpenAddressInMemoryEditor(VirtualMemoryAddress address)
{
MemoryEditorWindow* const editor = g_main_window->getMemoryEditorWindow();
if (!editor->scrollToMemoryAddress(address))
{
QMessageBox::critical(this, windowTitle(), tr("Failed to open memory editor at specified address."));
return;
}
QtUtils::ShowOrRaiseWindow(editor);
}
void MemoryScannerWindow::scanItemChanged(QTableWidgetItem* item)
@@ -464,6 +483,21 @@ void MemoryScannerWindow::watchItemChanged(QTableWidgetItem* item)
}
}
void MemoryScannerWindow::watchCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous)
{
m_ui.scanFreezeWatch->setEnabled((current != nullptr));
m_ui.scanRemoveWatch->setEnabled((current != nullptr));
}
void MemoryScannerWindow::watchItemDoubleClicked(QTableWidgetItem* item)
{
const QModelIndex index = m_ui.watchTable->indexFromItem(item);
if (!index.isValid() || index.column() != 1)
return;
tryOpenAddressInMemoryEditor(item->data(Qt::UserRole).toUInt());
}
void MemoryScannerWindow::updateScanValue()
{
QString value = m_ui.scanValue->text();
@@ -509,6 +543,7 @@ void MemoryScannerWindow::updateResults()
QTableWidgetItem* address_item = new QTableWidgetItem(formatHexValue(res.address, MemoryAccessSize::Word));
address_item->setFlags(address_item->flags() & ~(Qt::ItemIsEditable));
address_item->setTextAlignment(Qt::AlignCenter | Qt::AlignHCenter);
address_item->setData(Qt::UserRole, static_cast<uint>(res.address));
m_ui.scanTable->setItem(row, 0, address_item);
m_ui.scanTable->setItem(row, 1, createValueItem(m_scanner.GetSize(), res.value, m_scanner.GetValueSigned(), true));
@@ -572,6 +607,7 @@ void MemoryScannerWindow::updateWatch()
QTableWidgetItem* address_item = new QTableWidgetItem(formatHexValue(res.address, MemoryAccessSize::Word));
address_item->setFlags(address_item->flags() & ~(Qt::ItemIsEditable));
address_item->setData(Qt::UserRole, static_cast<uint>(res.address));
m_ui.watchTable->setItem(row, 1, address_item);
QTableWidgetItem* size_item =

View File

@@ -48,9 +48,11 @@ private:
void freezeWatchClicked();
void removeWatchClicked();
void scanCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous);
void watchCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous);
void scanItemChanged(QTableWidgetItem* item);
void scanItemDoubleClicked(QTableWidgetItem* item);
void watchCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous);
void watchItemChanged(QTableWidgetItem* item);
void watchItemDoubleClicked(QTableWidgetItem* item);
void updateScanValue();
void updateScanUi();
@@ -62,6 +64,8 @@ private:
void updateWatch();
void updateWatchValues();
void tryOpenAddressInMemoryEditor(VirtualMemoryAddress address);
int getSelectedResultIndexFirst() const;
int getSelectedResultIndexLast() const;
int getSelectedWatchIndexFirst() const;