Skip to content

Commit

Permalink
qt: Save geometry on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonKagstrom committed Jul 6, 2024
1 parent 2461c19 commit 2ee9a8c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 31 deletions.
34 changes: 22 additions & 12 deletions qt/emilpro/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QMetaType>
#include <QScrollBar>
#include <QShortcut>
#include <QTextBlock>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions qt/emilpro/mainwindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "jump_lane_delegate.hh"

#include <QMainWindow>
#include <QSettings>
#include <qstandarditemmodel.h>

namespace Ui
Expand Down Expand Up @@ -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();

Expand Down
43 changes: 30 additions & 13 deletions qt/emilpro/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
<enum>Qt::Vertical</enum>
</property>
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
Expand Down Expand Up @@ -144,6 +150,12 @@
</layout>
</widget>
<widget class="QWidget" name="sectionTab">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="title">
<string>Sections</string>
</attribute>
Expand Down Expand Up @@ -220,6 +232,12 @@
<number>1</number>
</property>
<widget class="QWidget" name="refersToTab">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="title">
<string>Refers to</string>
</attribute>
Expand All @@ -238,6 +256,12 @@
</property>
<item>
<widget class="QTableView" name="refersToTableView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Courier New</family>
Expand Down Expand Up @@ -273,6 +297,12 @@
</layout>
</widget>
<widget class="QWidget" name="referredByTab">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="title">
<string>Referenced by</string>
</attribute>
Expand Down Expand Up @@ -368,19 +398,6 @@
</attribute>
</widget>
</item>
<item>
<widget class="QLabel" name="instructionEncodingLine">
<property name="font">
<font>
<family>Courier New</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down

0 comments on commit 2ee9a8c

Please sign in to comment.