GUI: Simplify settings handling in Preferences dialog.

This commit is contained in:
Kimmo Varis 2011-05-13 10:25:52 +03:00
parent 214a94e1b7
commit 1002d2e785
3 changed files with 43 additions and 46 deletions

View File

@ -461,7 +461,7 @@ void MainWindow::CheckLockDownUI()
void MainWindow::ProgramSettings() void MainWindow::ProgramSettings()
{ {
SettingsDialog dialog(mSettings, mApplications, mTranslation, this); SettingsDialog dialog(mApplications, mTranslation, this);
if (dialog.exec() == QDialog::Accepted) if (dialog.exec() == QDialog::Accepted)
{ {
dialog.SaveSettingValues(); dialog.SaveSettingValues();

View File

@ -33,28 +33,27 @@
#include "translationhandler.h" #include "translationhandler.h"
#include "common.h" #include "common.h"
SettingsDialog::SettingsDialog(QSettings *programSettings, SettingsDialog::SettingsDialog(ApplicationList *list,
ApplicationList *list,
TranslationHandler *translator, TranslationHandler *translator,
QWidget *parent) : QWidget *parent) :
QDialog(parent), QDialog(parent),
mSettings(programSettings),
mApplications(list), mApplications(list),
mTempApplications(new ApplicationList(this)), mTempApplications(new ApplicationList(this)),
mTranslator(translator) mTranslator(translator)
{ {
mUI.setupUi(this); mUI.setupUi(this);
QSettings settings;
mTempApplications->Copy(list); mTempApplications->Copy(list);
mUI.mJobs->setText(programSettings->value(SETTINGS_CHECK_THREADS, 1).toString()); mUI.mJobs->setText(settings.value(SETTINGS_CHECK_THREADS, 1).toString());
mUI.mForce->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_CHECK_FORCE, false).toBool())); mUI.mForce->setCheckState(BoolToCheckState(settings.value(SETTINGS_CHECK_FORCE, false).toBool()));
mUI.mShowFullPath->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SHOW_FULL_PATH, false).toBool())); mUI.mShowFullPath->setCheckState(BoolToCheckState(settings.value(SETTINGS_SHOW_FULL_PATH, false).toBool()));
mUI.mShowNoErrorsMessage->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SHOW_NO_ERRORS, false).toBool())); mUI.mShowNoErrorsMessage->setCheckState(BoolToCheckState(settings.value(SETTINGS_SHOW_NO_ERRORS, false).toBool()));
mUI.mShowDebugWarnings->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SHOW_DEBUG_WARNINGS, false).toBool())); mUI.mShowDebugWarnings->setCheckState(BoolToCheckState(settings.value(SETTINGS_SHOW_DEBUG_WARNINGS, false).toBool()));
mUI.mSaveAllErrors->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SAVE_ALL_ERRORS, false).toBool())); mUI.mSaveAllErrors->setCheckState(BoolToCheckState(settings.value(SETTINGS_SAVE_ALL_ERRORS, false).toBool()));
mUI.mSaveFullPath->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SAVE_FULL_PATH, false).toBool())); mUI.mSaveFullPath->setCheckState(BoolToCheckState(settings.value(SETTINGS_SAVE_FULL_PATH, false).toBool()));
mUI.mInlineSuppressions->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_INLINE_SUPPRESSIONS, false).toBool())); mUI.mInlineSuppressions->setCheckState(BoolToCheckState(settings.value(SETTINGS_INLINE_SUPPRESSIONS, false).toBool()));
mUI.mEnableInconclusive->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool())); mUI.mEnableInconclusive->setCheckState(BoolToCheckState(settings.value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool()));
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(Ok())); connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(Ok()));
connect(mUI.mButtons, SIGNAL(rejected()), this, SLOT(reject())); connect(mUI.mButtons, SIGNAL(rejected()), this, SLOT(reject()));
@ -106,7 +105,8 @@ void SettingsDialog::AddIncludePath(const QString &path)
void SettingsDialog::InitIncludepathsList() void SettingsDialog::InitIncludepathsList()
{ {
const QString allPaths = mSettings->value(SETTINGS_GLOBAL_INCLUDE_PATHS).toString(); QSettings settings;
const QString allPaths = settings.value(SETTINGS_GLOBAL_INCLUDE_PATHS).toString();
const QStringList paths = allPaths.split(";", QString::SkipEmptyParts); const QStringList paths = allPaths.split(";", QString::SkipEmptyParts);
foreach(QString path, paths) foreach(QString path, paths)
{ {
@ -150,14 +150,16 @@ bool SettingsDialog::CheckStateToBool(Qt::CheckState state) const
void SettingsDialog::LoadSettings() void SettingsDialog::LoadSettings()
{ {
resize(mSettings->value(SETTINGS_CHECK_DIALOG_WIDTH, 800).toInt(), QSettings settings;
mSettings->value(SETTINGS_CHECK_DIALOG_HEIGHT, 600).toInt()); resize(settings.value(SETTINGS_CHECK_DIALOG_WIDTH, 800).toInt(),
settings.value(SETTINGS_CHECK_DIALOG_HEIGHT, 600).toInt());
} }
void SettingsDialog::SaveSettings() void SettingsDialog::SaveSettings()
{ {
mSettings->setValue(SETTINGS_CHECK_DIALOG_WIDTH, size().width()); QSettings settings;
mSettings->setValue(SETTINGS_CHECK_DIALOG_HEIGHT, size().height()); settings.setValue(SETTINGS_CHECK_DIALOG_WIDTH, size().width());
settings.setValue(SETTINGS_CHECK_DIALOG_HEIGHT, size().height());
} }
void SettingsDialog::SaveSettingValues() void SettingsDialog::SaveSettingValues()
@ -168,19 +170,20 @@ void SettingsDialog::SaveSettingValues()
jobs = 1; jobs = 1;
} }
mSettings->setValue(SETTINGS_CHECK_THREADS, jobs); QSettings settings;
SaveCheckboxValue(mUI.mForce, SETTINGS_CHECK_FORCE); settings.setValue(SETTINGS_CHECK_THREADS, jobs);
SaveCheckboxValue(mUI.mSaveAllErrors, SETTINGS_SAVE_ALL_ERRORS); SaveCheckboxValue(&settings, mUI.mForce, SETTINGS_CHECK_FORCE);
SaveCheckboxValue(mUI.mSaveFullPath, SETTINGS_SAVE_FULL_PATH); SaveCheckboxValue(&settings, mUI.mSaveAllErrors, SETTINGS_SAVE_ALL_ERRORS);
SaveCheckboxValue(mUI.mShowFullPath, SETTINGS_SHOW_FULL_PATH); SaveCheckboxValue(&settings, mUI.mSaveFullPath, SETTINGS_SAVE_FULL_PATH);
SaveCheckboxValue(mUI.mShowNoErrorsMessage, SETTINGS_SHOW_NO_ERRORS); SaveCheckboxValue(&settings, mUI.mShowFullPath, SETTINGS_SHOW_FULL_PATH);
SaveCheckboxValue(mUI.mShowDebugWarnings, SETTINGS_SHOW_DEBUG_WARNINGS); SaveCheckboxValue(&settings, mUI.mShowNoErrorsMessage, SETTINGS_SHOW_NO_ERRORS);
SaveCheckboxValue(mUI.mInlineSuppressions, SETTINGS_INLINE_SUPPRESSIONS); SaveCheckboxValue(&settings, mUI.mShowDebugWarnings, SETTINGS_SHOW_DEBUG_WARNINGS);
SaveCheckboxValue(mUI.mEnableInconclusive, SETTINGS_INCONCLUSIVE_ERRORS); SaveCheckboxValue(&settings, mUI.mInlineSuppressions, SETTINGS_INLINE_SUPPRESSIONS);
SaveCheckboxValue(&settings, mUI.mEnableInconclusive, SETTINGS_INCONCLUSIVE_ERRORS);
QListWidgetItem *currentLang = mUI.mListLanguages->currentItem(); QListWidgetItem *currentLang = mUI.mListLanguages->currentItem();
const QString langcode = currentLang->data(LangCodeRole).toString(); const QString langcode = currentLang->data(LangCodeRole).toString();
mSettings->setValue(SETTINGS_LANGUAGE, langcode); settings.setValue(SETTINGS_LANGUAGE, langcode);
const int count = mUI.mListIncludePaths->count(); const int count = mUI.mListIncludePaths->count();
QString includePaths; QString includePaths;
@ -190,12 +193,13 @@ void SettingsDialog::SaveSettingValues()
includePaths += item->text(); includePaths += item->text();
includePaths += ";"; includePaths += ";";
} }
mSettings->setValue(SETTINGS_GLOBAL_INCLUDE_PATHS, includePaths); settings.setValue(SETTINGS_GLOBAL_INCLUDE_PATHS, includePaths);
} }
void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name) void SettingsDialog::SaveCheckboxValue(QSettings *settings, QCheckBox *box,
const QString &name)
{ {
mSettings->setValue(name, CheckStateToBool(box->checkState())); settings->setValue(name, CheckStateToBool(box->checkState()));
} }
void SettingsDialog::AddApplication() void SettingsDialog::AddApplication()

View File

@ -40,8 +40,7 @@ class SettingsDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
SettingsDialog(QSettings *programSettings, SettingsDialog(ApplicationList *list,
ApplicationList *list,
TranslationHandler *translator, TranslationHandler *translator,
QWidget *parent = 0); QWidget *parent = 0);
virtual ~SettingsDialog(); virtual ~SettingsDialog();
@ -160,13 +159,13 @@ protected:
void LoadSettings(); void LoadSettings();
/** /**
* @brief Save a single checkboxes value * @brief Save a single checkboxes value
* *
* @param box checkbox to save * @param settings Pointer to Settings.
* @param name name for QSettings to store the value * @param box checkbox to save
*/ * @param name name for QSettings to store the value
void SaveCheckboxValue(QCheckBox *box, const QString &name); */
void SaveCheckboxValue(QSettings *settings, QCheckBox *box, const QString &name);
/** /**
* @brief Convert bool to Qt::CheckState * @brief Convert bool to Qt::CheckState
@ -194,12 +193,6 @@ protected:
*/ */
void InitTranslationsList(); void InitTranslationsList();
/**
* @brief Settings
*
*/
QSettings *mSettings;
/** /**
* @brief List of applications user has specified * @brief List of applications user has specified
* *