Qt/MemoryViewWidget: Don't use a member variable to hold information about the current mouse click.
This commit is contained in:
parent
26f9c8b847
commit
54ec0bd0d0
|
@ -269,6 +269,7 @@ void MemoryViewWidget::UpdateColumns(Type type, int first_column)
|
||||||
{
|
{
|
||||||
cell_item->setFlags({});
|
cell_item->setFlags({});
|
||||||
cell_item->setText(QStringLiteral("-"));
|
cell_item->setText(QStringLiteral("-"));
|
||||||
|
cell_item->setData(Qt::UserRole, cell_address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -477,17 +478,11 @@ void MemoryViewWidget::keyPressEvent(QKeyEvent* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 MemoryViewWidget::GetContextAddress() const
|
void MemoryViewWidget::ToggleBreakpoint(u32 addr, bool row)
|
||||||
{
|
|
||||||
return m_context_address;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemoryViewWidget::ToggleRowBreakpoint(bool row)
|
|
||||||
{
|
{
|
||||||
if (m_address_space != AddressSpace::Type::Effective)
|
if (m_address_space != AddressSpace::Type::Effective)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const u32 addr = row ? m_base_address : GetContextAddress();
|
|
||||||
const auto length = GetTypeSize(m_type);
|
const auto length = GetTypeSize(m_type);
|
||||||
const int breaks = row ? (m_bytes_per_row / length) : 1;
|
const int breaks = row ? (m_bytes_per_row / length) : 1;
|
||||||
bool overlap = false;
|
bool overlap = false;
|
||||||
|
@ -526,11 +521,6 @@ void MemoryViewWidget::ToggleRowBreakpoint(bool row)
|
||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryViewWidget::ToggleBreakpoint()
|
|
||||||
{
|
|
||||||
ToggleRowBreakpoint(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemoryViewWidget::wheelEvent(QWheelEvent* event)
|
void MemoryViewWidget::wheelEvent(QWheelEvent* event)
|
||||||
{
|
{
|
||||||
auto delta =
|
auto delta =
|
||||||
|
@ -549,18 +539,15 @@ void MemoryViewWidget::mousePressEvent(QMouseEvent* event)
|
||||||
if (item_selected == nullptr)
|
if (item_selected == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const u32 addr = item_selected->data(Qt::UserRole).toUInt();
|
const u32 address = item(row(item_selected), 1)->data(Qt::UserRole).toUInt();
|
||||||
|
|
||||||
m_context_address = addr;
|
|
||||||
m_base_address = item(row(item_selected), 1)->data(Qt::UserRole).toUInt();
|
|
||||||
|
|
||||||
switch (event->button())
|
switch (event->button())
|
||||||
{
|
{
|
||||||
case Qt::LeftButton:
|
case Qt::LeftButton:
|
||||||
if (column(item_selected) == 0)
|
if (column(item_selected) == 0)
|
||||||
ToggleRowBreakpoint(true);
|
ToggleBreakpoint(address, true);
|
||||||
else
|
else
|
||||||
SetAddress(m_base_address);
|
SetAddress(address);
|
||||||
|
|
||||||
Update();
|
Update();
|
||||||
break;
|
break;
|
||||||
|
@ -569,16 +556,13 @@ void MemoryViewWidget::mousePressEvent(QMouseEvent* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryViewWidget::OnCopyAddress()
|
void MemoryViewWidget::OnCopyAddress(u32 addr)
|
||||||
{
|
{
|
||||||
u32 addr = GetContextAddress();
|
|
||||||
QApplication::clipboard()->setText(QStringLiteral("%1").arg(addr, 8, 16, QLatin1Char('0')));
|
QApplication::clipboard()->setText(QStringLiteral("%1").arg(addr, 8, 16, QLatin1Char('0')));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryViewWidget::OnCopyHex()
|
void MemoryViewWidget::OnCopyHex(u32 addr)
|
||||||
{
|
{
|
||||||
u32 addr = GetContextAddress();
|
|
||||||
|
|
||||||
const auto length = GetTypeSize(m_type);
|
const auto length = GetTypeSize(m_type);
|
||||||
|
|
||||||
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
|
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
|
||||||
|
@ -588,30 +572,39 @@ void MemoryViewWidget::OnCopyHex()
|
||||||
QStringLiteral("%1").arg(value, sizeof(u64) * 2, 16, QLatin1Char('0')).left(length * 2));
|
QStringLiteral("%1").arg(value, sizeof(u64) * 2, 16, QLatin1Char('0')).left(length * 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryViewWidget::OnContextMenu()
|
void MemoryViewWidget::OnContextMenu(const QPoint& pos)
|
||||||
{
|
{
|
||||||
|
auto* item_selected = itemAt(pos);
|
||||||
|
|
||||||
|
// we don't have a meaningful context menu to show for when the user right-clicks free space in
|
||||||
|
// the table
|
||||||
|
if (!item_selected)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const u32 addr = item_selected->data(Qt::UserRole).toUInt();
|
||||||
|
|
||||||
auto* menu = new QMenu(this);
|
auto* menu = new QMenu(this);
|
||||||
|
|
||||||
menu->addAction(tr("Copy Address"), this, &MemoryViewWidget::OnCopyAddress);
|
menu->addAction(tr("Copy Address"), this, [this, addr] { OnCopyAddress(addr); });
|
||||||
|
|
||||||
auto* copy_hex = menu->addAction(tr("Copy Hex"), this, &MemoryViewWidget::OnCopyHex);
|
auto* copy_hex = menu->addAction(tr("Copy Hex"), this, [this, addr] { OnCopyHex(addr); });
|
||||||
|
|
||||||
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
|
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
|
||||||
copy_hex->setEnabled(Core::GetState() != Core::State::Uninitialized &&
|
copy_hex->setEnabled(Core::GetState() != Core::State::Uninitialized &&
|
||||||
accessors->IsValidAddress(GetContextAddress()));
|
accessors->IsValidAddress(addr));
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
menu->addAction(tr("Show in code"), this, [this] { emit ShowCode(GetContextAddress()); });
|
menu->addAction(tr("Show in code"), this, [this, addr] { emit ShowCode(addr); });
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
menu->addAction(tr("Add to watch"), this, [this] {
|
menu->addAction(tr("Add to watch"), this, [this, addr] {
|
||||||
const u32 address = GetContextAddress();
|
const QString name = QStringLiteral("mem_%1").arg(addr, 8, 16, QLatin1Char('0'));
|
||||||
const QString name = QStringLiteral("mem_%1").arg(address, 8, 16, QLatin1Char('0'));
|
emit RequestWatch(name, addr);
|
||||||
emit RequestWatch(name, address);
|
|
||||||
});
|
});
|
||||||
menu->addAction(tr("Toggle Breakpoint"), this, &MemoryViewWidget::ToggleBreakpoint);
|
|
||||||
|
menu->addAction(tr("Toggle Breakpoint"), this, [this, addr] { ToggleBreakpoint(addr, false); });
|
||||||
|
|
||||||
menu->exec(QCursor::pos());
|
menu->exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
|
class QPoint;
|
||||||
|
|
||||||
namespace AddressSpace
|
namespace AddressSpace
|
||||||
{
|
{
|
||||||
enum class Type;
|
enum class Type;
|
||||||
|
@ -44,8 +46,7 @@ public:
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
void UpdateFont();
|
void UpdateFont();
|
||||||
void ToggleBreakpoint();
|
void ToggleBreakpoint(u32 addr, bool row);
|
||||||
void ToggleRowBreakpoint(bool row);
|
|
||||||
|
|
||||||
void SetAddressSpace(AddressSpace::Type address_space);
|
void SetAddressSpace(AddressSpace::Type address_space);
|
||||||
AddressSpace::Type GetAddressSpace() const;
|
AddressSpace::Type GetAddressSpace() const;
|
||||||
|
@ -55,8 +56,6 @@ public:
|
||||||
|
|
||||||
void SetBPLoggingEnabled(bool enabled);
|
void SetBPLoggingEnabled(bool enabled);
|
||||||
|
|
||||||
u32 GetContextAddress() const;
|
|
||||||
|
|
||||||
void resizeEvent(QResizeEvent*) override;
|
void resizeEvent(QResizeEvent*) override;
|
||||||
void keyPressEvent(QKeyEvent* event) override;
|
void keyPressEvent(QKeyEvent* event) override;
|
||||||
void mousePressEvent(QMouseEvent* event) override;
|
void mousePressEvent(QMouseEvent* event) override;
|
||||||
|
@ -68,9 +67,9 @@ signals:
|
||||||
void RequestWatch(QString name, u32 address);
|
void RequestWatch(QString name, u32 address);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnContextMenu();
|
void OnContextMenu(const QPoint& pos);
|
||||||
void OnCopyAddress();
|
void OnCopyAddress(u32 addr);
|
||||||
void OnCopyHex();
|
void OnCopyHex(u32 addr);
|
||||||
void UpdateBreakpointTags();
|
void UpdateBreakpointTags();
|
||||||
void UpdateColumns(Type type, int first_column);
|
void UpdateColumns(Type type, int first_column);
|
||||||
|
|
||||||
|
@ -78,8 +77,6 @@ private:
|
||||||
Type m_type = Type::Hex32;
|
Type m_type = Type::Hex32;
|
||||||
BPType m_bp_type = BPType::ReadWrite;
|
BPType m_bp_type = BPType::ReadWrite;
|
||||||
bool m_do_log = true;
|
bool m_do_log = true;
|
||||||
u32 m_context_address;
|
|
||||||
u32 m_base_address;
|
|
||||||
u32 m_address = 0;
|
u32 m_address = 0;
|
||||||
int m_font_width = 0;
|
int m_font_width = 0;
|
||||||
int m_font_vspace = 0;
|
int m_font_vspace = 0;
|
||||||
|
|
Loading…
Reference in New Issue