Preferences: Remove the old dialog and use the new one

The new preferences dialog still needs a bit of fine tuning
but should already work.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-10-31 21:02:16 -02:00 committed by Dirk Hohndel
parent 8a3fb854c2
commit ff57881265
11 changed files with 31 additions and 65 deletions

View file

@ -30,7 +30,6 @@ set(SUBSURFACE_INTERFACE
mainwindow.cpp mainwindow.cpp
modeldelegates.cpp modeldelegates.cpp
notificationwidget.cpp notificationwidget.cpp
preferences.cpp
simplewidgets.cpp simplewidgets.cpp
starwidget.cpp starwidget.cpp
subsurfacewebservices.cpp subsurfacewebservices.cpp

View file

@ -15,7 +15,6 @@
#include "version.h" #include "version.h"
#include "divelistview.h" #include "divelistview.h"
#include "downloadfromdivecomputer.h" #include "downloadfromdivecomputer.h"
#include "preferences.h"
#include "subsurfacewebservices.h" #include "subsurfacewebservices.h"
#include "divecomputermanagementdialog.h" #include "divecomputermanagementdialog.h"
#include "about.h" #include "about.h"
@ -278,8 +277,6 @@ MainWindow::MainWindow() : QMainWindow(),
ui.menubar->show(); ui.menubar->show();
set_git_update_cb(&updateProgress); set_git_update_cb(&updateProgress);
PreferencesDialogV2 *d = new PreferencesDialogV2();
d->show();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -1785,6 +1782,7 @@ void MainWindow::editCurrentDive()
} }
} }
// TODO: Remove the dependency to the PreferencesDialog here.
#define PREF_PROFILE(QT_PREFS) \ #define PREF_PROFILE(QT_PREFS) \
QSettings s; \ QSettings s; \
s.beginGroup("TecDetails"); \ s.beginGroup("TecDetails"); \

View file

@ -1,43 +0,0 @@
#ifndef PREFERENCES_H
#define PREFERENCES_H
#include <QDialog>
#include "pref.h"
#include "ui_preferences.h"
#ifndef Q_OS_ANDROID
class QWebView;
#endif
class QAbstractButton;
class PreferencesDialog : public QDialog {
Q_OBJECT
public:
static PreferencesDialog *instance();
void showEvent(QShowEvent *);
void emitSettingsChanged();
signals:
void settingsChanged();
public
slots:
void buttonClicked(QAbstractButton *button);
void syncSettings();
void loadSettings();
void restorePrefs();
void rememberPrefs();
void facebookLoggedIn();
void facebookDisconnect();
private:
explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
void setUiFromPrefs();
Ui::PreferencesDialog ui;
struct preferences oldPrefs;
#ifndef Q_OS_ANDROID
QWebView *facebookWebView;
#endif
};
#endif // PREFERENCES_H

View file

@ -1,6 +1,5 @@
#include "preferences_network.h" #include "preferences_network.h"
#include "ui_preferences_network.h" #include "ui_preferences_network.h"
#include "preferences.h"
#include "dive.h" #include "dive.h"
#include "subsurfacewebservices.h" #include "subsurfacewebservices.h"
#include "subsurface-core/prefs-macros.h" #include "subsurface-core/prefs-macros.h"

View file

@ -16,7 +16,18 @@
#include <QAbstractButton> #include <QAbstractButton>
#include <QDebug> #include <QDebug>
PreferencesDialogV2::PreferencesDialogV2() PreferencesDialog* PreferencesDialog::instance()
{
PreferencesDialog *self = new PreferencesDialog();
return self;
}
void PreferencesDialog::emitSettingsChanged()
{
emit settingsChanged();
}
PreferencesDialog::PreferencesDialog()
{ {
pagesList = new QListWidget(); pagesList = new QListWidget();
pagesStack = new QStackedWidget(); pagesStack = new QStackedWidget();
@ -48,14 +59,14 @@ PreferencesDialogV2::PreferencesDialogV2()
connect(pagesList, &QListWidget::currentRowChanged, connect(pagesList, &QListWidget::currentRowChanged,
pagesStack, &QStackedWidget::setCurrentIndex); pagesStack, &QStackedWidget::setCurrentIndex);
connect(buttonBox, &QDialogButtonBox::clicked, connect(buttonBox, &QDialogButtonBox::clicked,
this, &PreferencesDialogV2::buttonClicked); this, &PreferencesDialog::buttonClicked);
} }
PreferencesDialogV2::~PreferencesDialogV2() PreferencesDialog::~PreferencesDialog()
{ {
} }
void PreferencesDialogV2::buttonClicked(QAbstractButton* btn) void PreferencesDialog::buttonClicked(QAbstractButton* btn)
{ {
QDialogButtonBox::ButtonRole role = buttonBox->buttonRole(btn); QDialogButtonBox::ButtonRole role = buttonBox->buttonRole(btn);
switch(role) { switch(role) {
@ -70,13 +81,13 @@ bool abstractpreferenceswidget_lessthan(AbstractPreferencesWidget *p1, AbstractP
return p1->positionHeight() <= p2->positionHeight(); return p1->positionHeight() <= p2->positionHeight();
} }
void PreferencesDialogV2::addPreferencePage(AbstractPreferencesWidget *page) void PreferencesDialog::addPreferencePage(AbstractPreferencesWidget *page)
{ {
pages.push_back(page); pages.push_back(page);
qSort(pages.begin(), pages.end(), abstractpreferenceswidget_lessthan); qSort(pages.begin(), pages.end(), abstractpreferenceswidget_lessthan);
} }
void PreferencesDialogV2::refreshPages() void PreferencesDialog::refreshPages()
{ {
// Remove things // Remove things
pagesList->clear(); pagesList->clear();
@ -95,7 +106,7 @@ void PreferencesDialogV2::refreshPages()
} }
} }
void PreferencesDialogV2::applyRequested() void PreferencesDialog::applyRequested()
{ {
Q_FOREACH(AbstractPreferencesWidget *page, pages) { Q_FOREACH(AbstractPreferencesWidget *page, pages) {
page->syncSettings(); page->syncSettings();
@ -104,7 +115,7 @@ void PreferencesDialogV2::applyRequested()
accept(); accept();
} }
void PreferencesDialogV2::cancelRequested() void PreferencesDialog::cancelRequested()
{ {
Q_FOREACH(AbstractPreferencesWidget *page, pages) { Q_FOREACH(AbstractPreferencesWidget *page, pages) {
page->refreshSettings(); page->refreshSettings();
@ -112,7 +123,7 @@ void PreferencesDialogV2::cancelRequested()
reject(); reject();
} }
void PreferencesDialogV2::defaultsRequested() void PreferencesDialog::defaultsRequested()
{ {
prefs = default_prefs; prefs = default_prefs;
Q_FOREACH(AbstractPreferencesWidget *page, pages) { Q_FOREACH(AbstractPreferencesWidget *page, pages) {

View file

@ -10,16 +10,18 @@ class QStackedWidget;
class QDialogButtonBox; class QDialogButtonBox;
class QAbstractButton; class QAbstractButton;
class PreferencesDialogV2 : public QDialog { class PreferencesDialog : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
PreferencesDialogV2(); static PreferencesDialog* instance();
virtual ~PreferencesDialogV2(); virtual ~PreferencesDialog();
void addPreferencePage(AbstractPreferencesWidget *page); void addPreferencePage(AbstractPreferencesWidget *page);
void refreshPages(); void refreshPages();
void emitSettingsChanged();
signals: signals:
void settingsChanged(); void settingsChanged();
private: private:
PreferencesDialog();
void cancelRequested(); void cancelRequested();
void applyRequested(); void applyRequested();
void defaultsRequested(); void defaultsRequested();

View file

@ -1,7 +1,7 @@
#include "divecartesianaxis.h" #include "divecartesianaxis.h"
#include "divetextitem.h" #include "divetextitem.h"
#include "helpers.h" #include "helpers.h"
#include "preferences.h" #include "preferences/preferencesdialog.h"
#include "diveplotdatamodel.h" #include "diveplotdatamodel.h"
#include "animationfunctions.h" #include "animationfunctions.h"
#include "mainwindow.h" #include "mainwindow.h"

View file

@ -1,7 +1,7 @@
#include "divepixmapitem.h" #include "divepixmapitem.h"
#include "animationfunctions.h" #include "animationfunctions.h"
#include "divepicturemodel.h" #include "divepicturemodel.h"
#include <preferences.h> #include "preferences/preferencesdialog.h"
#include <QDesktopServices> #include <QDesktopServices>
#include <QGraphicsView> #include <QGraphicsView>

View file

@ -5,7 +5,7 @@
#include "animationfunctions.h" #include "animationfunctions.h"
#include "dive.h" #include "dive.h"
#include "profile.h" #include "profile.h"
#include "preferences.h" #include "preferences/preferencesdialog.h"
#include "diveplannermodel.h" #include "diveplannermodel.h"
#include "helpers.h" #include "helpers.h"
#include "libdivecomputer/parser.h" #include "libdivecomputer/parser.h"

View file

@ -29,7 +29,7 @@
#include <QTableView> #include <QTableView>
#endif #endif
#include "mainwindow.h" #include "mainwindow.h"
#include <preferences.h> #include "preferences/preferencesdialog.h"
/* This is the global 'Item position' variable. /* This is the global 'Item position' variable.
* it should tell you where to position things up * it should tell you where to position things up

View file

@ -1,5 +1,5 @@
#include "ruleritem.h" #include "ruleritem.h"
#include "preferences.h" #include "preferences/preferencesdialog.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "profilewidget2.h" #include "profilewidget2.h"
#include "display.h" #include "display.h"