From 5cfdabb45abf81cf2965dd28b5a423439e6aa1f9 Mon Sep 17 00:00:00 2001 From: Johan K Date: Sun, 3 Aug 2014 19:38:34 +0200 Subject: [PATCH] Adding changes --- src/Base/QuantityParser.y | 2 +- src/Gui/InputField.cpp | 11 ++++++++--- src/Gui/QuantitySpinBox.cpp | 12 ++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Base/QuantityParser.y b/src/Base/QuantityParser.y index bf9bd9152..5615299b3 100644 --- a/src/Base/QuantityParser.y +++ b/src/Base/QuantityParser.y @@ -58,7 +58,7 @@ | SINH '(' num ')' { $$ = sinh($3.getValue()); } | TAN '(' num ')' { $$ = tan($3.getValue()); } | TANH '(' num ')' { $$ = tanh($3.getValue()); } - | SQRT '(' num ')' { $$ = tanh($3.getValue()); } + | SQRT '(' num ')' { $$ = sqrt($3.getValue()); } | COS '(' num ')' { $$ = cos($3.getValue()); } ; diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index 82c885b1d..bbd070470 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -181,7 +181,7 @@ void InputField::newInput(const QString & text) Quantity res; try { QString input = text; - input.remove(locale().groupSeparator()); + fixup(input); res = Quantity::parse(input); } catch(Base::Exception &e){ @@ -452,13 +452,14 @@ void InputField::selectNumber(void) { QByteArray str = text().toLatin1(); unsigned int i = 0; + Base::Console().Message("%i", locale().negativeSign().toAscii()); for (QByteArray::iterator it = str.begin(); it != str.end(); ++it) { if (*it >= '0' && *it <= '9') i++; else if (*it == ',' || *it == '.') i++; - else if (*it == '-') + else if (*it == '-' || *it == locale().negativeSign().toAscii()) i++; else // any non-number character break; @@ -529,6 +530,10 @@ void InputField::wheelEvent (QWheelEvent * event) void InputField::fixup(QString& input) const { input.remove(locale().groupSeparator()); + if(locale().negativeSign() != QChar::fromAscii('-')) + input.replace(locale().negativeSign(), QChar::fromAscii('-')); + if(locale().positiveSign() != QChar::fromAscii('+')) + input.replace(locale().positiveSign(), QChar::fromAscii('+')); } QValidator::State InputField::validate(QString& input, int& pos) const @@ -536,7 +541,7 @@ QValidator::State InputField::validate(QString& input, int& pos) const try { Quantity res; QString text = input; - text.remove(locale().groupSeparator()); + fixup(text); res = Quantity::parse(text); double factor; diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index c0c4ba6b4..88f54fcc3 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -146,7 +146,7 @@ void QuantitySpinBox::userInput(const QString & text) Base::Quantity res; try { QString input = text; - input.remove(locale().groupSeparator()); + fixup(input); res = Base::Quantity::parse(input); } catch (Base::Exception &e) { @@ -334,7 +334,7 @@ void QuantitySpinBox::selectNumber() i++; else if (*it == ',' || *it == '.') i++; - else if (*it == '-') + else if (*it == '-' || *it == locale().negativeSign().toAscii()) i++; else // any non-number character break; @@ -359,7 +359,7 @@ Base::Quantity QuantitySpinBox::valueFromText(const QString &text) const Q_D(const QuantitySpinBox); QString copy = text; - copy.remove(locale().groupSeparator()); + fixup( copy ); int pos = lineEdit()->cursorPosition(); QValidator::State state = QValidator::Acceptable; return d->validateAndInterpret(copy, pos, state); @@ -371,7 +371,7 @@ QValidator::State QuantitySpinBox::validate(QString &text, int &pos) const QValidator::State state; QString copy = text; - copy.remove(locale().groupSeparator()); + fixup(copy); d->validateAndInterpret(copy, pos, state); return state; } @@ -379,6 +379,10 @@ QValidator::State QuantitySpinBox::validate(QString &text, int &pos) const void QuantitySpinBox::fixup(QString &input) const { input.remove(locale().groupSeparator()); + if(locale().negativeSign() != QChar::fromAscii('-')) + input.replace(locale().negativeSign(), QChar::fromAscii('-')); + if(locale().positiveSign() != QChar::fromAscii('+')) + input.replace(locale().positiveSign(), QChar::fromAscii('+')); }