Skip to content

Commit c6e9ade

Browse files
committed
Minor improvements for emv-viewer
* Cleanup includes * Always accept close events * Only remember main splitter state when remembering input data. Otherwise favour bottom child of splitter.
1 parent 60b2e68 commit c6e9ade

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

viewer/emv-viewer-mainwindow.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
#include "emvtreeview.h"
2424
#include "emvtreeitem.h"
2525

26-
#include <QtCore/QStringLiteral>
27-
#include <QtCore/QString>
2826
#include <QtCore/QByteArray>
27+
#include <QtCore/QList>
2928
#include <QtCore/QSettings>
29+
#include <QtCore/QString>
30+
#include <QtCore/QStringLiteral>
3031
#include <QtCore/QTimer>
3132
#include <QtWidgets/QApplication>
3233
#include <QtWidgets/QScrollBar>
@@ -85,6 +86,7 @@ void EmvViewerMainWindow::closeEvent(QCloseEvent* event)
8586
{
8687
// Save current UI values
8788
saveSettings();
89+
event->accept();
8890
}
8991

9092
void EmvViewerMainWindow::loadSettings()
@@ -107,19 +109,22 @@ void EmvViewerMainWindow::loadSettings()
107109
check_box->setCheckState(state);
108110
}
109111

110-
// Load window and splitter states from settings
112+
// Load window and bottom splitter states from settings
111113
restoreGeometry(settings.value(QStringLiteral("geometry")).toByteArray());
112-
splitter->restoreState(settings.value(QStringLiteral("splitterState")).toByteArray());
113114
if (settings.contains(QStringLiteral("splitterBottomState"))) {
114115
splitterBottom->restoreState(settings.value(QStringLiteral("splitterBottomState")).toByteArray());
115116
} else {
116117
// Favour tree view child if no saved state available
117118
splitterBottom->setSizes({99999, 1});
118119
}
119120

120-
// Load input data
121+
// Load input data and main splitter state
121122
if (rememberCheckBox->isChecked()) {
122123
dataEdit->setPlainText(settings.value(dataEdit->objectName()).toString());
124+
splitter->restoreState(settings.value(QStringLiteral("splitterState")).toByteArray());
125+
} else {
126+
// Favour bottom child if no saved state available
127+
splitter->setSizes({1, 99999});
123128
}
124129
}
125130

@@ -142,14 +147,14 @@ void EmvViewerMainWindow::saveSettings() const
142147
settings.setValue(check_box->objectName(), check_box->checkState());
143148
}
144149

145-
// Save window and splitter states
150+
// Save window and bottom splitter states
146151
settings.setValue(QStringLiteral("geometry"), saveGeometry());
147-
settings.setValue(QStringLiteral("splitterState"), splitter->saveState());
148152
settings.setValue(QStringLiteral("splitterBottomState"), splitterBottom->saveState());
149153

150-
// Save input data
154+
// Save input data and main splitter state
151155
if (rememberCheckBox->isChecked()) {
152156
settings.setValue(dataEdit->objectName(), dataEdit->toPlainText());
157+
settings.setValue(QStringLiteral("splitterState"), splitter->saveState());
153158
}
154159

155160
settings.sync();

0 commit comments

Comments
 (0)