mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-01 06:30:26 +00:00
Implement Apply / Close without Saving for preferences
This hooks up the buttons correctly Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
de8395e09e
commit
77c4b8ef87
2 changed files with 42 additions and 8 deletions
|
@ -13,12 +13,22 @@ PreferencesDialog* PreferencesDialog::instance()
|
||||||
#define D(V, P) s.value(#V, default_prefs.P).toDouble()
|
#define D(V, P) s.value(#V, default_prefs.P).toDouble()
|
||||||
#define I(V, P) s.value(#V, default_prefs.P).toInt()
|
#define I(V, P) s.value(#V, default_prefs.P).toInt()
|
||||||
|
|
||||||
PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
|
PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f),
|
||||||
, ui(new Ui::PreferencesDialog())
|
ui(new Ui::PreferencesDialog())
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(syncSettings()));
|
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
|
||||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(resetSettings()));
|
reloadPrefs();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreferencesDialog::showEvent(QShowEvent *event)
|
||||||
|
{
|
||||||
|
reloadPrefs();
|
||||||
|
QDialog::showEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreferencesDialog::reloadPrefs()
|
||||||
|
{
|
||||||
|
|
||||||
oldPrefs = prefs;
|
oldPrefs = prefs;
|
||||||
|
|
||||||
|
@ -140,8 +150,30 @@ void PreferencesDialog::syncSettings()
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
s.sync();
|
s.sync();
|
||||||
|
|
||||||
oldPrefs = prefs;
|
|
||||||
emit settingsChanged();
|
emit settingsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreferencesDialog::buttonClicked(QAbstractButton* button)
|
||||||
|
{
|
||||||
|
switch(ui->buttonBox->standardButton(button)){
|
||||||
|
case QDialogButtonBox::Discard:
|
||||||
|
prefs = oldPrefs;
|
||||||
|
close();
|
||||||
|
break;
|
||||||
|
case QDialogButtonBox::Apply:
|
||||||
|
syncSettings();
|
||||||
|
emit settingsChanged();
|
||||||
|
break;
|
||||||
|
case QDialogButtonBox::FirstButton:
|
||||||
|
syncSettings();
|
||||||
|
oldPrefs = prefs;
|
||||||
|
emit settingsChanged();
|
||||||
|
close();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break; // ignore warnings.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#undef SB
|
#undef SB
|
||||||
|
|
|
@ -6,23 +6,25 @@
|
||||||
#include "../pref.h"
|
#include "../pref.h"
|
||||||
|
|
||||||
namespace Ui{
|
namespace Ui{
|
||||||
class PreferencesDialog;
|
class PreferencesDialog;
|
||||||
}
|
}
|
||||||
|
class QAbstractButton;
|
||||||
|
|
||||||
class PreferencesDialog :public QDialog{
|
class PreferencesDialog :public QDialog{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static PreferencesDialog* instance();
|
static PreferencesDialog* instance();
|
||||||
|
void showEvent(QShowEvent* );
|
||||||
signals:
|
signals:
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void buttonClicked(QAbstractButton* button);
|
||||||
void syncSettings();
|
void syncSettings();
|
||||||
void resetSettings();
|
void resetSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
explicit PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||||
|
void reloadPrefs();
|
||||||
Ui::PreferencesDialog* ui;
|
Ui::PreferencesDialog* ui;
|
||||||
struct preferences oldPrefs;
|
struct preferences oldPrefs;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue