From 85f8035b2611a3449bf394c36bd13b174aa56388 Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 22 Nov 2014 18:15:47 +0200 Subject: [PATCH] Refactoring. Keep access to all settings in one place. --HG-- branch : develop --- src/app/container/vformula.cpp | 3 +- src/app/core/core.pri | 6 +- src/app/core/vapplication.cpp | 15 +- src/app/core/vapplication.h | 8 +- src/app/core/vsettings.cpp | 402 ++++++++++++++++++ src/app/core/vsettings.h | 153 +++++++ .../dialogs/app/configpages/communitypage.cpp | 65 ++- .../app/configpages/configurationpage.cpp | 86 ++-- src/app/dialogs/app/configpages/pathpage.cpp | 13 +- .../dialogs/app/configpages/patternpage.cpp | 28 +- src/app/dialogs/app/dialogincrements.cpp | 3 +- .../app/dialogindividualmeasurements.cpp | 11 +- src/app/dialogs/tools/dialogtool.cpp | 3 +- src/app/main.cpp | 9 +- src/app/mainwindow.cpp | 55 +-- src/app/xml/vpattern.cpp | 17 +- 16 files changed, 673 insertions(+), 204 deletions(-) create mode 100644 src/app/core/vsettings.cpp create mode 100644 src/app/core/vsettings.h diff --git a/src/app/container/vformula.cpp b/src/app/container/vformula.cpp index a9662cd25..ed3659a20 100644 --- a/src/app/container/vformula.cpp +++ b/src/app/container/vformula.cpp @@ -30,6 +30,7 @@ #include "../container/calculator.h" #include "../container/vcontainer.h" #include "../core/vapplication.h" +#include "../core/vsettings.h" #include //VFormula @@ -239,7 +240,7 @@ void VFormula::Eval() else { QLocale loc; - if (qApp->getSettings()->value("configuration/osSeparator", 1).toBool()) + if (qApp->getSettings()->GetOsSeparator()) { loc = QLocale::system(); } diff --git a/src/app/core/core.pri b/src/app/core/core.pri index 8aaa30e45..567350a5a 100644 --- a/src/app/core/core.pri +++ b/src/app/core/core.pri @@ -1,9 +1,11 @@ HEADERS += \ core/vapplication.h \ core/vtranslation.h \ - core/undoevent.h + core/undoevent.h \ + core/vsettings.h SOURCES += \ core/vapplication.cpp \ core/vtranslation.cpp \ - core/undoevent.cpp + core/undoevent.cpp \ + core/vsettings.cpp diff --git a/src/app/core/vapplication.cpp b/src/app/core/vapplication.cpp index 6e29beff4..a10a3803e 100644 --- a/src/app/core/vapplication.cpp +++ b/src/app/core/vapplication.cpp @@ -35,6 +35,7 @@ #include "vmaingraphicsview.h" #include "../container/calculator.h" #include "../version.h" +#include "vsettings.h" #include #include @@ -1652,10 +1653,8 @@ QString VApplication::FormulaFromUser(const QString &formula) } } - bool osSeparatorValue = getSettings()->value("configuration/osSeparator", 1).toBool(); - QLocale loc = QLocale::system(); - if (loc != QLocale(QLocale::C) && osSeparatorValue) + if (loc != QLocale(QLocale::C) && getSettings()->GetOsSeparator()) { QList nKeys = numbers.keys(); QList nValues = numbers.values(); @@ -1768,10 +1767,8 @@ QString VApplication::FormulaToUser(const QString &formula) } } - bool osSeparatorValue = getSettings()->value("configuration/osSeparator", 1).toBool(); - QLocale loc = QLocale::system(); - if (loc != QLocale::C && osSeparatorValue) + if (loc != QLocale::C && getSettings()->GetOsSeparator()) { QList nKeys = numbers.keys(); QList nValues = numbers.values(); @@ -1838,7 +1835,7 @@ void VApplication::setOpeningPattern() */ void VApplication::OpenSettings() { - settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), + settings = new VSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName(), this); } @@ -1847,7 +1844,7 @@ void VApplication::OpenSettings() * @brief VApplication::getSettings hide settings constructor. * @return pointer to class for acssesing to settings in ini file. */ -QSettings *VApplication::getSettings() +VSettings *VApplication::getSettings() { SCASSERT(settings != nullptr); return settings; @@ -2040,7 +2037,7 @@ void VApplication::CollectReports() const return;// Settings was not opened. } - if (settings->value("configuration/send_report/state", 1).toBool()) + if (settings->GetSendReportState()) { // Try send report // Remove gist.json file before close app. connect(this, &VApplication::aboutToQuit, this, &VApplication::CleanGist, Qt::UniqueConnection); diff --git a/src/app/core/vapplication.h b/src/app/core/vapplication.h index 037ae225d..9d50fe6bc 100644 --- a/src/app/core/vapplication.h +++ b/src/app/core/vapplication.h @@ -32,7 +32,6 @@ #include #include "../options.h" #include "vtranslation.h" -#include #include "../widgets/vmaingraphicsview.h" class VApplication;// used in define @@ -41,6 +40,7 @@ class VMainGraphicsView; class VMainGraphicsScene; class VPattern; class QFile; +class VSettings; #if defined(qApp) #undef qApp @@ -90,8 +90,10 @@ public: void setMainWindow(QWidget *value); bool getOpeningPattern() const; void setOpeningPattern(); + void OpenSettings(); - QSettings *getSettings(); + VSettings *getSettings(); + VMainGraphicsScene *getCurrentScene() const; void setCurrentScene(VMainGraphicsScene *value); @@ -147,7 +149,7 @@ private: /** * @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable. */ - QSettings *settings; + VSettings *settings; VPattern *doc; QFile *log; diff --git a/src/app/core/vsettings.cpp b/src/app/core/vsettings.cpp new file mode 100644 index 000000000..dbf8d4e1c --- /dev/null +++ b/src/app/core/vsettings.cpp @@ -0,0 +1,402 @@ +/************************************************************************ + ** + ** @file vsettings.cpp + ** @author Roman Telezhynskyi + ** @date 22 11, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vsettings.h" + +#include + +const QString VSettings::SettingConfigurationOsSeparator = QStringLiteral("configuration/osSeparator"); +const QString VSettings::SettingConfigurationAutosaveState = QStringLiteral("configuration/autosave/state"); +const QString VSettings::SettingConfigurationAutosaveTime = QStringLiteral("configuration/autosave/time"); +const QString VSettings::SettingConfigurationSendReportState = QStringLiteral("configuration/send_report/state"); +const QString VSettings::SettingConfigurationLocale = QStringLiteral("configuration/locale"); +const QString VSettings::SettingConfigurationUnit = QStringLiteral("configuration/unit"); +const QString VSettings::SettingConfigurationLabelLanguage = QStringLiteral("configuration/label_language"); + +const QString VSettings::SettingPathsIndividualMeasurements = QStringLiteral("paths/individual_measurements"); +const QString VSettings::SettingPathsPattern = QStringLiteral("paths/pattern"); + +const QString VSettings::SettingPatternUser = QStringLiteral("pattern/user"); +const QString VSettings::SettingPatternGraphicalOutput = QStringLiteral("pattern/graphicalOutput"); +const QString VSettings::SettingPatternUndo = QStringLiteral("pattern/undo"); + +const QString VSettings::SettingGeneralRecentFileList = QStringLiteral("recentFileList"); +const QString VSettings::SettingGeneralRestoreFileList = QStringLiteral("restoreFileList"); +const QString VSettings::SettingGeneralGeometry = QStringLiteral("geometry"); +const QString VSettings::SettingGeneralWindowState = QStringLiteral("windowState"); + +const QString VSettings::SettingCommunityServer = QStringLiteral("community/server"); +const QString VSettings::SettingCommunityServerSecure = QStringLiteral("community/serverSecure"); +const QString VSettings::SettingCommunityUseProxy = QStringLiteral("community/useProxy"); +const QString VSettings::SettingCommunityProxyAddress = QStringLiteral("community/proxyAddress"); +const QString VSettings::SettingCommunityProxyPort = QStringLiteral("community/proxyPort"); +const QString VSettings::SettingCommunityProxyUser = QStringLiteral("community/proxyUser"); +const QString VSettings::SettingCommunityProxyPass = QStringLiteral("community/proxyPass"); +const QString VSettings::SettingCommunityUsername = QStringLiteral("community/username"); +const QString VSettings::SettingCommunitySavePassword = QStringLiteral("community/savePassword"); +const QString VSettings::SettingCommunityUserPassword = QStringLiteral("community/userpassword"); + +//--------------------------------------------------------------------------------------------------------------------- +VSettings::VSettings(Format format, Scope scope, const QString &organization, const QString &application, + QObject *parent) + :QSettings(format, scope, organization, application, parent) +{} + +//--------------------------------------------------------------------------------------------------------------------- +bool VSettings::GetOsSeparator() +{ + return value(SettingConfigurationOsSeparator, 1).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSettings::SetOsSeparator(const bool &value) +{ + setValue(SettingConfigurationOsSeparator, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VSettings::GetAutosaveState() +{ + return value(SettingConfigurationAutosaveState, 1).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSettings::SetAutosaveState(const bool &value) +{ + setValue(SettingConfigurationAutosaveState, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VSettings::GetAutosaveTime() +{ + bool ok = false; + int val = value(SettingConfigurationAutosaveTime, 1).toInt(&ok); + if (ok == false) + { + qDebug()<<"Could not convert value"< + ** @date 22 11, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VSETTINGS_H +#define VSETTINGS_H + +#include + +class VSettings : public QSettings +{ + Q_OBJECT +public: + VSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), + QObject *parent = 0); + + bool GetOsSeparator(); + void SetOsSeparator(const bool &value); + + bool GetAutosaveState(); + void SetAutosaveState(const bool &value); + + int GetAutosaveTime(); + void SetAutosaveTime(const int &value); + + bool GetSendReportState(); + void SetSendReportState(const bool &value); + + QString GetLocale(); + void SetLocale(const QString &value); + + QString GetUnit(); + void SetUnit(const QString &value); + + QString GetLabelLanguage(); + void SetLabelLanguage(const QString &value); + + QString GetPathIndividualMeasurements(); + void SetPathIndividualMeasurements(const QString &value); + + QString GetPathPattern(); + void SetPathPattern(const QString &value); + + QString GetUser(); + void SetUser(const QString &value); + + bool GetGraphicalOutput(); + void SetGraphicalOutput(const bool &value); + + int GetUndoCount(); + void SetUndoCount(const int &value); + + QStringList GetRecentFileList(); + void SetRecentFileList(const QStringList &value); + + QStringList GetRestoreFileList(); + void SetRestoreFileList(const QStringList &value); + + QByteArray GetGeometry(); + void SetGeometry(const QByteArray &value); + + QByteArray GetWindowState(); + void SetWindowState(const QByteArray &value); + + QString GetServer(); + void SetServer(const QString &value); + + bool GetServerSecure(); + void SetServerSecure(const bool &value); + + bool GetProxy(); + void SetProxy(const bool &value); + + QString GetProxyAddress(); + void SetProxyAddress(const QString &value); + + QString GetProxyPort(); + void SetProxyPort(const QString &value); + + QString GetProxyUser(); + void SetProxyUser(const QString &value); + + QString GetProxyPass(); + void SetProxyPass(const QString &value); + + QString GetUsername(); + void SetUsername(const QString &value); + + bool GetSavePassword(); + void SetSavePassword(const bool &value); + + QString GetUserPassword(); + void SetUserPassword(const QString &value); + +private: + Q_DISABLE_COPY(VSettings) + static const QString SettingConfigurationOsSeparator; + static const QString SettingConfigurationAutosaveState; + static const QString SettingConfigurationAutosaveTime; + static const QString SettingConfigurationSendReportState; + static const QString SettingConfigurationLocale; + static const QString SettingConfigurationUnit; + static const QString SettingConfigurationLabelLanguage; + + static const QString SettingPathsIndividualMeasurements; + static const QString SettingPathsPattern; + + static const QString SettingPatternUser; + static const QString SettingPatternGraphicalOutput; + static const QString SettingPatternUndo; + + static const QString SettingGeneralRecentFileList; + static const QString SettingGeneralRestoreFileList; + static const QString SettingGeneralGeometry; + static const QString SettingGeneralWindowState; + + static const QString SettingCommunityServer; + static const QString SettingCommunityServerSecure; + static const QString SettingCommunityUseProxy; + static const QString SettingCommunityProxyAddress; + static const QString SettingCommunityProxyPort; + static const QString SettingCommunityProxyUser; + static const QString SettingCommunityProxyPass; + static const QString SettingCommunityUsername; + static const QString SettingCommunitySavePassword; + static const QString SettingCommunityUserPassword; +}; + +#endif // VSETTINGS_H diff --git a/src/app/dialogs/app/configpages/communitypage.cpp b/src/app/dialogs/app/configpages/communitypage.cpp index 9ebab2e36..e770424c0 100644 --- a/src/app/dialogs/app/configpages/communitypage.cpp +++ b/src/app/dialogs/app/configpages/communitypage.cpp @@ -29,6 +29,7 @@ #include "communitypage.h" #include "../../../options.h" #include "../../../core/vapplication.h" +#include "../../../core/vsettings.h" #include #include #include @@ -57,17 +58,17 @@ CommunityPage::CommunityPage(QWidget *parent): //--------------------------------------------------------------------------------------------------------------------- void CommunityPage::Apply() { - qApp->getSettings()->setValue("community/server", this->server->text()); - qApp->getSettings()->setValue("community/serverSecure", this->secureComm->isChecked()); - qApp->getSettings()->setValue("community/useProxy", this->useProxy->isChecked()); - qApp->getSettings()->setValue("community/proxyAddress", this->proxyAddress->text()); - qApp->getSettings()->setValue("community/proxyPort", this->proxyPort->text()); - qApp->getSettings()->setValue("community/proxyUser", this->proxyUser->text()); - qApp->getSettings()->setValue("community/proxyPass", this->proxyPass->text()); + qApp->getSettings()->SetServer(this->server->text()); + qApp->getSettings()->SetServerSecure(this->secureComm->isChecked()); + qApp->getSettings()->SetProxy(this->useProxy->isChecked()); + qApp->getSettings()->SetProxyAddress(this->proxyAddress->text()); + qApp->getSettings()->SetProxyPort(this->proxyPort->text()); + qApp->getSettings()->SetProxyUser(this->proxyUser->text()); + qApp->getSettings()->SetProxyPass(this->proxyPass->text()); - qApp->getSettings()->setValue("community/username", this->username->text()); - qApp->getSettings()->setValue("community/savePassword", this->savePassword->isChecked()); - qApp->getSettings()->setValue("community/userpassword", this->userpassword->text()); + qApp->getSettings()->SetUsername(this->username->text()); + qApp->getSettings()->SetSavePassword(this->savePassword->isChecked()); + qApp->getSettings()->SetUserPassword(this->userpassword->text()); } @@ -99,17 +100,13 @@ void CommunityPage::PasswordCheckChanged() //--------------------------------------------------------------------------------------------------------------------- QGroupBox *CommunityPage::ServerGroup() { - QSettings *settings = qApp->getSettings(); - SCASSERT(settings != nullptr); - QGroupBox *ServerGroup = new QGroupBox(tr("Server")); QFormLayout *serverLayout = new QFormLayout; - CommunityPage::add_lineedit(&this->server, serverLayout, - settings->value("community/server", "community.valentina-project.org").toString(), tr("Server name/IP")); + CommunityPage::add_lineedit(&this->server, serverLayout, qApp->getSettings()->GetServer(), tr("Server name/IP")); - CommunityPage::add_checkbox(&this->secureComm, serverLayout, - settings->value("community/serverSecure", 0).toBool(), tr("Secure connection")); + CommunityPage::add_checkbox(&this->secureComm, serverLayout, qApp->getSettings()->GetServerSecure(), + tr("Secure connection")); ServerGroup->setLayout(serverLayout); return ServerGroup; @@ -140,21 +137,12 @@ QGroupBox *CommunityPage::ProxyGroup() QFormLayout *proxyLayout = new QFormLayout; - CommunityPage::add_checkbox(&this->useProxy, proxyLayout, - qApp->getSettings()->value("community/useProxy", 0).toBool(), tr("Use Proxy")); - - CommunityPage::add_lineedit(&this->proxyAddress, proxyLayout, - qApp->getSettings()->value("community/proxyAddress", "").toString(), tr("Proxy address")); - - CommunityPage::add_lineedit(&this->proxyPort, proxyLayout, - qApp->getSettings()->value("community/proxyPort", "").toString(), tr("Proxy port")); - - CommunityPage::add_lineedit(&this->proxyUser, proxyLayout, - qApp->getSettings()->value("community/proxyUser", "").toString(), tr("Proxy user")); - - CommunityPage::add_lineedit(&this->proxyPass, proxyLayout, - qApp->getSettings()->value("community/proxyPass", "").toString(), tr("Proxy pass")); - + CommunityPage::add_checkbox(&this->useProxy, proxyLayout, qApp->getSettings()->GetProxy(), tr("Use Proxy")); + CommunityPage::add_lineedit(&this->proxyAddress, proxyLayout, qApp->getSettings()->GetProxyAddress(), + tr("Proxy address")); + CommunityPage::add_lineedit(&this->proxyPort, proxyLayout, qApp->getSettings()->GetProxyPort(), tr("Proxy port")); + CommunityPage::add_lineedit(&this->proxyUser, proxyLayout, qApp->getSettings()->GetProxyUser(), tr("Proxy user")); + CommunityPage::add_lineedit(&this->proxyPass, proxyLayout, qApp->getSettings()->GetProxyPass(), tr("Proxy pass")); connect(this->useProxy, &QCheckBox::stateChanged, this, &CommunityPage::ProxyCheckChanged); this->ProxyCheckChanged(); @@ -169,14 +157,11 @@ QGroupBox *CommunityPage::UserGroup() QGroupBox *userGroup = new QGroupBox(tr("User settings")); QFormLayout *userLayout = new QFormLayout; - CommunityPage::add_lineedit(&this->username, userLayout, - qApp->getSettings()->value("community/username", "").toString(), tr("User Name")); - - CommunityPage::add_checkbox(&this->savePassword, userLayout, - qApp->getSettings()->value("community/savePassword", 0).toBool(), tr("Save password")); - - CommunityPage::add_lineedit(&this->userpassword, userLayout, - qApp->getSettings()->value("community/userpassword", "").toString(), tr("Password")); + CommunityPage::add_lineedit(&this->username, userLayout, qApp->getSettings()->GetUsername(), tr("User Name")); + CommunityPage::add_checkbox(&this->savePassword, userLayout, qApp->getSettings()->GetSavePassword(), + tr("Save password")); + CommunityPage::add_lineedit(&this->userpassword, userLayout, qApp->getSettings()->GetUserPassword(), + tr("Password")); connect(this->savePassword, &QCheckBox::stateChanged, this, &CommunityPage::PasswordCheckChanged); this->PasswordCheckChanged(); diff --git a/src/app/dialogs/app/configpages/configurationpage.cpp b/src/app/dialogs/app/configpages/configurationpage.cpp index 4cc4e01de..1d6d0f624 100644 --- a/src/app/dialogs/app/configpages/configurationpage.cpp +++ b/src/app/dialogs/app/configpages/configurationpage.cpp @@ -29,6 +29,7 @@ #include "configurationpage.h" #include "../../../options.h" #include "../../../core/vapplication.h" +#include "../../../core/vsettings.h" #include #include #include @@ -62,46 +63,38 @@ ConfigurationPage::ConfigurationPage(QWidget *parent) //--------------------------------------------------------------------------------------------------------------------- void ConfigurationPage::Apply() { - qApp->getSettings()->setValue("configuration/autosave/state", autoSaveCheck->isChecked()); - qApp->getSettings()->setValue("configuration/autosave/time", autoTime->value()); + qApp->getSettings()->SetAutosaveState(autoSaveCheck->isChecked()); + qApp->getSettings()->SetAutosaveTime(autoTime->value()); QTimer *autoSaveTimer = qApp->getAutoSaveTimer(); SCASSERT(autoSaveTimer); - if (autoSaveCheck->isChecked()) - { - autoSaveTimer->start(autoTime->value()*60000); - } - else - { - autoSaveTimer->stop(); - } + autoSaveCheck->isChecked() ? autoSaveTimer->start(autoTime->value()*60000) : autoSaveTimer->stop(); - qApp->getSettings()->setValue("configuration/osSeparator", osOptionCheck->isChecked()); - - qApp->getSettings()->setValue("configuration/send_report/state", sendReportCheck->isChecked()); + qApp->getSettings()->SetOsSeparator(osOptionCheck->isChecked()); + qApp->getSettings()->SetSendReportState(sendReportCheck->isChecked()); if (langChanged) { - QString locale = qvariant_cast(langCombo->itemData(langCombo->currentIndex())); - qApp->getSettings()->setValue("configuration/locale", locale); + const QString locale = qvariant_cast(langCombo->itemData(langCombo->currentIndex())); + qApp->getSettings()->SetLocale(locale); langChanged = false; - QString text = tr("Setup user interface language updated and will be used the next time start") + " " + - QApplication::applicationName(); + const QString text = tr("Setup user interface language updated and will be used the next time start") + " " + + QApplication::applicationName(); QMessageBox::information(this, QApplication::applicationName(), text); } if (this->unitChanged) { - QString unit = qvariant_cast(this->unitCombo->itemData(this->unitCombo->currentIndex())); - qApp->getSettings()->setValue("configuration/unit", unit); + const QString unit = qvariant_cast(this->unitCombo->itemData(this->unitCombo->currentIndex())); + qApp->getSettings()->SetUnit(unit); this->unitChanged = false; - QString text = tr("Default unit updated and will be used the next pattern creation"); + const QString text = tr("Default unit updated and will be used the next pattern creation"); QMessageBox::information(this, QApplication::applicationName(), text); } if (labelLangChanged) { - QString locale = qvariant_cast(labelCombo->itemData(labelCombo->currentIndex())); - qApp->getSettings()->setValue("configuration/label_language", locale); + const QString locale = qvariant_cast(labelCombo->itemData(labelCombo->currentIndex())); + qApp->getSettings()->SetLabelLanguage(locale); labelLangChanged = false; } } @@ -127,31 +120,19 @@ void ConfigurationPage::LabelLangChanged() //--------------------------------------------------------------------------------------------------------------------- QGroupBox *ConfigurationPage::SaveGroup() { - QSettings *settings = qApp->getSettings(); - SCASSERT(settings != nullptr); - QGroupBox *saveGroup = new QGroupBox(tr("Save")); autoSaveCheck = new QCheckBox(tr("Auto-save modified pattern")); - bool autoSaveValue = settings->value("configuration/autosave/state", 1).toBool(); - autoSaveCheck->setChecked(autoSaveValue); - - QLabel *intervalLabel = new QLabel(tr("Interval:")); + autoSaveCheck->setChecked(qApp->getSettings()->GetAutosaveState()); autoTime = new QSpinBox(); - bool ok = true; - qint32 autoTimeValue = settings->value("configuration/autosave/time", 1).toInt(&ok); - if (ok == false) - { - autoTimeValue = 5; - } autoTime->setRange(1, 60); - autoTime->setValue(autoTimeValue); + autoTime->setValue(qApp->getSettings()->GetAutosaveTime()); autoTime->setSuffix(tr("min")); QHBoxLayout *autosaveLayout = new QHBoxLayout; autosaveLayout->addWidget(autoSaveCheck); - autosaveLayout->addWidget(intervalLabel); + autosaveLayout->addWidget(new QLabel(tr("Interval:"))); autosaveLayout->addWidget(autoTime); QVBoxLayout *saveLayout = new QVBoxLayout; @@ -163,19 +144,12 @@ QGroupBox *ConfigurationPage::SaveGroup() //--------------------------------------------------------------------------------------------------------------------- QGroupBox *ConfigurationPage::LangGroup() { - QSettings *settings = qApp->getSettings(); - SCASSERT(settings != nullptr); - QGroupBox *langGroup = new QGroupBox(tr("Language")); QLabel *guiLabel = new QLabel(tr("GUI language")); langCombo = new QComboBox; - // format systems language - QString checkedLocale = settings->value("configuration/locale", QLocale::system().name()).toString(); - - QString m_langPath = qApp->translationsPath(); - QDir dir(m_langPath); - QStringList fileNames = dir.entryList(QStringList("valentina_*.qm")); + QDir dir(qApp->translationsPath()); + const QStringList fileNames = dir.entryList(QStringList("valentina_*.qm")); for (int i = 0; i < fileNames.size(); ++i) { @@ -198,7 +172,7 @@ QGroupBox *ConfigurationPage::LangGroup() langCombo->addItem(ico, lang, "en_US"); // set default translators and language checked - qint32 index = langCombo->findData(checkedLocale); + qint32 index = langCombo->findData(qApp->getSettings()->GetLocale()); if (index != -1) { langCombo->setCurrentIndex(index); @@ -214,8 +188,7 @@ QGroupBox *ConfigurationPage::LangGroup() QLabel *separatorLabel = new QLabel(tr("Decimal separator parts")); osOptionCheck = new QCheckBox(tr("With OS options (%1)").arg(QLocale::system().decimalPoint().toLatin1())); - bool osOptionValue = settings->value("configuration/osSeparator", 1).toBool(); - osOptionCheck->setChecked(osOptionValue); + osOptionCheck->setChecked(qApp->getSettings()->GetOsSeparator()); QHBoxLayout *separatorLayout = new QHBoxLayout; separatorLayout->addWidget(separatorLabel); @@ -225,14 +198,12 @@ QGroupBox *ConfigurationPage::LangGroup() this->unitCombo = new QComboBox; QLabel *unitLabel = new QLabel(tr("Default unit")); - QString checkedUnit = settings->value("configuration/unit", "cm").toString(); - this->unitCombo->addItem(tr("Centimeters"), "cm"); this->unitCombo->addItem(tr("Millimiters"), "mm"); this->unitCombo->addItem(tr("Inches"), "in"); // set default unit - qint32 indexUnit = this->unitCombo->findData(checkedUnit); + qint32 indexUnit = this->unitCombo->findData(qApp->getSettings()->GetUnit()); if (indexUnit != -1) { this->unitCombo->setCurrentIndex(indexUnit); @@ -249,12 +220,9 @@ QGroupBox *ConfigurationPage::LangGroup() QLabel *labelName = new QLabel(tr("Label language")); labelCombo = new QComboBox; - QString checkedLabelLocale = settings->value("configuration/label_language", - QLocale::system().bcp47Name()).toString(); - SetLabelComboBox(VApplication::LabelLanguages()); - index = labelCombo->findData(checkedLabelLocale); + index = labelCombo->findData(qApp->getSettings()->GetLabelLanguage()); if (index != -1) { labelCombo->setCurrentIndex(index); @@ -281,14 +249,10 @@ QGroupBox *ConfigurationPage::LangGroup() //--------------------------------------------------------------------------------------------------------------------- QGroupBox *ConfigurationPage::SendGroup() { - QSettings *settings = qApp->getSettings(); - SCASSERT(settings != nullptr); - QGroupBox *sendGroup = new QGroupBox(tr("Send crash reports")); sendReportCheck = new QCheckBox(tr("Send crash reports (recommended)")); - bool sendReportValue = settings->value("configuration/send_report/state", 1).toBool(); - sendReportCheck->setChecked(sendReportValue); + sendReportCheck->setChecked(qApp->getSettings()->GetSendReportState()); QLabel *description = new QLabel(tr("After each crash Valentina collect information that may help us fix a " "problem. We do not collect any personal information. Find more about what " diff --git a/src/app/dialogs/app/configpages/pathpage.cpp b/src/app/dialogs/app/configpages/pathpage.cpp index cb77d1ade..bf2a8e686 100644 --- a/src/app/dialogs/app/configpages/pathpage.cpp +++ b/src/app/dialogs/app/configpages/pathpage.cpp @@ -29,6 +29,7 @@ #include "pathpage.h" #include "../../../options.h" #include "../../../core/vapplication.h" +#include "../../../core/vsettings.h" #include #include #include @@ -61,8 +62,8 @@ PathPage::PathPage(QWidget *parent) //--------------------------------------------------------------------------------------------------------------------- void PathPage::Apply() { - qApp->getSettings()->setValue("paths/individual_measurements", pathTable->item(0, 1)->text()); - qApp->getSettings()->setValue("paths/pattern", pathTable->item(1, 1)->text()); + qApp->getSettings()->SetPathIndividualMeasurements(pathTable->item(0, 1)->text()); + qApp->getSettings()->SetPathPattern(pathTable->item(1, 1)->text()); } //--------------------------------------------------------------------------------------------------------------------- @@ -138,15 +139,11 @@ void PathPage::InitTable() QStringList tableHeader = QStringList() << tr("Type") << tr("Path"); pathTable->setHorizontalHeaderLabels(tableHeader); - QString path; - pathTable->setItem(0, 0, new QTableWidgetItem(tr("Individual measurements"))); - path = qApp->getSettings()->value("paths/individual_measurements", QDir::homePath()).toString(); - pathTable->setItem(0, 1, new QTableWidgetItem(path)); + pathTable->setItem(0, 1, new QTableWidgetItem(qApp->getSettings()->GetPathIndividualMeasurements())); pathTable->setItem(1, 0, new QTableWidgetItem(tr("Patterns"))); - path = qApp->getSettings()->value("paths/pattern", QDir::homePath()).toString(); - pathTable->setItem(1, 1, new QTableWidgetItem(path)); + pathTable->setItem(1, 1, new QTableWidgetItem(qApp->getSettings()->GetPathPattern())); pathTable->verticalHeader()->setDefaultSectionSize(20); pathTable->resizeColumnsToContents(); diff --git a/src/app/dialogs/app/configpages/patternpage.cpp b/src/app/dialogs/app/configpages/patternpage.cpp index d063d25e5..5b0669e1d 100644 --- a/src/app/dialogs/app/configpages/patternpage.cpp +++ b/src/app/dialogs/app/configpages/patternpage.cpp @@ -29,6 +29,7 @@ #include "patternpage.h" #include "../../../options.h" #include "../../../core/vapplication.h" +#include "../../../core/vsettings.h" #include "../../../widgets/vmaingraphicsview.h" #include #include @@ -57,35 +58,27 @@ PatternPage::PatternPage(QWidget *parent): //--------------------------------------------------------------------------------------------------------------------- void PatternPage::Apply() { - qApp->getSettings()->setValue("pattern/user", userName->text()); + qApp->getSettings()->SetUser(userName->text()); // Scene antialiasing - qApp->getSettings()->setValue("pattern/graphicalOutput", graphOutputCheck->isChecked()); + qApp->getSettings()->SetGraphicalOutput(graphOutputCheck->isChecked()); qApp->getSceneView()->setRenderHint(QPainter::Antialiasing, graphOutputCheck->isChecked()); qApp->getSceneView()->setRenderHint(QPainter::SmoothPixmapTransform, graphOutputCheck->isChecked()); /* Maximum number of commands in undo stack may only be set when the undo stack is empty, since setting it on a * non-empty stack might delete the command at the current index. Calling setUndoLimit() on a non-empty stack * prints a warning and does nothing.*/ - qApp->getSettings()->setValue("pattern/undo", undoCount->value()); + qApp->getSettings()->SetUndoCount(undoCount->value()); } //--------------------------------------------------------------------------------------------------------------------- QGroupBox *PatternPage::UserGroup() { - QSettings *settings = qApp->getSettings(); - SCASSERT(settings != nullptr); - QGroupBox *userGroup = new QGroupBox(tr("User")); QLabel *nameLabel = new QLabel(tr("User name")); userName = new QLineEdit; -#ifdef Q_OS_WIN - QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString(); -#else - QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString(); -#endif - userName->setText(user); + userName->setText(qApp->getSettings()->GetUser()); QHBoxLayout *nameLayout = new QHBoxLayout; nameLayout->addWidget(nameLabel); @@ -103,8 +96,7 @@ QGroupBox *PatternPage::GraphOutputGroup() QGroupBox *graphOutputGroup = new QGroupBox(tr("Graphical output")); graphOutputCheck = new QCheckBox(tr("Use antialiasing")); - bool graphOutputValue = qApp->getSettings()->value("pattern/graphicalOutput", 1).toBool(); - graphOutputCheck->setChecked(graphOutputValue); + graphOutputCheck->setChecked(qApp->getSettings()->GetGraphicalOutput()); QHBoxLayout *graphLayout = new QHBoxLayout; graphLayout->addWidget(graphOutputCheck); @@ -122,13 +114,7 @@ QGroupBox *PatternPage::UndoGroup() QLabel *undoLabel = new QLabel(tr("Count steps (0 - no limit)")); undoCount = new QSpinBox; undoCount->setMinimum(0); - bool ok = true; - qint32 count = qApp->getSettings()->value("pattern/undo", 0).toInt(&ok); - if (ok == false) - { - count = 0; - } - undoCount->setValue(count); + undoCount->setValue(qApp->getSettings()->GetUndoCount()); QHBoxLayout *countLayout = new QHBoxLayout; countLayout->addWidget(undoLabel); diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index cf1b12916..6cd58cc02 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -32,6 +32,7 @@ #include "../../widgets/textdelegate.h" #include "../../xml/vstandardmeasurements.h" #include "../../xml/vindividualmeasurements.h" +#include "../../core/vsettings.h" #include #include @@ -510,7 +511,7 @@ void DialogIncrements::OpenTable() const QString filter(tr("Individual measurements (*.vit)")); //Use standard path to individual measurements - QString path = qApp->getSettings()->value("paths/individual_measurements", QDir::homePath()).toString(); + const QString path = qApp->getSettings()->GetPathIndividualMeasurements(); const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter); if (filePath.isEmpty()) diff --git a/src/app/dialogs/app/dialogindividualmeasurements.cpp b/src/app/dialogs/app/dialogindividualmeasurements.cpp index ea5f45094..f7c8718ce 100644 --- a/src/app/dialogs/app/dialogindividualmeasurements.cpp +++ b/src/app/dialogs/app/dialogindividualmeasurements.cpp @@ -29,13 +29,15 @@ #include "dialogindividualmeasurements.h" #include "ui_dialogindividualmeasurements.h" #include "../../xml/vindividualmeasurements.h" +#include "../../core/vapplication.h" +#include "../../core/vsettings.h" +#include "../../container/vcontainer.h" + #include #include #include #include #include -#include "../../core/vapplication.h" -#include "../../container/vcontainer.h" //--------------------------------------------------------------------------------------------------------------------- DialogIndividualMeasurements::DialogIndividualMeasurements(VContainer *data, const QString &patternPieceName, @@ -195,7 +197,7 @@ void DialogIndividualMeasurements::CheckState() void DialogIndividualMeasurements::OpenTable() { const QString filter(tr("Individual measurements (*.vit)")); - QString path = qApp->getSettings()->value("paths/individual_measurements", QDir::homePath()).toString(); + const QString path = qApp->getSettings()->GetPathIndividualMeasurements(); QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter); if (fileName.isEmpty()) @@ -251,9 +253,8 @@ void DialogIndividualMeasurements::InitUnits() ui->comboBoxUnits->addItem(tr("Millimiters"), QVariant(VDomDocument::UnitsToStr(Unit::Mm))); ui->comboBoxUnits->addItem(tr("Inches"), QVariant(VDomDocument::UnitsToStr(Unit::Inch))); - const QString checkedUnit = qApp->getSettings()->value("configuration/unit", "cm").toString(); // set default unit - const qint32 indexUnit = ui->comboBoxUnits->findData(checkedUnit); + const qint32 indexUnit = ui->comboBoxUnits->findData(qApp->getSettings()->GetUnit()); if (indexUnit != -1) { ui->comboBoxUnits->setCurrentIndex(indexUnit); diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 4d5264391..a8da5a01c 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -35,6 +35,7 @@ #include "../../tools/vabstracttool.h" #include "../../../libs/qmuparser/qmuparsererror.h" #include "../../core/vapplication.h" +#include "../../core/vsettings.h" #include "../../xml/vdomdocument.h" #include #include @@ -512,7 +513,7 @@ qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QSt else { QLocale loc; - if (qApp->getSettings()->value("configuration/osSeparator", 1).toBool()) + if (qApp->getSettings()->GetOsSeparator()) { loc = QLocale::system(); } diff --git a/src/app/main.cpp b/src/app/main.cpp index e51971557..e8d06c2b4 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -28,15 +28,16 @@ #include "mainwindow.h" #include "core/vapplication.h" +#include "core/vsettings.h" +#include "tablewindow.h" +#include "version.h" + #include #include #include #include - #include #include -#include "tablewindow.h" -#include "version.h" //--------------------------------------------------------------------------------------------------------------------- int main(int argc, char *argv[]) @@ -73,7 +74,7 @@ int main(int argc, char *argv[]) qDebug()<<"Built on"<<__DATE__<<"at"<<__TIME__; qDebug()<<"Command-line arguments:"<getSettings()->value("configuration/locale", QLocale::system().name()).toString(); + const QString checkedLocale = qApp->getSettings()->GetLocale(); qDebug()<<"Checked locale:"<getSettings()->value("paths/pattern", QDir::homePath()).toString(); QString dir; if (curFile.isEmpty()) { - dir = path + "/" + tr("pattern") + ".val"; + dir = qApp->getSettings()->GetPathPattern() + "/" + tr("pattern") + ".val"; } else { @@ -1377,7 +1377,7 @@ void MainWindow::Open() { const QString filter(tr("Pattern files (*.val)")); //Get list last open files - const QStringList files = qApp->getSettings()->value("recentFileList").toStringList(); + const QStringList files = qApp->getSettings()->GetRecentFileList(); QString dir; if (files.isEmpty()) { @@ -1464,9 +1464,9 @@ void MainWindow::FileClosedCorrect() WriteSettings(); //File was closed correct. - QStringList restoreFiles = qApp->getSettings()->value("restoreFileList").toStringList(); + QStringList restoreFiles = qApp->getSettings()->GetRestoreFileList(); restoreFiles.removeAll(curFile); - qApp->getSettings()->setValue("restoreFileList", restoreFiles); + qApp->getSettings()->SetRestoreFileList(restoreFiles); // Remove autosave file QFile autofile(curFile +".autosave"); @@ -1997,7 +1997,7 @@ void MainWindow::setCurrentFile(const QString &fileName) } else { - QStringList files = qApp->getSettings()->value("recentFileList").toStringList(); + QStringList files = qApp->getSettings()->GetRecentFileList(); files.removeAll(fileName); files.prepend(fileName); while (files.size() > MaxRecentFiles) @@ -2005,13 +2005,13 @@ void MainWindow::setCurrentFile(const QString &fileName) files.removeLast(); } - qApp->getSettings()->setValue("recentFileList", files); + qApp->getSettings()->SetRecentFileList(files); UpdateRecentFileActions(); - QStringList restoreFiles = qApp->getSettings()->value("restoreFileList").toStringList(); + QStringList restoreFiles = qApp->getSettings()->GetRestoreFileList(); restoreFiles.removeAll(fileName); restoreFiles.prepend(fileName); - qApp->getSettings()->setValue("restoreFileList", restoreFiles); + qApp->getSettings()->SetRestoreFileList(restoreFiles); } shownName+="[*]"; setWindowTitle(shownName); @@ -2034,22 +2034,16 @@ QString MainWindow::strippedName(const QString &fullFileName) */ void MainWindow::ReadSettings() { - restoreGeometry(qApp->getSettings()->value("geometry").toByteArray()); - restoreState(qApp->getSettings()->value("windowState").toByteArray()); + restoreGeometry(qApp->getSettings()->GetGeometry()); + restoreState(qApp->getSettings()->GetWindowState()); // Scene antialiasing - bool graphOutputValue = qApp->getSettings()->value("pattern/graphicalOutput", 1).toBool(); + const bool graphOutputValue = qApp->getSettings()->GetGraphicalOutput(); ui->view->setRenderHint(QPainter::Antialiasing, graphOutputValue); ui->view->setRenderHint(QPainter::SmoothPixmapTransform, graphOutputValue); // Stack limit - bool ok = true; - qint32 count = qApp->getSettings()->value("pattern/undo", 0).toInt(&ok); - if (ok == false) - { - count = 0; - } - qApp->getUndoStack()->setUndoLimit(count); + qApp->getUndoStack()->setUndoLimit(qApp->getSettings()->GetUndoCount()); } //--------------------------------------------------------------------------------------------------------------------- @@ -2058,8 +2052,8 @@ void MainWindow::ReadSettings() */ void MainWindow::WriteSettings() { - qApp->getSettings()->setValue("geometry", saveGeometry()); - qApp->getSettings()->setValue("windowState", saveState()); + qApp->getSettings()->SetGeometry(saveGeometry()); + qApp->getSettings()->SetWindowState(saveState()); } //--------------------------------------------------------------------------------------------------------------------- @@ -2090,9 +2084,8 @@ bool MainWindow::MaybeSave() //--------------------------------------------------------------------------------------------------------------------- void MainWindow::UpdateRecentFileActions() { - QStringList files = qApp->getSettings()->value("recentFileList").toStringList(); - - int numRecentFiles = qMin(files.size(), static_cast(MaxRecentFiles)); + const QStringList files = qApp->getSettings()->GetRecentFileList(); + const int numRecentFiles = qMin(files.size(), static_cast(MaxRecentFiles)); for (int i = 0; i < numRecentFiles; ++i) { @@ -2222,15 +2215,9 @@ void MainWindow::InitAutoSave() connect(autoSaveTimer, &QTimer::timeout, this, &MainWindow::AutoSavePattern); autoSaveTimer->stop(); - bool autoSave = qApp->getSettings()->value("configuration/autosave/state", 1).toBool(); - if (autoSave) + if (qApp->getSettings()->GetAutosaveState()) { - bool ok = true; - qint32 autoTime = qApp->getSettings()->value("configuration/autosave/time", 1).toInt(&ok); - if (ok == false) - { - autoTime = 1; - } + const qint32 autoTime = qApp->getSettings()->GetAutosaveTime(); autoSaveTimer->start(autoTime*60000); qCDebug(vMainWindow)<<"Autosaving each"<getSettings()->value("restoreFileList").toStringList(); + QStringList files = qApp->getSettings()->GetRestoreFileList(); if (files.size() > 0) { qCDebug(vMainWindow)<<"Reopen files after crash."; @@ -2389,7 +2376,7 @@ void MainWindow::ReopenFilesAfterCrash(QStringList &args) } } files.clear(); - qApp->getSettings()->setValue("restoreFileList", files); + qApp->getSettings()->SetRestoreFileList(files); if (restoreFiles.size() > 0) { diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 4fb6a1f72..310fae47d 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -38,6 +38,7 @@ #include "../exception/vexceptionemptyparameter.h" #include "../exception/vexceptionundo.h" #include "../core/undoevent.h" +#include "../core/vsettings.h" #include "vstandardmeasurements.h" #include "vindividualmeasurements.h" #include "../../libs/qmuparser/qmuparsererror.h" @@ -1701,13 +1702,9 @@ void VPattern::CheckTagExists(const QString &tag) //--------------------------------------------------------------------------------------------------------------------- QString VPattern::GetLabelBase(unsigned int index) const { - QString checkedLocale = qApp->getSettings()->value("configuration/label_language", - QLocale::system().bcp47Name()).toString(); - QStringList list = VApplication::LabelLanguages(); - QStringList alphabet; - switch (list.indexOf(checkedLocale)) + switch (list.indexOf(qApp->getSettings()->GetLabelLanguage())) { case 0: // de { @@ -2378,15 +2375,7 @@ void VPattern::SetGradationSizes(const QMap &options) //--------------------------------------------------------------------------------------------------------------------- QString VPattern::GetAuthor() const { - QSettings *settings = qApp->getSettings(); - SCASSERT(settings != nullptr); -#ifdef Q_OS_WIN - QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString(); -#else - QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString(); -#endif - - return UniqueTagText(TagAuthor, user); + return UniqueTagText(TagAuthor, qApp->getSettings()->GetUser()); } //---------------------------------------------------------------------------------------------------------------------