From 2ee9a8cf3ed350366c4b5f821fefa7fb8ea82a1b Mon Sep 17 00:00:00 2001 From: Simon Kagstrom Date: Sat, 6 Jul 2024 10:02:41 +0200 Subject: [PATCH] qt: Save geometry on shutdown --- qt/emilpro/mainwindow.cc | 34 ++++++++++++++++++++----------- qt/emilpro/mainwindow.hh | 9 +++------ qt/emilpro/mainwindow.ui | 43 ++++++++++++++++++++++++++++------------ 3 files changed, 55 insertions(+), 31 deletions(-) diff --git a/qt/emilpro/mainwindow.cc b/qt/emilpro/mainwindow.cc index 1e214f2..be77ced 100644 --- a/qt/emilpro/mainwindow.cc +++ b/qt/emilpro/mainwindow.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -38,21 +39,20 @@ MainWindow::MainWindow(QWidget* parent) MainWindow::~MainWindow() { + SaveSettings(); + delete m_instruction_view_model; delete m_symbol_view_model; delete m_ui; } -void -MainWindow::addHistoryEntry(uint64_t address) -{ -} - bool MainWindow::Init(int argc, char* argv[]) { m_ui->setupUi(this); + RestoreSettings(); + SetupSectionView(); SetupSymbolView(); SetupInstructionView(); @@ -365,7 +365,6 @@ MainWindow::on_insnCurrentChanged(const QModelIndex& index, const QModelIndex& p { encoding += fmt::format("{:02x} ", x); } - m_ui->instructionEncodingLine->setText(encoding.c_str()); m_instruction_item_delegate.HighlightStrings(insn.UsedRegisters()); @@ -723,18 +722,29 @@ MainWindow::on_symbolTimerTriggered() } void -MainWindow::refresh() +MainWindow::RestoreSettings() { -} + QSettings settings("ska", "emilpro"); -void -MainWindow::restoreState() -{ + settings.beginGroup("MainWindow"); + + if (const auto geometry = settings.value("geometry", QByteArray()).toByteArray(); + !geometry.isEmpty()) + { + restoreGeometry(geometry); + } + + settings.endGroup(); } void -MainWindow::saveState() +MainWindow::SaveSettings() { + QSettings settings("ska", "emilpro"); + + settings.beginGroup("MainWindow"); + settings.setValue("geometry", saveGeometry()); + settings.endGroup(); } void diff --git a/qt/emilpro/mainwindow.hh b/qt/emilpro/mainwindow.hh index 49a182c..bc68a47 100644 --- a/qt/emilpro/mainwindow.hh +++ b/qt/emilpro/mainwindow.hh @@ -9,6 +9,7 @@ #include "jump_lane_delegate.hh" #include +#include #include namespace Ui @@ -92,15 +93,11 @@ private: void SetupInfoBox(); - void addHistoryEntry(uint64_t addr); - - void refresh(); - void LoadFile(const std::string& filename); - void saveState(); + void SaveSettings(); - void restoreState(); + void RestoreSettings(); void OnHistoryIndexChanged(); diff --git a/qt/emilpro/mainwindow.ui b/qt/emilpro/mainwindow.ui index c58e1b4..1a06a0f 100644 --- a/qt/emilpro/mainwindow.ui +++ b/qt/emilpro/mainwindow.ui @@ -45,6 +45,12 @@ Qt::Vertical + + + 0 + 1 + + Qt::Vertical @@ -144,6 +150,12 @@ + + + 0 + 0 + + Sections @@ -220,6 +232,12 @@ 1 + + + 0 + 0 + + Refers to @@ -238,6 +256,12 @@ + + + 0 + 0 + + Courier New @@ -273,6 +297,12 @@ + + + 0 + 0 + + Referenced by @@ -368,19 +398,6 @@ - - - - - Courier New - 12 - - - - - - -