Merge pull request #11232 from TryTwo/PR_MemoryView_highlighting

Debugger MemoryViewWidget: always highlight target address
This commit is contained in:
Admiral H. Curtiss 2022-12-04 14:07:19 +01:00 committed by GitHub
commit 2bd47d1435
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 7 deletions

View File

@ -56,8 +56,17 @@ public:
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setShowGrid(false); setShowGrid(false);
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
setSelectionMode(SingleSelection); // Selection will be set programmatically. User will still get an outline on clicked items.
setSelectionMode(NoSelection);
setTextElideMode(Qt::TextElideMode::ElideNone); setTextElideMode(Qt::TextElideMode::ElideNone);
// Prevent colors from changing based on focus.
QPalette palette(m_view->palette());
palette.setBrush(QPalette::Inactive, QPalette::Highlight, palette.brush(QPalette::Highlight));
palette.setBrush(QPalette::Inactive, QPalette::HighlightedText,
palette.brush(QPalette::HighlightedText));
setPalette(palette);
setRowCount(30); setRowCount(30);
setColumnCount(8); setColumnCount(8);
@ -398,9 +407,6 @@ void MemoryViewWidget::Update()
row_item->setText(QStringLiteral("%1").arg(row_address, 8, 16, QLatin1Char('0'))); row_item->setText(QStringLiteral("%1").arg(row_address, 8, 16, QLatin1Char('0')));
row_item->setData(USER_ROLE_CELL_ADDRESS, row_address); row_item->setData(USER_ROLE_CELL_ADDRESS, row_address);
if (row_address == address)
row_item->setSelected(true);
for (int c = 0; c < m_data_columns; c++) for (int c = 0; c < m_data_columns; c++)
{ {
auto* item = m_table->item(i, c + MISC_COLUMNS); auto* item = m_table->item(i, c + MISC_COLUMNS);
@ -440,6 +446,10 @@ void MemoryViewWidget::UpdateColumns()
const Type type = static_cast<Type>(cell_item->data(USER_ROLE_VALUE_TYPE).toInt()); const Type type = static_cast<Type>(cell_item->data(USER_ROLE_VALUE_TYPE).toInt());
cell_item->setText(ValueToString(cell_address, type)); cell_item->setText(ValueToString(cell_address, type));
// Set search address to selected / colored
if (cell_address == m_address_highlight)
cell_item->setSelected(true);
} }
} }
} }
@ -743,6 +753,7 @@ void MemoryViewWidget::SetBPType(BPType type)
void MemoryViewWidget::SetAddress(u32 address) void MemoryViewWidget::SetAddress(u32 address)
{ {
m_address_highlight = address;
if (m_address == address) if (m_address == address)
return; return;
@ -868,21 +879,23 @@ void MemoryViewWidget::ScrollbarActionTriggered(int action)
{ {
// User is currently dragging the scrollbar. // User is currently dragging the scrollbar.
// Adjust the memory view by the exact drag difference. // Adjust the memory view by the exact drag difference.
SetAddress(m_address + difference * m_bytes_per_row); m_address += difference * m_bytes_per_row;
Update();
} }
else else
{ {
if (std::abs(difference) == 1) if (std::abs(difference) == 1)
{ {
// User clicked the arrows at the top or bottom, go up/down one row. // User clicked the arrows at the top or bottom, go up/down one row.
SetAddress(m_address + difference * m_bytes_per_row); m_address += difference * m_bytes_per_row;
} }
else else
{ {
// User clicked the free part of the scrollbar, go up/down one page. // User clicked the free part of the scrollbar, go up/down one page.
SetAddress(m_address + (difference < 0 ? -1 : 1) * m_bytes_per_row * m_table->rowCount()); m_address += (difference < 0 ? -1 : 1) * m_bytes_per_row * m_table->rowCount();
} }
Update();
// Manually reset the draggable part of the bar back to the center. // Manually reset the draggable part of the bar back to the center.
m_scrollbar->setSliderPosition(SCROLLBAR_CENTER); m_scrollbar->setSliderPosition(SCROLLBAR_CENTER);
} }
@ -893,3 +906,8 @@ void MemoryViewWidget::ScrollbarSliderReleased()
// Reset the draggable part of the bar back to the center. // Reset the draggable part of the bar back to the center.
m_scrollbar->setValue(SCROLLBAR_CENTER); m_scrollbar->setValue(SCROLLBAR_CENTER);
} }
void MemoryViewWidget::SetFocus() const
{
m_table->setFocus();
}

View File

@ -60,6 +60,7 @@ public:
void SetDisplay(Type type, int bytes_per_row, int alignment, bool dual_view); void SetDisplay(Type type, int bytes_per_row, int alignment, bool dual_view);
void SetBPType(BPType type); void SetBPType(BPType type);
void SetAddress(u32 address); void SetAddress(u32 address);
void SetFocus() const;
void SetBPLoggingEnabled(bool enabled); void SetBPLoggingEnabled(bool enabled);
@ -85,6 +86,7 @@ private:
BPType m_bp_type = BPType::ReadWrite; BPType m_bp_type = BPType::ReadWrite;
bool m_do_log = true; bool m_do_log = true;
u32 m_address = 0x80000000; u32 m_address = 0x80000000;
u32 m_address_highlight = 0;
int m_font_width = 0; int m_font_width = 0;
int m_font_vspace = 0; int m_font_vspace = 0;
int m_bytes_per_row = 16; int m_bytes_per_row = 16;