Refactoring - hide settings constructor. Using pointer instead.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-10 12:36:46 +03:00
parent e64e218bf1
commit 227cc6a2c0
13 changed files with 107 additions and 133 deletions

View File

@ -97,9 +97,7 @@ Calculator::Calculator(const QString &formula, bool fromUser)
DefinePostfixOprt(qApp->PostfixOperator(mm_Oprt), MmUnit); DefinePostfixOprt(qApp->PostfixOperator(mm_Oprt), MmUnit);
DefinePostfixOprt(qApp->PostfixOperator(in_Oprt), InchUnit); DefinePostfixOprt(qApp->PostfixOperator(in_Oprt), InchUnit);
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), bool osSeparatorValue = qApp->getSettings()->value("configuration/osSeparator", 1).toBool();
QApplication::applicationName());
bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
if (osSeparatorValue) if (osSeparatorValue)
{ {

View File

@ -57,19 +57,17 @@ CommunityPage::CommunityPage(QWidget *parent):
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void CommunityPage::Apply() void CommunityPage::Apply()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), qApp->getSettings()->setValue("community/server", this->server->text());
QApplication::applicationName()); qApp->getSettings()->setValue("community/serverSecure", this->secureComm->isChecked());
settings.setValue("community/server", this->server->text()); qApp->getSettings()->setValue("community/useProxy", this->useProxy->isChecked());
settings.setValue("community/serverSecure", this->secureComm->isChecked()); qApp->getSettings()->setValue("community/proxyAddress", this->proxyAddress->text());
settings.setValue("community/useProxy", this->useProxy->isChecked()); qApp->getSettings()->setValue("community/proxyPort", this->proxyPort->text());
settings.setValue("community/proxyAddress", this->proxyAddress->text()); qApp->getSettings()->setValue("community/proxyUser", this->proxyUser->text());
settings.setValue("community/proxyPort", this->proxyPort->text()); qApp->getSettings()->setValue("community/proxyPass", this->proxyPass->text());
settings.setValue("community/proxyUser", this->proxyUser->text());
settings.setValue("community/proxyPass", this->proxyPass->text());
settings.setValue("community/username", this->username->text()); qApp->getSettings()->setValue("community/username", this->username->text());
settings.setValue("community/savePassword", this->savePassword->isChecked()); qApp->getSettings()->setValue("community/savePassword", this->savePassword->isChecked());
settings.setValue("community/userpassword", this->userpassword->text()); qApp->getSettings()->setValue("community/userpassword", this->userpassword->text());
} }
@ -101,17 +99,17 @@ void CommunityPage::PasswordCheckChanged()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QGroupBox *CommunityPage::ServerGroup() QGroupBox *CommunityPage::ServerGroup()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QSettings *settings = qApp->getSettings();
QApplication::applicationName()); SCASSERT(settings != nullptr);
QGroupBox *ServerGroup = new QGroupBox(tr("Server")); QGroupBox *ServerGroup = new QGroupBox(tr("Server"));
QFormLayout *serverLayout = new QFormLayout; QFormLayout *serverLayout = new QFormLayout;
CommunityPage::add_lineedit(&this->server, serverLayout, CommunityPage::add_lineedit(&this->server, serverLayout,
settings.value("community/server", "community.valentina-project.org").toString(), tr("Server name/IP")); settings->value("community/server", "community.valentina-project.org").toString(), tr("Server name/IP"));
CommunityPage::add_checkbox(&this->secureComm, serverLayout, CommunityPage::add_checkbox(&this->secureComm, serverLayout,
settings.value("community/serverSecure", 0).toBool(), tr("Secure connection")); settings->value("community/serverSecure", 0).toBool(), tr("Secure connection"));
ServerGroup->setLayout(serverLayout); ServerGroup->setLayout(serverLayout);
return ServerGroup; return ServerGroup;
@ -138,26 +136,24 @@ void CommunityPage::add_lineedit(QLineEdit** theline, QFormLayout *layout, QStri
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QGroupBox *CommunityPage::ProxyGroup() QGroupBox *CommunityPage::ProxyGroup()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QGroupBox *proxyGroup = new QGroupBox(tr("Proxy settings")); QGroupBox *proxyGroup = new QGroupBox(tr("Proxy settings"));
QFormLayout *proxyLayout = new QFormLayout; QFormLayout *proxyLayout = new QFormLayout;
CommunityPage::add_checkbox(&this->useProxy, proxyLayout, CommunityPage::add_checkbox(&this->useProxy, proxyLayout,
settings.value("community/useProxy", 0).toBool(), tr("Use Proxy")); qApp->getSettings()->value("community/useProxy", 0).toBool(), tr("Use Proxy"));
CommunityPage::add_lineedit(&this->proxyAddress, proxyLayout, CommunityPage::add_lineedit(&this->proxyAddress, proxyLayout,
settings.value("community/proxyAddress", "").toString(), tr("Proxy address")); qApp->getSettings()->value("community/proxyAddress", "").toString(), tr("Proxy address"));
CommunityPage::add_lineedit(&this->proxyPort, proxyLayout, CommunityPage::add_lineedit(&this->proxyPort, proxyLayout,
settings.value("community/proxyPort", "").toString(), tr("Proxy port")); qApp->getSettings()->value("community/proxyPort", "").toString(), tr("Proxy port"));
CommunityPage::add_lineedit(&this->proxyUser, proxyLayout, CommunityPage::add_lineedit(&this->proxyUser, proxyLayout,
settings.value("community/proxyUser", "").toString(), tr("Proxy user")); qApp->getSettings()->value("community/proxyUser", "").toString(), tr("Proxy user"));
CommunityPage::add_lineedit(&this->proxyPass, proxyLayout, CommunityPage::add_lineedit(&this->proxyPass, proxyLayout,
settings.value("community/proxyPass", "").toString(), tr("Proxy pass")); qApp->getSettings()->value("community/proxyPass", "").toString(), tr("Proxy pass"));
connect(this->useProxy, &QCheckBox::stateChanged, this, &CommunityPage::ProxyCheckChanged); connect(this->useProxy, &QCheckBox::stateChanged, this, &CommunityPage::ProxyCheckChanged);
this->ProxyCheckChanged(); this->ProxyCheckChanged();
@ -170,19 +166,17 @@ QGroupBox *CommunityPage::ProxyGroup()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QGroupBox *CommunityPage::UserGroup() QGroupBox *CommunityPage::UserGroup()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QGroupBox *userGroup = new QGroupBox(tr("User settings")); QGroupBox *userGroup = new QGroupBox(tr("User settings"));
QFormLayout *userLayout = new QFormLayout; QFormLayout *userLayout = new QFormLayout;
CommunityPage::add_lineedit(&this->username, userLayout, CommunityPage::add_lineedit(&this->username, userLayout,
settings.value("community/username", "").toString(), tr("User Name")); qApp->getSettings()->value("community/username", "").toString(), tr("User Name"));
CommunityPage::add_checkbox(&this->savePassword, userLayout, CommunityPage::add_checkbox(&this->savePassword, userLayout,
settings.value("community/savePassword", 0).toBool(), tr("Save password")); qApp->getSettings()->value("community/savePassword", 0).toBool(), tr("Save password"));
CommunityPage::add_lineedit(&this->userpassword, userLayout, CommunityPage::add_lineedit(&this->userpassword, userLayout,
settings.value("community/userpassword", "").toString(), tr("Password")); qApp->getSettings()->value("community/userpassword", "").toString(), tr("Password"));
connect(this->savePassword, &QCheckBox::stateChanged, this, &CommunityPage::PasswordCheckChanged); connect(this->savePassword, &QCheckBox::stateChanged, this, &CommunityPage::PasswordCheckChanged);
this->PasswordCheckChanged(); this->PasswordCheckChanged();

View File

@ -59,10 +59,8 @@ ConfigurationPage::ConfigurationPage(QWidget *parent)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void ConfigurationPage::Apply() void ConfigurationPage::Apply()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), qApp->getSettings()->setValue("configuration/autosave/state", autoSaveCheck->isChecked());
QApplication::applicationName()); qApp->getSettings()->setValue("configuration/autosave/time", autoTime->value());
settings.setValue("configuration/autosave/state", autoSaveCheck->isChecked());
settings.setValue("configuration/autosave/time", autoTime->value());
QTimer *autoSaveTimer = qApp->getAutoSaveTimer(); QTimer *autoSaveTimer = qApp->getAutoSaveTimer();
SCASSERT(autoSaveTimer); SCASSERT(autoSaveTimer);
@ -76,12 +74,12 @@ void ConfigurationPage::Apply()
autoSaveTimer->stop(); autoSaveTimer->stop();
} }
settings.setValue("configuration/osSeparator", osOptionCheck->isChecked()); qApp->getSettings()->setValue("configuration/osSeparator", osOptionCheck->isChecked());
if (langChanged) if (langChanged)
{ {
QString locale = qvariant_cast<QString>(langCombo->itemData(langCombo->currentIndex())); QString locale = qvariant_cast<QString>(langCombo->itemData(langCombo->currentIndex()));
settings.setValue("configuration/locale", locale); qApp->getSettings()->setValue("configuration/locale", locale);
langChanged = false; langChanged = false;
QString text = QString(tr("Setup user interface language updated and will be used the next time start") + " " + QString text = QString(tr("Setup user interface language updated and will be used the next time start") + " " +
QApplication::applicationName()); QApplication::applicationName());
@ -90,7 +88,7 @@ void ConfigurationPage::Apply()
if (this->unitChanged) if (this->unitChanged)
{ {
QString unit = qvariant_cast<QString>(this->unitCombo->itemData(this->unitCombo->currentIndex())); QString unit = qvariant_cast<QString>(this->unitCombo->itemData(this->unitCombo->currentIndex()));
settings.setValue("configuration/unit", unit); qApp->getSettings()->setValue("configuration/unit", unit);
this->unitChanged = false; this->unitChanged = false;
QString text = QString(tr("Default unit updated and will be used the next pattern creation")); QString text = QString(tr("Default unit updated and will be used the next pattern creation"));
QMessageBox::information(this, QApplication::applicationName(), text); QMessageBox::information(this, QApplication::applicationName(), text);
@ -112,20 +110,20 @@ void ConfigurationPage::UnitChanged()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QGroupBox *ConfigurationPage::SaveGroup() QGroupBox *ConfigurationPage::SaveGroup()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QSettings *settings = qApp->getSettings();
QApplication::applicationName()); SCASSERT(settings != nullptr);
QGroupBox *saveGroup = new QGroupBox(tr("Save")); QGroupBox *saveGroup = new QGroupBox(tr("Save"));
autoSaveCheck = new QCheckBox(tr("Auto-save modified pattern")); autoSaveCheck = new QCheckBox(tr("Auto-save modified pattern"));
bool autoSaveValue = settings.value("configuration/autosave/state", 1).toBool(); bool autoSaveValue = settings->value("configuration/autosave/state", 1).toBool();
autoSaveCheck->setChecked(autoSaveValue); autoSaveCheck->setChecked(autoSaveValue);
QLabel *intervalLabel = new QLabel(tr("Interval:")); QLabel *intervalLabel = new QLabel(tr("Interval:"));
autoTime = new QSpinBox(); autoTime = new QSpinBox();
bool ok = true; bool ok = true;
qint32 autoTimeValue = settings.value("configuration/autosave/time", 5).toInt(&ok); qint32 autoTimeValue = settings->value("configuration/autosave/time", 5).toInt(&ok);
if (ok == false) if (ok == false)
{ {
autoTimeValue = 5; autoTimeValue = 5;
@ -148,8 +146,8 @@ QGroupBox *ConfigurationPage::SaveGroup()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QGroupBox *ConfigurationPage::LangGroup() QGroupBox *ConfigurationPage::LangGroup()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QSettings *settings = qApp->getSettings();
QApplication::applicationName()); SCASSERT(settings != nullptr);
QGroupBox *langGroup = new QGroupBox(tr("Language")); QGroupBox *langGroup = new QGroupBox(tr("Language"));
QLabel *guiLabel = new QLabel(tr("GUI language")); QLabel *guiLabel = new QLabel(tr("GUI language"));
@ -158,7 +156,7 @@ QGroupBox *ConfigurationPage::LangGroup()
// format systems language // format systems language
QString defaultLocale = QLocale::system().name(); // e.g. "de_DE" QString defaultLocale = QLocale::system().name(); // e.g. "de_DE"
defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de" defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de"
QString checkedLocale = settings.value("configuration/locale", defaultLocale).toString(); QString checkedLocale = settings->value("configuration/locale", defaultLocale).toString();
QString m_langPath = qApp->translationsPath(); QString m_langPath = qApp->translationsPath();
QDir dir(m_langPath); QDir dir(m_langPath);
@ -199,7 +197,7 @@ QGroupBox *ConfigurationPage::LangGroup()
QLabel *separatorLabel = new QLabel(tr("Decimal separator parts")); QLabel *separatorLabel = new QLabel(tr("Decimal separator parts"));
osOptionCheck = new QCheckBox(tr("With OS options (%1)").arg(QLocale::system().decimalPoint().toLatin1())); osOptionCheck = new QCheckBox(tr("With OS options (%1)").arg(QLocale::system().decimalPoint().toLatin1()));
bool osOptionValue = settings.value("configuration/osSeparator", 1).toBool(); bool osOptionValue = settings->value("configuration/osSeparator", 1).toBool();
osOptionCheck->setChecked(osOptionValue); osOptionCheck->setChecked(osOptionValue);
QHBoxLayout *separatorLayout = new QHBoxLayout; QHBoxLayout *separatorLayout = new QHBoxLayout;
@ -210,7 +208,7 @@ QGroupBox *ConfigurationPage::LangGroup()
this->unitCombo = new QComboBox; this->unitCombo = new QComboBox;
QLabel *unitLabel = new QLabel(tr("Default unit")); QLabel *unitLabel = new QLabel(tr("Default unit"));
QString checkedUnit = settings.value("configuration/unit", "cm").toString(); QString checkedUnit = settings->value("configuration/unit", "cm").toString();
this->unitCombo->addItem(tr("Centimeters"), "cm"); this->unitCombo->addItem(tr("Centimeters"), "cm");
this->unitCombo->addItem(tr("Milimiters"), "mm"); this->unitCombo->addItem(tr("Milimiters"), "mm");

View File

@ -60,11 +60,8 @@ PathPage::PathPage(QWidget *parent)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PathPage::Apply() void PathPage::Apply()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), qApp->getSettings()->setValue("paths/individual_measurements", pathTable->item(0, 1)->text());
QApplication::applicationName()); qApp->getSettings()->setValue("paths/pattern", pathTable->item(1, 1)->text());
settings.setValue("paths/individual_measurements", pathTable->item(0, 1)->text());
settings.setValue("paths/pattern", pathTable->item(1, 1)->text());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -140,17 +137,14 @@ void PathPage::InitTable()
QStringList tableHeader{tr("Type"), tr("Path")}; QStringList tableHeader{tr("Type"), tr("Path")};
pathTable->setHorizontalHeaderLabels(tableHeader); pathTable->setHorizontalHeaderLabels(tableHeader);
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QString path; QString path;
pathTable->setItem(0, 0, new QTableWidgetItem(tr("Individual measurements"))); pathTable->setItem(0, 0, new QTableWidgetItem(tr("Individual measurements")));
path = settings.value("paths/individual_measurements", QDir::homePath()).toString(); path = qApp->getSettings()->value("paths/individual_measurements", QDir::homePath()).toString();
pathTable->setItem(0, 1, new QTableWidgetItem(path)); pathTable->setItem(0, 1, new QTableWidgetItem(path));
pathTable->setItem(1, 0, new QTableWidgetItem(tr("Patterns"))); pathTable->setItem(1, 0, new QTableWidgetItem(tr("Patterns")));
path = settings.value("paths/pattern", QDir::homePath()).toString(); path = qApp->getSettings()->value("paths/pattern", QDir::homePath()).toString();
pathTable->setItem(1, 1, new QTableWidgetItem(path)); pathTable->setItem(1, 1, new QTableWidgetItem(path));
pathTable->verticalHeader()->setDefaultSectionSize(20); pathTable->verticalHeader()->setDefaultSectionSize(20);

View File

@ -56,35 +56,33 @@ PatternPage::PatternPage(QWidget *parent):
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PatternPage::Apply() void PatternPage::Apply()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), qApp->getSettings()->setValue("pattern/user", userName->text());
QApplication::applicationName());
settings.setValue("pattern/user", userName->text());
// Scene antialiasing // Scene antialiasing
settings.setValue("pattern/graphicalOutput", graphOutputCheck->isChecked()); qApp->getSettings()->setValue("pattern/graphicalOutput", graphOutputCheck->isChecked());
qApp->getSceneView()->setRenderHint(QPainter::Antialiasing, graphOutputCheck->isChecked()); qApp->getSceneView()->setRenderHint(QPainter::Antialiasing, graphOutputCheck->isChecked());
qApp->getSceneView()->setRenderHint(QPainter::SmoothPixmapTransform, 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 /* 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 * non-empty stack might delete the command at the current index. Calling setUndoLimit() on a non-empty stack
* prints a warning and does nothing.*/ * prints a warning and does nothing.*/
settings.setValue("pattern/undo", undoCount->value()); qApp->getSettings()->setValue("pattern/undo", undoCount->value());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QGroupBox *PatternPage::UserGroup() QGroupBox *PatternPage::UserGroup()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QSettings *settings = qApp->getSettings();
QApplication::applicationName()); SCASSERT(settings != nullptr);
QGroupBox *userGroup = new QGroupBox(tr("User")); QGroupBox *userGroup = new QGroupBox(tr("User"));
QLabel *nameLabel = new QLabel(tr("User name")); QLabel *nameLabel = new QLabel(tr("User name"));
userName = new QLineEdit; userName = new QLineEdit;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QString user = settings.value("pattern/user", QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString(); QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString();
#else #else
QString user = settings.value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString(); QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString();
#endif #endif
userName->setText(user); userName->setText(user);
@ -101,13 +99,10 @@ QGroupBox *PatternPage::UserGroup()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QGroupBox *PatternPage::GraphOutputGroup() QGroupBox *PatternPage::GraphOutputGroup()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QGroupBox *graphOutputGroup = new QGroupBox(tr("Graphical output")); QGroupBox *graphOutputGroup = new QGroupBox(tr("Graphical output"));
graphOutputCheck = new QCheckBox(tr("Use antialiasing")); graphOutputCheck = new QCheckBox(tr("Use antialiasing"));
bool graphOutputValue = settings.value("pattern/graphicalOutput", 1).toBool(); bool graphOutputValue = qApp->getSettings()->value("pattern/graphicalOutput", 1).toBool();
graphOutputCheck->setChecked(graphOutputValue); graphOutputCheck->setChecked(graphOutputValue);
QHBoxLayout *graphLayout = new QHBoxLayout; QHBoxLayout *graphLayout = new QHBoxLayout;
@ -122,15 +117,12 @@ QGroupBox *PatternPage::GraphOutputGroup()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QGroupBox *PatternPage::UndoGroup() QGroupBox *PatternPage::UndoGroup()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QGroupBox *undoGroup = new QGroupBox(tr("Undo")); QGroupBox *undoGroup = new QGroupBox(tr("Undo"));
QLabel *undoLabel = new QLabel(tr("Count steps (0 - no limit)")); QLabel *undoLabel = new QLabel(tr("Count steps (0 - no limit)"));
undoCount = new QSpinBox; undoCount = new QSpinBox;
undoCount->setMinimum(0); undoCount->setMinimum(0);
bool ok = true; bool ok = true;
qint32 count = settings.value("pattern/undo", 0).toInt(&ok); qint32 count = qApp->getSettings()->value("pattern/undo", 0).toInt(&ok);
if (ok == false) if (ok == false)
{ {
count = 0; count = 0;

View File

@ -453,9 +453,7 @@ void DialogIncrements::OpenTable()
const QString filter(tr("Individual measurements (*.vit)")); const QString filter(tr("Individual measurements (*.vit)"));
//Use standard path to individual measurements //Use standard path to individual measurements
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QString path = qApp->getSettings()->value("paths/individual_measurements", QDir::homePath()).toString();
QApplication::applicationName());
QString path = settings.value("paths/individual_measurements", QDir::homePath()).toString();
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter); const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter);
if (filePath.isEmpty()) if (filePath.isEmpty())

View File

@ -193,10 +193,7 @@ void DialogIndividualMeasurements::CheckState()
void DialogIndividualMeasurements::OpenTable() void DialogIndividualMeasurements::OpenTable()
{ {
const QString filter(tr("Individual measurements (*.vit)")); const QString filter(tr("Individual measurements (*.vit)"));
QString path = qApp->getSettings()->value("paths/individual_measurements", QDir::homePath()).toString();
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QString path = settings.value("paths/individual_measurements", QDir::homePath()).toString();
QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter); QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter);
if (fileName.isEmpty()) if (fileName.isEmpty())
@ -248,14 +245,11 @@ void DialogIndividualMeasurements::NewTable()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogIndividualMeasurements::InitUnits() void DialogIndividualMeasurements::InitUnits()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
ui->comboBoxUnits->addItem(tr("Centimeters"), QVariant(VDomDocument::UnitsToStr(Unit::Cm))); ui->comboBoxUnits->addItem(tr("Centimeters"), QVariant(VDomDocument::UnitsToStr(Unit::Cm)));
ui->comboBoxUnits->addItem(tr("Milimiters"), QVariant(VDomDocument::UnitsToStr(Unit::Mm))); ui->comboBoxUnits->addItem(tr("Milimiters"), QVariant(VDomDocument::UnitsToStr(Unit::Mm)));
ui->comboBoxUnits->addItem(tr("Inches"), QVariant(VDomDocument::UnitsToStr(Unit::Inch, true))); ui->comboBoxUnits->addItem(tr("Inches"), QVariant(VDomDocument::UnitsToStr(Unit::Inch, true)));
const QString checkedUnit = settings.value("configuration/unit", "cm").toString(); const QString checkedUnit = qApp->getSettings()->value("configuration/unit", "cm").toString();
// set default unit // set default unit
const qint32 indexUnit = ui->comboBoxUnits->findData(checkedUnit); const qint32 indexUnit = ui->comboBoxUnits->findData(checkedUnit);
if (indexUnit != -1) if (indexUnit != -1)

View File

@ -31,6 +31,7 @@
#include <QSettings> #include <QSettings>
#include <QPushButton> #include <QPushButton>
#include "../../xml/vpattern.h" #include "../../xml/vpattern.h"
#include "../../widgets/vapplication.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) : DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) :
@ -40,12 +41,12 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent)
SCASSERT(doc != nullptr); SCASSERT(doc != nullptr);
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QSettings *settings = qApp->getSettings();
QApplication::applicationName()); SCASSERT(settings != nullptr);
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QString user = settings.value("pattern/user", QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString(); QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString();
#else #else
QString user = settings.value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString(); QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString();
#endif #endif
ui->lineEditAuthor->setText(this->doc->UniqueTagText("author", user)); ui->lineEditAuthor->setText(this->doc->UniqueTagText("author", user));

View File

@ -459,11 +459,7 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la
const qreal result = cal->EvalFormula(formula); const qreal result = cal->EvalFormula(formula);
delete cal; delete cal;
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), if (qApp->getSettings()->value("configuration/osSeparator", 1).toBool())
QApplication::applicationName());
bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
if (osSeparatorValue)
{ {
QLocale loc = QLocale::system(); QLocale loc = QLocale::system();
label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true)); label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true));

View File

@ -142,11 +142,11 @@ int main(int argc, char *argv[])
// Setting the Application version // Setting the Application version
app.setApplicationVersion(APP_VERSION); app.setApplicationVersion(APP_VERSION);
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), app.OpenSettings();
QApplication::applicationName());
QString defaultLocale = QLocale::system().name(); // e.g. "de_DE" QString defaultLocale = QLocale::system().name(); // e.g. "de_DE"
defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de" defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de"
QString checkedLocale = settings.value("configuration/locale", defaultLocale).toString(); QString checkedLocale = qApp->getSettings()->value("configuration/locale", defaultLocale).toString();
QTranslator qtTranslator; QTranslator qtTranslator;
qtTranslator.load("qt_" + checkedLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); qtTranslator.load("qt_" + checkedLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));

View File

@ -1409,9 +1409,7 @@ void MainWindow::ActionDetails(bool checked)
bool MainWindow::SaveAs() bool MainWindow::SaveAs()
{ {
QString filters(tr("Pattern files (*.val)")); QString filters(tr("Pattern files (*.val)"));
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QString path = qApp->getSettings()->value("paths/pattern", QDir::homePath()).toString();
QApplication::applicationName());
QString path = settings.value("paths/pattern", QDir::homePath()).toString();
QString dir; QString dir;
if (curFile.isEmpty()) if (curFile.isEmpty())
{ {
@ -1467,9 +1465,7 @@ void MainWindow::Open()
{ {
const QString filter(tr("Pattern files (*.val)")); const QString filter(tr("Pattern files (*.val)"));
//Get list last open files //Get list last open files
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), const QStringList files = qApp->getSettings()->value("recentFileList").toStringList();
QApplication::applicationName());
const QStringList files = settings.value("recentFileList").toStringList();
QString dir; QString dir;
if (files.isEmpty()) if (files.isEmpty())
{ {
@ -1936,9 +1932,7 @@ void MainWindow::setCurrentFile(const QString &fileName)
} }
else else
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QStringList files = qApp->getSettings()->value("recentFileList").toStringList();
QApplication::applicationName());
QStringList files = settings.value("recentFileList").toStringList();
files.removeAll(fileName); files.removeAll(fileName);
files.prepend(fileName); files.prepend(fileName);
while (files.size() > MaxRecentFiles) while (files.size() > MaxRecentFiles)
@ -1946,7 +1940,7 @@ void MainWindow::setCurrentFile(const QString &fileName)
files.removeLast(); files.removeLast();
} }
settings.setValue("recentFileList", files); qApp->getSettings()->setValue("recentFileList", files);
UpdateRecentFileActions(); UpdateRecentFileActions();
} }
shownName+="[*]"; shownName+="[*]";
@ -1970,21 +1964,19 @@ QString MainWindow::strippedName(const QString &fullFileName)
*/ */
void MainWindow::ReadSettings() void MainWindow::ReadSettings()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QPoint pos = qApp->getSettings()->value("pos", QPoint(10, 10)).toPoint();
QApplication::applicationName()); QSize size = qApp->getSettings()->value("size", QSize(1000, 800)).toSize();
QPoint pos = settings.value("pos", QPoint(10, 10)).toPoint();
QSize size = settings.value("size", QSize(1000, 800)).toSize();
resize(size); resize(size);
move(pos); move(pos);
// Scene antialiasing // Scene antialiasing
bool graphOutputValue = settings.value("pattern/graphicalOutput", 1).toBool(); bool graphOutputValue = qApp->getSettings()->value("pattern/graphicalOutput", 1).toBool();
view->setRenderHint(QPainter::Antialiasing, graphOutputValue); view->setRenderHint(QPainter::Antialiasing, graphOutputValue);
view->setRenderHint(QPainter::SmoothPixmapTransform, graphOutputValue); view->setRenderHint(QPainter::SmoothPixmapTransform, graphOutputValue);
// Stack limit // Stack limit
bool ok = true; bool ok = true;
qint32 count = settings.value("pattern/undo", 0).toInt(&ok); qint32 count = qApp->getSettings()->value("pattern/undo", 0).toInt(&ok);
if (ok == false) if (ok == false)
{ {
count = 0; count = 0;
@ -1998,10 +1990,8 @@ void MainWindow::ReadSettings()
*/ */
void MainWindow::WriteSettings() void MainWindow::WriteSettings()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), qApp->getSettings()->setValue("pos", pos());
QApplication::applicationName()); qApp->getSettings()->setValue("size", size());
settings.setValue("pos", pos());
settings.setValue("size", size());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -2032,9 +2022,7 @@ bool MainWindow::MaybeSave()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindow::UpdateRecentFileActions() void MainWindow::UpdateRecentFileActions()
{ {
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QStringList files = qApp->getSettings()->value("recentFileList").toStringList();
QApplication::applicationName());
QStringList files = settings.value("recentFileList").toStringList();
int numRecentFiles = qMin(files.size(), static_cast<int>(MaxRecentFiles)); int numRecentFiles = qMin(files.size(), static_cast<int>(MaxRecentFiles));
@ -2128,13 +2116,11 @@ void MainWindow::InitAutoSave()
connect(autoSaveTimer, &QTimer::timeout, this, &MainWindow::AutoSavePattern); connect(autoSaveTimer, &QTimer::timeout, this, &MainWindow::AutoSavePattern);
autoSaveTimer->stop(); autoSaveTimer->stop();
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), bool autoSave = qApp->getSettings()->value("configuration/autosave/state", 1).toBool();
QApplication::applicationName());
bool autoSave = settings.value("configuration/autosave/state", 1).toBool();
if (autoSave) if (autoSave)
{ {
bool ok = true; bool ok = true;
qint32 autoTime = settings.value("configuration/autosave/time", 5).toInt(&ok); qint32 autoTime = qApp->getSettings()->value("configuration/autosave/time", 5).toInt(&ok);
if (ok == false) if (ok == false)
{ {
autoTime = 5; autoTime = 5;

View File

@ -38,7 +38,6 @@
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QProcess> #include <QProcess>
#include <QSettings>
#include <QUndoStack> #include <QUndoStack>
#include <QtMath> #include <QtMath>
@ -59,7 +58,7 @@ VApplication::VApplication(int &argc, char **argv)
guiTexts(QMap<QString, VTranslation>()), descriptions(QMap<QString, VTranslation>()), guiTexts(QMap<QString, VTranslation>()), descriptions(QMap<QString, VTranslation>()),
variables(QMap<QString, VTranslation>()), functions(QMap<QString, VTranslation>()), variables(QMap<QString, VTranslation>()), functions(QMap<QString, VTranslation>()),
postfixOperators(QMap<QString, VTranslation>()), undoStack(nullptr), sceneView(nullptr), autoSaveTimer(nullptr), postfixOperators(QMap<QString, VTranslation>()), undoStack(nullptr), sceneView(nullptr), autoSaveTimer(nullptr),
mainWindow(nullptr), openingPattern(false) mainWindow(nullptr), openingPattern(false), settings(nullptr)
{ {
undoStack = new QUndoStack(this); undoStack = new QUndoStack(this);
@ -1796,9 +1795,7 @@ QString VApplication::FormulaFromUser(const QString &formula)
} }
} }
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), bool osSeparatorValue = getSettings()->value("configuration/osSeparator", 1).toBool();
QApplication::applicationName());
bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
QLocale loc = QLocale::system(); QLocale loc = QLocale::system();
if (loc != QLocale(QLocale::C) && osSeparatorValue) if (loc != QLocale(QLocale::C) && osSeparatorValue)
@ -1914,9 +1911,7 @@ QString VApplication::FormulaToUser(const QString &formula)
} }
} }
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), bool osSeparatorValue = getSettings()->value("configuration/osSeparator", 1).toBool();
QApplication::applicationName());
bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
QLocale loc = QLocale::system(); QLocale loc = QLocale::system();
if (loc != QLocale::C && osSeparatorValue) if (loc != QLocale::C && osSeparatorValue)
@ -1978,4 +1973,25 @@ void VApplication::setOpeningPattern()
openingPattern = !openingPattern; openingPattern = !openingPattern;
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VApplication::OpenSettings get acsses to application settings.
*
* Because we can create object in constructor we open file separately.
*/
void VApplication::OpenSettings()
{
settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName(), this);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VApplication::getSettings hide settings constructor.
* @return pointer to class for acssesing to settings in ini file.
*/
QSettings *VApplication::getSettings()
{
SCASSERT(settings != nullptr);
return settings;
}

View File

@ -32,8 +32,9 @@
#include <QApplication> #include <QApplication>
#include "../options.h" #include "../options.h"
#include "vtranslation.h" #include "vtranslation.h"
#include <QSettings>
class VApplication; class VApplication;// used in define
class QUndoStack; class QUndoStack;
class VMainGraphicsView; class VMainGraphicsView;
@ -80,6 +81,8 @@ public:
void setMainWindow(QWidget *value); void setMainWindow(QWidget *value);
bool getOpeningPattern() const; bool getOpeningPattern() const;
void setOpeningPattern(); void setOpeningPattern();
void OpenSettings();
QSettings *getSettings();
private: private:
Q_DISABLE_COPY(VApplication) Q_DISABLE_COPY(VApplication)
Unit _patternUnit; Unit _patternUnit;
@ -105,6 +108,10 @@ private:
* we can allow user use Undo option. * we can allow user use Undo option.
*/ */
bool openingPattern; bool openingPattern;
/**
* @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable.
*/
QSettings *settings;
void InitLineWidth(); void InitLineWidth();
void InitMeasurements(); void InitMeasurements();
void InitVariables(); void InitVariables();