aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/mainwindow.cpp
diff options
context:
space:
mode:
authorGravatar Amit Chaudhuri <amit.k.chaudhuri@gmail.com>2013-04-27 10:09:57 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-04-27 20:44:36 -0700
commit89f02c42aa2fb49a811cb6e31dd40cd56dee0cf9 (patch)
tree6b4dd4cc75dd4a1319e19380bc0c8141b36b0907 /qt-ui/mainwindow.cpp
parent1d0d42f861fc3a658eb22b99ba58616d716e095e (diff)
downloadsubsurface-89f02c42aa2fb49a811cb6e31dd40cd56dee0cf9.tar.gz
Add support for remembering settings
Use QSettings to provide persistent storage of settings. For example, we store and restore the size of the MainWindow. We use the organisation name hohndel.org and keep subsurface as the application name. A section is specified for things to do with the MainWindow; other sections could be added e.g. for preferred units? Signed-off-by: Amit Chaudhuri <amit.k.chaudhuri@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/mainwindow.cpp')
-rw-r--r--qt-ui/mainwindow.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 8cdc60193..0c6691a06 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -12,6 +12,8 @@
#include <QtDebug>
#include <QDateTime>
#include <QSortFilterProxyModel>
+#include <QSettings>
+#include <QCloseEvent>
#include "divelistview.h"
#include "starwidget.h"
@@ -31,6 +33,7 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()),
ui->ListWidget->setModel(sortModel);
setWindowIcon(QIcon(":subsurface-icon"));
+ readSettings();
}
void MainWindow::on_actionNew_triggered()
@@ -138,6 +141,11 @@ void MainWindow::on_actionPreferences_triggered()
void MainWindow::on_actionQuit_triggered()
{
qDebug("actionQuit");
+ if (unsaved_changes() && (askSaveChanges() == FALSE))
+ {
+ return;
+ }
+
}
void MainWindow::on_actionDownloadDC_triggered()
@@ -284,3 +292,32 @@ bool MainWindow::askSaveChanges()
}
return false;
}
+
+void MainWindow::readSettings()
+{
+ QSettings settings("hohndel.org","subsurface");
+
+ /* note: section/key i.e. forward slash to separate */
+ QSize sz = settings.value("MainWindow/size").value<QSize>();
+ resize(sz);
+}
+
+void MainWindow::writeSettings()
+{
+ QSettings settings("hohndel.org","subsurface");
+ settings.beginGroup("MainWindow");
+ settings.setValue("size",size());
+ settings.endGroup();
+ /* other groups here; avoid '/' and '\' in keys with setValue(...) please */
+}
+
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+ if (unsaved_changes() && (askSaveChanges() == FALSE))
+ {
+ event->ignore();
+ return;
+ }
+ event->accept();
+ writeSettings();
+} \ No newline at end of file