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 <QDebug>
#include <QSettings>
#include "../widgets/vapplication.h"
int Calculator::iVal = -1;
@ -68,12 +69,24 @@ 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();
if (osSeparatorValue)
{
QLocale loc = QLocale::system();
SetDecSep(loc.decimalPoint().toLatin1());
SetThousandsSep(loc.groupSeparator().toLatin1());
SetArgSep(';');
}
else
{
SetArgSep(',');
SetDecSep('.');
}
}
else
{
DefinePostfixOprt(cm_Oprt, CmUnit);
DefinePostfixOprt(mm_Oprt, MmUnit);

View File

@ -51,7 +51,7 @@ void ConfigurationPage::Apply()
QApplication::applicationName());
settings.setValue("configuration/autosave/state", autoSaveCheck->isChecked());
settings.setValue("configuration/autosave/time", autoTime->value());
//settings.setValue("configuration/osSeparator", osOptionCheck->isChecked());
settings.setValue("configuration/osSeparator", osOptionCheck->isChecked());
if (langChanged)
{
QString locale = qvariant_cast<QString>(langCombo->itemData(langCombo->currentIndex()));
@ -157,10 +157,9 @@ QGroupBox *ConfigurationPage::LangGroup()
QLabel *separatorLabel = new QLabel(tr("Decimal separator parts"));
osOptionCheck = new QCheckBox(tr("With OS options (.)"));
//bool osOptionValue = settings.value("configuration/osSeparator", 1).toBool();
//osOptionCheck->setChecked(osOptionValue);
osOptionCheck->setEnabled(false);
osOptionCheck = new QCheckBox(tr("With OS options (%1)").arg(QLocale::system().decimalPoint().toLatin1()));
bool osOptionValue = settings.value("configuration/osSeparator", 1).toBool();
osOptionCheck->setChecked(osOptionValue);
QHBoxLayout *separatorLayout = new QHBoxLayout;
separatorLayout->addWidget(separatorLabel);

View File

@ -336,8 +336,20 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label)
Calculator cal(data);
const qreal result = cal.EvalFormula(formula);
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
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;
palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76));
emit ToolTip("");

View File

@ -36,6 +36,7 @@
#include <QMessageBox>
#include <QDebug>
#include <QDir>
#include <QSettings>
#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();
if(loc != QLocale(QLocale::C))
if(loc != QLocale(QLocale::C) && osSeparatorValue)
{
QList<int> nKeys = numbers.keys();
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();
if(loc != QLocale::C)
if(loc != QLocale::C && osSeparatorValue)
{
QList<int> nKeys = numbers.keys();
QList<QString> nValues = numbers.values();