Qt: Use header resize mode for memory scanner

pull/3499/head
Stenzek 3 months ago
parent 73f326cd75
commit bb7833168e
No known key found for this signature in database

@ -90,7 +90,7 @@ static QString formatValue(u32 value, bool is_signed)
MemoryScannerWindow::MemoryScannerWindow() : QWidget()
{
m_ui.setupUi(this);
QtUtils::RestoreWindowGeometry("MemoryScannerWindow", this);
setupAdditionalUi();
connectUi();
m_ui.cheatEngineAddress->setText(tr("Address of RAM for HxD Usage: 0x%1")
@ -99,6 +99,13 @@ MemoryScannerWindow::MemoryScannerWindow() : QWidget()
MemoryScannerWindow::~MemoryScannerWindow() = default;
void MemoryScannerWindow::setupAdditionalUi()
{
QtUtils::SetColumnWidthsForTableView(m_ui.scanTable, {-1, 100, 100, 100});
QtUtils::SetColumnWidthsForTableView(m_ui.watchTable, {-1, 100, 100, 150, 40});
QtUtils::RestoreWindowGeometry("MemoryScannerWindow", this);
}
void MemoryScannerWindow::connectUi()
{
m_ui.scanStartAddress->setText(formatHexValue(m_scanner.GetStartAddress(), MemoryAccessSize::Word));
@ -201,12 +208,6 @@ void MemoryScannerWindow::enableUi(bool enabled)
m_ui.scanRemoveWatch->setEnabled(enabled && !m_ui.watchTable->selectedItems().empty());
}
void MemoryScannerWindow::showEvent(QShowEvent* event)
{
QWidget::showEvent(event);
resizeColumns();
}
void MemoryScannerWindow::closeEvent(QCloseEvent* event)
{
QtUtils::SaveWindowGeometry("MemoryScannerWindow", this);
@ -214,18 +215,6 @@ void MemoryScannerWindow::closeEvent(QCloseEvent* event)
emit closed();
}
void MemoryScannerWindow::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
resizeColumns();
}
void MemoryScannerWindow::resizeColumns()
{
QtUtils::ResizeColumnsForTableView(m_ui.scanTable, {-1, 100, 100, 100});
QtUtils::ResizeColumnsForTableView(m_ui.watchTable, {-1, 100, 100, 150, 40});
}
int MemoryScannerWindow::getSelectedResultIndexFirst() const
{
QList<QTableWidgetSelectionRange> sel = m_ui.scanTable->selectedRanges();

@ -27,9 +27,7 @@ Q_SIGNALS:
void closed();
protected:
void showEvent(QShowEvent* event);
void closeEvent(QCloseEvent* event);
void resizeEvent(QResizeEvent* event);
private Q_SLOTS:
void onSystemStarted();
@ -57,9 +55,9 @@ private:
SCAN_INTERVAL = 100,
};
void setupAdditionalUi();
void connectUi();
void enableUi(bool enabled);
void resizeColumns();
void updateResults();
void updateResultsValues();
void updateWatch();

@ -41,9 +41,6 @@
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarPolicy::ScrollBarAlwaysOn</enum>
</property>
<column>
<property name="text">
<string>Address</string>

@ -147,6 +147,20 @@ ALWAYS_INLINE_RELEASE static void ResizeColumnsForView(T* view, const std::initi
}
}
template<class T>
static void SetColumnWidthForView(T* const view, QHeaderView* const header, const std::initializer_list<int>& widths)
{
int column_index = 0;
for (const int width : widths)
{
header->setSectionResizeMode(column_index, (width < 0) ? QHeaderView::Stretch : QHeaderView::Fixed);
if (width > 0)
view->setColumnWidth(column_index, width);
column_index++;
}
}
void QtUtils::ResizeColumnsForTableView(QTableView* view, const std::initializer_list<int>& widths)
{
ResizeColumnsForView(view, widths);
@ -157,6 +171,16 @@ void QtUtils::ResizeColumnsForTreeView(QTreeView* view, const std::initializer_l
ResizeColumnsForView(view, widths);
}
void QtUtils::SetColumnWidthsForTableView(QTableView* view, const std::initializer_list<int>& widths)
{
SetColumnWidthForView(view, view->horizontalHeader(), widths);
}
void QtUtils::SetColumnWidthsForTreeView(QTreeView* view, const std::initializer_list<int>& widths)
{
SetColumnWidthForView(view, view->header(), widths);
}
void QtUtils::OpenURL(QWidget* parent, const QUrl& qurl)
{
if (!QDesktopServices::openUrl(qurl))

@ -75,6 +75,11 @@ inline void CloseAndDeleteWindow(T*& window)
void ResizeColumnsForTableView(QTableView* view, const std::initializer_list<int>& widths);
void ResizeColumnsForTreeView(QTreeView* view, const std::initializer_list<int>& widths);
/// For any positive values, sets the corresponding column width to the specified value.
/// Any values of -1 will stretch the column to use the remaining space.
void SetColumnWidthsForTableView(QTableView* view, const std::initializer_list<int>& widths);
void SetColumnWidthsForTreeView(QTreeView* view, const std::initializer_list<int>& widths);
/// Returns a key id for a key event, including any modifiers that we need (e.g. Keypad).
/// NOTE: Defined in QtKeyCodes.cpp, not QtUtils.cpp.
u32 KeyEventToCode(const QKeyEvent* ev);

Loading…
Cancel
Save