[PATCH] Add support for remembering settings

Dirk Hohndel dirk at hohndel.org
Sat Apr 27 20:50:56 PDT 2013


On Sat, 2013-04-27 at 16:45 +0100, Amit Chaudhuri wrote:
> Syntax police: fair cop.  
> 
> New Line @ EOF - wonder why?

That's something your editor does - most editors will add that
automagically (which sometimes can be annoying - but for C/C++ files
it's kinda traditional to have that.

> Using ini & / or leaving as is - let's see how Dirk feels after his
> black belt sparring sessions ;)

I think we want to use QSettings. That means it's portable and we don't
need to worry about things.
If Tomaz at all get the successor implemented for Qt 5.x we can always
consider switching in a few years, but until then I'd go with QSettings.

/D



> On Sat, Apr 27, 2013 at 1:05 PM, Lubomir I. Ivanov
> <neolit123 at gmail.com> wrote:
>         On 27 April 2013 12:09,  <amit.k.chaudhuri at gmail.com> wrote:
>         > From: Amit Chaudhuri <amit.k.chaudhuri at gmail.com>
>         >
>         > 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 at gmail.com>
>         
>         
>         
>         oh hai, i'm the annoying syntax police. :-)
>         a couple of quick things bellow.
>         
>         > ---
>         >  qt-ui/mainwindow.cpp |   37
>         +++++++++++++++++++++++++++++++++++++
>         >  qt-ui/mainwindow.h   |    5 +++++
>         >  2 files changed, 42 insertions(+)
>         >
>         > diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
>         > index 8cdc601..0c6691a 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;
>         > +       }
>         > +
>         >  }
>         >
>         
>         
>         opening curly brace for branches _should be_ at the same line
>         as the
>         "if", "else" conditions:
>         
>         if (hello) {
>         }
>         
>         >  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 */
>         > +}
>         > +
>         
>         
>         we might want to use IniFormat for portability instead of
>         native
>         formats, i.e. writing to similar OS locations and with the
>         same
>         format:
>         http://qt-project.org/doc/qt-4.8/qsettings.html#Format-enum
>         
>         i think i've already suggested that before and i'm personally
>         against
>         using the Windows registry for writing, regardless of it being
>         the
>         "native" Windows format.
>         
>         > +void MainWindow::closeEvent(QCloseEvent *event)
>         > +{
>         > +       if (unsaved_changes() && (askSaveChanges() ==
>         FALSE))
>         > +       {
>         > +               event->ignore();
>         > +               return;
>         > +       }
>         > +       event->accept();
>         > +       writeSettings();
>         
>         
>         same as the first comment.
>         
>         > +}
>         > \ No newline at end of file
>         
>         
>         hmm, it says no newline at EOF?
>         
>         lubomir
>         --
> 
> 
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface




More information about the subsurface mailing list