Setting decimal separator parts from OS oprions.

--HG--
branch : develop
This commit is contained in:
dismine 2014-05-29 11:46:28 +03:00
parent 18f168da5e
commit 01ee27d33c
4 changed files with 46 additions and 13 deletions

View File

@ -28,6 +28,7 @@
#include "calculator.h" #include "calculator.h"
#include <QDebug> #include <QDebug>
#include <QSettings>
#include "../widgets/vapplication.h" #include "../widgets/vapplication.h"
int Calculator::iVal = -1; int Calculator::iVal = -1;
@ -68,10 +69,22 @@ 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);
QLocale loc = QLocale::system(); QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
SetDecSep(loc.decimalPoint().toLatin1()); QApplication::applicationName());
SetThousandsSep(loc.groupSeparator().toLatin1()); bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
SetArgSep(';');
if (osSeparatorValue)
{
QLocale loc = QLocale::system();
SetDecSep(loc.decimalPoint().toLatin1());
SetThousandsSep(loc.groupSeparator().toLatin1());
SetArgSep(';');
}
else
{
SetArgSep(',');
SetDecSep('.');
}
} }
else else
{ {

View File

@ -51,7 +51,7 @@ void ConfigurationPage::Apply()
QApplication::applicationName()); QApplication::applicationName());
settings.setValue("configuration/autosave/state", autoSaveCheck->isChecked()); settings.setValue("configuration/autosave/state", autoSaveCheck->isChecked());
settings.setValue("configuration/autosave/time", autoTime->value()); settings.setValue("configuration/autosave/time", autoTime->value());
//settings.setValue("configuration/osSeparator", osOptionCheck->isChecked()); settings.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()));
@ -157,10 +157,9 @@ 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 (.)")); 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);
osOptionCheck->setEnabled(false);
QHBoxLayout *separatorLayout = new QHBoxLayout; QHBoxLayout *separatorLayout = new QHBoxLayout;
separatorLayout->addWidget(separatorLabel); separatorLayout->addWidget(separatorLabel);

View File

@ -336,8 +336,20 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label)
Calculator cal(data); Calculator cal(data);
const qreal result = cal.EvalFormula(formula); const qreal result = cal.EvalFormula(formula);
QLocale loc = QLocale::system(); QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
label->setText(loc.toString(result)); QApplication::applicationName());
bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
if (osSeparatorValue)
{
QLocale loc = QLocale::system();
label->setText(loc.toString(result));
}
else
{
QLocale loc = QLocale(QLocale::C);
label->setText(loc.toString(result));
}
flag = true; flag = true;
palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76));
emit ToolTip(""); emit ToolTip("");

View File

@ -36,6 +36,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QSettings>
#include <container/calculator.h> #include <container/calculator.h>
@ -1789,8 +1790,12 @@ QString VApplication::FormulaFromUser(const QString &formula)
} }
} }
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
QLocale loc = QLocale::system(); QLocale loc = QLocale::system();
if(loc != QLocale(QLocale::C)) if(loc != QLocale(QLocale::C) && osSeparatorValue)
{ {
QList<int> nKeys = numbers.keys(); QList<int> nKeys = numbers.keys();
QList<QString> nValues = numbers.values(); QList<QString> nValues = numbers.values();
@ -1903,8 +1908,12 @@ QString VApplication::FormulaToUser(const QString &formula)
} }
} }
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
bool osSeparatorValue = settings.value("configuration/osSeparator", 1).toBool();
QLocale loc = QLocale::system(); QLocale loc = QLocale::system();
if(loc != QLocale::C) if(loc != QLocale::C && osSeparatorValue)
{ {
QList<int> nKeys = numbers.keys(); QList<int> nKeys = numbers.keys();
QList<QString> nValues = numbers.values(); QList<QString> nValues = numbers.values();