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(in_Oprt), InchUnit);
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
bool osSeparatorValue = qApp->getSettings()->value("configuration/osSeparator", 1).toBool();
if (osSeparatorValue)
{

View File

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

View File

@ -59,10 +59,8 @@ ConfigurationPage::ConfigurationPage(QWidget *parent)
//---------------------------------------------------------------------------------------------------------------------
void ConfigurationPage::Apply()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
settings.setValue("configuration/autosave/state", autoSaveCheck->isChecked());
settings.setValue("configuration/autosave/time", autoTime->value());
qApp->getSettings()->setValue("configuration/autosave/state", autoSaveCheck->isChecked());
qApp->getSettings()->setValue("configuration/autosave/time", autoTime->value());
QTimer *autoSaveTimer = qApp->getAutoSaveTimer();
SCASSERT(autoSaveTimer);
@ -76,12 +74,12 @@ void ConfigurationPage::Apply()
autoSaveTimer->stop();
}
settings.setValue("configuration/osSeparator", osOptionCheck->isChecked());
qApp->getSettings()->setValue("configuration/osSeparator", osOptionCheck->isChecked());
if (langChanged)
{
QString locale = qvariant_cast<QString>(langCombo->itemData(langCombo->currentIndex()));
settings.setValue("configuration/locale", locale);
qApp->getSettings()->setValue("configuration/locale", locale);
langChanged = false;
QString text = QString(tr("Setup user interface language updated and will be used the next time start") + " " +
QApplication::applicationName());
@ -90,7 +88,7 @@ void ConfigurationPage::Apply()
if (this->unitChanged)
{
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;
QString text = QString(tr("Default unit updated and will be used the next pattern creation"));
QMessageBox::information(this, QApplication::applicationName(), text);
@ -112,20 +110,20 @@ void ConfigurationPage::UnitChanged()
//---------------------------------------------------------------------------------------------------------------------
QGroupBox *ConfigurationPage::SaveGroup()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
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();
bool autoSaveValue = settings->value("configuration/autosave/state", 1).toBool();
autoSaveCheck->setChecked(autoSaveValue);
QLabel *intervalLabel = new QLabel(tr("Interval:"));
autoTime = new QSpinBox();
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)
{
autoTimeValue = 5;
@ -148,8 +146,8 @@ QGroupBox *ConfigurationPage::SaveGroup()
//---------------------------------------------------------------------------------------------------------------------
QGroupBox *ConfigurationPage::LangGroup()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QSettings *settings = qApp->getSettings();
SCASSERT(settings != nullptr);
QGroupBox *langGroup = new QGroupBox(tr("Language"));
QLabel *guiLabel = new QLabel(tr("GUI language"));
@ -158,7 +156,7 @@ QGroupBox *ConfigurationPage::LangGroup()
// format systems language
QString defaultLocale = QLocale::system().name(); // e.g. "de_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();
QDir dir(m_langPath);
@ -199,7 +197,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();
bool osOptionValue = settings->value("configuration/osSeparator", 1).toBool();
osOptionCheck->setChecked(osOptionValue);
QHBoxLayout *separatorLayout = new QHBoxLayout;
@ -210,7 +208,7 @@ QGroupBox *ConfigurationPage::LangGroup()
this->unitCombo = new QComboBox;
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("Milimiters"), "mm");

View File

@ -60,11 +60,8 @@ PathPage::PathPage(QWidget *parent)
//---------------------------------------------------------------------------------------------------------------------
void PathPage::Apply()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
settings.setValue("paths/individual_measurements", pathTable->item(0, 1)->text());
settings.setValue("paths/pattern", pathTable->item(1, 1)->text());
qApp->getSettings()->setValue("paths/individual_measurements", pathTable->item(0, 1)->text());
qApp->getSettings()->setValue("paths/pattern", pathTable->item(1, 1)->text());
}
//---------------------------------------------------------------------------------------------------------------------
@ -140,17 +137,14 @@ void PathPage::InitTable()
QStringList tableHeader{tr("Type"), tr("Path")};
pathTable->setHorizontalHeaderLabels(tableHeader);
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QString path;
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(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->verticalHeader()->setDefaultSectionSize(20);

View File

@ -56,35 +56,33 @@ PatternPage::PatternPage(QWidget *parent):
//---------------------------------------------------------------------------------------------------------------------
void PatternPage::Apply()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
settings.setValue("pattern/user", userName->text());
qApp->getSettings()->setValue("pattern/user", userName->text());
// 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::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.*/
settings.setValue("pattern/undo", undoCount->value());
qApp->getSettings()->setValue("pattern/undo", undoCount->value());
}
//---------------------------------------------------------------------------------------------------------------------
QGroupBox *PatternPage::UserGroup()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
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();
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();
QString user = settings->value("pattern/user", QString::fromLocal8Bit(qgetenv("USER").constData())).toString();
#endif
userName->setText(user);
@ -101,13 +99,10 @@ QGroupBox *PatternPage::UserGroup()
//---------------------------------------------------------------------------------------------------------------------
QGroupBox *PatternPage::GraphOutputGroup()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QGroupBox *graphOutputGroup = new QGroupBox(tr("Graphical output"));
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);
QHBoxLayout *graphLayout = new QHBoxLayout;
@ -122,15 +117,12 @@ QGroupBox *PatternPage::GraphOutputGroup()
//---------------------------------------------------------------------------------------------------------------------
QGroupBox *PatternPage::UndoGroup()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QGroupBox *undoGroup = new QGroupBox(tr("Undo"));
QLabel *undoLabel = new QLabel(tr("Count steps (0 - no limit)"));
undoCount = new QSpinBox;
undoCount->setMinimum(0);
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)
{
count = 0;

View File

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

View File

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

View File

@ -31,6 +31,7 @@
#include <QSettings>
#include <QPushButton>
#include "../../xml/vpattern.h"
#include "../../widgets/vapplication.h"
//---------------------------------------------------------------------------------------------------------------------
DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent) :
@ -40,12 +41,12 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, QWidget *parent)
SCASSERT(doc != nullptr);
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QSettings *settings = qApp->getSettings();
SCASSERT(settings != nullptr);
#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
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
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);
delete cal;
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
if (osSeparatorValue)
if (qApp->getSettings()->value("configuration/osSeparator", 1).toBool())
{
QLocale loc = QLocale::system();
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
app.setApplicationVersion(APP_VERSION);
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
app.OpenSettings();
QString defaultLocale = QLocale::system().name(); // e.g. "de_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;
qtTranslator.load("qt_" + checkedLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));

View File

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

View File

@ -38,7 +38,6 @@
#include <QDebug>
#include <QDir>
#include <QProcess>
#include <QSettings>
#include <QUndoStack>
#include <QtMath>
@ -59,7 +58,7 @@ VApplication::VApplication(int &argc, char **argv)
guiTexts(QMap<QString, VTranslation>()), descriptions(QMap<QString, VTranslation>()),
variables(QMap<QString, VTranslation>()), functions(QMap<QString, VTranslation>()),
postfixOperators(QMap<QString, VTranslation>()), undoStack(nullptr), sceneView(nullptr), autoSaveTimer(nullptr),
mainWindow(nullptr), openingPattern(false)
mainWindow(nullptr), openingPattern(false), settings(nullptr)
{
undoStack = new QUndoStack(this);
@ -1796,9 +1795,7 @@ QString VApplication::FormulaFromUser(const QString &formula)
}
}
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
bool osSeparatorValue = getSettings()->value("configuration/osSeparator", 1).toBool();
QLocale loc = QLocale::system();
if (loc != QLocale(QLocale::C) && osSeparatorValue)
@ -1914,9 +1911,7 @@ QString VApplication::FormulaToUser(const QString &formula)
}
}
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
bool osSeparatorValue = getSettings()->value("configuration/osSeparator", 1).toBool();
QLocale loc = QLocale::system();
if (loc != QLocale::C && osSeparatorValue)
@ -1978,4 +1973,25 @@ void VApplication::setOpeningPattern()
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 "../options.h"
#include "vtranslation.h"
#include <QSettings>
class VApplication;
class VApplication;// used in define
class QUndoStack;
class VMainGraphicsView;
@ -80,6 +81,8 @@ public:
void setMainWindow(QWidget *value);
bool getOpeningPattern() const;
void setOpeningPattern();
void OpenSettings();
QSettings *getSettings();
private:
Q_DISABLE_COPY(VApplication)
Unit _patternUnit;
@ -105,6 +108,10 @@ private:
* we can allow user use Undo option.
*/
bool openingPattern;
/**
* @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable.
*/
QSettings *settings;
void InitLineWidth();
void InitMeasurements();
void InitVariables();